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).strict_int_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).strict_int_value (
"any: DIM must be an integer")-1);
167 error (
"any: invalid dimension argument = %d", dim + 1);
169 return ovl (args(0).any (dim));
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");
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));
446template <
typename T,
typename ET>
455 f.xelem (i) = math::log2 (
x(i), exp);
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
669 error (
"rem: unexpected: found %s instead of integer - please report this bug",
btyp_class_name[btyp0].c_str ());
678 else if (args(0).is_single_type () || args(1).is_single_type ())
680 if (args(0).is_scalar_type () && args(1).is_scalar_type ())
681 retval = math::rem (args(0).float_value (), args(1).float_value ());
686 retval = binmap<float> (a0, a1, math::rem<float>,
"rem");
691 if (args(0).is_scalar_type () && args(1).is_scalar_type ())
692 retval = math::rem (args(0).scalar_value (), args(1).scalar_value ());
693 else if (args(0).issparse () || args(1).issparse ())
697 retval = binmap<double> (m0, m1, math::rem<double>,
"rem");
701 NDArray a0 = args(0).array_value ();
702 NDArray a1 = args(1).array_value ();
703 retval = binmap<double> (a0, a1, math::rem<double>,
"rem");
808 if (args.length () != 2)
813 if (! args(0).isnumeric ())
816 if (! args(1).isnumeric ())
819 if (args(0).iscomplex () || args(1).iscomplex ())
820 error (
"mod: not defined for complex numbers");
832 error (
"mod: cannot combine %s and %s",
833 args(0).class_name ().c_str (),
834 args(1).class_name ().c_str ());
838#define MAKE_INT_BRANCH(X) \
841 X##NDArray a0 = args(0).X##_array_value (); \
842 X##NDArray a1 = args(1).X##_array_value (); \
843 retval = binmap<octave_##X,octave_##X,octave_##X> (a0, a1, mod, "mod"); \
856#undef MAKE_INT_BRANCH
868 error (
"mod: unexpected: found %s instead of integer - please report this bug",
btyp_class_name[btyp0].c_str ());
877 else if (args(0).is_single_type () || args(1).is_single_type ())
879 if (args(0).is_scalar_type () && args(1).is_scalar_type ())
880 retval = math::mod (args(0).float_value (), args(1).float_value ());
885 retval = binmap<float> (a0, a1, math::mod<float>,
"mod");
890 if (args(0).is_scalar_type () && args(1).is_scalar_type ())
891 retval = math::mod (args(0).scalar_value (), args(1).scalar_value ());
892 else if (args(0).issparse () || args(1).issparse ())
896 retval = binmap<double> (m0, m1, math::mod<double>,
"mod");
900 NDArray a0 = args(0).array_value ();
901 NDArray a1 = args(1).array_value ();
902 retval = binmap<double> (a0, a1, math::mod<double>,
"mod");
963#define DATA_REDUCTION(FCN) \
965 int nargin = args.length (); \
967 if (nargin < 1 || nargin > 2) \
970 octave_value retval; \
972 octave_value arg = args(0); \
974 int dim = (nargin == 1 ? -1 : args(1).int_value (true) - 1); \
977 error (#FCN ": invalid dimension argument = %d", dim + 1); \
981 if (arg.issparse ()) \
983 SparseMatrix tmp = arg.sparse_matrix_value (); \
985 retval = tmp.FCN (dim); \
987 else if (arg.is_single_type ()) \
989 FloatNDArray tmp = arg.float_array_value (); \
991 retval = tmp.FCN (dim); \
995 NDArray tmp = arg.array_value (); \
997 retval = tmp.FCN (dim); \
1000 else if (arg.iscomplex ()) \
1002 if (arg.issparse ()) \
1004 SparseComplexMatrix tmp = arg.sparse_complex_matrix_value (); \
1006 retval = tmp.FCN (dim); \
1008 else if (arg.is_single_type ()) \
1010 FloatComplexNDArray tmp \
1011 = arg.float_complex_array_value (); \
1013 retval = tmp.FCN (dim); \
1017 ComplexNDArray tmp = arg.complex_array_value (); \
1019 retval = tmp.FCN (dim); \
1023 err_wrong_type_arg (#FCN, arg); \
1027DEFUN (cumprod, args, ,
1073DEFUN (cumsum, args, ,
1098 int nargin = args.length ();
1100 bool isnative =
false;
1101 bool isdouble =
false;
1103 if (nargin > 1 && args(nargin - 1).is_string ())
1105 std::string str = args(nargin - 1).string_value ();
1107 if (str ==
"native")
1109 else if (str ==
"double")
1112 error (
"cumsum: unrecognized string argument");
1117 if (nargin < 1 || nargin > 2)
1123 dim = args(1).int_value () - 1;
1125 error (
"cumsum: invalid dimension argument = %d", dim + 1);
1158#define MAKE_INT_BRANCH(X) \
1161 retval = arg.X ## _array_value ().cumsum (dim); \
1163 retval = arg.array_value ().cumsum (dim); \
1175#undef MAKE_INT_BRANCH
1182 retval = (cs != 0.0);
1190 retval = (cs != 0.0);
1259 int nargin = args.
length ();
1261 if (nargin < 1 || nargin > 3)
1267 retval = args(0).
diag ();
1268 else if (nargin == 2)
1270 octave_idx_type k = args(1).strict_idx_type_value (
"diag: invalid argument K");
1272 retval = args(0).
diag (k);
1279 error (
"diag: V must be a vector");
1281 octave_idx_type m = args(1).strict_idx_type_value (
"diag: invalid dimension M");
1282 octave_idx_type n = args(2).strict_idx_type_value (
"diag: invalid dimension N");
1284 retval = arg0.
diag (m, n);
1408 int nargin = args.
length ();
1410 bool isnative =
false;
1411 bool isdouble =
false;
1413 if (nargin > 1 && args(nargin - 1).is_string ())
1415 std::string str = args(nargin - 1).string_value ();
1417 if (str ==
"native")
1419 else if (str ==
"double")
1422 error (
"prod: unrecognized type argument '%s'", str.c_str ());
1427 if (nargin < 1 || nargin > 2)
1437 dim = args(1).int_value () - 1;
1439 error (
"prod: invalid dimension DIM = %d", dim + 1);
1469#define MAKE_INT_BRANCH(X) \
1472 retval = arg.X ## _array_value ().prod (dim); \
1474 retval = arg.array_value ().prod (dim); \
1486#undef MAKE_INT_BRANCH
1588 int n_args = args.
length ();
1589 for (
int i = 0; i < n_args; i++)
1590 if (args(i).
numel () != 1)
1596template <
typename TYPE,
typename T>
1598single_type_concat (
Array<T>& result,
1602 int n_args = args.
length ();
1605 && all_scalar_1x1 (args))
1609 if (dim == -1 || dim == -2)
1612 dv.resize (dim+1, 1);
1617 for (
int j = 0; j < n_args; j++)
1621 result(j) = octave_value_extract<T> (args(j));
1628 for (
int j = 0; j < n_args; j++)
1632 array_list[j] = octave_value_extract<TYPE> (args(j));
1639template <
typename TYPE,
typename T>
1652 sparse_list[j] = octave_value_extract<TYPE> (args(j));
1659template <
typename TYPE>
1665 single_type_concat<TYPE, typename TYPE::element_type> (result, args, dim);
1670template <
typename MAP>
1676 int n_args = args.
length ();
1679 for (
int j = 0; j < n_args; j++)
1683 map_list[j] = octave_value_extract<MAP> (args(j));
1694 if (all_scalar_1x1 (args))
1695 single_type_concat_map<octave_scalar_map> (result, args, dim);
1697 single_type_concat_map<octave_map> (result, args, dim);
1703attempt_type_conversion (
const octave_value& ov, std::string dtype)
1725 result = interp.
feval (fcn,
ovl (ov), 1);
1729 error (ee,
"conversion from %s to %s failed", dtype.c_str (),
1733 if (result.
empty ())
1734 error (
"conversion from %s to %s failed", dtype.c_str (),
1747 error (
"no constructor for %s!", dtype.c_str ());
1753 result = interp.
feval (fcn,
ovl (ov), 1);
1757 error (ee,
"%s constructor failed for %s argument", dtype.c_str (),
1761 if (result.
empty ())
1762 error (
"%s constructor failed for %s argument", dtype.c_str (),
1773 const std::string& cattype,
int dim)
1799 error (ee,
"%s/%s method failed", dtype.c_str (), cattype.c_str ());
1803 error (
"%s/%s method did not return a value", dtype.c_str (),
1823 if (t1_type == dtype)
1826 tmp(j++) = attempt_type_conversion (elt, dtype);
1831 octave_map m = do_single_type_concat_map (tmp, dim);
1833 std::string cname = tmp(0).class_name ();
1834 std::list<std::string> parents = tmp(0).parent_class_name_list ();
1852 int n_args = args.
length ();
1856 else if (n_args == 1)
1858 else if (n_args > 1)
1860 std::string result_type;
1862 bool all_strings_p =
true;
1863 bool all_sq_strings_p =
true;
1864 bool all_dq_strings_p =
true;
1865 bool all_real_p =
true;
1866 bool all_cmplx_p =
true;
1867 bool any_sparse_p =
false;
1868 bool any_cell_p =
false;
1869 bool any_class_p =
false;
1871 bool first_elem_is_struct =
false;
1873 for (
int i = 0; i < n_args; i++)
1877 result_type = args(i).class_name ();
1879 first_elem_is_struct = args(i).isstruct ();
1884 if (all_strings_p && ! args(i).is_string ())
1885 all_strings_p =
false;
1886 if (all_sq_strings_p && ! args(i).is_sq_string ())
1887 all_sq_strings_p =
false;
1888 if (all_dq_strings_p && ! args(i).is_dq_string ())
1889 all_dq_strings_p =
false;
1890 if (all_real_p && ! args(i).isreal ())
1892 if (all_cmplx_p && ! (args(i).iscomplex ()
1893 || args(i).isreal ()))
1894 all_cmplx_p =
false;
1895 if (! any_sparse_p && args(i).issparse ())
1896 any_sparse_p =
true;
1897 if (! any_cell_p && args(i).iscell ())
1899 if (! any_class_p && args(i).isobject ())
1903 if (any_cell_p && ! any_class_p && ! first_elem_is_struct)
1906 for (
int i = 0; i < n_args; i++)
1908 if (args(i).iscell ())
1909 args(j++) = args(i);
1912 if (args(i).isempty ())
1915 args(j++) =
Cell (args(i));
1926 else if (result_type ==
"double")
1931 retval = do_single_type_concat<SparseMatrix> (args, dim);
1933 retval = do_single_type_concat<SparseComplexMatrix> (args, dim);
1938 retval = do_single_type_concat<NDArray> (args, dim);
1940 retval = do_single_type_concat<ComplexNDArray> (args, dim);
1943 else if (result_type ==
"single")
1946 retval = do_single_type_concat<FloatNDArray> (args, dim);
1948 retval = do_single_type_concat<FloatComplexNDArray> (args, dim);
1950 else if (result_type ==
"char")
1952 char type = (all_dq_strings_p ?
'"' :
'\'');
1954 if (! all_strings_p)
1956 "numeric", result_type);
1960 charNDArray result = do_single_type_concat<charNDArray> (args, dim);
1964 else if (result_type ==
"logical")
1967 retval = do_single_type_concat<SparseBoolMatrix> (args, dim);
1969 retval = do_single_type_concat<boolNDArray> (args, dim);
1971 else if (result_type ==
"int8")
1972 retval = do_single_type_concat<int8NDArray> (args, dim);
1973 else if (result_type ==
"int16")
1974 retval = do_single_type_concat<int16NDArray> (args, dim);
1975 else if (result_type ==
"int32")
1976 retval = do_single_type_concat<int32NDArray> (args, dim);
1977 else if (result_type ==
"int64")
1978 retval = do_single_type_concat<int64NDArray> (args, dim);
1979 else if (result_type ==
"uint8")
1980 retval = do_single_type_concat<uint8NDArray> (args, dim);
1981 else if (result_type ==
"uint16")
1982 retval = do_single_type_concat<uint16NDArray> (args, dim);
1983 else if (result_type ==
"uint32")
1984 retval = do_single_type_concat<uint32NDArray> (args, dim);
1985 else if (result_type ==
"uint64")
1986 retval = do_single_type_concat<uint64NDArray> (args, dim);
1987 else if (result_type ==
"cell")
1988 retval = do_single_type_concat<Cell> (args, dim);
1989 else if (result_type ==
"struct")
1990 retval = do_single_type_concat_map (args, dim);
1999 if (dim == -1 || dim == -2)
2005 for (
int i = 1; i < args.
length (); i++)
2007 if (! (dv.*concat_rule) (args(i).dims (), dim))
2008 error (
"cat: dimension mismatch");
2029 int dv_len = dv.
ndims ();
2032 for (
int j = 0; j < n_args; j++)
2044 error (
"%s: indexing error", fname.c_str ());
2049 ra_idx(dim) += (dim < dv_tmp.
ndims () ? dv_tmp(dim) : 1);
2060DEFUN (horzcat, args, ,
2078 return do_cat (args, -2,
"horzcat");
2302DEFUN (vertcat, args, ,
2320 return do_cat (args, -1,
"vertcat");
2378 int dim = args(0).strict_int_value (
"cat: DIM must be an integer") - 1;
2381 error (
"cat: DIM must be a valid dimension");
2383 return ovl (do_cat (args.
slice (1, args.
length () - 1), dim,
"cat"));
2550 if (args.
length () != 2 || args(1).length () < args(1).ndims ())
2553 Array<int> vec = args(1).int_vector_value ();
2557 int n = vec.
numel ();
2558 for (
int i = 0; i < n; i++)
2564DEFUN (permute, args, ,
2594 return do_permute (args,
false);
2597DEFUN (ipermute, args, ,
2613 return do_permute (args,
true);
2616DEFUN (length, args, ,
2631 return ovl (args(0).length ());
2634DEFUN (ndims, args, ,
2662 while ((ndims > 2) && (sz(ndims - 1) == 1))
2717 int nargin = args.
length ();
2725 retval = args(0).numel ();
2726 else if (nargin > 1)
2736DEFUN (size, args, nargout,
2809 int nargin = args.
length ();
2819 int ndims = dimensions.
ndims ();
2825 dimensions = dimensions.
redim (nargout);
2826 ndims = dimensions.
ndims ();
2832 m(i) = dimensions(i);
2843 query_dims(i) = args(i+1).idx_type_value (
true);
2846 query_dims = args(1).octave_idx_type_vector_value (
true);
2848 if (nargout > 1 && nargout != query_dims.
numel ())
2849 error (
"size: nargout > 1 but does not match number of requested dimensions");
2860 error (
"size: requested dimension DIM (= %"
2861 OCTAVE_IDX_TYPE_FORMAT
") out of range", nd);
2863 m(i) = nd <= ndims ? dimensions (nd-1) : 1;
2956DEFUN (size_equal, args, ,
2967 int nargin = args.
length ();
2973 for (
int i = 1; i < nargin; ++i)
2977 if (a_dims != b_dims)
2995 return ovl (args(0).nnz ());
3014DEFUN (nzmax, args, ,
3031 return ovl (args(0).nzmax ());
3086DEFUN (columns, args, ,
3150 int nargin = args.
length ();
3152 bool isnative =
false;
3153 bool isdouble =
false;
3154 bool isextra =
false;
3156 if (nargin > 1 && args(nargin - 1).is_string ())
3158 std::string str = args(nargin - 1).string_value ();
3160 if (str ==
"native")
3162 else if (str ==
"double")
3164 else if (str ==
"extra")
3167 error (
"sum: unrecognized type argument '%s'", str.c_str ());
3172 if (nargin < 1 || nargin > 2)
3178 dim = args(1).int_value () - 1;
3180 error (
"sum: invalid dimension DIM = %d", dim + 1);
3192 warning (
"sum: 'extra' not yet implemented for sparse matrices");
3205 warning (
"sum: 'extra' not yet implemented for sparse matrices");
3215 if (isdouble || isextra)
3222 if (isdouble || isextra)
3228#define MAKE_INT_BRANCH(X) \
3231 retval = arg.X ## _array_value ().sum (dim); \
3233 retval = arg.X ## _array_value ().dsum (dim); \
3245#undef MAKE_INT_BRANCH
3342DEFUN (sumsq, args, ,
3382DEFUN (islogical, args, ,
3396 return ovl (args(0).islogical ());
3473DEFUN (iscomplex, args, ,
3483 return ovl (args(0).iscomplex ());
3503DEFUN (isfloat, args, ,
3515 return ovl (args(0).isfloat ());
3521DEFUN (complex, args, ,
3551 int nargin = args.
length ();
3553 if (nargin < 1 || nargin > 2)
3574 if (arg.
numel () == 1)
3589 if (arg.
numel () == 1)
3614 if (re.
numel () == 1)
3617 if (re_val.
nnz () == 0)
3629 i < im_val.
cidx (j + 1); i++)
3630 result.
data (im_val.
ridx (i) + off)
3636 else if (im.
numel () == 1)
3639 if (im_val.
nnz () == 0)
3652 i < re_val.
cidx (j + 1); i++)
3653 result.
data (re_val.
ridx (i) + off)
3661 if (re_val.
dims () != im_val.
dims ())
3662 error (
"complex: dimension mismatch");
3672 if (re.
numel () == 1)
3676 if (im.
numel () == 1)
3700 if (im.
numel () == 1)
3716 if (re_val.
dims () != im_val.
dims ())
3717 error (
"complex: dimension mismatch");
3730 else if (re.
numel () == 1)
3734 if (im.
numel () == 1)
3757 if (im.
numel () == 1)
3772 if (re_val.
dims () != im_val.
dims ())
3773 error (
"complex: dimension mismatch");
3832DEFUN (isreal, args, ,
3845 return ovl (args(0).isreal ());
3848DEFUN (isempty, args, ,
3859 return ovl (args(0).isempty ());
3867DEFUN (isnumeric, args, ,
3881 return ovl (args(0).isnumeric ());
3900DEFUN (isscalar, args, ,
3917 return ovl (sz.
numel () == 2 && sz(0) == 1 && sz(1) == 1);
3957 return ovl (sz.
numel () == 2 && (sz(0) == 1 || sz(1) == 1));
3980DEFUN (isrow, args, ,
3997 return ovl (sz.
numel () == 2 && sz(0) == 1);
4029DEFUN (iscolumn, args, ,
4046 return ovl (sz.
numel () == 2 && sz(1) == 1);
4078DEFUN (ismatrix, args, ,
4096 return ovl (sz.
numel () == 2 && sz(0) >= 0 && sz(1) >= 0);
4127DEFUN (issquare, args, ,
4144 return ovl (sz.
numel () == 2 && sz(0) == sz(1));
4173 int nargin = args.
length ();
4178 bool issparse =
false;
4179 bool iscomplex =
false;
4181 if (nargin > 0 && args(nargin-1).is_string ())
4183 std::string nm = args(nargin-1).string_value ();
4189 if (nargin > 1 && args(nargin-2).is_string ()
4190 && args(nargin-2).string_value () ==
"like")
4192 std::string nm = args(nargin-1).class_name ();
4193 issparse = args(nargin-1).issparse ();
4194 iscomplex = args(nargin-1).iscomplex ();
4210 dims.resize (nargin);
4212 for (
int i = 0; i < nargin; i++)
4214 if (args(i).
numel () > 1)
4215 error (
"%s: dimensions must be scalars.", fcn);
4217 dims(i) = (args(i).isempty () ? 0 : args(i).idx_type_value (
true));
4223 dims.chop_trailing_singletons ();
4235 if (dims.ndims () > 2)
4236 error (
"%s: sparse ND arrays not supported.", fcn);
4244 retval =
SparseMatrix (dims(0), dims(1),
static_cast<double> (val));
4253 error (
"%s: invalid class name for sparse", fcn);
4312 error (
"%s: invalid class name", fcn);
4325 int nargin = args.
length ();
4330 bool issparse =
false;
4331 bool iscomplex =
false;
4333 if (nargin > 0 && args(nargin-1).is_string ())
4335 std::string nm = args(nargin-1).string_value ();
4341 if (nargin > 1 && args(nargin-2).is_string ()
4342 && args(nargin-2).string_value () ==
"like"
4343 && (std::string(fcn) ==
"Inf"
4344 || std::string(fcn) ==
"NaN" || std::string(fcn) ==
"NA"))
4346 if (! args(nargin-1).isfloat ())
4347 error (
"%s: input followed by 'like' must be floating point", fcn);
4348 std::string nm = args(nargin-1).class_name ();
4349 issparse = args(nargin-1).issparse ();
4350 iscomplex = args(nargin-1).iscomplex ();
4366 dims.resize (nargin);
4368 for (
int i = 0; i < nargin; i++)
4370 if (args(i).
numel () > 1)
4371 error (
"%s: dimensions must be scalars.", fcn);
4373 dims(i) = (args(i).isempty () ? 0 : args(i).idx_type_value (
true));
4379 dims.chop_trailing_singletons ();
4388 if (dims.ndims () > 2)
4389 error (
"%s: sparse ND arrays not supported", fcn);
4394 retval =
SparseMatrix (dims(0), dims(1),
static_cast<double> (val));
4416 error (
"%s: invalid class name", fcn);
4428 int nargin = args.
length ();
4434 if (nargin > 0 && args(nargin-1).is_string ())
4436 std::string nm = args(nargin-1).string_value ();
4453 dims.resize (nargin);
4455 for (
int i = 0; i < nargin; i++)
4457 if (args(i).
numel () > 1)
4458 error (
"%s: dimensions must be scalars.", fcn);
4460 dims(i) = (args(i).isempty () ? 0 : args(i).idx_type_value (
true));
4466 dims.chop_trailing_singletons ();
4476 retval =
FloatNDArray (dims,
static_cast<float> (val));
4484 error (
"%s: invalid class name", fcn);
4497 int nargin = args.
length ();
4503 if (nargin > 0 && args(nargin-1).is_string ())
4505 std::string nm = args(nargin-1).string_value ();
4522 dims.resize (nargin);
4524 for (
int i = 0; i < nargin; i++)
4526 if (args(i).
numel () > 1)
4527 error (
"%s: dimensions must be scalars.", fcn);
4529 dims(i) = (args(i).isempty () ? 0 : args(i).idx_type_value (
true));
4535 dims.chop_trailing_singletons ();
4554 error (
"%s: invalid class name", fcn);
4566 int nargin = args.
length ();
4573 if (nargin > 0 && args(nargin-1).is_string ())
4575 std::string nm = args(nargin-1).string_value ();
4579 error (
"%s: invalid data type '%s'", fcn, nm.c_str ());
4582 bool issparse =
false;
4584 if (nargin > 1 && args(nargin-2).is_string ()
4585 && args(nargin-2).string_value () ==
"like")
4587 if (! args(nargin-1).islogical ())
4588 error (R
"(%s: input followed by "like" must be logical)", fcn);
4590 issparse = args(nargin-1).issparse ();
4605 dims.resize (nargin);
4607 for (
int i = 0; i < nargin; i++)
4609 if (args(i).
numel () > 1)
4610 error (
"%s: dimensions must be scalars.", fcn);
4612 dims(i) = (args(i).isempty () ? 0 : args(i).idx_type_value (
true));
4618 dims.chop_trailing_singletons ();
4627 if (dims.ndims () > 2)
4628 error (
"%s: sparse ND arrays not supported", fcn);
4673 return fill_matrix (args, 1,
"ones");
4732DEFUN (zeros, args, ,
4760 return fill_matrix (args, 0,
"zeros");
5000 double e_val = exp (1.0);
5003 return fill_matrix (args, e_val,
"e");
5006template <
typename T>
5010 T epsval =
x.abs ();
5011 typedef typename T::value_type P;
5014 P val = epsval.xelem (i);
5015 if (math::isnan (val) || math::isinf (val))
5016 epsval(i) = numeric_limits<P>::NaN ();
5017 else if (val < std::numeric_limits<P>::min ())
5018 epsval(i) = std::numeric_limits<P>::denorm_min ();
5022 math::frexp (val, &exponent);
5023 const P digits = std::numeric_limits<P>::digits;
5024 epsval(i) = std::pow (
static_cast<P
> (2.0),
5025 static_cast<P
> (exponent - digits));
5068 if (args.
length () == 1 && ! args(0).is_string ())
5082 error (
"eps: X must be of a floating point type");
5085 retval = fill_matrix (args, std::numeric_limits<double>::epsilon (),
5086 std::numeric_limits<float>::epsilon (),
"eps");
5162 double pi_val = M_PI;
5164 double pi_val = 4.0 *
atan (1.0);
5167 return fill_matrix (args, pi_val,
"pi");
5170DEFUN (realmax, args, ,
5205 return fill_matrix (args, std::numeric_limits<double>::max (),
5206 std::numeric_limits<float>::max (),
"realmax");
5209DEFUN (realmin, args, ,
5244 return fill_matrix (args, std::numeric_limits<double>::min (),
5245 std::numeric_limits<float>::min (),
"realmin");
5286 return fill_matrix (args,
Complex (0.0, 1.0),
"I");
5333DEFUN (
false, args, ,
5352 return fill_matrix (args,
false,
"false");
5387 return fill_matrix (args,
true,
"true");
5403template <
typename MT>
5409 typename MT::element_type one (1);
5411 if (nr == 1 && nc == 1)
5417 typename MT::element_type zero (0);
5421 if (nr > 0 && nc > 0)
5423 int n = std::min (nr, nc);
5425 for (
int i = 0; i < n; i++)
5435#define INSTANTIATE_EYE(T) \
5436 template octave_value identity_matrix<T> (int, int)
5505 error (
"eye: invalid class name");
5512#undef INT_EYE_MATRIX
5564 int nargin = args.
length ();
5570 if (nargin > 0 && args(nargin-1).is_string ())
5572 std::string nm = args(nargin-1).string_value ();
5585 else if (nargin == 1)
5623template <
typename MT>
5628 typedef typename MT::column_vector_type CVT;
5629 typedef typename MT::element_type T;
5635 T bs = octave_value_extract<T> (base);
5638 T ls = octave_value_extract<T> (limit);
5643 CVT lv = octave_value_extract<CVT> (limit);
5644 CVT bv (lv.numel (), bs);
5650 CVT bv = octave_value_extract<CVT> (base);
5653 T ls = octave_value_extract<T> (limit);
5654 CVT lv (bv.numel (), ls);
5659 CVT lv = octave_value_extract<CVT> (limit);
5693 int nargin = args.
length ();
5695 if (nargin != 2 && nargin != 3)
5708 error (
"linspace: N must be a scalar");
5718 bool isvector1 = sz1.
ndims () == 2 && (sz1(0) == 1 || sz1(1) == 1);
5720 bool isvector2 = sz2.
ndims () == 2 && (sz2(0) == 1 || sz2(1) == 1);
5722 if (! isvector1 || ! isvector2)
5723 error (
"linspace: START, END must be scalars or vectors");
5730 retval = do_linspace<FloatComplexMatrix> (arg_1, arg_2, npoints);
5732 retval = do_linspace<FloatMatrix> (arg_1, arg_2, npoints);
5737 retval = do_linspace<ComplexMatrix> (arg_1, arg_2, npoints);
5739 retval = do_linspace<Matrix> (arg_1, arg_2, npoints);
5861DEFUN (resize, args, ,
5907 int nargin = args.
length ();
5917 int ndim = vec.
numel ();
5928 for (
int i = 0; i < ndim; i++)
5931 retval = retval.
resize (dv,
true);
5942 retval = retval.
resize (dv,
true);
5950DEFUN (reshape, args, ,
5984 int nargin = args.
length ();
5997 if (new_size.
numel () < 2)
5998 error (
"reshape: SIZE must have 2 or more dimensions");
6004 if (new_size(i) < 0)
6005 error (
"reshape: SIZE must be non-negative");
6007 new_dims(i) = new_size(i);
6015 for (
int i = 1; i < nargin; i++)
6017 if (args(i).isempty ())
6020 error (
"reshape: only a single dimension can be unknown");
6027 new_dims(i-1) = args(i).idx_type_value ();
6029 if (new_dims(i-1) < 0)
6030 error (
"reshape: SIZE must be non-negative");
6039 new_dims(empty_dim-1) = 0;
6045 if (a_nel != size_empty_dim * nel)
6046 error (
"reshape: SIZE is not divisible by the product of "
6047 "known dimensions (= %" OCTAVE_IDX_TYPE_FORMAT
")",
6050 new_dims(empty_dim-1) = size_empty_dim;
6055 retval = args(0).reshape (new_dims);
6101 int nargin = args.
length ();
6103 if (nargin < 1 || nargin > 2)
6109 dim = args(1).idx_type_value ();
6112 error (
"vec: DIM must be greater than zero");
6124 for (
int i = 0; i < dim-1; i++)
6127 new_dims(dim-1) = retval.
numel ();
6129 retval = retval.
reshape (new_dims);
6150DEFUN (squeeze, args, ,
6163 return ovl (args(0).squeeze ());
6177 return ovl (args(0).full_value ());
6243 int nargin = args.
length ();
6245 if (nargin < 1 || nargin > 3)
6250 if (x_arg.
ndims () != 2)
6251 error (
"norm: only valid for 2-D objects");
6253 enum {sfmatrix, sfcols, sfrows, sffrob, sfinf, sfneginf} strflag = sfmatrix;
6254 if (nargin > 1 && args(nargin-1).is_string ())
6256 std::string str = args(nargin-1).string_value ();
6257 std::transform (str.begin (), str.end (), str.begin (), tolower);
6258 if (str ==
"cols" || str ==
"columns")
6260 else if (str ==
"rows")
6262 else if (str ==
"fro")
6264 else if (str ==
"inf")
6266 else if (str ==
"-inf")
6269 error (
"norm: unrecognized option: %s", str.c_str ());
6282 std::transform (str.begin (), str.end (), str.begin (), tolower);
6283 if (strflag != sfcols && strflag != sfrows)
6284 error (
"norm: invalid combination of options");
6286 if (str ==
"cols" || str ==
"columns" || str ==
"rows")
6287 error (
"norm: invalid combination of options");
6291 else if (str ==
"inf")
6292 p_arg = numeric_limits<double>::Inf ();
6293 else if (str ==
"-inf")
6294 p_arg = -numeric_limits<double>::Inf ();
6296 error (
"norm: unrecognized option: %s", str.c_str ());
6306 retval =
xnorm (x_arg, p_arg);
6322 retval =
xnorm (x_arg, numeric_limits<double>::Inf ());
6326 retval =
xnorm (x_arg, -numeric_limits<double>::Inf ());
6444DEFUN (uplus, args, ,
6454DEFUN (uminus, args, ,
6464DEFUN (transpose, args, ,
6496DEFUN (ctranspose, args, ,
6535 return binary_op (op, args(0), args(1));
6543 int nargin = args.
length ();
6551 retval =
binary_op (op, args(0), args(1));
6554 retval =
binary_op (op, args(0), args(1));
6556 for (
int i = 2; i < nargin; i++)
6557 retval.
assign (aop, args(i));
6594DEFUN (minus, args, ,
6604DEFUN (mtimes, args, ,
6625DEFUN (mrdivide, args, ,
6640DEFUN (mpower, args, ,
6652DEFUN (mldivide, args, ,
6731DEFUN (times, args, ,
6752DEFUN (rdivide, args, ,
6764DEFUN (power, args, ,
6782DEFUN (ldivide, args, ,
6837DEFUN (colon, args, ,
6850 int nargin = args.
length ();
6852 if (nargin < 2 || nargin > 3)
6857 :
colon_op (args(0), args(1), args(2)));
6860static double tic_toc_timestamp = -1.0;
6862DEFUN (tic, args, nargout,
6915 warning (
"tic: ignoring extra arguments");
6924 double frac = std::modf (tmp, &ip);
6925 uint64_t microsecs =
static_cast<uint64_t
> (CLOCKS_PER_SEC * frac);
6926 microsecs += CLOCKS_PER_SEC *
static_cast<uint64_t
> (ip);
6930 tic_toc_timestamp = tmp;
6935DEFUN (toc, args, nargout,
6953 int nargin = args.
length ();
6958 double start_time = tic_toc_timestamp;
6962 octave_uint64 id = args(0).xuint64_scalar_value (
"toc: invalid ID");
6964 uint64_t val =
id.value ();
6967 = (
static_cast<double> (val / CLOCKS_PER_SEC)
6968 +
static_cast<double> (val % CLOCKS_PER_SEC)
6976 error (
"toc: function called before timer initialization with tic()");
6980 double etime = now.double_value () - start_time;
6986 octave_stdout <<
"Elapsed time is " << etime <<
" seconds.\n";
6998DEFUN (cputime, args, ,
7020 sys::cpu_time cpu_tm;
7022 double usr = cpu_tm.user ();
7023 double sys = cpu_tm.system ();
7025 return ovl (usr + sys, usr, sys);
7028DEFUN (sort, args, nargout,
7098 int nargin = args.
length ();
7100 if (nargin < 1 || nargin > 3)
7104 bool return_idx = (nargout > 1);
7105 bool have_sortmode = (nargin > 1 && args(1).is_string ());
7113 std::string mode = args(1).string_value ();
7114 if (mode ==
"ascend")
7116 else if (mode ==
"descend")
7119 error (R
"(sort: MODE must be either "ascend" or "descend")");
7124 if (! args(1).is_scalar_type () || args(1).iscomplex ()
7125 || args(1).double_value () <= 0)
7126 error (
"sort: DIM must be a positive scalar integer");
7129 dim = args(1).strict_int_value (
"sort: DIM must be a positive scalar integer") - 1;
7136 error (
"sort: DIM argument must precede MODE argument");
7138 std::string mode = args(2).xstring_value (
"sort: MODE must be a string");
7140 if (mode ==
"ascend")
7142 else if (mode ==
"descend")
7145 error (R
"(sort: MODE must be either "ascend" or "descend")");
7149 if (nargin == 1 || have_sortmode)
7162 retval(0) = arg.
sort (sidx, dim, smode);
7167 retval =
ovl (arg.
sort (dim, smode));
7425DEFUN (__sort_rows_idx__, args, ,
7431 int nargin = args.
length ();
7433 if (nargin < 1 || nargin > 2)
7436 if (nargin == 2 && ! args(1).is_string ())
7437 error (
"__sort_rows_idx__: second argument must be a string");
7442 std::string mode = args(1).string_value ();
7443 if (mode ==
"ascend")
7445 else if (mode ==
"descend")
7448 error (R
"(__sort_rows_idx__: MODE must be either "ascend" or "descend")");
7454 error (
"__sort_rows_idx__: sparse matrices not yet supported");
7456 if (arg.
ndims () != 2)
7457 error (
"__sort_rows_idx__: needs a 2-D object");
7473 std::string mode = arg.
xstring_value (
"issorted: MODE must be a string");
7475 if (mode ==
"ascend")
7477 else if (mode ==
"descend")
7479 else if (mode ==
"either" || mode ==
"monotonic")
7482 error (R
"(issorted: MODE must be "ascend", "descend", "monotonic", or "either")");
7487DEFUN (issorted, args, ,
7507 int nargin = args.
length ();
7509 if (nargin < 1 || nargin > 3)
7512 bool by_rows =
false;
7519 smode = get_sort_mode_option (args(2));
7521 std::string tmp = args(1).xstring_value (
"issorted: second argument must be a string");
7525 smode = get_sort_mode_option (args(1));
7537 error (
"issorted: sparse matrices not yet supported");
7539 if (arg.
ndims () != 2)
7540 error (
"issorted: A must be a 2-D object");
7547 error (
"issorted: needs a vector");
7549 retval = args(0).issorted (smode) !=
UNSORTED;
7624DEFUN (nth_element, args, ,
7648 int nargin = args.
length ();
7650 if (nargin < 2 || nargin > 3)
7656 dim = args(2).int_value (
true) - 1;
7658 error (
"nth_element: DIM must be a valid dimension");
7686#define MAKE_INT_BRANCH(X) \
7688 retval = argx.X ## _array_value ().nth_element (n, dim); \
7701#undef MAKE_INT_BRANCH
7712 error (
"nth_element: invalid index %s", ie.what ());
7733template <
typename NDT>
7735do_accumarray_sum (
const idx_vector& idx,
const NDT& vals,
7738 typedef typename NDT::element_type T;
7741 else if (idx.
extent (n) > n)
7742 error (
"accumarray: index out of range");
7746 if (vals.numel () == 1)
7747 retval.idx_add (idx, vals (0));
7748 else if (vals.numel () == idx.
length (n))
7749 retval.idx_add (idx, vals);
7751 error (
"accumarray: dimensions mismatch");
7756DEFUN (__accumarray_sum__, args, ,
7762 int nargin = args.
length ();
7764 if (nargin < 2 || nargin > 3)
7767 if (! args(0).isnumeric ())
7768 error (
"__accumarray_sum__: first argument must be numeric");
7777 n = args(2).idx_type_value (
true);
7784 if (r.increment () == 0)
7791 retval = do_accumarray_sum (idx,
7800 retval = do_accumarray_sum (idx,
7804 retval = do_accumarray_sum (idx, vals.
array_value (), n);
7811 error (
"__accumarray_sum__: invalid index %s", ie.what ());
7817template <
typename NDT>
7819do_accumarray_minmax (
const idx_vector& idx,
const NDT& vals,
7821 const typename NDT::element_type& zero_val)
7823 typedef typename NDT::element_type T;
7826 else if (idx.
extent (n) > n)
7827 error (
"accumarray: index out of range");
7833 = ismin ? (&
MArray<T>::idx_min) : (&
MArray<T>::idx_max);
7836 if (vals.numel () == 1)
7837 (retval.*op) (idx, NDT (
dim_vector (l, 1), vals(0)));
7838 else if (vals.numel () == l)
7839 (retval.*op) (idx, vals);
7841 error (
"accumarray: dimensions mismatch");
7850 int nargin = args.
length ();
7852 if (nargin < 3 || nargin > 4)
7855 if (! args(0).isnumeric ())
7856 error (
"accumarray: first argument must be numeric");
7865 n = args(3).idx_type_value (
true);
7873 retval = do_accumarray_minmax (idx, vals.
array_value (), n, ismin,
7888 retval = do_accumarray_minmax (idx,
7894#define MAKE_INT_BRANCH(X) \
7896 retval = do_accumarray_minmax (idx, vals.X ## _array_value (), \
7897 n, ismin, zero.X ## _scalar_value ()); \
7909#undef MAKE_INT_BRANCH
7912 retval = do_accumarray_minmax (idx, vals.
array_value (), n, ismin,
7922 error (
"do_accumarray_minmax_fcn: invalid index %s", ie.what ());
7928DEFUN (__accumarray_min__, args, ,
7934 return do_accumarray_minmax_fcn (args,
true);
7937DEFUN (__accumarray_max__, args, ,
7943 return do_accumarray_minmax_fcn (args,
false);
7946template <
typename NDT>
7948do_accumdim_sum (
const idx_vector& idx,
const NDT& vals,
7951 typedef typename NDT::element_type T;
7954 else if (idx.
extent (n) > n)
7955 error (
"accumdim: index out of range");
7961 dim = vals.dims ().first_non_singleton ();
7962 else if (dim >= rdv.
ndims ())
7967 NDT retval (rdv, T ());
7969 if (idx.
length () != vals_dim(dim))
7970 error (
"accumdim: dimension mismatch");
7972 retval.idx_add_nd (idx, vals, dim);
7977DEFUN (__accumdim_sum__, args, ,
7983 int nargin = args.
length ();
7985 if (nargin < 2 || nargin > 4)
7988 if (! args(0).isnumeric ())
7989 error (
"__accumdim_sum__: first argument must be numeric");
7998 dim = args(2).int_value () - 1;
8002 n = args(3).idx_type_value (
true);
8009 retval = do_accumdim_sum (idx,
8022 retval = do_accumdim_sum (idx, vals.
array_value (), dim, n);
8029 error (
"__accumdim_sum__: invalid index %s", ie.what ());
8035template <
typename NDT>
8038 const NDT& tval,
const NDT& fval)
8040 typedef typename NDT::element_type T;
8044 bool tscl = tval.numel () == 1;
8045 bool fscl = fval.numel () == 1;
8047 if ((! tscl && tval.dims () != dv) || (! fscl && fval.dims () != dv))
8048 error (
"merge: MASK, TVAL, and FVAL dimensions must match");
8050 T *rv = retval.rwdata ();
8053 const T *tv = tval.data ();
8054 const T *fv = fval.data ();
8055 const bool *mv = mask.
data ();
8064 rv[i] = (mv[i] ? ts : fs);
8070 rv[i] = (mv[i] ? ts : fv[i]);
8079 rv[i] = (mv[i] ? tv[i] : fs);
8084 rv[i] = (mv[i] ? tv[i] : fv[i]);
8091#define MAKE_INT_BRANCH(INTX) \
8092 else if (tval.is_ ## INTX ## _type () && fval.is_ ## INTX ## _type ()) \
8094 retval = do_merge (mask, \
8095 tval.INTX ## _array_value (), \
8096 fval.INTX ## _array_value ()); \
8099DEFUN (merge, args, ,
8134 if (! (args(0).islogical () || args(0).isnumeric ()))
8135 error (
"merge: first argument must be logical or numeric");
8142 retval = (mask_val.
is_true () ? args(1) : args(2));
8153 retval = do_merge (mask,
8157 retval = do_merge (mask,
8164 retval = do_merge (mask,
8168 retval = do_merge (mask,
8178 sq_string ?
'\'' :
'"');
8182 retval = do_merge (mask,
8197 error (
"merge: cannot merge %s with %s with array mask",
8207#undef MAKE_INT_BRANCH
8209template <
typename SparseT>
8214 SparseT retval = array;
8218 while (order > 0 && k > 0)
8220 idx_vector col1 (
':'), col2 (
':'), sl1 (1, k), sl2 (0, k-1);
8221 retval = SparseT (retval.index (col1, sl1))
8222 - SparseT (retval.index (col2, sl2));
8231 while (order > 0 && k > 0)
8233 idx_vector col1 (
':'), col2 (
':'), sl1 (1, k), sl2 (0, k-1);
8234 retval = SparseT (retval.index (sl1, col1))
8235 - SparseT (retval.index (sl2, col2));
8257 if (dv(dim) <= order)
8266 if (dim == dv.
ndims ())
8268 retval = do_diff (array, order, dim - 1);
8271 else if (dv(dim) == 1)
8275 retval = do_diff (array, dv(dim) - 1, dim);
8276 order -= dv(dim) - 1;
8305 error (
"diff: unexpected integer type - please report this bug");
8363 int nargin = args.
length ();
8365 if (nargin < 1 || nargin > 3)
8368 if (! (args(0).isnumeric () || args(0).islogical ()))
8369 error (
"diff: X must be numeric or logical");
8375 if (args(1).is_scalar_type ())
8376 order = args(1).idx_type_value (
true,
false);
8377 else if (! args(1).is_zero_by_zero ())
8378 error (
"diff: order K must be a scalar or []");
8380 error (
"diff: order K must be non-negative");
8385 dim = args(2).int_value (
true,
false);
8386 if (dim < 1 || dim > args(0).ndims ())
8387 error (
"diff: DIM must be a valid dimension");
8392 return do_diff (args(0), order, dim);
8408template <
typename T>
8414 if (rep.
ndims () != 2 || rep.
rows () != 2)
8415 error (
"repelems: R must be a 2-row, N-column matrix of integers");
8423 error (
"repelems: second row must contain non-negative numbers");
8428 retval.
clear (1, l);
8429 T *dest = retval.
rwdata ();
8434 std::fill_n (dest, k, src.
checkelem (rep(0, i) - 1));
8441DEFUN (repelems, args, ,
8472 const Matrix rm = args(1).matrix_value ();
8474 if (rm.
rows () != 2 || rm.
ndims () != 2)
8475 error (
"repelems: R must be a matrix with two rows");
8484 if (
static_cast<double> (rx) != rm(i))
8485 error (
"repelems: R must be a matrix of integers");
8490 switch (
x.builtin_type ())
8492#define BTYP_BRANCH(X, EX) \
8494 retval = do_repelems (x.EX ## _value (), r); \
8537 if (! args(0).isnumeric ())
8538 error (
"base64_encode: encoding is supported only for numeric arrays");
8540 if (args(0).iscomplex () || args(0).issparse ())
8541 error (
"base64_encode: encoding complex or sparse data is not supported");
8547#define MAKE_INT_BRANCH(X) \
8548 if (args(0).is_ ## X ## _type ()) \
8550 const X##NDArray in = args(0). X## _array_value (); \
8551 std::size_t inlen = in.numel () * sizeof (X## _t) / sizeof (char); \
8552 const char *inc = reinterpret_cast<const char *> (in.data ()); \
8554 if (base64_encode (inc, inlen, &out)) \
8556 retval(0) = octave_value (out); \
8570#undef MAKE_INT_BRANCH
8573 error (
"base_64_decode: unexpected integer type - please report this bug");
8575 else if (args(0).is_single_type ())
8579 inlen = in.
numel () *
sizeof (
float) /
sizeof (
char);
8581 inc =
reinterpret_cast<const char *
> (in.
data ());
8593 inlen = in.
numel () *
sizeof (
double) /
sizeof (
char);
8595 inc =
reinterpret_cast<const char *
> (in.
data ());
8642 int nargin = args.
length ();
8644 if (nargin < 1 || nargin > 2)
8647 std::string str = args(0).xstring_value (
"base64_decode: first argument must be a character array");
8656 = args(1).octave_idx_type_vector_value ();
8662 retval = retval.
reshape (dims);
8665 return ovl (retval);
8686DEFUN (__base64_decode_bytes__, args, ,
8698 int nargin = args.
length ();
8700 if (nargin < 1 || nargin > 2)
8703 std::string str = args(0).xstring_value (
"__base64_decode_bytes__: first argument must be a character array");
8712 = args(1).octave_idx_type_vector_value ();
8718 retval = retval.
reshape (dims);
8721 return ovl (retval);
8740OCTAVE_END_NAMESPACE(octave)
bool isvector(const dim_vector &dim)
ComplexMatrix linspace(const ComplexColumnVector &x1, const ComplexColumnVector &x2, octave_idx_type n)
ComplexNDArray concat(NDArray &ra, ComplexNDArray &rb, const Array< octave_idx_type > &ra_idx)
N Dimensional Array with copy-on-write semantics.
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 > 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.
octave_idx_type columns() const
Array< T, Alloc > reshape(octave_idx_type nr, octave_idx_type nc) const
Size of the specified dimension.
const T * data() const
Size of the specified dimension.
T * rwdata()
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
void resize(octave_idx_type nr, octave_idx_type nc, double rfv=0)
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.
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
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.
symbol_table & get_symbol_table()
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
Array< std::string > cellstr_value() const
bool is_int8_type() const
Complex complex_value(bool frc_str_conv=false) const
Array< octave_idx_type > sort_rows_idx(sortmode mode=ASCENDING) 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
double scalar_value(bool frc_str_conv=false) const
octave_idx_type numel() const
std::string string_value(bool force=false) const
octave_value & assign(assign_op op, const std::string &type, const std::list< octave_value_list > &idx, const octave_value &rhs)
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
octave_idx_type length() 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
octave::range< double > range_value() const
double double_value(bool frc_str_conv=false) const
SparseComplexMatrix sparse_complex_matrix_value(bool frc_str_conv=false) 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,...)
void err_wrong_type_arg(const char *name, const char *s)
void warn_implicit_conversion(const char *id, const char *from, const char *to)
std::string get_dispatch_type(const octave_value_list &args, builtin_type_t &builtin_type)
double norm(const ColumnVector &v)
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)
Complex atan(const Complex &x)
F77_RET_T const F77_DBLE * x
F77_RET_T const F77_DBLE const F77_DBLE * f
bool base64_encode(const char *inc, const std::size_t inlen, char **out)
intNDArray< octave_uint8 > base64_decode_bytes(const std::string &str)
Array< double > base64_decode(const std::string &str)
std::complex< double > Complex
std::complex< float > FloatComplex
octave_int< uint64_t > octave_uint64
#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
std::string btyp_class_name[btyp_num_types+1]
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.
#define panic_unless(cond)
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_arg)
void get_dimensions(const octave_value &a, const char *warn_for, dim_vector &dim)
void check_dimensions(dim_vector &dim, const char *warnfor)