44 template <
class ArrayType>
47 int nargout,
int dim,
bool ismin)
50 ArrayType array = octave_value_extract<ArrayType> (
arg);
60 retval(0) = array.min (idx, dim);
62 retval(0) = array.max (idx, dim);
69 retval(0) = array.min (dim);
71 retval(0) = array.max (dim);
88 int nargout,
int dim,
bool ismin)
122 int nargout,
int dim,
bool ismin)
134 retval(0) = array.
all (dim);
136 retval(0) = array.
any (dim);
141 retval = do_minmax_red_op<int8NDArray> (
arg, nargout, dim, ismin);
143 retval(0) = retval(0).bool_array_value ();
149 template <
class ArrayType>
154 typedef typename ArrayType::element_type ScalarType;
160 ScalarType
x = octave_value_extract<ScalarType> (argx);
161 ArrayType y = octave_value_extract<ArrayType> (argy);
172 ArrayType
x = octave_value_extract<ArrayType> (argx);
173 ScalarType y = octave_value_extract<ScalarType> (argy);
184 ArrayType
x = octave_value_extract<ArrayType> (argx);
185 ArrayType y = octave_value_extract<ArrayType> (argy);
222 else if (y.numel () == 1)
231 else if (y.numel () == 1)
242 int nargout,
bool ismin)
246 const char *func = ismin ?
"min" :
"max";
248 int nargin = args.
length ();
250 if (nargin == 3 || nargin == 1)
256 dim = args(2).int_value (
true) - 1;
259 error (
"%s: DIM must be a valid dimension", func);
263 if (! args(1).is_empty ())
264 warning (
"%s: second argument is ignored", func);
271 if (arg.
is_range () && (dim == -1 || dim == 1))
274 if (range.
nelem () < 1)
282 retval(0) = range.
min ();
284 retval(1) =
static_cast<double>
285 (range.
inc () < 0 ? range.
nelem () : 1);
289 retval(0) = range.
max ();
291 retval(1) =
static_cast<double>
292 (range.
inc () >= 0 ? range.
nelem () : 1);
296 retval = do_minmax_red_op<SparseMatrix> (arg, nargout, dim,
299 retval = do_minmax_red_op<NDArray> (
arg, nargout, dim, ismin);
305 retval = do_minmax_red_op<SparseComplexMatrix> (arg, nargout, dim,
308 retval = do_minmax_red_op<ComplexNDArray> (
arg, nargout, dim,
313 retval = do_minmax_red_op<FloatNDArray> (
arg, nargout, dim, ismin);
316 retval = do_minmax_red_op<FloatComplexNDArray> (
arg, nargout, dim,
322 #define MAKE_INT_BRANCH(X) \
324 retval = do_minmax_red_op<X ## NDArray> (arg, nargout, dim, ismin); \
334 #undef MAKE_INT_BRANCH
342 else if (nargin == 2)
366 retval = do_minmax_bin_op<SparseMatrix> (argx, argy, ismin);
368 retval = do_minmax_bin_op<NDArray> (argx, argy, ismin);
376 retval = do_minmax_bin_op<SparseComplexMatrix> (argx, argy,
379 retval = do_minmax_bin_op<ComplexNDArray> (argx, argy, ismin);
383 retval = do_minmax_bin_op<FloatNDArray> (argx, argy, ismin);
386 retval = do_minmax_bin_op<FloatComplexNDArray> (argx, argy, ismin);
391 #define MAKE_INT_BRANCH(X) \
393 retval = do_minmax_bin_op<X ## NDArray> (argx, argy, ismin); \
403 #undef MAKE_INT_BRANCH
411 error (
"%s: cannot compute %s (%s, %s)", func, func,
412 argx.type_name ().c_str (), argy.type_name ().c_str ());
417 retval(0) = retval(0).bool_array_value ();
428 @deftypefn {Built-in Function} {} min (@var{x})\n\
429 @deftypefnx {Built-in Function} {} min (@var{x}, [], @var{dim})\n\
430 @deftypefnx {Built-in Function} {[@var{w}, @var{iw}] =} min (@var{x})\n\
431 @deftypefnx {Built-in Function} {} min (@var{x}, @var{y})\n\
432 Find minimum values in the array @var{x}.\n\
434 For a vector argument, return the minimum value. For a matrix argument,\n\
435 return a row vector with the minimum value of each column. For a\n\
436 multi-dimensional array, @code{min} operates along the first non-singleton\n\
439 If the optional third argument @var{dim} is present then operate along\n\
440 this dimension. In this case the second argument is ignored and should be\n\
441 set to the empty matrix.\n\
443 For two matrices (or a matrix and a scalar), return the pairwise minimum.\n\
448 min (min (@var{x}))\n\
452 returns the smallest element of the 2-D matrix @var{x}, and\n\
457 @result{} 2.0000 3.0000 3.1416 3.1416\n\
462 compares each element of the range @code{2:5} with @code{pi}, and returns a\n\
463 row vector of the minimum values.\n\
465 For complex arguments, the magnitude of the elements are used for\n\
466 comparison. If the magnitudes are identical, then the results are ordered\n\
467 by phase angle in the range (-pi, pi]. Hence,\n\
477 because all entries have magnitude 1, but -i has the smallest phase angle\n\
480 If called with one input and two output arguments, @code{min} also returns\n\
481 the first index of the minimum value(s). Thus,\n\
485 [x, ix] = min ([1, 3, 0, 2, 0])\n\
490 @seealso{max, cummin, cummax}\n\
649 @deftypefn {Built-in Function} {} max (@var{x})\n\
650 @deftypefnx {Built-in Function} {} max (@var{x}, [], @var{dim})\n\
651 @deftypefnx {Built-in Function} {[@var{w}, @var{iw}] =} max (@var{x})\n\
652 @deftypefnx {Built-in Function} {} max (@var{x}, @var{y})\n\
653 Find maximum values in the array @var{x}.\n\
655 For a vector argument, return the maximum value. For a matrix argument,\n\
656 return a row vector with the maximum value of each column. For a\n\
657 multi-dimensional array, @code{max} operates along the first non-singleton\n\
660 If the optional third argument @var{dim} is present then operate along\n\
661 this dimension. In this case the second argument is ignored and should be\n\
662 set to the empty matrix.\n\
664 For two matrices (or a matrix and a scalar), return the pairwise maximum.\n\
669 max (max (@var{x}))\n\
673 returns the largest element of the 2-D matrix @var{x}, and\n\
678 @result{} 3.1416 3.1416 4.0000 5.0000\n\
683 compares each element of the range @code{2:5} with @code{pi}, and returns a\n\
684 row vector of the maximum values.\n\
686 For complex arguments, the magnitude of the elements are used for\n\
687 comparison. If the magnitudes are identical, then the results are ordered\n\
688 by phase angle in the range (-pi, pi]. Hence,\n\
698 because all entries have magnitude 1, but -1 has the largest phase angle\n\
701 If called with one input and two output arguments, @code{max} also returns\n\
702 the first index of the maximum value(s). Thus,\n\
706 [x, ix] = max ([1, 3, 5, 2, 5])\n\
711 @seealso{min, cummax, cummin}\n\
871 template <
class ArrayType>
874 int nargout,
int dim,
bool ismin)
877 ArrayType array = octave_value_extract<ArrayType> (
arg);
887 retval(0) = array.cummin (idx, dim);
889 retval(0) = array.cummax (idx, dim);
896 retval(0) = array.cummin (dim);
898 retval(0) = array.cummax (dim);
906 int nargout,
bool ismin)
910 const char *func = ismin ?
"cummin" :
"cummax";
912 int nargin = args.
length ();
914 if (nargin == 1 || nargin == 2)
920 dim = args(1).int_value (
true) - 1;
923 error (
"%s: DIM must be a valid dimension", func);
931 retval = do_cumminmax_red_op<NDArray> (
arg, nargout, dim, ismin);
934 retval = do_cumminmax_red_op<ComplexNDArray> (
arg, nargout, dim,
938 retval = do_cumminmax_red_op<FloatNDArray> (
arg, nargout, dim, ismin);
941 retval = do_cumminmax_red_op<FloatComplexNDArray> (
arg, nargout, dim,
944 #define MAKE_INT_BRANCH(X) \
946 retval = do_cumminmax_red_op<X ## NDArray> (arg, nargout, dim, \
957 #undef MAKE_INT_BRANCH
960 retval = do_cumminmax_red_op<int8NDArray> (
arg, nargout, dim,
963 retval(0) = retval(0).bool_array_value ();
976 DEFUN (cummin, args, nargout,
978 @deftypefn {Built-in Function} {} cummin (@var{x})\n\
979 @deftypefnx {Built-in Function} {} cummin (@var{x}, @var{dim})\n\
980 @deftypefnx {Built-in Function} {[@var{w}, @var{iw}] =} cummin (@var{x})\n\
981 Return the cumulative minimum values along dimension @var{dim}.\n\
983 If @var{dim} is unspecified it defaults to column-wise operation. For\n\
988 cummin ([5 4 6 2 3 1])\n\
989 @result{} 5 4 4 2 2 1\n\
993 If called with two output arguments the index of the minimum value is also\n\
998 [w, iw] = cummin ([5 4 6 2 3 1])\n\
1005 @seealso{cummax, min, max}\n\
1032 DEFUN (cummax, args, nargout,
1034 @deftypefn {Built-in Function} {} cummax (@var{x})\n\
1035 @deftypefnx {Built-in Function} {} cummax (@var{x}, @var{dim})\n\
1036 @deftypefnx {Built-in Function} {[@var{w}, @var{iw}] =} cummax (@dots{})\n\
1037 Return the cumulative maximum values along dimension @var{dim}.\n\
1039 If @var{dim} is unspecified it defaults to column-wise operation. For\n\
1044 cummax ([1 3 2 6 4 5])\n\
1045 @result{} 1 3 3 6 6 6\n\
1049 If called with two output arguments the index of the maximum value is also\n\
1054 [w, iw] = cummax ([1 3 2 6 4 5])\n\
1061 @seealso{cummin, max, min}\n\
boolNDArray all(int dim=-1) const
charNDArray max(int dim=-1) const
bool is_empty(void) const
bool is_range(void) const
void gripe_wrong_type_arg(const char *name, const char *s, bool is_error)
OCTINTERP_API void print_usage(void)
octave_idx_type numel(void) const
Number of elements in the array.
octave_idx_type length(void) const
octave_idx_type nelem(void) const
bool is_scalar_type(void) const
#define DEFUN(name, args_name, nargout_name, doc)
void error(const char *fmt,...)
boolNDArray any(int dim=-1) const
static octave_value_list do_cumminmax_body(const octave_value_list &args, int nargout, bool ismin)
octave_value_list do_minmax_red_op< boolNDArray >(const octave_value &arg, int nargout, int dim, bool ismin)
builtin_type_t btyp_mixed_numeric(builtin_type_t x, builtin_type_t y)
bool is_sparse_type(void) const
Range range_value(void) const
static octave_value_list do_minmax_body(const octave_value_list &args, int nargout, bool ismin)
static octave_value_list do_cumminmax_red_op(const octave_value &arg, int nargout, int dim, bool ismin)
static octave_value do_minmax_bin_op(const octave_value &argx, const octave_value &argy, bool ismin)
charNDArray octave_value_extract< charNDArray >(const octave_value &v)
static octave_value_list do_minmax_red_op(const octave_value &arg, int nargout, int dim, bool ismin)
#define MAKE_INT_BRANCH(X)
void warning(const char *fmt,...)
charNDArray max(char d, const charNDArray &m)
charNDArray min(int dim=-1) const
void resize(octave_idx_type n, const octave_value &rfv=octave_value())
octave_value do_minmax_bin_op< charNDArray >(const octave_value &argx, const octave_value &argy, bool ismin)
builtin_type_t builtin_type(void) const
octave_value_list do_minmax_red_op< charNDArray >(const octave_value &arg, int nargout, int dim, bool ismin)
return octave_value(v1.char_array_value().concat(v2.char_array_value(), ra_idx),((a1.is_sq_string()||a2.is_sq_string())? '\'': '"'))
F77_RET_T const double * x
charNDArray min(char d, const charNDArray &m)