26 #if defined (HAVE_CONFIG_H)
93 int nargin = args.length ();
95 if (nargin < 1 || nargin > 2)
98 int dim = (nargin == 1 ? -1
99 : args(1).xint_value (
"all: DIM must be an integer")-1);
102 error (
"all: invalid dimension argument = %d", dim + 1);
104 return ovl (args(0).all (dim));
158 int nargin = args.length ();
160 if (nargin < 1 || nargin > 2)
163 int dim = (nargin == 1 ? -1
164 : args(1).xint_value (
"any: DIM must be an integer")-1);
167 error (
"any: invalid dimension argument = %d", dim + 1);
169 return ovl (args(0).any (dim));
195 DEFUN (atan2, args, ,
209 if (args.length () != 2)
214 if (! args(0).isnumeric ())
217 if (! args(1).isnumeric ())
220 if (args(0).iscomplex () || args(1).iscomplex ())
221 error (
"atan2: not defined for complex numbers");
223 if (args(0).is_single_type () || args(1).is_single_type ())
225 if (args(0).is_scalar_type () && args(1).is_scalar_type ())
226 retval = atan2f (args(0).float_value (), args(1).float_value ());
231 retval = binmap<float> (a0, a1, std::atan2,
"atan2");
236 if (args(0).is_scalar_type () && args(1).is_scalar_type ())
237 retval = atan2 (args(0).scalar_value (), args(1).scalar_value ());
238 else if (args(0).issparse ())
242 retval = binmap<double> (m0, m1, std::atan2,
"atan2");
246 NDArray a0 = args(0).array_value ();
247 NDArray a1 = args(1).array_value ();
248 retval = binmap<double> (a0, a1, std::atan2,
"atan2");
341 retval = binmap<float> (a0, a1, std::hypot,
"hypot");
352 retval = binmap<double> (m0, m1, std::hypot,
"hypot");
358 retval = binmap<double> (a0, a1, std::hypot,
"hypot");
365 DEFUN (hypot, args, ,
387 int nargin = args.length ();
395 retval = do_hypot (args(0), args(1));
400 for (
int i = 1; i < nargin; i++)
401 retval = do_hypot (retval, args(i));
446 template <
typename T,
typename ET>
499 if (args.length () != 1)
505 retval =
ovl (args(0).
log2 ());
506 else if (args(0).is_single_type ())
508 if (args(0).isreal ())
517 else if (args(0).iscomplex ())
527 else if (args(0).isreal ())
536 else if (args(0).iscomplex ())
609 if (args.length () != 2)
614 if (! args(0).isnumeric ())
617 if (! args(1).isnumeric ())
620 if (args(0).iscomplex () || args(1).iscomplex ())
621 error (
"rem: not defined for complex numbers");
633 error (
"rem: cannot combine %s and %s",
634 args(0).class_name ().c_str (),
635 args(1).class_name ().c_str ());
639 #define MAKE_INT_BRANCH(X) \
642 X##NDArray a0 = args(0).X##_array_value (); \
643 X##NDArray a1 = args(1).X##_array_value (); \
644 retval = binmap<octave_##X,octave_##X,octave_##X> (a0, a1, rem, "rem"); \
657 #undef MAKE_INT_BRANCH
663 else if (args(0).is_single_type () || args(1).is_single_type ())
665 if (args(0).is_scalar_type () && args(1).is_scalar_type ())
666 retval =
math::rem (args(0).float_value (), args(1).float_value ());
671 retval = binmap<float> (a0, a1, math::rem<float>,
"rem");
676 if (args(0).is_scalar_type () && args(1).is_scalar_type ())
677 retval =
math::rem (args(0).scalar_value (), args(1).scalar_value ());
678 else if (args(0).issparse () || args(1).issparse ())
682 retval = binmap<double> (m0, m1, math::rem<double>,
"rem");
686 NDArray a0 = args(0).array_value ();
687 NDArray a1 = args(1).array_value ();
688 retval = binmap<double> (a0, a1, math::rem<double>,
"rem");
793 if (args.length () != 2)
798 if (! args(0).isnumeric ())
801 if (! args(1).isnumeric ())
804 if (args(0).iscomplex () || args(1).iscomplex ())
805 error (
"mod: not defined for complex numbers");
817 error (
"mod: cannot combine %s and %s",
818 args(0).class_name ().c_str (),
819 args(1).class_name ().c_str ());
823 #define MAKE_INT_BRANCH(X) \
826 X##NDArray a0 = args(0).X##_array_value (); \
827 X##NDArray a1 = args(1).X##_array_value (); \
828 retval = binmap<octave_##X,octave_##X,octave_##X> (a0, a1, mod, "mod"); \
841 #undef MAKE_INT_BRANCH
847 else if (args(0).is_single_type () || args(1).is_single_type ())
849 if (args(0).is_scalar_type () && args(1).is_scalar_type ())
850 retval =
math::mod (args(0).float_value (), args(1).float_value ());
855 retval = binmap<float> (a0, a1, math::mod<float>,
"mod");
860 if (args(0).is_scalar_type () && args(1).is_scalar_type ())
861 retval =
math::mod (args(0).scalar_value (), args(1).scalar_value ());
862 else if (args(0).issparse () || args(1).issparse ())
866 retval = binmap<double> (m0, m1, math::mod<double>,
"mod");
870 NDArray a0 = args(0).array_value ();
871 NDArray a1 = args(1).array_value ();
872 retval = binmap<double> (a0, a1, math::mod<double>,
"mod");
933 #define DATA_REDUCTION(FCN) \
935 int nargin = args.length (); \
937 if (nargin < 1 || nargin > 2) \
940 octave_value retval; \
942 octave_value arg = args(0); \
944 int dim = (nargin == 1 ? -1 : args(1).int_value (true) - 1); \
947 error (#FCN ": invalid dimension argument = %d", dim + 1); \
951 if (arg.issparse ()) \
953 SparseMatrix tmp = arg.sparse_matrix_value (); \
955 retval = tmp.FCN (dim); \
957 else if (arg.is_single_type ()) \
959 FloatNDArray tmp = arg.float_array_value (); \
961 retval = tmp.FCN (dim); \
965 NDArray tmp = arg.array_value (); \
967 retval = tmp.FCN (dim); \
970 else if (arg.iscomplex ()) \
972 if (arg.issparse ()) \
974 SparseComplexMatrix tmp = arg.sparse_complex_matrix_value (); \
976 retval = tmp.FCN (dim); \
978 else if (arg.is_single_type ()) \
980 FloatComplexNDArray tmp \
981 = arg.float_complex_array_value (); \
983 retval = tmp.FCN (dim); \
987 ComplexNDArray tmp = arg.complex_array_value (); \
989 retval = tmp.FCN (dim); \
993 err_wrong_type_arg (#FCN, arg); \
997 DEFUN (cumprod, args, ,
1043 DEFUN (cumsum, args, ,
1068 int nargin = args.length ();
1070 bool isnative =
false;
1071 bool isdouble =
false;
1073 if (nargin > 1 && args(nargin - 1).is_string ())
1075 std::string str = args(nargin - 1).string_value ();
1077 if (str ==
"native")
1079 else if (str ==
"double")
1082 error (
"cumsum: unrecognized string argument");
1087 if (nargin < 1 || nargin > 2)
1093 dim = args(1).int_value () - 1;
1095 error (
"cumsum: invalid dimension argument = %d", dim + 1);
1128 #define MAKE_INT_BRANCH(X) \
1131 retval = arg.X ## _array_value ().cumsum (dim); \
1133 retval = arg.array_value ().cumsum (dim); \
1145 #undef MAKE_INT_BRANCH
1152 retval = (cs != 0.0);
1160 retval = (cs != 0.0);
1196 DEFUN (diag, args, ,
1229 int nargin = args.length ();
1231 if (nargin < 1 || nargin > 3)
1237 retval = args(0).
diag ();
1238 else if (nargin == 2)
1240 octave_idx_type k = args(1).xidx_type_value (
"diag: invalid argument K");
1242 retval = args(0).
diag (k);
1249 error (
"diag: V must be a vector");
1254 retval = arg0.
diag (
m,
n);
1347 DEFUN (prod, args, ,
1378 int nargin = args.length ();
1380 bool isnative =
false;
1381 bool isdouble =
false;
1383 if (nargin > 1 && args(nargin - 1).is_string ())
1385 std::string str = args(nargin - 1).string_value ();
1387 if (str ==
"native")
1389 else if (str ==
"double")
1392 error (
"prod: unrecognized type argument '%s'", str.c_str ());
1397 if (nargin < 1 || nargin > 2)
1407 dim = args(1).int_value () - 1;
1409 error (
"prod: invalid dimension DIM = %d", dim + 1);
1439 #define MAKE_INT_BRANCH(X) \
1442 retval = arg.X ## _array_value ().prod (dim); \
1444 retval = arg.array_value ().prod (dim); \
1456 #undef MAKE_INT_BRANCH
1558 int n_args = args.
length ();
1559 for (
int i = 0; i < n_args; i++)
1560 if (args(i).
numel () != 1)
1566 template <
typename TYPE,
typename T>
1568 single_type_concat (
Array<T>& result,
1572 int n_args = args.
length ();
1575 && all_scalar_1x1 (args))
1579 if (dim == -1 || dim == -2)
1582 dv.resize (dim+1, 1);
1587 for (
int j = 0; j < n_args; j++)
1591 result(j) = octave_value_extract<T> (args(j));
1598 for (
int j = 0; j < n_args; j++)
1602 array_list[j] = octave_value_extract<TYPE> (args(j));
1609 template <
typename TYPE,
typename T>
1622 sparse_list[j] = octave_value_extract<TYPE> (args(j));
1629 template <
typename TYPE>
1635 single_type_concat<TYPE, typename TYPE::element_type> (result, args, dim);
1640 template <
typename MAP>
1646 int n_args = args.
length ();
1649 for (
int j = 0; j < n_args; j++)
1653 map_list[j] = octave_value_extract<MAP> (args(j));
1664 if (all_scalar_1x1 (args))
1665 single_type_concat_map<octave_scalar_map> (result, args, dim);
1667 single_type_concat_map<octave_map> (result, args, dim);
1673 attempt_type_conversion (
const octave_value& ov, std::string dtype)
1695 result = interp.
feval (fcn,
ovl (ov), 1);
1699 error (ee,
"conversion from %s to %s failed", dtype.c_str (),
1703 if (result.
empty ())
1704 error (
"conversion from %s to %s failed", dtype.c_str (),
1717 error (
"no constructor for %s!", dtype.c_str ());
1723 result = interp.
feval (fcn,
ovl (ov), 1);
1727 error (ee,
"%s constructor failed for %s argument", dtype.c_str (),
1731 if (result.
empty ())
1732 error (
"%s constructor failed for %s argument", dtype.c_str (),
1743 const std::string& cattype,
int dim)
1769 error (ee,
"%s/%s method failed", dtype.c_str (), cattype.c_str ());
1773 error (
"%s/%s method did not return a value", dtype.c_str (),
1793 if (t1_type == dtype)
1796 tmp(j++) = attempt_type_conversion (elt, dtype);
1801 octave_map m = do_single_type_concat_map (tmp, dim);
1803 std::string cname = tmp(0).class_name ();
1804 std::list<std::string> parents = tmp(0).parent_class_name_list ();
1822 int n_args = args.
length ();
1826 else if (n_args == 1)
1828 else if (n_args > 1)
1830 std::string result_type;
1832 bool all_strings_p =
true;
1833 bool all_sq_strings_p =
true;
1834 bool all_dq_strings_p =
true;
1835 bool all_real_p =
true;
1836 bool all_cmplx_p =
true;
1837 bool any_sparse_p =
false;
1838 bool any_cell_p =
false;
1839 bool any_class_p =
false;
1841 bool first_elem_is_struct =
false;
1843 for (
int i = 0; i < n_args; i++)
1847 result_type = args(i).class_name ();
1849 first_elem_is_struct = args(i).isstruct ();
1854 if (all_strings_p && ! args(i).is_string ())
1855 all_strings_p =
false;
1856 if (all_sq_strings_p && ! args(i).is_sq_string ())
1857 all_sq_strings_p =
false;
1858 if (all_dq_strings_p && ! args(i).is_dq_string ())
1859 all_dq_strings_p =
false;
1860 if (all_real_p && ! args(i).isreal ())
1862 if (all_cmplx_p && ! (args(i).iscomplex ()
1863 || args(i).isreal ()))
1864 all_cmplx_p =
false;
1865 if (! any_sparse_p && args(i).issparse ())
1866 any_sparse_p =
true;
1867 if (! any_cell_p && args(i).iscell ())
1869 if (! any_class_p && args(i).isobject ())
1873 if (any_cell_p && ! any_class_p && ! first_elem_is_struct)
1876 for (
int i = 0; i < n_args; i++)
1878 if (args(i).iscell ())
1879 args(j++) = args(i);
1882 if (args(i).isempty ())
1885 args(j++) =
Cell (args(i));
1896 else if (result_type ==
"double")
1901 retval = do_single_type_concat<SparseMatrix> (args, dim);
1903 retval = do_single_type_concat<SparseComplexMatrix> (args, dim);
1908 retval = do_single_type_concat<NDArray> (args, dim);
1910 retval = do_single_type_concat<ComplexNDArray> (args, dim);
1913 else if (result_type ==
"single")
1916 retval = do_single_type_concat<FloatNDArray> (args, dim);
1918 retval = do_single_type_concat<FloatComplexNDArray> (args, dim);
1920 else if (result_type ==
"char")
1922 char type = (all_dq_strings_p ?
'"' :
'\'');
1924 if (! all_strings_p)
1926 "numeric", result_type);
1930 charNDArray result = do_single_type_concat<charNDArray> (args, dim);
1934 else if (result_type ==
"logical")
1937 retval = do_single_type_concat<SparseBoolMatrix> (args, dim);
1939 retval = do_single_type_concat<boolNDArray> (args, dim);
1941 else if (result_type ==
"int8")
1942 retval = do_single_type_concat<int8NDArray> (args, dim);
1943 else if (result_type ==
"int16")
1944 retval = do_single_type_concat<int16NDArray> (args, dim);
1945 else if (result_type ==
"int32")
1946 retval = do_single_type_concat<int32NDArray> (args, dim);
1947 else if (result_type ==
"int64")
1948 retval = do_single_type_concat<int64NDArray> (args, dim);
1949 else if (result_type ==
"uint8")
1950 retval = do_single_type_concat<uint8NDArray> (args, dim);
1951 else if (result_type ==
"uint16")
1952 retval = do_single_type_concat<uint16NDArray> (args, dim);
1953 else if (result_type ==
"uint32")
1954 retval = do_single_type_concat<uint32NDArray> (args, dim);
1955 else if (result_type ==
"uint64")
1956 retval = do_single_type_concat<uint64NDArray> (args, dim);
1957 else if (result_type ==
"cell")
1958 retval = do_single_type_concat<Cell> (args, dim);
1959 else if (result_type ==
"struct")
1960 retval = do_single_type_concat_map (args, dim);
1969 if (dim == -1 || dim == -2)
1975 for (
int i = 1; i < args.
length (); i++)
1977 if (! (dv.*concat_rule) (args(i).dims (), dim))
1978 error (
"cat: dimension mismatch");
1999 int dv_len = dv.
ndims ();
2002 for (
int j = 0; j < n_args; j++)
2014 error (
"%s: indexing error", fname.c_str ());
2019 ra_idx(dim) += (dim < dv_tmp.
ndims () ? dv_tmp(dim) : 1);
2030 DEFUN (horzcat, args, ,
2048 return do_cat (args, -2,
"horzcat");
2272 DEFUN (vertcat, args, ,
2290 return do_cat (args, -1,
"vertcat");
2348 int dim = args(0).xint_value (
"cat: DIM must be an integer") - 1;
2351 error (
"cat: DIM must be a valid dimension");
2353 return ovl (do_cat (args.
slice (1, args.
length () - 1), dim,
"cat"));
2520 if (args.
length () != 2 || args(1).length () < args(1).ndims ())
2523 Array<int> vec = args(1).int_vector_value ();
2528 for (
int i = 0; i <
n; i++)
2534 DEFUN (permute, args, ,
2564 return do_permute (args,
false);
2567 DEFUN (ipermute, args, ,
2583 return do_permute (args,
true);
2586 DEFUN (length, args, ,
2601 return ovl (args(0).length ());
2604 DEFUN (ndims, args, ,
2632 while ((ndims > 2) && (sz(ndims - 1) == 1))
2687 int nargin = args.
length ();
2695 retval = args(0).numel ();
2696 else if (nargin > 1)
2706 DEFUN (size, args, nargout,
2779 int nargin = args.
length ();
2789 int ndims = dimensions.
ndims ();
2795 dimensions = dimensions.
redim (nargout);
2796 ndims = dimensions.
ndims ();
2799 m.resize (1, ndims);
2802 m(i) = dimensions(i);
2813 query_dims(i) = args(i+1).idx_type_value (
true);
2816 query_dims = args(1).octave_idx_type_vector_value (
true);
2818 if (nargout > 1 && nargout != query_dims.
numel ())
2819 error (
"size: nargout > 1 but does not match number of requested dimensions");
2830 error (
"size: requested dimension DIM (= %"
2831 OCTAVE_IDX_TYPE_FORMAT
") out of range", nd);
2833 m(i) = nd <= ndims ? dimensions (nd-1) : 1;
2926 DEFUN (size_equal, args, ,
2937 int nargin = args.
length ();
2943 for (
int i = 1; i < nargin; ++i)
2947 if (a_dims != b_dims)
2965 return ovl (args(0).nnz ());
2984 DEFUN (nzmax, args, ,
3001 return ovl (args(0).nzmax ());
3004 DEFUN (rows, args, ,
3049 DEFUN (columns, args, ,
3106 int nargin = args.
length ();
3108 bool isnative =
false;
3109 bool isdouble =
false;
3110 bool isextra =
false;
3112 if (nargin > 1 && args(nargin - 1).is_string ())
3114 std::string str = args(nargin - 1).string_value ();
3116 if (str ==
"native")
3118 else if (str ==
"double")
3120 else if (str ==
"extra")
3123 error (
"sum: unrecognized type argument '%s'", str.c_str ());
3128 if (nargin < 1 || nargin > 2)
3134 dim = args(1).int_value () - 1;
3136 error (
"sum: invalid dimension DIM = %d", dim + 1);
3148 warning (
"sum: 'extra' not yet implemented for sparse matrices");
3161 warning (
"sum: 'extra' not yet implemented for sparse matrices");
3171 if (isdouble || isextra)
3178 if (isdouble || isextra)
3184 #define MAKE_INT_BRANCH(X) \
3187 retval = arg.X ## _array_value ().sum (dim); \
3189 retval = arg.X ## _array_value ().dsum (dim); \
3201 #undef MAKE_INT_BRANCH
3298 DEFUN (sumsq, args, ,
3338 DEFUN (islogical, args, ,
3352 return ovl (args(0).islogical ());
3429 DEFUN (iscomplex, args, ,
3439 return ovl (args(0).iscomplex ());
3459 DEFUN (isfloat, args, ,
3471 return ovl (args(0).isfloat ());
3477 DEFUN (complex, args, ,
3507 int nargin = args.
length ();
3509 if (nargin < 1 || nargin > 2)
3530 if (arg.
numel () == 1)
3545 if (arg.
numel () == 1)
3570 if (re.
numel () == 1)
3573 if (re_val.
nnz () == 0)
3585 i < im_val.
cidx (j + 1); i++)
3586 result.
data (im_val.
ridx (i) + off)
3592 else if (im.
numel () == 1)
3595 if (im_val.
nnz () == 0)
3608 i < re_val.
cidx (j + 1); i++)
3609 result.
data (re_val.
ridx (i) + off)
3617 if (re_val.
dims () != im_val.
dims ())
3618 error (
"complex: dimension mismatch");
3628 if (re.
numel () == 1)
3632 if (im.
numel () == 1)
3656 if (im.
numel () == 1)
3672 if (re_val.
dims () != im_val.
dims ())
3673 error (
"complex: dimension mismatch");
3686 else if (re.
numel () == 1)
3690 if (im.
numel () == 1)
3713 if (im.
numel () == 1)
3728 if (re_val.
dims () != im_val.
dims ())
3729 error (
"complex: dimension mismatch");
3788 DEFUN (isreal, args, ,
3801 return ovl (args(0).isreal ());
3804 DEFUN (isempty, args, ,
3815 return ovl (args(0).isempty ());
3823 DEFUN (isnumeric, args, ,
3837 return ovl (args(0).isnumeric ());
3856 DEFUN (isscalar, args, ,
3873 return ovl (sz.
numel () == 2 && sz(0) == 1 && sz(1) == 1);
3913 return ovl (sz.
numel () == 2 && (sz(0) == 1 || sz(1) == 1));
3936 DEFUN (isrow, args, ,
3953 return ovl (sz.
numel () == 2 && sz(0) == 1);
3985 DEFUN (iscolumn, args, ,
4002 return ovl (sz.
numel () == 2 && sz(1) == 1);
4034 DEFUN (ismatrix, args, ,
4052 return ovl (sz.
numel () == 2 && sz(0) >= 0 && sz(1) >= 0);
4083 DEFUN (issquare, args, ,
4100 return ovl (sz.
numel () == 2 && sz(0) == sz(1));
4129 int nargin = args.
length ();
4134 bool issparse =
false;
4135 bool iscomplex =
false;
4137 if (nargin > 0 && args(nargin-1).is_string ())
4139 std::string nm = args(nargin-1).string_value ();
4145 if (nargin > 1 && args(nargin-2).is_string ()
4146 && args(nargin-2).string_value () ==
"like")
4148 std::string nm = args(nargin-1).class_name ();
4149 issparse = args(nargin-1).issparse ();
4150 iscomplex = args(nargin-1).iscomplex ();
4166 dims.resize (nargin);
4168 for (
int i = 0; i < nargin; i++)
4170 if (args(i).
numel () > 1)
4171 error (
"%s: dimensions must be scalars.", fcn);
4173 dims(i) = (args(i).isempty () ? 0 : args(i).idx_type_value (
true));
4179 dims.chop_trailing_singletons ();
4191 if (dims.ndims () > 2)
4192 error (
"%s: sparse ND arrays not supported.", fcn);
4200 retval =
SparseMatrix (dims(0), dims(1),
static_cast<double> (val));
4209 error (
"%s: invalid class name for sparse", fcn);
4268 error (
"%s: invalid class name", fcn);
4281 int nargin = args.
length ();
4286 bool issparse =
false;
4287 bool iscomplex =
false;
4289 if (nargin > 0 && args(nargin-1).is_string ())
4291 std::string nm = args(nargin-1).string_value ();
4297 if (nargin > 1 && args(nargin-2).is_string ()
4298 && args(nargin-2).string_value () ==
"like"
4299 && (std::string(fcn) ==
"Inf"
4300 || std::string(fcn) ==
"NaN" || std::string(fcn) ==
"NA"))
4302 if (! args(nargin-1).isfloat ())
4303 error (
"%s: input followed by 'like' must be floating point", fcn);
4304 std::string nm = args(nargin-1).class_name ();
4305 issparse = args(nargin-1).issparse ();
4306 iscomplex = args(nargin-1).iscomplex ();
4322 dims.resize (nargin);
4324 for (
int i = 0; i < nargin; i++)
4326 if (args(i).
numel () > 1)
4327 error (
"%s: dimensions must be scalars.", fcn);
4329 dims(i) = (args(i).isempty () ? 0 : args(i).idx_type_value (
true));
4335 dims.chop_trailing_singletons ();
4344 if (dims.ndims () > 2)
4345 error (
"%s: sparse ND arrays not supported", fcn);
4350 retval =
SparseMatrix (dims(0), dims(1),
static_cast<double> (val));
4372 error (
"%s: invalid class name", fcn);
4384 int nargin = args.
length ();
4390 if (nargin > 0 && args(nargin-1).is_string ())
4392 std::string nm = args(nargin-1).string_value ();
4409 dims.resize (nargin);
4411 for (
int i = 0; i < nargin; i++)
4413 if (args(i).
numel () > 1)
4414 error (
"%s: dimensions must be scalars.", fcn);
4416 dims(i) = (args(i).isempty () ? 0 : args(i).idx_type_value (
true));
4422 dims.chop_trailing_singletons ();
4432 retval =
FloatNDArray (dims,
static_cast<float> (val));
4440 error (
"%s: invalid class name", fcn);
4453 int nargin = args.
length ();
4459 if (nargin > 0 && args(nargin-1).is_string ())
4461 std::string nm = args(nargin-1).string_value ();
4478 dims.resize (nargin);
4480 for (
int i = 0; i < nargin; i++)
4482 if (args(i).
numel () > 1)
4483 error (
"%s: dimensions must be scalars.", fcn);
4485 dims(i) = (args(i).isempty () ? 0 : args(i).idx_type_value (
true));
4491 dims.chop_trailing_singletons ();
4510 error (
"%s: invalid class name", fcn);
4522 int nargin = args.
length ();
4529 if (nargin > 0 && args(nargin-1).is_string ())
4531 std::string nm = args(nargin-1).string_value ();
4535 error (
"%s: invalid data type '%s'", fcn, nm.c_str ());
4538 bool issparse =
false;
4540 if (nargin > 1 && args(nargin-2).is_string ()
4541 && args(nargin-2).string_value () ==
"like")
4543 if (! args(nargin-1).islogical ())
4544 error (R
"(%s: input followed by "like" must be logical)", fcn);
4546 issparse = args(nargin-1).issparse ();
4561 dims.resize (nargin);
4563 for (
int i = 0; i < nargin; i++)
4565 if (args(i).
numel () > 1)
4566 error (
"%s: dimensions must be scalars.", fcn);
4568 dims(i) = (args(i).isempty () ? 0 : args(i).idx_type_value (
true));
4574 dims.chop_trailing_singletons ();
4583 if (dims.ndims () > 2)
4584 error (
"%s: sparse ND arrays not supported", fcn);
4594 DEFUN (ones, args, ,
4629 return fill_matrix (args, 1,
"ones");
4688 DEFUN (zeros, args, ,
4716 return fill_matrix (args, 0,
"zeros");
4956 double e_val = exp (1.0);
4959 return fill_matrix (args, e_val,
"e");
4962 template <
typename T>
4966 T epsval =
x.abs ();
4967 typedef typename T::value_type P;
4970 P val = epsval.xelem (i);
4974 epsval(i) = std::numeric_limits<P>::denorm_min ();
4979 const P digits = std::numeric_limits<P>::digits;
4980 epsval(i) =
std::pow (
static_cast<P
> (2.0),
4981 static_cast<P
> (exponent - digits));
5024 if (args.
length () == 1 && ! args(0).is_string ())
5038 error (
"eps: X must be of a floating point type");
5041 retval = fill_matrix (args, std::numeric_limits<double>::epsilon (),
5042 std::numeric_limits<float>::epsilon (),
"eps");
5118 double pi_val = M_PI;
5120 double pi_val = 4.0 *
atan (1.0);
5123 return fill_matrix (args, pi_val,
"pi");
5126 DEFUN (realmax, args, ,
5165 DEFUN (realmin, args, ,
5242 return fill_matrix (args,
Complex (0.0, 1.0),
"I");
5289 DEFUN (
false, args, ,
5308 return fill_matrix (args,
false,
"false");
5324 DEFUN (
true, args, ,
5343 return fill_matrix (args,
true,
"true");
5359 template <
typename MT>
5365 typename MT::element_type one (1);
5367 if (nr == 1 && nc == 1)
5373 typename MT::element_type zero (0);
5377 if (nr > 0 && nc > 0)
5381 for (
int i = 0; i <
n; i++)
5391 #define INSTANTIATE_EYE(T) \
5392 template octave_value identity_matrix<T> (int, int)
5461 error (
"eye: invalid class name");
5468 #undef INT_EYE_MATRIX
5520 int nargin = args.
length ();
5526 if (nargin > 0 && args(nargin-1).is_string ())
5528 std::string nm = args(nargin-1).string_value ();
5541 else if (nargin == 1)
5579 template <
typename MT>
5584 typedef typename MT::column_vector_type CVT;
5585 typedef typename MT::element_type T;
5591 T bs = octave_value_extract<T> (base);
5594 T ls = octave_value_extract<T> (limit);
5599 CVT lv = octave_value_extract<CVT> (limit);
5600 CVT bv (lv.numel (), bs);
5606 CVT bv = octave_value_extract<CVT> (base);
5609 T ls = octave_value_extract<T> (limit);
5610 CVT lv (bv.numel (), ls);
5615 CVT lv = octave_value_extract<CVT> (limit);
5649 int nargin = args.
length ();
5651 if (nargin != 2 && nargin != 3)
5664 error (
"linspace: N must be a scalar");
5674 bool isvector1 = sz1.
ndims () == 2 && (sz1(0) == 1 || sz1(1) == 1);
5676 bool isvector2 = sz2.
ndims () == 2 && (sz2(0) == 1 || sz2(1) == 1);
5678 if (! isvector1 || ! isvector2)
5679 error (
"linspace: START, END must be scalars or vectors");
5686 retval = do_linspace<FloatComplexMatrix> (arg_1, arg_2, npoints);
5688 retval = do_linspace<FloatMatrix> (arg_1, arg_2, npoints);
5693 retval = do_linspace<ComplexMatrix> (arg_1, arg_2, npoints);
5695 retval = do_linspace<Matrix> (arg_1, arg_2, npoints);
5817 DEFUN (resize, args, ,
5863 int nargin = args.
length ();
5873 int ndim = vec.
numel ();
5884 for (
int i = 0; i < ndim; i++)
5887 retval = retval.
resize (dv,
true);
5898 retval = retval.
resize (dv,
true);
5906 DEFUN (reshape, args, ,
5940 int nargin = args.
length ();
5953 if (new_size.
numel () < 2)
5954 error (
"reshape: SIZE must have 2 or more dimensions");
5960 if (new_size(i) < 0)
5961 error (
"reshape: SIZE must be non-negative");
5963 new_dims(i) = new_size(i);
5971 for (
int i = 1; i < nargin; i++)
5973 if (args(i).isempty ())
5976 error (
"reshape: only a single dimension can be unknown");
5983 new_dims(i-1) = args(i).idx_type_value ();
5985 if (new_dims(i-1) < 0)
5986 error (
"reshape: SIZE must be non-negative");
5995 new_dims(empty_dim-1) = 0;
6001 if (a_nel != size_empty_dim * nel)
6002 error (
"reshape: SIZE is not divisible by the product of "
6003 "known dimensions (= %" OCTAVE_IDX_TYPE_FORMAT
")",
6006 new_dims(empty_dim-1) = size_empty_dim;
6011 retval = args(0).reshape (new_dims);
6057 int nargin = args.
length ();
6059 if (nargin < 1 || nargin > 2)
6065 dim = args(1).idx_type_value ();
6068 error (
"vec: DIM must be greater than zero");
6080 for (
int i = 0; i < dim-1; i++)
6083 new_dims(dim-1) = retval.
numel ();
6085 retval = retval.
reshape (new_dims);
6106 DEFUN (squeeze, args, ,
6119 return ovl (args(0).squeeze ());
6122 DEFUN (full, args, ,
6133 return ovl (args(0).full_value ());
6199 int nargin = args.
length ();
6201 if (nargin < 1 || nargin > 3)
6206 if (x_arg.
ndims () != 2)
6207 error (
"norm: only valid for 2-D objects");
6209 enum {sfmatrix, sfcols, sfrows, sffrob, sfinf, sfneginf} strflag = sfmatrix;
6210 if (nargin > 1 && args(nargin-1).is_string ())
6212 std::string str = args(nargin-1).string_value ();
6213 std::transform (str.begin (), str.end (), str.begin (), tolower);
6214 if (str ==
"cols" || str ==
"columns")
6216 else if (str ==
"rows")
6218 else if (str ==
"fro")
6220 else if (str ==
"inf")
6222 else if (str ==
"-inf")
6225 error (
"norm: unrecognized option: %s", str.c_str ());
6238 std::transform (str.begin (), str.end (), str.begin (), tolower);
6239 if (strflag != sfcols && strflag != sfrows)
6240 error (
"norm: invalid combination of options");
6242 if (str ==
"cols" || str ==
"columns" || str ==
"rows")
6243 error (
"norm: invalid combination of options");
6247 else if (str ==
"inf")
6249 else if (str ==
"-inf")
6252 error (
"norm: unrecognized option: %s", str.c_str ());
6262 retval =
xnorm (x_arg, p_arg);
6400 DEFUN (uplus, args, ,
6410 DEFUN (uminus, args, ,
6420 DEFUN (transpose, args, ,
6452 DEFUN (ctranspose, args, ,
6491 return binary_op (op, args(0), args(1));
6499 int nargin = args.
length ();
6507 retval =
binary_op (op, args(0), args(1));
6510 retval =
binary_op (op, args(0), args(1));
6512 for (
int i = 2; i < nargin; i++)
6513 retval.
assign (aop, args(i));
6519 DEFUN (plus, args, ,
6550 DEFUN (minus, args, ,
6560 DEFUN (mtimes, args, ,
6581 DEFUN (mrdivide, args, ,
6596 DEFUN (mpower, args, ,
6608 DEFUN (mldivide, args, ,
6687 DEFUN (times, args, ,
6708 DEFUN (rdivide, args, ,
6720 DEFUN (power, args, ,
6738 DEFUN (ldivide, args, ,
6793 DEFUN (colon, args, ,
6806 int nargin = args.
length ();
6808 if (nargin < 2 || nargin > 3)
6813 :
colon_op (args(0), args(1), args(2)));
6816 static double tic_toc_timestamp = -1.0;
6818 DEFUN (tic, args, nargout,
6871 warning (
"tic: ignoring extra arguments");
6880 double frac = std::modf (tmp, &ip);
6881 uint64_t microsecs =
static_cast<uint64_t
> (CLOCKS_PER_SEC * frac);
6882 microsecs += CLOCKS_PER_SEC *
static_cast<uint64_t
> (ip);
6886 tic_toc_timestamp = tmp;
6891 DEFUN (toc, args, nargout,
6909 int nargin = args.
length ();
6914 double start_time = tic_toc_timestamp;
6918 octave_uint64 id = args(0).xuint64_scalar_value (
"toc: invalid ID");
6920 uint64_t val =
id.value ();
6923 = (
static_cast<double> (val / CLOCKS_PER_SEC)
6924 +
static_cast<double> (val % CLOCKS_PER_SEC)
6932 error (
"toc: function called before timer initialization with tic()");
6936 double etime = now.double_value () - start_time;
6942 octave_stdout <<
"Elapsed time is " << etime <<
" seconds.\n";
6954 DEFUN (cputime, args, ,
6976 sys::cpu_time cpu_tm;
6978 double usr = cpu_tm.user ();
6979 double sys = cpu_tm.system ();
6981 return ovl (usr + sys, usr, sys);
6984 DEFUN (sort, args, nargout,
7054 int nargin = args.
length ();
7056 if (nargin < 1 || nargin > 3)
7060 bool return_idx = (nargout > 1);
7061 bool have_sortmode = (nargin > 1 && args(1).is_string ());
7069 std::string mode = args(1).string_value ();
7070 if (mode ==
"ascend")
7072 else if (mode ==
"descend")
7075 error (R
"(sort: MODE must be either "ascend" or "descend")");
7078 dim = args(1).nint_value () - 1;
7084 error (
"sort: DIM must be a valid dimension");
7086 std::string mode = args(2).xstring_value (
"sort: MODE must be a string");
7088 if (mode ==
"ascend")
7090 else if (mode ==
"descend")
7093 error (R
"(sort: MODE must be either "ascend" or "descend")");
7097 if (nargin == 1 || have_sortmode)
7104 error (
"sort: DIM must be a valid dimension");
7115 retval(0) = arg.
sort (sidx, dim, smode);
7119 retval =
ovl (arg.
sort (dim, smode));
7353 DEFUN (__sort_rows_idx__, args, ,
7359 int nargin = args.
length ();
7361 if (nargin < 1 || nargin > 2)
7364 if (nargin == 2 && ! args(1).is_string ())
7365 error (
"__sort_rows_idx__: second argument must be a string");
7370 std::string mode = args(1).string_value ();
7371 if (mode ==
"ascend")
7373 else if (mode ==
"descend")
7376 error (R
"(__sort_rows_idx__: MODE must be either "ascend" or "descend")");
7382 error (
"__sort_rows_idx__: sparse matrices not yet supported");
7384 if (arg.
ndims () != 2)
7385 error (
"__sort_rows_idx__: needs a 2-D object");
7401 std::string mode = arg.
xstring_value (
"issorted: MODE must be a string");
7403 if (mode ==
"ascend")
7405 else if (mode ==
"descend")
7407 else if (mode ==
"either")
7410 error (R
"(issorted: MODE must be "ascend", "descend", or "either")");
7415 DEFUN (issorted, args, ,
7433 int nargin = args.
length ();
7435 if (nargin < 1 || nargin > 3)
7438 bool by_rows =
false;
7445 smode = get_sort_mode_option (args(2));
7447 std::string tmp = args(1).xstring_value (
"issorted: second argument must be a string");
7451 smode = get_sort_mode_option (args(1));
7463 error (
"issorted: sparse matrices not yet supported");
7465 if (arg.
ndims () != 2)
7466 error (
"issorted: A must be a 2-D object");
7473 error (
"issorted: needs a vector");
7475 retval = args(0).issorted (smode) !=
UNSORTED;
7544 DEFUN (nth_element, args, ,
7568 int nargin = args.
length ();
7570 if (nargin < 2 || nargin > 3)
7576 dim = args(2).int_value (
true) - 1;
7578 error (
"nth_element: DIM must be a valid dimension");
7606 #define MAKE_INT_BRANCH(X) \
7608 retval = argx.X ## _array_value ().nth_element (n, dim); \
7621 #undef MAKE_INT_BRANCH
7632 error (
"nth_element: invalid index %s", ie.what ());
7653 template <
typename NDT>
7655 do_accumarray_sum (
const idx_vector& idx,
const NDT& vals,
7658 typedef typename NDT::element_type T;
7662 error (
"accumarray: index out of range");
7666 if (vals.numel () == 1)
7667 retval.idx_add (idx, vals (0));
7668 else if (vals.numel () == idx.
length (
n))
7669 retval.idx_add (idx, vals);
7671 error (
"accumarray: dimensions mismatch");
7676 DEFUN (__accumarray_sum__, args, ,
7682 int nargin = args.
length ();
7684 if (nargin < 2 || nargin > 3)
7687 if (! args(0).isnumeric ())
7688 error (
"__accumarray_sum__: first argument must be numeric");
7697 n = args(2).idx_type_value (
true);
7704 if (
r.increment () == 0)
7711 retval = do_accumarray_sum (idx,
7720 retval = do_accumarray_sum (idx,
7724 retval = do_accumarray_sum (idx, vals.
array_value (),
n);
7731 error (
"__accumarray_sum__: invalid index %s", ie.what ());
7737 template <
typename NDT>
7739 do_accumarray_minmax (
const idx_vector& idx,
const NDT& vals,
7741 const typename NDT::element_type& zero_val)
7743 typedef typename NDT::element_type T;
7747 error (
"accumarray: index out of range");
7756 if (vals.numel () == 1)
7757 (retval.*op) (idx, NDT (
dim_vector (l, 1), vals(0)));
7758 else if (vals.numel () == l)
7759 (retval.*op) (idx, vals);
7761 error (
"accumarray: dimensions mismatch");
7770 int nargin = args.
length ();
7772 if (nargin < 3 || nargin > 4)
7775 if (! args(0).isnumeric ())
7776 error (
"accumarray: first argument must be numeric");
7785 n = args(3).idx_type_value (
true);
7793 retval = do_accumarray_minmax (idx, vals.
array_value (),
n, ismin,
7808 retval = do_accumarray_minmax (idx,
7814 #define MAKE_INT_BRANCH(X) \
7816 retval = do_accumarray_minmax (idx, vals.X ## _array_value (), \
7817 n, ismin, zero.X ## _scalar_value ()); \
7829 #undef MAKE_INT_BRANCH
7832 retval = do_accumarray_minmax (idx, vals.
array_value (),
n, ismin,
7842 error (
"do_accumarray_minmax_fcn: invalid index %s", ie.what ());
7848 DEFUN (__accumarray_min__, args, ,
7854 return do_accumarray_minmax_fcn (args,
true);
7857 DEFUN (__accumarray_max__, args, ,
7863 return do_accumarray_minmax_fcn (args,
false);
7866 template <
typename NDT>
7868 do_accumdim_sum (
const idx_vector& idx,
const NDT& vals,
7871 typedef typename NDT::element_type T;
7875 error (
"accumdim: index out of range");
7882 else if (dim >= rdv.
ndims ())
7887 NDT retval (rdv, T ());
7889 if (idx.
length () != vals_dim(dim))
7890 error (
"accumdim: dimension mismatch");
7892 retval.idx_add_nd (idx, vals, dim);
7897 DEFUN (__accumdim_sum__, args, ,
7903 int nargin = args.
length ();
7905 if (nargin < 2 || nargin > 4)
7908 if (! args(0).isnumeric ())
7909 error (
"__accumdim_sum__: first argument must be numeric");
7918 dim = args(2).int_value () - 1;
7922 n = args(3).idx_type_value (
true);
7929 retval = do_accumdim_sum (idx,
7942 retval = do_accumdim_sum (idx, vals.
array_value (), dim,
n);
7949 error (
"__accumdim_sum__: invalid index %s", ie.what ());
7955 template <
typename NDT>
7958 const NDT& tval,
const NDT& fval)
7960 typedef typename NDT::element_type T;
7964 bool tscl = tval.numel () == 1;
7965 bool fscl = fval.numel () == 1;
7967 if ((! tscl && tval.dims () != dv) || (! fscl && fval.dims () != dv))
7968 error (
"merge: MASK, TVAL, and FVAL dimensions must match");
7970 T *rv = retval.fortran_vec ();
7973 const T *tv = tval.data ();
7974 const T *fv = fval.data ();
7975 const bool *mv = mask.
data ();
7984 rv[i] = (mv[i] ? ts : fs);
7990 rv[i] = (mv[i] ? ts : fv[i]);
7999 rv[i] = (mv[i] ? tv[i] : fs);
8004 rv[i] = (mv[i] ? tv[i] : fv[i]);
8011 #define MAKE_INT_BRANCH(INTX) \
8012 else if (tval.is_ ## INTX ## _type () && fval.is_ ## INTX ## _type ()) \
8014 retval = do_merge (mask, \
8015 tval.INTX ## _array_value (), \
8016 fval.INTX ## _array_value ()); \
8019 DEFUN (merge, args, ,
8054 if (! (args(0).islogical () || args(0).isnumeric ()))
8055 error (
"merge: first argument must be logical or numeric");
8062 retval = (mask_val.
is_true () ? args(1) : args(2));
8073 retval = do_merge (mask,
8077 retval = do_merge (mask,
8084 retval = do_merge (mask,
8088 retval = do_merge (mask,
8098 sq_string ?
'\'' :
'"');
8102 retval = do_merge (mask,
8117 error (
"merge: cannot merge %s with %s with array mask",
8127 #undef MAKE_INT_BRANCH
8129 template <
typename SparseT>
8134 SparseT retval = array;
8138 while (order > 0 && k > 0)
8140 idx_vector col1 (
':'), col2 (
':'), sl1 (1, k), sl2 (0, k-1);
8141 retval = SparseT (retval.index (col1, sl1))
8142 - SparseT (retval.index (col2, sl2));
8151 while (order > 0 && k > 0)
8153 idx_vector col1 (
':'), col2 (
':'), sl1 (1, k), sl2 (0, k-1);
8154 retval = SparseT (retval.index (sl1, col1))
8155 - SparseT (retval.index (sl2, col2));
8177 if (dv(dim) <= order)
8186 if (dim == dv.
ndims ())
8188 retval = do_diff (array, order, dim - 1);
8191 else if (dv(dim) == 1)
8195 retval = do_diff (array, dv(dim) - 1, dim);
8196 order -= dv(dim) - 1;
8253 DEFUN (diff, args, ,
8285 int nargin = args.
length ();
8287 if (nargin < 1 || nargin > 3)
8290 if (! (args(0).isnumeric () || args(0).islogical ()))
8291 error (
"diff: X must be numeric or logical");
8297 if (args(1).is_scalar_type ())
8298 order = args(1).idx_type_value (
true,
false);
8299 else if (! args(1).is_zero_by_zero ())
8300 error (
"diff: order K must be a scalar or []");
8302 error (
"diff: order K must be non-negative");
8307 dim = args(2).int_value (
true,
false);
8308 if (dim < 1 || dim > args(0).ndims ())
8309 error (
"diff: DIM must be a valid dimension");
8314 return do_diff (args(0), order, dim);
8330 template <
typename T>
8336 if (rep.
ndims () != 2 || rep.
rows () != 2)
8337 error (
"repelems: R must be a 2-row, N-column matrix of integers");
8345 error (
"repelems: second row must contain non-negative numbers");
8350 retval.
clear (1, l);
8356 std::fill_n (dest, k, src.
checkelem (rep(0, i) - 1));
8363 DEFUN (repelems, args, ,
8394 const Matrix rm = args(1).matrix_value ();
8396 if (rm.
rows () != 2 || rm.
ndims () != 2)
8397 error (
"repelems: R must be a matrix with two rows");
8406 if (
static_cast<double> (rx) != rm(i))
8407 error (
"repelems: R must be a matrix of integers");
8412 switch (
x.builtin_type ())
8414 #define BTYP_BRANCH(X, EX) \
8416 retval = do_repelems (x.EX ## _value (), r); \
8459 if (! args(0).isnumeric ())
8460 error (
"base64_encode: encoding is supported only for numeric arrays");
8462 if (args(0).iscomplex () || args(0).issparse ())
8463 error (
"base64_encode: encoding complex or sparse data is not supported");
8469 #define MAKE_INT_BRANCH(X) \
8470 if (args(0).is_ ## X ## _type ()) \
8472 const X##NDArray in = args(0). X## _array_value (); \
8473 std::size_t inlen = in.numel () * sizeof (X## _t) / sizeof (char); \
8474 const char *inc = reinterpret_cast<const char *> (in.data ()); \
8476 if (base64_encode (inc, inlen, &out)) \
8478 retval(0) = octave_value (out); \
8492 #undef MAKE_INT_BRANCH
8497 else if (args(0).is_single_type ())
8501 inlen = in.
numel () *
sizeof (float) /
sizeof (
char);
8503 inc =
reinterpret_cast<const char *
> (in.
data ());
8515 inlen = in.
numel () *
sizeof (double) /
sizeof (
char);
8517 inc =
reinterpret_cast<const char *
> (in.
data ());
8564 int nargin = args.
length ();
8566 if (nargin < 1 || nargin > 2)
8569 std::string str = args(0).string_value ();
8578 = args(1).octave_idx_type_vector_value ();
8584 retval = retval.
reshape (dims);
8587 return ovl (retval);
8608 DEFUN (__base64_decode_bytes__, args, ,
8620 int nargin = args.
length ();
8622 if (nargin < 1 || nargin > 2)
8625 std::string str = args(0).string_value ();
8634 = args(1).octave_idx_type_vector_value ();
8640 retval = retval.
reshape (dims);
8643 return ovl (retval);
8662 OCTAVE_END_NAMESPACE(
octave)
bool isvector(const dim_vector &dim)
ComplexMatrix linspace(const ComplexColumnVector &x1, const ComplexColumnVector &x2, octave_idx_type n)
charNDArray max(char d, const charNDArray &m)
charNDArray min(char d, const charNDArray &m)
T * fortran_vec()
Size of the specified dimension.
Array< T, Alloc > nth_element(const octave::idx_vector &n, int dim=0) const
Returns the n-th element in increasing order, using the same ordering as used for sort.
int ndims() const
Size of the specified dimension.
octave_idx_type rows() const
void resize(const dim_vector &dv, const T &rfv)
Size of the specified dimension.
const T * data() const
Size of the specified dimension.
octave_idx_type columns() const
const dim_vector & dims() const
Return a const-reference so that dims ()(i) works efficiently.
T & xelem(octave_idx_type n)
Size of the specified dimension.
Array< T, Alloc > reshape(octave_idx_type nr, octave_idx_type nc) const
Size of the specified dimension.
T & checkelem(octave_idx_type n)
Size of the specified dimension.
static Array< T, Alloc > cat(int dim, octave_idx_type n, const Array< T, Alloc > *array_list)
Concatenation along a specified (0-based) dimension, equivalent to cat().
octave_idx_type numel() const
Number of elements in the array.
ComplexNDArray prod(int dim=-1) const
ComplexNDArray cumsum(int dim=-1) const
ComplexNDArray diff(octave_idx_type order=1, int dim=-1) const
ComplexNDArray xsum(int dim=-1) const
ComplexNDArray sum(int dim=-1) const
FloatComplexNDArray sum(int dim=-1) const
ComplexNDArray dsum(int dim=-1) const
FloatComplexNDArray diff(octave_idx_type order=1, int dim=-1) const
FloatComplexNDArray prod(int dim=-1) const
FloatComplexNDArray cumsum(int dim=-1) const
ComplexNDArray dprod(int dim=-1) const
FloatNDArray sum(int dim=-1) const
FloatNDArray prod(int dim=-1) const
NDArray dprod(int dim=-1) const
FloatNDArray cumsum(int dim=-1) const
NDArray dsum(int dim=-1) const
FloatNDArray diff(octave_idx_type order=1, int dim=-1) const
Template for N-dimensional array classes with like-type math operators.
MArray< T > reshape(const dim_vector &new_dims) const
NDArray diff(octave_idx_type order=1, int dim=-1) const
NDArray cumsum(int dim=-1) const
NDArray prod(int dim=-1) const
NDArray xsum(int dim=-1) const
NDArray sum(int dim=-1) const
SparseBoolMatrix all(int dim=-1) const
SparseMatrix sum(int dim=-1) const
SparseBoolMatrix any(int dim=-1) const
SparseComplexMatrix prod(int dim=-1) const
SparseComplexMatrix sum(int dim=-1) const
SparseComplexMatrix cumsum(int dim=-1) const
SparseMatrix sum(int dim=-1) const
SparseMatrix prod(int dim=-1) const
SparseMatrix cumsum(int dim=-1) const
octave_idx_type cols() const
static Sparse< T, Alloc > cat(int dim, octave_idx_type n, const Sparse< T, Alloc > *sparse_list)
octave_idx_type nnz() const
Actual number of nonzero terms.
octave_idx_type rows() const
boolNDArray any(int dim=-1) const
boolNDArray all(int dim=-1) const
Vector representing the dimensions (size) of an Array.
bool concat(const dim_vector &dvb, int dim)
This corresponds to cat().
octave_idx_type numel(int n=0) const
Number of elements that a matrix with this dimensions would have.
void resize(int n, int fill_value=0)
static dim_vector alloc(int n)
octave_idx_type ndims() const
Number of dimensions.
bool hvcat(const dim_vector &dvb, int dim)
This corresponds to [,] (horzcat, dim = 0) and [;] (vertcat, dim = 1).
int first_non_singleton(int def=0) const
dim_vector redim(int n) const
Force certain dimensionality, preserving numel ().
octave_idx_type length(octave_idx_type n=0) const
octave_idx_type extent(octave_idx_type n) const
intNDArray diff(octave_idx_type order=1, int dim=-1) const
symbol_table & get_symbol_table()
octave_value_list feval(const char *name, const octave_value_list &args=octave_value_list(), int nargout=0)
Evaluate an Octave function (built-in or interpreted) and return the list of result values.
static data_type string_to_data_type(const std::string &s)
static octave_map cat(int dim, octave_idx_type n, const octave_scalar_map *map_list)
void resize(octave_idx_type n, const octave_value &rfv=octave_value())
Array< octave_value > array_value() const
octave_value_list slice(octave_idx_type offset, octave_idx_type len, bool tags=false) const
octave_idx_type length() const
bool is_uint32_type() const
boolNDArray bool_array_value(bool warn=false) const
SparseMatrix sparse_matrix_value(bool frc_str_conv=false) const
std::string class_name() const
bool bool_value(bool warn=false) const
FloatComplexNDArray xfloat_complex_array_value(const char *fmt,...) const
int32NDArray int32_array_value() const
uint16NDArray uint16_array_value() const
int16NDArray int16_array_value() const
int8NDArray int8_array_value() const
octave_idx_type rows() const
bool is_scalar_type() const
bool is_sq_string() const
octave::range< double > range_value() const
bool is_int8_type() const
Complex complex_value(bool frc_str_conv=false) const
octave_idx_type idx_type_value(bool req_int=false, bool frc_str_conv=false) const
Complex xcomplex_value(const char *fmt,...) const
octave_value sort(octave_idx_type dim=0, sortmode mode=ASCENDING) const
ComplexNDArray complex_array_value(bool frc_str_conv=false) const
bool is_single_type() const
charNDArray char_array_value(bool frc_str_conv=false) const
FloatComplex float_complex_value(bool frc_str_conv=false) const
bool is_uint8_type() const
bool is_uint64_type() const
bool is_uint16_type() const
uint64NDArray uint64_array_value() const
float float_value(bool frc_str_conv=false) const
SparseComplexMatrix xsparse_complex_matrix_value(const char *fmt,...) const
bool is_int16_type() const
octave_value reshape(const dim_vector &dv) const
octave_value & assign(assign_op op, const std::string &type, const std::list< octave_value_list > &idx, const octave_value &rhs)
double scalar_value(bool frc_str_conv=false) const
octave_idx_type numel() const
std::string string_value(bool force=false) const
bool is_int64_type() const
ComplexNDArray xcomplex_array_value(const char *fmt,...) const
sortmode is_sorted_rows(sortmode mode=UNSORTED) const
octave_value single_subsref(const std::string &type, const octave_value_list &idx)
int64NDArray int64_array_value() const
SparseBoolMatrix sparse_bool_matrix_value(bool warn=false) const
NDArray array_value(bool frc_str_conv=false) const
FloatComplex xfloat_complex_value(const char *fmt,...) const
bool is_double_type() const
bool is_int32_type() const
uint8NDArray uint8_array_value() const
std::string xstring_value(const char *fmt,...) const
FloatComplexNDArray float_complex_array_value(bool frc_str_conv=false) const
octave_value resize(const dim_vector &dv, bool fill=false) const
FloatNDArray float_array_value(bool frc_str_conv=false) const
uint32NDArray uint32_array_value() const
octave_idx_type columns() const
builtin_type_t builtin_type() const
octave_value diag(octave_idx_type k=0) const
double double_value(bool frc_str_conv=false) const
SparseComplexMatrix sparse_complex_matrix_value(bool frc_str_conv=false) const
Array< std::string > cellstr_value() const
Array< octave_idx_type > sort_rows_idx(sortmode mode=ASCENDING) const
octave_value find_method(const std::string &name, const std::string &dispatch_type)
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
#define INSTANTIATE_EYE(T)
template octave_value identity_matrix< int8NDArray >(int, int)
octave_value do_class_concat(const octave_value_list &ovl, const std::string &cattype, int dim)
template octave_value identity_matrix< uint64NDArray >(int, int)
template octave_value identity_matrix< int16NDArray >(int, int)
#define BTYP_BRANCH(X, EX)
void map_2_xlog2(const Array< T > &x, Array< T > &f, Array< ET > &e)
template octave_value identity_matrix< int64NDArray >(int, int)
template octave_value identity_matrix< int32NDArray >(int, int)
template octave_value identity_matrix< uint8NDArray >(int, int)
octave_value identity_matrix(int nr, int nc)
#define MAKE_INT_BRANCH(X)
template octave_value identity_matrix< uint16NDArray >(int, int)
#define DATA_REDUCTION(FCN)
template octave_value identity_matrix< boolNDArray >(int, int)
template octave_value identity_matrix< uint32NDArray >(int, int)
#define DEFUN(name, args_name, nargout_name, doc)
Macro to define a builtin function.
#define DEFALIAS(alias, name)
Macro to define an alias for another existing function name.
void warning(const char *fmt,...)
void() error(const char *fmt,...)
#define error_unless(cond)
#define panic_impossible()
void err_wrong_type_arg(const char *name, const char *s)
void warn_implicit_conversion(const char *id, const char *from, const char *to)
double norm(const ColumnVector &v)
ColumnVector transform(const Matrix &m, double x, double y, double z)
octave::idx_vector idx_vector
intNDArray< octave_int16 > int16NDArray
intNDArray< octave_int32 > int32NDArray
intNDArray< octave_int64 > int64NDArray
intNDArray< octave_int8 > int8NDArray
interpreter & __get_interpreter__()
double lo_ieee_na_value()
float lo_ieee_float_nan_value()
float lo_ieee_float_na_value()
double lo_ieee_nan_value()
float lo_ieee_float_inf_value()
double lo_ieee_inf_value()
Complex log2(const Complex &x)
double frexp(double x, int *expptr)
Complex atan(const Complex &x)
F77_RET_T const F77_DBLE * x
F77_RET_T const F77_DBLE const F77_DBLE * f
std::string get_dispatch_type(const octave_value_list &args, builtin_type_t &builtin_type)
void get_dimensions(const octave_value &a, const char *warn_for, dim_vector &dim)
Array< double > base64_decode(const std::string &str)
bool base64_encode(const char *inc, const std::size_t inlen, char **out)
intNDArray< octave_uint8 > base64_decode_bytes(const std::string &str)
std::complex< double > Complex
std::complex< float > FloatComplex
octave_int< uint64_t > octave_uint64
octave_int< T > pow(const octave_int< T > &a, const octave_int< T > &b)
#define OCTAVE_LOCAL_BUFFER(T, buf, size)
double xfrobnorm(const Matrix &x)
double xnorm(const ColumnVector &x, double p)
RowVector xcolnorms(const Matrix &m, double p)
ColumnVector xrownorms(const Matrix &m, double p)
T::size_type numel(const T &str)
const octave_base_value const Array< octave_idx_type > & ra_idx
return octave_value(v1.char_array_value() . concat(v2.char_array_value(), ra_idx),((a1.is_sq_string()||a2.is_sq_string()) ? '\'' :'"'))
octave_value colon_op(const octave_value &base, const octave_value &increment, const octave_value &limit, bool is_for_cmd_expr=false)
octave_value cat_op(type_info &ti, const octave_value &a, const octave_value &b, const Array< octave_idx_type > &ra_idx)
octave_value binary_op(type_info &ti, octave_value::binary_op op, const octave_value &a, const octave_value &b)
octave_value unary_op(type_info &ti, octave_value::unary_op op, const octave_value &a)
octave_value_list ovl(const OV_Args &... args)
Construct an octave_value_list with less typing.
void maybe_warn_string_concat(bool all_dq_strings_p, bool all_sq_strings_p)
std::string get_concat_class(const std::string &c1, const std::string &c2)
intNDArray< octave_uint16 > uint16NDArray
intNDArray< octave_uint32 > uint32NDArray
intNDArray< octave_uint64 > uint64NDArray
intNDArray< octave_uint8 > uint8NDArray
octave_idx_type dims_to_numel(const dim_vector &dims, const octave_value_list &idx)
void check_dimensions(dim_vector &dim, const char *warnfor)