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);
213 if (argx.is_scalar_type () == 1)
225 else if (argy.is_scalar_type () == 1)
255 int nargout,
bool ismin)
259 const char *func = ismin ?
"min" :
"max";
261 int nargin = args.
length ();
263 if (nargin == 3 || nargin == 1)
269 dim = args(2).int_value (
true) - 1;
272 error (
"%s: DIM must be a valid dimension", func);
276 if (! args(1).is_empty ())
277 warning (
"%s: second argument is ignored", func);
284 if (arg.
is_range () && (dim == -1 || dim == 1))
287 if (range.
nelem () == 0)
295 retval(0) = range.
min ();
297 retval(1) =
static_cast<double>
298 (range.
inc () < 0 ? range.
nelem () : 1);
302 retval(0) = range.
max ();
304 retval(1) =
static_cast<double>
305 (range.
inc () >= 0 ? range.
nelem () : 1);
309 retval = do_minmax_red_op<SparseMatrix> (arg, nargout, dim,
312 retval = do_minmax_red_op<NDArray> (
arg, nargout, dim, ismin);
318 retval = do_minmax_red_op<SparseComplexMatrix> (arg, nargout, dim,
321 retval = do_minmax_red_op<ComplexNDArray> (
arg, nargout, dim,
326 retval = do_minmax_red_op<FloatNDArray> (
arg, nargout, dim, ismin);
329 retval = do_minmax_red_op<FloatComplexNDArray> (
arg, nargout, dim,
335 #define MAKE_INT_BRANCH(X) \
337 retval = do_minmax_red_op<X ## NDArray> (arg, nargout, dim, ismin); \
347 #undef MAKE_INT_BRANCH
355 else if (nargin == 2)
370 && (argy.is_sparse_type () || argy.is_scalar_type ()))
372 retval = do_minmax_bin_op<SparseMatrix> (argx, argy, ismin);
374 retval = do_minmax_bin_op<NDArray> (argx, argy, ismin);
380 && (argy.is_sparse_type () || argy.is_scalar_type ()))
382 retval = do_minmax_bin_op<SparseComplexMatrix> (argx, argy,
385 retval = do_minmax_bin_op<ComplexNDArray> (argx, argy, ismin);
389 retval = do_minmax_bin_op<FloatNDArray> (argx, argy, ismin);
392 retval = do_minmax_bin_op<FloatComplexNDArray> (argx, argy, ismin);
397 #define MAKE_INT_BRANCH(X) \
399 retval = do_minmax_bin_op<X ## NDArray> (argx, argy, ismin); \
409 #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 ());
423 @deftypefn {Built-in Function} {} min (@var{x})\n\
424 @deftypefnx {Built-in Function} {} min (@var{x}, @var{y})\n\
425 @deftypefnx {Built-in Function} {} min (@var{x}, [], @var{dim})\n\
426 @deftypefnx {Built-in Function} {} min (@var{x}, @var{y}, @var{dim})\n\
427 @deftypefnx {Built-in Function} {[@var{w}, @var{iw}] =} min (@var{x})\n\
428 For a vector argument, return the minimum value. For a matrix\n\
429 argument, return the minimum value from each column, as a row\n\
430 vector, or over the dimension @var{dim} if defined, in which case @var{y} \n\
431 should be set to the empty matrix (it's ignored otherwise). For two matrices\n\
432 (or a matrix and scalar), return the pair-wise minimum.\n\
436 min (min (@var{x}))\n\
440 returns the smallest element of @var{x}, and\n\
445 @result{} 2.0000 3.0000 3.1416 3.1416\n\
450 compares each element of the range @code{2:5} with @code{pi}, and\n\
451 returns a row vector of the minimum values.\n\
453 For complex arguments, the magnitude of the elements are used for\n\
456 If called with one input and two output arguments,\n\
457 @code{min} also returns the first index of the\n\
458 minimum value(s). Thus,\n\
462 [x, ix] = min ([1, 3, 0, 2, 0])\n\
467 @seealso{max, cummin, cummax}\n\
498 @deftypefn {Built-in Function} {} max (@var{x})\n\
499 @deftypefnx {Built-in Function} {} max (@var{x}, @var{y})\n\
500 @deftypefnx {Built-in Function} {} max (@var{x}, [], @var{dim})\n\
501 @deftypefnx {Built-in Function} {} max (@var{x}, @var{y}, @var{dim})\n\
502 @deftypefnx {Built-in Function} {[@var{w}, @var{iw}] =} max (@var{x})\n\
503 For a vector argument, return the maximum value. For a matrix\n\
504 argument, return the maximum value from each column, as a row\n\
505 vector, or over the dimension @var{dim} if defined, in which case @var{y} \n\
506 should be set to the empty matrix (it's ignored otherwise). For two matrices\n\
507 (or a matrix and scalar), return the pair-wise maximum.\n\
511 max (max (@var{x}))\n\
515 returns the largest element of the matrix @var{x}, and\n\
520 @result{} 3.1416 3.1416 4.0000 5.0000\n\
525 compares each element of the range @code{2:5} with @code{pi}, and\n\
526 returns a row vector of the maximum values.\n\
528 For complex arguments, the magnitude of the elements are used for\n\
531 If called with one input and two output arguments,\n\
532 @code{max} also returns the first index of the\n\
533 maximum value(s). Thus,\n\
537 [x, ix] = max ([1, 3, 5, 2, 5])\n\
542 @seealso{min, cummax, cummin}\n\
567 template <
class ArrayType>
570 int nargout,
int dim,
bool ismin)
573 ArrayType array = octave_value_extract<ArrayType> (
arg);
583 retval(0) = array.cummin (idx, dim);
585 retval(0) = array.cummax (idx, dim);
592 retval(0) = array.cummin (dim);
594 retval(0) = array.cummax (dim);
602 int nargout,
bool ismin)
606 const char *func = ismin ?
"cummin" :
"cummax";
608 int nargin = args.
length ();
610 if (nargin == 1 || nargin == 2)
616 dim = args(1).int_value (
true) - 1;
619 error (
"%s: DIM must be a valid dimension", func);
627 retval = do_cumminmax_red_op<NDArray> (
arg, nargout, dim, ismin);
630 retval = do_cumminmax_red_op<ComplexNDArray> (
arg, nargout, dim,
634 retval = do_cumminmax_red_op<FloatNDArray> (
arg, nargout, dim, ismin);
637 retval = do_cumminmax_red_op<FloatComplexNDArray> (
arg, nargout, dim,
640 #define MAKE_INT_BRANCH(X) \
642 retval = do_cumminmax_red_op<X ## NDArray> (arg, nargout, dim, \
653 #undef MAKE_INT_BRANCH
656 retval = do_cumminmax_red_op<int8NDArray> (
arg, nargout, dim,
659 retval(0) = retval(0).bool_array_value ();
672 DEFUN (cummin, args, nargout,
674 @deftypefn {Built-in Function} {} cummin (@var{x})\n\
675 @deftypefnx {Built-in Function} {} cummin (@var{x}, @var{dim})\n\
676 @deftypefnx {Built-in Function} {[@var{w}, @var{iw}] =} cummin (@var{x})\n\
677 Return the cumulative minimum values along dimension @var{dim}.\n\
679 If @var{dim} is unspecified it defaults to column-wise operation. For\n\
684 cummin ([5 4 6 2 3 1])\n\
685 @result{} 5 4 4 2 2 1\n\
689 If called with two output arguments the index of the minimum value is also\n\
694 [w, iw] = cummin ([5 4 6 2 3 1])\n\
701 @seealso{cummax, min, max}\n\
726 DEFUN (cummax, args, nargout,
728 @deftypefn {Built-in Function} {} cummax (@var{x})\n\
729 @deftypefnx {Built-in Function} {} cummax (@var{x}, @var{dim})\n\
730 @deftypefnx {Built-in Function} {[@var{w}, @var{iw}] =} cummax (@dots{})\n\
731 Return the cumulative maximum values along dimension @var{dim}.\n\
733 If @var{dim} is unspecified it defaults to column-wise operation. For\n\
738 cummax ([1 3 2 6 4 5])\n\
739 @result{} 1 3 3 6 6 6\n\
743 If called with two output arguments the index of the maximum value is also\n\
748 [w, iw] = cummax ([1 3 2 6 4 5])\n\
755 @seealso{cummin, max, min}\n\