annotate libinterp/corefcn/max.cc @ 31605:e88a07dec498 stable

maint: Use macros to begin/end C++ namespaces. * oct-conf-post-public.in.h: Define two macros (OCTAVE_BEGIN_NAMESPACE, OCTAVE_END_NAMESPACE) that can be used to start/end a namespace. * mk-opts.pl, build-env.h, build-env.in.cc, __betainc__.cc, __contourc__.cc, __dsearchn__.cc, __eigs__.cc, __expint__.cc, __ftp__.cc, __gammainc__.cc, __ichol__.cc, __ilu__.cc, __isprimelarge__.cc, __lin_interpn__.cc, __magick_read__.cc, __pchip_deriv__.cc, __qp__.cc, amd.cc, auto-shlib.cc, auto-shlib.h, balance.cc, base-text-renderer.cc, base-text-renderer.h, besselj.cc, bitfcns.cc, bsxfun.cc, c-file-ptr-stream.cc, c-file-ptr-stream.h, call-stack.cc, call-stack.h, ccolamd.cc, cellfun.cc, chol.cc, colamd.cc, colloc.cc, conv2.cc, daspk.cc, dasrt.cc, dassl.cc, data.cc, data.h, debug.cc, defaults.cc, defaults.h, defun-int.h, defun.cc, det.cc, dirfns.cc, display.cc, display.h, dlmread.cc, dmperm.cc, dot.cc, dynamic-ld.cc, dynamic-ld.h, eig.cc, ellipj.cc, environment.cc, environment.h, error.cc, error.h, errwarn.h, event-manager.cc, event-manager.h, event-queue.cc, event-queue.h, fcn-info.cc, fcn-info.h, fft.cc, fft2.cc, fftn.cc, file-io.cc, filter.cc, find.cc, ft-text-renderer.cc, ft-text-renderer.h, gcd.cc, getgrent.cc, getpwent.cc, getrusage.cc, givens.cc, gl-render.cc, gl-render.h, gl2ps-print.cc, gl2ps-print.h, graphics-toolkit.cc, graphics-toolkit.h, graphics.cc, graphics.in.h, gsvd.cc, gtk-manager.cc, gtk-manager.h, hash.cc, help.cc, help.h, hess.cc, hex2num.cc, hook-fcn.cc, hook-fcn.h, input.cc, input.h, interpreter-private.cc, interpreter-private.h, interpreter.cc, interpreter.h, inv.cc, jsondecode.cc, jsonencode.cc, kron.cc, latex-text-renderer.cc, latex-text-renderer.h, load-path.cc, load-path.h, load-save.cc, load-save.h, lookup.cc, ls-ascii-helper.cc, ls-ascii-helper.h, ls-oct-text.cc, ls-utils.cc, ls-utils.h, lsode.cc, lu.cc, mappers.cc, matrix_type.cc, max.cc, mex-private.h, mex.cc, mgorth.cc, nproc.cc, oct-fstrm.cc, oct-fstrm.h, oct-hdf5-types.cc, oct-hdf5-types.h, oct-hist.cc, oct-hist.h, oct-iostrm.cc, oct-iostrm.h, oct-opengl.h, oct-prcstrm.cc, oct-prcstrm.h, oct-procbuf.cc, oct-procbuf.h, oct-process.cc, oct-process.h, oct-stdstrm.h, oct-stream.cc, oct-stream.h, oct-strstrm.cc, oct-strstrm.h, oct-tex-lexer.in.ll, oct-tex-parser.yy, ordqz.cc, ordschur.cc, pager.cc, pager.h, pinv.cc, pow2.cc, pr-flt-fmt.cc, pr-output.cc, procstream.cc, procstream.h, psi.cc, qr.cc, quad.cc, quadcc.cc, qz.cc, rand.cc, rcond.cc, regexp.cc, schur.cc, settings.cc, settings.h, sighandlers.cc, sighandlers.h, sparse-xdiv.cc, sparse-xdiv.h, sparse-xpow.cc, sparse-xpow.h, sparse.cc, spparms.cc, sqrtm.cc, stack-frame.cc, stack-frame.h, stream-euler.cc, strfind.cc, strfns.cc, sub2ind.cc, svd.cc, sylvester.cc, symbfact.cc, syminfo.cc, syminfo.h, symrcm.cc, symrec.cc, symrec.h, symscope.cc, symscope.h, symtab.cc, symtab.h, syscalls.cc, sysdep.cc, sysdep.h, text-engine.cc, text-engine.h, text-renderer.cc, text-renderer.h, time.cc, toplev.cc, tril.cc, tsearch.cc, typecast.cc, url-handle-manager.cc, url-handle-manager.h, urlwrite.cc, utils.cc, utils.h, variables.cc, variables.h, xdiv.cc, xdiv.h, xnorm.cc, xnorm.h, xpow.cc, xpow.h, __delaunayn__.cc, __fltk_uigetfile__.cc, __glpk__.cc, __init_fltk__.cc, __init_gnuplot__.cc, __ode15__.cc, __voronoi__.cc, audiodevinfo.cc, audioread.cc, convhulln.cc, fftw.cc, gzip.cc, mk-build-env-features.sh, mk-builtins.pl, cdef-class.cc, cdef-class.h, cdef-fwd.h, cdef-manager.cc, cdef-manager.h, cdef-method.cc, cdef-method.h, cdef-object.cc, cdef-object.h, cdef-package.cc, cdef-package.h, cdef-property.cc, cdef-property.h, cdef-utils.cc, cdef-utils.h, ov-base.cc, ov-base.h, ov-bool-mat.cc, ov-builtin.h, ov-cell.cc, ov-class.cc, ov-class.h, ov-classdef.cc, ov-classdef.h, ov-complex.cc, ov-fcn-handle.cc, ov-fcn-handle.h, ov-fcn.h, ov-java.cc, ov-java.h, ov-mex-fcn.h, ov-null-mat.cc, ov-oncleanup.cc, ov-struct.cc, ov-typeinfo.cc, ov-typeinfo.h, ov-usr-fcn.cc, ov-usr-fcn.h, ov.cc, ov.h, octave.cc, octave.h, mk-ops.sh, op-b-b.cc, op-b-bm.cc, op-b-sbm.cc, op-bm-b.cc, op-bm-bm.cc, op-bm-sbm.cc, op-cdm-cdm.cc, op-cell.cc, op-chm.cc, op-class.cc, op-cm-cm.cc, op-cm-cs.cc, op-cm-m.cc, op-cm-s.cc, op-cm-scm.cc, op-cm-sm.cc, op-cs-cm.cc, op-cs-cs.cc, op-cs-m.cc, op-cs-s.cc, op-cs-scm.cc, op-cs-sm.cc, op-dm-dm.cc, op-dm-scm.cc, op-dm-sm.cc, op-dm-template.cc, op-dms-template.cc, op-fcdm-fcdm.cc, op-fcm-fcm.cc, op-fcm-fcs.cc, op-fcm-fm.cc, op-fcm-fs.cc, op-fcn.cc, op-fcs-fcm.cc, op-fcs-fcs.cc, op-fcs-fm.cc, op-fcs-fs.cc, op-fdm-fdm.cc, op-fm-fcm.cc, op-fm-fcs.cc, op-fm-fm.cc, op-fm-fs.cc, op-fs-fcm.cc, op-fs-fcs.cc, op-fs-fm.cc, op-fs-fs.cc, op-i16-i16.cc, op-i32-i32.cc, op-i64-i64.cc, op-i8-i8.cc, op-int-concat.cc, op-m-cm.cc, op-m-cs.cc, op-m-m.cc, op-m-s.cc, op-m-scm.cc, op-m-sm.cc, op-mi.cc, op-pm-pm.cc, op-pm-scm.cc, op-pm-sm.cc, op-pm-template.cc, op-range.cc, op-s-cm.cc, op-s-cs.cc, op-s-m.cc, op-s-s.cc, op-s-scm.cc, op-s-sm.cc, op-sbm-b.cc, op-sbm-bm.cc, op-sbm-sbm.cc, op-scm-cm.cc, op-scm-cs.cc, op-scm-m.cc, op-scm-s.cc, op-scm-scm.cc, op-scm-sm.cc, op-sm-cm.cc, op-sm-cs.cc, op-sm-m.cc, op-sm-s.cc, op-sm-scm.cc, op-sm-sm.cc, op-str-m.cc, op-str-s.cc, op-str-str.cc, op-struct.cc, op-ui16-ui16.cc, op-ui32-ui32.cc, op-ui64-ui64.cc, op-ui8-ui8.cc, ops.h, anon-fcn-validator.cc, anon-fcn-validator.h, bp-table.cc, bp-table.h, comment-list.cc, comment-list.h, filepos.h, lex.h, lex.ll, oct-lvalue.cc, oct-lvalue.h, oct-parse.yy, parse.h, profiler.cc, profiler.h, pt-anon-scopes.cc, pt-anon-scopes.h, pt-arg-list.cc, pt-arg-list.h, pt-args-block.cc, pt-args-block.h, pt-array-list.cc, pt-array-list.h, pt-assign.cc, pt-assign.h, pt-binop.cc, pt-binop.h, pt-bp.cc, pt-bp.h, pt-cbinop.cc, pt-cbinop.h, pt-cell.cc, pt-cell.h, pt-check.cc, pt-check.h, pt-classdef.cc, pt-classdef.h, pt-cmd.h, pt-colon.cc, pt-colon.h, pt-const.cc, pt-const.h, pt-decl.cc, pt-decl.h, pt-eval.cc, pt-eval.h, pt-except.cc, pt-except.h, pt-exp.cc, pt-exp.h, pt-fcn-handle.cc, pt-fcn-handle.h, pt-id.cc, pt-id.h, pt-idx.cc, pt-idx.h, pt-jump.h, pt-loop.cc, pt-loop.h, pt-mat.cc, pt-mat.h, pt-misc.cc, pt-misc.h, pt-pr-code.cc, pt-pr-code.h, pt-select.cc, pt-select.h, pt-spmd.cc, pt-spmd.h, pt-stmt.cc, pt-stmt.h, pt-tm-const.cc, pt-tm-const.h, pt-unop.cc, pt-unop.h, pt-vm-eval.cc, pt-walk.cc, pt-walk.h, pt.cc, pt.h, token.cc, token.h, Range.cc, Range.h, idx-vector.cc, idx-vector.h, range-fwd.h, CollocWt.cc, CollocWt.h, aepbalance.cc, aepbalance.h, chol.cc, chol.h, gepbalance.cc, gepbalance.h, gsvd.cc, gsvd.h, hess.cc, hess.h, lo-mappers.cc, lo-mappers.h, lo-specfun.cc, lo-specfun.h, lu.cc, lu.h, oct-convn.cc, oct-convn.h, oct-fftw.cc, oct-fftw.h, oct-norm.cc, oct-norm.h, oct-rand.cc, oct-rand.h, oct-spparms.cc, oct-spparms.h, qr.cc, qr.h, qrp.cc, qrp.h, randgamma.cc, randgamma.h, randmtzig.cc, randmtzig.h, randpoisson.cc, randpoisson.h, schur.cc, schur.h, sparse-chol.cc, sparse-chol.h, sparse-lu.cc, sparse-lu.h, sparse-qr.cc, sparse-qr.h, svd.cc, svd.h, child-list.cc, child-list.h, dir-ops.cc, dir-ops.h, file-ops.cc, file-ops.h, file-stat.cc, file-stat.h, lo-sysdep.cc, lo-sysdep.h, lo-sysinfo.cc, lo-sysinfo.h, mach-info.cc, mach-info.h, oct-env.cc, oct-env.h, oct-group.cc, oct-group.h, oct-password.cc, oct-password.h, oct-syscalls.cc, oct-syscalls.h, oct-time.cc, oct-time.h, oct-uname.cc, oct-uname.h, action-container.cc, action-container.h, base-list.h, cmd-edit.cc, cmd-edit.h, cmd-hist.cc, cmd-hist.h, f77-fcn.h, file-info.cc, file-info.h, lo-array-errwarn.cc, lo-array-errwarn.h, lo-hash.cc, lo-hash.h, lo-ieee.h, lo-regexp.cc, lo-regexp.h, lo-utils.cc, lo-utils.h, oct-base64.cc, oct-base64.h, oct-glob.cc, oct-glob.h, oct-inttypes.h, oct-mutex.cc, oct-mutex.h, oct-refcount.h, oct-shlib.cc, oct-shlib.h, oct-sparse.cc, oct-sparse.h, oct-string.h, octave-preserve-stream-state.h, pathsearch.cc, pathsearch.h, quit.cc, quit.h, unwind-prot.cc, unwind-prot.h, url-transfer.cc, url-transfer.h : Use new macros to begin/end C++ namespaces.
author Rik <rik@octave.org>
date Thu, 01 Dec 2022 14:23:45 -0800
parents c9788d7f6e65
children aac27ad79be6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
1 ////////////////////////////////////////////////////////////////////////
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
2 //
30564
796f54d4ddbf update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
3 // Copyright (C) 1996-2022 The Octave Project Developers
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
4 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
5 // See the file COPYRIGHT.md in the top-level directory of this
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
6 // distribution or <https://octave.org/copyright/>.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
7 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
8 // This file is part of Octave.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
9 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
10 // Octave is free software: you can redistribute it and/or modify it
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
11 // under the terms of the GNU General Public License as published by
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
12 // the Free Software Foundation, either version 3 of the License, or
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
13 // (at your option) any later version.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
14 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
15 // Octave is distributed in the hope that it will be useful, but
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
18 // GNU General Public License for more details.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
19 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
20 // You should have received a copy of the GNU General Public License
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
21 // along with Octave; see the file COPYING. If not, see
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
22 // <https://www.gnu.org/licenses/>.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
23 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
24 ////////////////////////////////////////////////////////////////////////
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
25
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21604
diff changeset
26 #if defined (HAVE_CONFIG_H)
21301
40de9f8f23a6 Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents: 21265
diff changeset
27 # include "config.h"
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
28 #endif
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
29
23662
bd77ab816e43 eliminate obsolete file lo-math.h
John W. Eaton <jwe@octave.org>
parents: 23583
diff changeset
30 #include <cmath>
bd77ab816e43 eliminate obsolete file lo-math.h
John W. Eaton <jwe@octave.org>
parents: 23583
diff changeset
31
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
32 #include "lo-ieee.h"
3248
68259f410026 [project @ 1999-07-13 03:34:54 by jwe]
jwe
parents: 3243
diff changeset
33 #include "lo-mappers.h"
4844
9f7ef92b50b0 [project @ 2004-04-02 17:26:53 by jwe]
jwe
parents: 4522
diff changeset
34 #include "dNDArray.h"
9f7ef92b50b0 [project @ 2004-04-02 17:26:53 by jwe]
jwe
parents: 4522
diff changeset
35 #include "CNDArray.h"
4153
6b96ce9f5743 [project @ 2002-11-06 20:38:49 by jwe]
jwe
parents: 4102
diff changeset
36 #include "quit.h"
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
37
15039
e753177cde93 maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents: 14501
diff changeset
38 #include "defun.h"
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
39 #include "error.h"
21100
e39e05d90788 Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents: 20946
diff changeset
40 #include "errwarn.h"
20940
48b2ad5ee801 maint: Rename oct-obj.[cc|h] to ovl.[cc|h] for clarity.
Rik <rik@octave.org>
parents: 20921
diff changeset
41 #include "ovl.h"
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
42
4844
9f7ef92b50b0 [project @ 2004-04-02 17:26:53 by jwe]
jwe
parents: 4522
diff changeset
43 #include "ov-cx-mat.h"
7505
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7231
diff changeset
44 #include "ov-re-sparse.h"
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7231
diff changeset
45 #include "ov-cx-sparse.h"
4844
9f7ef92b50b0 [project @ 2004-04-02 17:26:53 by jwe]
jwe
parents: 4522
diff changeset
46
31605
e88a07dec498 maint: Use macros to begin/end C++ namespaces.
Rik <rik@octave.org>
parents: 30896
diff changeset
47 OCTAVE_BEGIN_NAMESPACE(octave)
29958
32c3a5805893 move DEFUN and DEFMETHOD functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29359
diff changeset
48
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21100
diff changeset
49 template <typename ArrayType>
9790
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
50 static octave_value_list
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
51 do_minmax_red_op (const octave_value& arg,
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
52 int nargout, int dim, bool ismin)
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
53 {
20892
c07bee629973 2015 Code Sprint: use ovl ().
Rik <rik@octave.org>
parents: 20853
diff changeset
54 octave_value_list retval (nargout > 1 ? 2 : 1);
9790
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
55 ArrayType array = octave_value_extract<ArrayType> (arg);
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
56
20892
c07bee629973 2015 Code Sprint: use ovl ().
Rik <rik@octave.org>
parents: 20853
diff changeset
57 if (nargout <= 1)
9790
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
58 {
20892
c07bee629973 2015 Code Sprint: use ovl ().
Rik <rik@octave.org>
parents: 20853
diff changeset
59 if (ismin)
c07bee629973 2015 Code Sprint: use ovl ().
Rik <rik@octave.org>
parents: 20853
diff changeset
60 retval(0) = array.min (dim);
c07bee629973 2015 Code Sprint: use ovl ().
Rik <rik@octave.org>
parents: 20853
diff changeset
61 else
c07bee629973 2015 Code Sprint: use ovl ().
Rik <rik@octave.org>
parents: 20853
diff changeset
62 retval(0) = array.max (dim);
c07bee629973 2015 Code Sprint: use ovl ().
Rik <rik@octave.org>
parents: 20853
diff changeset
63 }
c07bee629973 2015 Code Sprint: use ovl ().
Rik <rik@octave.org>
parents: 20853
diff changeset
64 else
c07bee629973 2015 Code Sprint: use ovl ().
Rik <rik@octave.org>
parents: 20853
diff changeset
65 {
9790
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
66 Array<octave_idx_type> idx;
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
67 if (ismin)
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
68 retval(0) = array.min (idx, dim);
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
69 else
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
70 retval(0) = array.max (idx, dim);
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
71
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
72 retval(1) = octave_value (idx, true, true);
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
73 }
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
74
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
75 return retval;
8777
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 7919
diff changeset
76 }
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 7919
diff changeset
77
16370
7ce21619a4b9 min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents: 15195
diff changeset
78 // Matlab returns double arrays for min/max operations on character
7ce21619a4b9 min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents: 15195
diff changeset
79 // arrays, so we specialize here to get that behavior. Other possible
7ce21619a4b9 min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents: 15195
diff changeset
80 // solutions are to convert the argument to double here and call the
7ce21619a4b9 min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents: 15195
diff changeset
81 // code for double, but that could waste memory, or to have the
7ce21619a4b9 min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents: 15195
diff changeset
82 // underlying charNDArray::min/max functions return NDArray instead of
7ce21619a4b9 min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents: 15195
diff changeset
83 // charNDArray, but that is inconsistent with the way other min/max
7ce21619a4b9 min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents: 15195
diff changeset
84 // functions work.
7ce21619a4b9 min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents: 15195
diff changeset
85
7ce21619a4b9 min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents: 15195
diff changeset
86 template <>
7ce21619a4b9 min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents: 15195
diff changeset
87 octave_value_list
7ce21619a4b9 min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents: 15195
diff changeset
88 do_minmax_red_op<charNDArray> (const octave_value& arg,
7ce21619a4b9 min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents: 15195
diff changeset
89 int nargout, int dim, bool ismin)
7ce21619a4b9 min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents: 15195
diff changeset
90 {
20892
c07bee629973 2015 Code Sprint: use ovl ().
Rik <rik@octave.org>
parents: 20853
diff changeset
91 octave_value_list retval (nargout > 1 ? 2 : 1);
16370
7ce21619a4b9 min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents: 15195
diff changeset
92 charNDArray array = octave_value_extract<charNDArray> (arg);
7ce21619a4b9 min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents: 15195
diff changeset
93
20892
c07bee629973 2015 Code Sprint: use ovl ().
Rik <rik@octave.org>
parents: 20853
diff changeset
94 if (nargout <= 1)
16370
7ce21619a4b9 min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents: 15195
diff changeset
95 {
20892
c07bee629973 2015 Code Sprint: use ovl ().
Rik <rik@octave.org>
parents: 20853
diff changeset
96 if (ismin)
c07bee629973 2015 Code Sprint: use ovl ().
Rik <rik@octave.org>
parents: 20853
diff changeset
97 retval(0) = NDArray (array.min (dim));
c07bee629973 2015 Code Sprint: use ovl ().
Rik <rik@octave.org>
parents: 20853
diff changeset
98 else
c07bee629973 2015 Code Sprint: use ovl ().
Rik <rik@octave.org>
parents: 20853
diff changeset
99 retval(0) = NDArray (array.max (dim));
c07bee629973 2015 Code Sprint: use ovl ().
Rik <rik@octave.org>
parents: 20853
diff changeset
100 }
c07bee629973 2015 Code Sprint: use ovl ().
Rik <rik@octave.org>
parents: 20853
diff changeset
101 else
c07bee629973 2015 Code Sprint: use ovl ().
Rik <rik@octave.org>
parents: 20853
diff changeset
102 {
16370
7ce21619a4b9 min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents: 15195
diff changeset
103 Array<octave_idx_type> idx;
7ce21619a4b9 min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents: 15195
diff changeset
104 if (ismin)
7ce21619a4b9 min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents: 15195
diff changeset
105 retval(0) = NDArray (array.min (idx, dim));
7ce21619a4b9 min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents: 15195
diff changeset
106 else
7ce21619a4b9 min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents: 15195
diff changeset
107 retval(0) = NDArray (array.max (idx, dim));
7ce21619a4b9 min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents: 15195
diff changeset
108
7ce21619a4b9 min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents: 15195
diff changeset
109 retval(1) = octave_value (idx, true, true);
7ce21619a4b9 min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents: 15195
diff changeset
110 }
7ce21619a4b9 min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents: 15195
diff changeset
111
7ce21619a4b9 min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents: 15195
diff changeset
112 return retval;
7ce21619a4b9 min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents: 15195
diff changeset
113 }
7ce21619a4b9 min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents: 15195
diff changeset
114
21265
f780d057a3ec Let max/min return a second (index) value for sparse logicals (bug #41512).
Lachlan Andrew <lachlanbis@gmail.com>
parents: 21200
diff changeset
115 // Specialization for bool arrays (dense or sparse).
9993
b22a2f4b34aa support min/max with logical arrays
Jaroslav Hajek <highegg@gmail.com>
parents: 9791
diff changeset
116 template <>
b22a2f4b34aa support min/max with logical arrays
Jaroslav Hajek <highegg@gmail.com>
parents: 9791
diff changeset
117 octave_value_list
b22a2f4b34aa support min/max with logical arrays
Jaroslav Hajek <highegg@gmail.com>
parents: 9791
diff changeset
118 do_minmax_red_op<boolNDArray> (const octave_value& arg,
b22a2f4b34aa support min/max with logical arrays
Jaroslav Hajek <highegg@gmail.com>
parents: 9791
diff changeset
119 int nargout, int dim, bool ismin)
b22a2f4b34aa support min/max with logical arrays
Jaroslav Hajek <highegg@gmail.com>
parents: 9791
diff changeset
120 {
b22a2f4b34aa support min/max with logical arrays
Jaroslav Hajek <highegg@gmail.com>
parents: 9791
diff changeset
121 octave_value_list retval;
b22a2f4b34aa support min/max with logical arrays
Jaroslav Hajek <highegg@gmail.com>
parents: 9791
diff changeset
122
23583
b7747a2c88b2 maint: Deprecate is_sparse_type and replace with issparse.
Rik <rik@octave.org>
parents: 23577
diff changeset
123 if (! arg.issparse ())
9993
b22a2f4b34aa support min/max with logical arrays
Jaroslav Hajek <highegg@gmail.com>
parents: 9791
diff changeset
124 {
21265
f780d057a3ec Let max/min return a second (index) value for sparse logicals (bug #41512).
Lachlan Andrew <lachlanbis@gmail.com>
parents: 21200
diff changeset
125 if (nargout <= 1)
f780d057a3ec Let max/min return a second (index) value for sparse logicals (bug #41512).
Lachlan Andrew <lachlanbis@gmail.com>
parents: 21200
diff changeset
126 {
f780d057a3ec Let max/min return a second (index) value for sparse logicals (bug #41512).
Lachlan Andrew <lachlanbis@gmail.com>
parents: 21200
diff changeset
127 // This case can be handled using any/all.
f780d057a3ec Let max/min return a second (index) value for sparse logicals (bug #41512).
Lachlan Andrew <lachlanbis@gmail.com>
parents: 21200
diff changeset
128 boolNDArray array = arg.bool_array_value ();
9993
b22a2f4b34aa support min/max with logical arrays
Jaroslav Hajek <highegg@gmail.com>
parents: 9791
diff changeset
129
23577
80c42f4cca13 maint: Deprecate is_empty and replace with isempty.
Rik <rik@octave.org>
parents: 23573
diff changeset
130 if (array.isempty ())
21265
f780d057a3ec Let max/min return a second (index) value for sparse logicals (bug #41512).
Lachlan Andrew <lachlanbis@gmail.com>
parents: 21200
diff changeset
131 retval(0) = array;
f780d057a3ec Let max/min return a second (index) value for sparse logicals (bug #41512).
Lachlan Andrew <lachlanbis@gmail.com>
parents: 21200
diff changeset
132 else if (ismin)
f780d057a3ec Let max/min return a second (index) value for sparse logicals (bug #41512).
Lachlan Andrew <lachlanbis@gmail.com>
parents: 21200
diff changeset
133 retval(0) = array.all (dim);
f780d057a3ec Let max/min return a second (index) value for sparse logicals (bug #41512).
Lachlan Andrew <lachlanbis@gmail.com>
parents: 21200
diff changeset
134 else
f780d057a3ec Let max/min return a second (index) value for sparse logicals (bug #41512).
Lachlan Andrew <lachlanbis@gmail.com>
parents: 21200
diff changeset
135 retval(0) = array.any (dim);
f780d057a3ec Let max/min return a second (index) value for sparse logicals (bug #41512).
Lachlan Andrew <lachlanbis@gmail.com>
parents: 21200
diff changeset
136 }
9993
b22a2f4b34aa support min/max with logical arrays
Jaroslav Hajek <highegg@gmail.com>
parents: 9791
diff changeset
137 else
21265
f780d057a3ec Let max/min return a second (index) value for sparse logicals (bug #41512).
Lachlan Andrew <lachlanbis@gmail.com>
parents: 21200
diff changeset
138 {
f780d057a3ec Let max/min return a second (index) value for sparse logicals (bug #41512).
Lachlan Andrew <lachlanbis@gmail.com>
parents: 21200
diff changeset
139 // any/all don't have indexed versions, so do it via a conversion.
f780d057a3ec Let max/min return a second (index) value for sparse logicals (bug #41512).
Lachlan Andrew <lachlanbis@gmail.com>
parents: 21200
diff changeset
140 retval = do_minmax_red_op<int8NDArray> (arg, nargout, dim, ismin);
f780d057a3ec Let max/min return a second (index) value for sparse logicals (bug #41512).
Lachlan Andrew <lachlanbis@gmail.com>
parents: 21200
diff changeset
141
f780d057a3ec Let max/min return a second (index) value for sparse logicals (bug #41512).
Lachlan Andrew <lachlanbis@gmail.com>
parents: 21200
diff changeset
142 retval(0) = retval(0).bool_array_value ();
f780d057a3ec Let max/min return a second (index) value for sparse logicals (bug #41512).
Lachlan Andrew <lachlanbis@gmail.com>
parents: 21200
diff changeset
143 }
9993
b22a2f4b34aa support min/max with logical arrays
Jaroslav Hajek <highegg@gmail.com>
parents: 9791
diff changeset
144 }
b22a2f4b34aa support min/max with logical arrays
Jaroslav Hajek <highegg@gmail.com>
parents: 9791
diff changeset
145 else
b22a2f4b34aa support min/max with logical arrays
Jaroslav Hajek <highegg@gmail.com>
parents: 9791
diff changeset
146 {
21604
d7a268e68e69 maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
147 // Sparse: Don't use any/all trick, as full matrix could exceed memory.
21265
f780d057a3ec Let max/min return a second (index) value for sparse logicals (bug #41512).
Lachlan Andrew <lachlanbis@gmail.com>
parents: 21200
diff changeset
148 // Instead, convert to double.
f780d057a3ec Let max/min return a second (index) value for sparse logicals (bug #41512).
Lachlan Andrew <lachlanbis@gmail.com>
parents: 21200
diff changeset
149 retval = do_minmax_red_op<SparseMatrix> (arg, nargout, dim, ismin);
20555
f90c8372b7ba eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20228
diff changeset
150
21265
f780d057a3ec Let max/min return a second (index) value for sparse logicals (bug #41512).
Lachlan Andrew <lachlanbis@gmail.com>
parents: 21200
diff changeset
151 retval(0) = retval(0).sparse_bool_matrix_value ();
9993
b22a2f4b34aa support min/max with logical arrays
Jaroslav Hajek <highegg@gmail.com>
parents: 9791
diff changeset
152 }
b22a2f4b34aa support min/max with logical arrays
Jaroslav Hajek <highegg@gmail.com>
parents: 9791
diff changeset
153
b22a2f4b34aa support min/max with logical arrays
Jaroslav Hajek <highegg@gmail.com>
parents: 9791
diff changeset
154 return retval;
b22a2f4b34aa support min/max with logical arrays
Jaroslav Hajek <highegg@gmail.com>
parents: 9791
diff changeset
155 }
b22a2f4b34aa support min/max with logical arrays
Jaroslav Hajek <highegg@gmail.com>
parents: 9791
diff changeset
156
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21100
diff changeset
157 template <typename ArrayType>
9790
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
158 static octave_value
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
159 do_minmax_bin_op (const octave_value& argx, const octave_value& argy,
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
160 bool ismin)
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
161 {
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
162 typedef typename ArrayType::element_type ScalarType;
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
163
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
164 octave_value retval;
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
165
19412
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
166 if (argx.is_scalar_type ())
9790
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
167 {
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
168 ScalarType x = octave_value_extract<ScalarType> (argx);
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
169 ArrayType y = octave_value_extract<ArrayType> (argy);
7189
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents: 7017
diff changeset
170
20555
f90c8372b7ba eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20228
diff changeset
171 if (ismin)
9790
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
172 retval = min (x, y);
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
173 else
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
174 retval = max (x, y);
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
175 }
19412
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
176 else if (argy.is_scalar_type ())
9790
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
177 {
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
178 ArrayType x = octave_value_extract<ArrayType> (argx);
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
179 ScalarType y = octave_value_extract<ScalarType> (argy);
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
180
20555
f90c8372b7ba eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20228
diff changeset
181 if (ismin)
9790
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
182 retval = min (x, y);
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
183 else
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
184 retval = max (x, y);
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
185 }
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
186 else
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
187 {
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
188 ArrayType x = octave_value_extract<ArrayType> (argx);
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
189 ArrayType y = octave_value_extract<ArrayType> (argy);
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
190
20555
f90c8372b7ba eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20228
diff changeset
191 if (ismin)
9790
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
192 retval = min (x, y);
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
193 else
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
194 retval = max (x, y);
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
195 }
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
196
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
197 return retval;
8777
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 7919
diff changeset
198 }
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 7919
diff changeset
199
16370
7ce21619a4b9 min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents: 15195
diff changeset
200 // Matlab returns double arrays for min/max operations on character
7ce21619a4b9 min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents: 15195
diff changeset
201 // arrays, so we specialize here to get that behavior. Other possible
7ce21619a4b9 min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents: 15195
diff changeset
202 // solutions are to convert the arguments to double here and call the
7ce21619a4b9 min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents: 15195
diff changeset
203 // code for double, but that could waste a lot of memory, or to have the
7ce21619a4b9 min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents: 15195
diff changeset
204 // underlying charNDArray::min/max functions return NDArray instead of
7ce21619a4b9 min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents: 15195
diff changeset
205 // charNDArray, but that is inconsistent with the way other min/max
7ce21619a4b9 min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents: 15195
diff changeset
206 // functions work.
7ce21619a4b9 min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents: 15195
diff changeset
207
7ce21619a4b9 min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents: 15195
diff changeset
208 template <>
7ce21619a4b9 min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents: 15195
diff changeset
209 octave_value
7ce21619a4b9 min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents: 15195
diff changeset
210 do_minmax_bin_op<charNDArray> (const octave_value& argx,
7ce21619a4b9 min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents: 15195
diff changeset
211 const octave_value& argy, bool ismin)
7ce21619a4b9 min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents: 15195
diff changeset
212 {
7ce21619a4b9 min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents: 15195
diff changeset
213 octave_value retval;
7ce21619a4b9 min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents: 15195
diff changeset
214
19412
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
215 charNDArray x = octave_value_extract<charNDArray> (argx);
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
216 charNDArray y = octave_value_extract<charNDArray> (argy);
16370
7ce21619a4b9 min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents: 15195
diff changeset
217
20555
f90c8372b7ba eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20228
diff changeset
218 if (ismin)
19412
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
219 {
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
220 if (x.numel () == 1)
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
221 retval = NDArray (min (x(0), y));
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
222 else if (y.numel () == 1)
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
223 retval = NDArray (min (x, y(0)));
16370
7ce21619a4b9 min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents: 15195
diff changeset
224 else
7ce21619a4b9 min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents: 15195
diff changeset
225 retval = NDArray (min (x, y));
7ce21619a4b9 min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents: 15195
diff changeset
226 }
7ce21619a4b9 min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents: 15195
diff changeset
227 else
7ce21619a4b9 min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents: 15195
diff changeset
228 {
19412
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
229 if (x.numel () == 1)
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
230 retval = NDArray (max (x(0), y));
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
231 else if (y.numel () == 1)
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
232 retval = NDArray (max (x, y(0)));
16370
7ce21619a4b9 min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents: 15195
diff changeset
233 else
7ce21619a4b9 min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents: 15195
diff changeset
234 retval = NDArray (max (x, y));
7ce21619a4b9 min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents: 15195
diff changeset
235 }
7ce21619a4b9 min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents: 15195
diff changeset
236
7ce21619a4b9 min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents: 15195
diff changeset
237 return retval;
7ce21619a4b9 min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents: 15195
diff changeset
238 }
7ce21619a4b9 min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents: 15195
diff changeset
239
9790
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
240 static octave_value_list
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
241 do_minmax_body (const octave_value_list& args,
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
242 int nargout, bool ismin)
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
243 {
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
244 int nargin = args.length ();
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7662
diff changeset
245
20802
8bb38ba1bad6 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20743
diff changeset
246 if (nargin < 1 || nargin > 3)
8bb38ba1bad6 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20743
diff changeset
247 print_usage ();
20921
4d3daf7e43f3 eliminate trailing whitespace in source files
John W. Eaton <jwe@octave.org>
parents: 20892
diff changeset
248
20892
c07bee629973 2015 Code Sprint: use ovl ().
Rik <rik@octave.org>
parents: 20853
diff changeset
249 octave_value_list retval (nargout > 1 ? 2 : 1);
c07bee629973 2015 Code Sprint: use ovl ().
Rik <rik@octave.org>
parents: 20853
diff changeset
250
30896
c9788d7f6e65 maint: Use "fcn" as preferred abbreviation for "function" in libinterp/.
Rik <rik@octave.org>
parents: 30888
diff changeset
251 const char *fcn = (ismin ? "min" : "max");
20892
c07bee629973 2015 Code Sprint: use ovl ().
Rik <rik@octave.org>
parents: 20853
diff changeset
252
9790
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
253 if (nargin == 3 || nargin == 1)
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
254 {
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
255 octave_value arg = args(0);
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
256 int dim = -1;
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
257 if (nargin == 3)
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
258 {
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
259 dim = args(2).int_value (true) - 1;
20743
b6408331bfa2 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20555
diff changeset
260
b6408331bfa2 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20555
diff changeset
261 if (dim < 0)
30896
c9788d7f6e65 maint: Use "fcn" as preferred abbreviation for "function" in libinterp/.
Rik <rik@octave.org>
parents: 30888
diff changeset
262 error ("%s: DIM must be a valid dimension", fcn);
8777
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 7919
diff changeset
263
23577
80c42f4cca13 maint: Deprecate is_empty and replace with isempty.
Rik <rik@octave.org>
parents: 23573
diff changeset
264 if (! args(1).isempty ())
30896
c9788d7f6e65 maint: Use "fcn" as preferred abbreviation for "function" in libinterp/.
Rik <rik@octave.org>
parents: 30888
diff changeset
265 warning ("%s: second argument is ignored", fcn);
9790
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
266 }
7189
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents: 7017
diff changeset
267
9790
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
268 switch (arg.builtin_type ())
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
269 {
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
270 case btyp_double:
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
271 {
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
272 if (arg.is_range () && (dim == -1 || dim == 1))
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
273 {
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29958
diff changeset
274 range<double> range = arg.range_value ();
20228
00cf2847355d Deprecate Array::nelem() and Range::nelem() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents: 20172
diff changeset
275 if (range.numel () < 1)
9790
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
276 {
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
277 retval(0) = arg;
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
278 if (nargout > 1)
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
279 retval(1) = arg;
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
280 }
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
281 else if (ismin)
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
282 {
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
283 retval(0) = range.min ();
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
284 if (nargout > 1)
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
285 retval(1) = static_cast<double>
28636
a3db48e66ef8 use Range::increment instead of Range::inc
John W. Eaton <jwe@octave.org>
parents: 27955
diff changeset
286 (range.increment () < 0 ? range.numel () : 1);
9790
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
287 }
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
288 else
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
289 {
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
290 retval(0) = range.max ();
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
291 if (nargout > 1)
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
292 retval(1) = static_cast<double>
30346
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 29961
diff changeset
293 (range.increment () >= 0 ? range.numel ()
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 29961
diff changeset
294 : 1);
9790
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
295 }
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
296 }
23583
b7747a2c88b2 maint: Deprecate is_sparse_type and replace with issparse.
Rik <rik@octave.org>
parents: 23577
diff changeset
297 else if (arg.issparse ())
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
298 retval = do_minmax_red_op<SparseMatrix> (arg, nargout, dim,
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
299 ismin);
9790
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
300 else
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
301 retval = do_minmax_red_op<NDArray> (arg, nargout, dim, ismin);
20802
8bb38ba1bad6 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20743
diff changeset
302
9790
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
303 }
20802
8bb38ba1bad6 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20743
diff changeset
304 break;
8bb38ba1bad6 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20743
diff changeset
305
9790
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
306 case btyp_complex:
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
307 {
23583
b7747a2c88b2 maint: Deprecate is_sparse_type and replace with issparse.
Rik <rik@octave.org>
parents: 23577
diff changeset
308 if (arg.issparse ())
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
309 retval = do_minmax_red_op<SparseComplexMatrix> (arg, nargout, dim,
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
310 ismin);
9790
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
311 else
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
312 retval = do_minmax_red_op<ComplexNDArray> (arg, nargout, dim,
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
313 ismin);
9790
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
314 }
20802
8bb38ba1bad6 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20743
diff changeset
315 break;
8bb38ba1bad6 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20743
diff changeset
316
9790
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
317 case btyp_float:
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
318 retval = do_minmax_red_op<FloatNDArray> (arg, nargout, dim, ismin);
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
319 break;
20802
8bb38ba1bad6 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20743
diff changeset
320
9790
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
321 case btyp_float_complex:
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
322 retval = do_minmax_red_op<FloatComplexNDArray> (arg, nargout, dim,
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
323 ismin);
9790
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
324 break;
20802
8bb38ba1bad6 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20743
diff changeset
325
16370
7ce21619a4b9 min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents: 15195
diff changeset
326 case btyp_char:
7ce21619a4b9 min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents: 15195
diff changeset
327 retval = do_minmax_red_op<charNDArray> (arg, nargout, dim, ismin);
7ce21619a4b9 min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents: 15195
diff changeset
328 break;
20802
8bb38ba1bad6 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20743
diff changeset
329
22407
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22323
diff changeset
330 #define MAKE_INT_BRANCH(X) \
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22323
diff changeset
331 case btyp_ ## X: \
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22323
diff changeset
332 retval = do_minmax_red_op<X ## NDArray> (arg, nargout, dim, ismin); \
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22323
diff changeset
333 break;
20802
8bb38ba1bad6 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20743
diff changeset
334
9790
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
335 MAKE_INT_BRANCH (int8);
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
336 MAKE_INT_BRANCH (int16);
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
337 MAKE_INT_BRANCH (int32);
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
338 MAKE_INT_BRANCH (int64);
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
339 MAKE_INT_BRANCH (uint8);
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
340 MAKE_INT_BRANCH (uint16);
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
341 MAKE_INT_BRANCH (uint32);
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
342 MAKE_INT_BRANCH (uint64);
20802
8bb38ba1bad6 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20743
diff changeset
343
9790
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
344 #undef MAKE_INT_BRANCH
20802
8bb38ba1bad6 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20743
diff changeset
345
9993
b22a2f4b34aa support min/max with logical arrays
Jaroslav Hajek <highegg@gmail.com>
parents: 9791
diff changeset
346 case btyp_bool:
b22a2f4b34aa support min/max with logical arrays
Jaroslav Hajek <highegg@gmail.com>
parents: 9791
diff changeset
347 retval = do_minmax_red_op<boolNDArray> (arg, nargout, dim, ismin);
b22a2f4b34aa support min/max with logical arrays
Jaroslav Hajek <highegg@gmail.com>
parents: 9791
diff changeset
348 break;
20802
8bb38ba1bad6 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20743
diff changeset
349
9790
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
350 default:
30896
c9788d7f6e65 maint: Use "fcn" as preferred abbreviation for "function" in libinterp/.
Rik <rik@octave.org>
parents: 30888
diff changeset
351 err_wrong_type_arg (fcn, arg);
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
352 }
9790
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
353 }
20802
8bb38ba1bad6 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20743
diff changeset
354 else
9790
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
355 {
18100
6a71e5030df5 Follow coding convention of defining and initializing only 1 variable per line in liboctinterp.
Rik <rik@octave.org>
parents: 18076
diff changeset
356 octave_value argx = args(0);
6a71e5030df5 Follow coding convention of defining and initializing only 1 variable per line in liboctinterp.
Rik <rik@octave.org>
parents: 18076
diff changeset
357 octave_value argy = args(1);
6a71e5030df5 Follow coding convention of defining and initializing only 1 variable per line in liboctinterp.
Rik <rik@octave.org>
parents: 18076
diff changeset
358 builtin_type_t xtyp = argx.builtin_type ();
6a71e5030df5 Follow coding convention of defining and initializing only 1 variable per line in liboctinterp.
Rik <rik@octave.org>
parents: 18076
diff changeset
359 builtin_type_t ytyp = argy.builtin_type ();
16370
7ce21619a4b9 min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents: 15195
diff changeset
360 builtin_type_t rtyp;
7ce21619a4b9 min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents: 15195
diff changeset
361 if (xtyp == btyp_char && ytyp == btyp_char)
7ce21619a4b9 min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents: 15195
diff changeset
362 rtyp = btyp_char;
20946
6eff66fb8a02 style fixes for comments
John W. Eaton <jwe@octave.org>
parents: 20940
diff changeset
363 // FIXME: This is what should happen when boolNDArray has max()
6eff66fb8a02 style fixes for comments
John W. Eaton <jwe@octave.org>
parents: 20940
diff changeset
364 // else if (xtyp == btyp_bool && ytyp == btyp_bool)
6eff66fb8a02 style fixes for comments
John W. Eaton <jwe@octave.org>
parents: 20940
diff changeset
365 // rtyp = btyp_bool;
16370
7ce21619a4b9 min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents: 15195
diff changeset
366 else
7ce21619a4b9 min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents: 15195
diff changeset
367 rtyp = btyp_mixed_numeric (xtyp, ytyp);
9790
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
368
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
369 switch (rtyp)
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
370 {
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
371 case btyp_double:
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
372 {
23583
b7747a2c88b2 maint: Deprecate is_sparse_type and replace with issparse.
Rik <rik@octave.org>
parents: 23577
diff changeset
373 if ((argx.issparse ()
b7747a2c88b2 maint: Deprecate is_sparse_type and replace with issparse.
Rik <rik@octave.org>
parents: 23577
diff changeset
374 && (argy.issparse () || argy.is_scalar_type ()))
b7747a2c88b2 maint: Deprecate is_sparse_type and replace with issparse.
Rik <rik@octave.org>
parents: 23577
diff changeset
375 || (argy.issparse () && argx.is_scalar_type ()))
9790
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
376 retval = do_minmax_bin_op<SparseMatrix> (argx, argy, ismin);
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
377 else
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
378 retval = do_minmax_bin_op<NDArray> (argx, argy, ismin);
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
379 }
20802
8bb38ba1bad6 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20743
diff changeset
380 break;
8bb38ba1bad6 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20743
diff changeset
381
9790
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
382 case btyp_complex:
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
383 {
23583
b7747a2c88b2 maint: Deprecate is_sparse_type and replace with issparse.
Rik <rik@octave.org>
parents: 23577
diff changeset
384 if ((argx.issparse ()
b7747a2c88b2 maint: Deprecate is_sparse_type and replace with issparse.
Rik <rik@octave.org>
parents: 23577
diff changeset
385 && (argy.issparse () || argy.is_scalar_type ()))
b7747a2c88b2 maint: Deprecate is_sparse_type and replace with issparse.
Rik <rik@octave.org>
parents: 23577
diff changeset
386 || (argy.issparse () && argx.is_scalar_type ()))
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
387 retval = do_minmax_bin_op<SparseComplexMatrix> (argx, argy,
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
388 ismin);
9790
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
389 else
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
390 retval = do_minmax_bin_op<ComplexNDArray> (argx, argy, ismin);
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
391 }
20802
8bb38ba1bad6 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20743
diff changeset
392 break;
8bb38ba1bad6 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20743
diff changeset
393
9790
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
394 case btyp_float:
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
395 retval = do_minmax_bin_op<FloatNDArray> (argx, argy, ismin);
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
396 break;
20802
8bb38ba1bad6 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20743
diff changeset
397
9790
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
398 case btyp_float_complex:
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
399 retval = do_minmax_bin_op<FloatComplexNDArray> (argx, argy, ismin);
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
400 break;
20802
8bb38ba1bad6 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20743
diff changeset
401
16370
7ce21619a4b9 min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents: 15195
diff changeset
402 case btyp_char:
7ce21619a4b9 min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents: 15195
diff changeset
403 retval = do_minmax_bin_op<charNDArray> (argx, argy, ismin);
7ce21619a4b9 min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents: 15195
diff changeset
404 break;
20802
8bb38ba1bad6 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20743
diff changeset
405
22407
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22323
diff changeset
406 #define MAKE_INT_BRANCH(X) \
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22323
diff changeset
407 case btyp_ ## X: \
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22323
diff changeset
408 retval = do_minmax_bin_op<X ## NDArray> (argx, argy, ismin); \
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22323
diff changeset
409 break;
20802
8bb38ba1bad6 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20743
diff changeset
410
9790
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
411 MAKE_INT_BRANCH (int8);
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
412 MAKE_INT_BRANCH (int16);
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
413 MAKE_INT_BRANCH (int32);
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
414 MAKE_INT_BRANCH (int64);
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
415 MAKE_INT_BRANCH (uint8);
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
416 MAKE_INT_BRANCH (uint16);
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
417 MAKE_INT_BRANCH (uint32);
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
418 MAKE_INT_BRANCH (uint64);
20802
8bb38ba1bad6 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20743
diff changeset
419
9790
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
420 #undef MAKE_INT_BRANCH
20802
8bb38ba1bad6 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20743
diff changeset
421
20946
6eff66fb8a02 style fixes for comments
John W. Eaton <jwe@octave.org>
parents: 20940
diff changeset
422 // FIXME: This is what should happen when boolNDArray has max()
6eff66fb8a02 style fixes for comments
John W. Eaton <jwe@octave.org>
parents: 20940
diff changeset
423 // case btyp_bool:
6eff66fb8a02 style fixes for comments
John W. Eaton <jwe@octave.org>
parents: 20940
diff changeset
424 // retval = do_minmax_bin_op<boolNDArray> (argx, argy, ismin);
6eff66fb8a02 style fixes for comments
John W. Eaton <jwe@octave.org>
parents: 20940
diff changeset
425 // break;
6eff66fb8a02 style fixes for comments
John W. Eaton <jwe@octave.org>
parents: 20940
diff changeset
426
9790
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
427 default:
30896
c9788d7f6e65 maint: Use "fcn" as preferred abbreviation for "function" in libinterp/.
Rik <rik@octave.org>
parents: 30888
diff changeset
428 error ("%s: cannot compute %s (%s, %s)", fcn, fcn,
9790
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
429 argx.type_name ().c_str (), argy.type_name ().c_str ());
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
430 }
19412
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
431
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
432 // FIXME: Delete when boolNDArray has max()
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
433 if (xtyp == btyp_bool && ytyp == btyp_bool)
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
434 retval(0) = retval(0).bool_array_value ();
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
435
9790
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
436 }
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
437
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
438 return retval;
7505
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7231
diff changeset
439 }
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7231
diff changeset
440
15039
e753177cde93 maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents: 14501
diff changeset
441 DEFUN (min, args, nargout,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
442 doc: /* -*- texinfo -*-
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30565
diff changeset
443 @deftypefn {} {@var{m} =} min (@var{x})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30565
diff changeset
444 @deftypefnx {} {@var{m} =} min (@var{x}, [], @var{dim})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30565
diff changeset
445 @deftypefnx {} {[@var{m}, @var{im}] =} min (@var{x})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30565
diff changeset
446 @deftypefnx {} {@var{m} =} min (@var{x}, @var{y})
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
447 Find minimum values in the array @var{x}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
448
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
449 For a vector argument, return the minimum value. For a matrix argument,
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
450 return a row vector with the minimum value of each column. For a
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
451 multi-dimensional array, @code{min} operates along the first non-singleton
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
452 dimension.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
453
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
454 If the optional third argument @var{dim} is present then operate along
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
455 this dimension. In this case the second argument is ignored and should be
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
456 set to the empty matrix.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
457
27955
179ece36a2eb doc: Clarify two-input argument form for max() and min() (bug #57573).
Rik <rik@octave.org>
parents: 27923
diff changeset
458 For two inputs (@var{x} and @var{y}), return the pairwise minimum according to
179ece36a2eb doc: Clarify two-input argument form for max() and min() (bug #57573).
Rik <rik@octave.org>
parents: 27923
diff changeset
459 the rules for @ref{Broadcasting}.
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
460
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
461 Thus,
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
462
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
463 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
464 min (min (@var{x}))
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
465 @end example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
466
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
467 @noindent
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
468 returns the smallest element of the 2-D matrix @var{x}, and
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
469
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
470 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
471 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
472 min (2:5, pi)
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
473 @result{} 2.0000 3.0000 3.1416 3.1416
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
474 @end group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
475 @end example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
476
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
477 @noindent
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
478 compares each element of the range @code{2:5} with @code{pi}, and returns a
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
479 row vector of the minimum values.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
480
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
481 For complex arguments, the magnitude of the elements are used for
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
482 comparison. If the magnitudes are identical, then the results are ordered
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
483 by phase angle in the range (-pi, pi]. Hence,
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
484
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
485 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
486 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
487 min ([-1 i 1 -i])
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
488 @result{} -i
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
489 @end group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
490 @end example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
491
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
492 @noindent
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
493 because all entries have magnitude 1, but -i has the smallest phase angle
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
494 with value -pi/2.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
495
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
496 If called with one input and two output arguments, @code{min} also returns
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
497 the first index of the minimum value(s). Thus,
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
498
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
499 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
500 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
501 [x, ix] = min ([1, 3, 0, 2, 0])
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
502 @result{} x = 0
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
503 ix = 3
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
504 @end group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
505 @end example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
506 @seealso{max, cummin, cummax}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
507 @end deftypefn */)
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
508 {
9790
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
509 return do_minmax_body (args, nargout, true);
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
510 }
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
511
7600
24abf5a702d9 Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents: 7505
diff changeset
512 /*
19412
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
513 ## Test generic double class
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
514 %!assert (min ([1, 4, 2, 3]), 1)
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
515 %!assert (min ([1; -10; 5; -2]), -10)
19412
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
516 %!assert (min ([4, 2i 4.999; -2, 2, 3+4i]), [-2, 2, 4.999])
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
517 ## Special routines for char arrays
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
518 %!assert (min (["abc", "ABC"]), 65)
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
519 %!assert (min (["abc"; "CBA"]), [67 66 65])
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
520 ## Special routines for logical arrays
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
521 %!assert (min (logical ([])), logical ([]))
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
522 %!assert (min (logical ([0 0 1 0])), false)
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
523 %!assert (min (logical ([0 0 1 0; 0 1 1 0])), logical ([0 0 1 0]))
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
524 ## Single values
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
525 %!assert (min (single ([1, 4, 2, 3])), single (1))
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
526 %!assert (min (single ([1; -10; 5; -2])), single (-10))
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
527 %!assert (min (single ([4, 2i 4.999; -2, 2, 3+4i])), single ([-2, 2, 4.999]))
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
528 ## Integer values
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
529 %!assert (min (uint8 ([1, 4, 2, 3])), uint8 (1))
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
530 %!assert (min (uint8 ([1; -10; 5; -2])), uint8 (-10))
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
531 %!assert (min (int8 ([1, 4, 2, 3])), int8 (1))
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
532 %!assert (min (int8 ([1; -10; 5; -2])), int8 (-10))
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
533 %!assert (min (uint16 ([1, 4, 2, 3])), uint16 (1))
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
534 %!assert (min (uint16 ([1; -10; 5; -2])), uint16 (-10))
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
535 %!assert (min (int16 ([1, 4, 2, 3])), int16 (1))
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
536 %!assert (min (int16 ([1; -10; 5; -2])), int16 (-10))
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
537 %!assert (min (uint32 ([1, 4, 2, 3])), uint32 (1))
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
538 %!assert (min (uint32 ([1; -10; 5; -2])), uint32 (-10))
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
539 %!assert (min (int32 ([1, 4, 2, 3])), int32 (1))
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
540 %!assert (min (int32 ([1; -10; 5; -2])), int32 (-10))
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
541 %!assert (min (uint64 ([1, 4, 2, 3])), uint64 (1))
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
542 %!assert (min (uint64 ([1; -10; 5; -2])), uint64 (-10))
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
543 %!assert (min (int64 ([1, 4, 2, 3])), int64 (1))
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
544 %!assert (min (int64 ([1; -10; 5; -2])), int64 (-10))
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
545 ## Sparse double values
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
546 %!assert (min (sparse ([1, 4, 2, 3])), sparse (1))
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
547 %!assert (min (sparse ([1; -10; 5; -2])), sparse(-10))
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
548 ## FIXME: sparse doesn't order complex values by phase angle
23690
8bba52bd04d2 * max.cc: Tag %!xtest tests with bug number.
John W. Eaton <jwe@octave.org>
parents: 23662
diff changeset
549 %!test <51307>
19412
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
550 %! assert (min (sparse ([4, 2i 4.999; -2, 2, 3+4i])), sparse ([-2, 2, 4.999]));
7600
24abf5a702d9 Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents: 7505
diff changeset
551
19412
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
552 ## Test dimension argument
7600
24abf5a702d9 Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents: 7505
diff changeset
553 %!test
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
554 %! x = reshape (1:8, [2,2,2]);
19412
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
555 %! assert (min (x, [], 1), reshape ([1, 3, 5, 7], [1,2,2]));
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
556 %! assert (min (x, [], 2), reshape ([1, 2, 5, 6], [2,1,2]));
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
557 %! [y, i] = min (x, [], 3);
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
558 %! assert (ndims (y), 2);
19412
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
559 %! assert (y, [1, 3; 2, 4]);
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
560 %! assert (ndims (i), 2);
19412
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
561 %! assert (i, [1, 1; 1, 1]);
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
562
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
563 ## Test 2-output forms for various arg types
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
564 ## Special routines for char arrays
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
565 %!test
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
566 %! [y, i] = min (["abc", "ABC"]);
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
567 %! assert (y, 65);
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
568 %! assert (i, 4);
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
569 ## Special routines for logical arrays
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
570 %!test
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
571 %! x = logical ([0 0 1 0]);
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
572 %! [y, i] = min (x);
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
573 %! assert (y, false);
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
574 %! assert (i, 1);
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
575 ## Special handling of ranges
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
576 %!test
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
577 %! rng = 1:2:10;
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
578 %! [y, i] = min (rng);
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
579 %! assert (y, 1);
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
580 %! assert (i, 1);
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
581 %! rng = 10:-2:1;
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
582 %! [y, i] = min (rng);
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
583 %! assert (y, 2);
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
584 %! assert (i, 5);
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
585
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
586 ## Test 2-input calling form for various arg types
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
587 ## Test generic double class
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
588 %!test
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
589 %! x = [1, 2, 3, 4]; y = fliplr (x);
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
590 %! assert (min (x, y), [1 2 2 1]);
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
591 %! assert (min (x, 3), [1 2 3 3]);
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
592 %! assert (min (2, x), [1 2 2 2]);
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
593 %! assert (min (x, 2.1i), [1 2 2.1i 2.1i]);
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
594 ## FIXME: Ordering of complex results with equal magnitude is not by phase
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
595 ## angle in the 2-input form. Instead, it is in the order in which it
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
596 ## appears in the argument list.
23690
8bba52bd04d2 * max.cc: Tag %!xtest tests with bug number.
John W. Eaton <jwe@octave.org>
parents: 23662
diff changeset
597 %!test <51307>
19412
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
598 %! x = [1, 2, 3, 4]; y = fliplr (x);
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
599 %! assert (min (x, 2i), [2i 2i 3 4]);
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
600 ## Special routines for char arrays
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
601 %!assert (min ("abc", "b"), [97 98 98])
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
602 %!assert (min ("b", "cba"), [98 98 97])
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
603 ## Special handling for logical arrays
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
604 %!assert (min ([true false], false), [false false])
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
605 %!assert (min (true, [true false]), [true false])
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
606 ## Single values
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
607 %!test
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
608 %! x = single ([1, 2, 3, 4]); y = fliplr (x);
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
609 %! assert (min (x, y), single ([1 2 2 1]));
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
610 %! assert (min (x, 3), single ([1 2 3 3]));
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
611 %! assert (min (2, x), single ([1 2 2 2]));
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
612 %! assert (min (x, 2.1i), single ([1 2 2.1i 2.1i]));
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
613 ## Integer values
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
614 %!test
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
615 %! x = uint8 ([1, 2, 3, 4]); y = fliplr (x);
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
616 %! assert (min (x, y), uint8 ([1 2 2 1]));
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
617 %! assert (min (x, 3), uint8 ([1 2 3 3]));
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
618 %! assert (min (2, x), uint8 ([1 2 2 2]));
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
619 %! x = int8 ([1, 2, 3, 4]); y = fliplr (x);
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
620 %! assert (min (x, y), int8 ([1 2 2 1]));
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
621 %! assert (min (x, 3), int8 ([1 2 3 3]));
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
622 %! assert (min (2, x), int8 ([1 2 2 2]));
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
623 %! x = uint16 ([1, 2, 3, 4]); y = fliplr (x);
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
624 %! assert (min (x, y), uint16 ([1 2 2 1]));
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
625 %! assert (min (x, 3), uint16 ([1 2 3 3]));
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
626 %! assert (min (2, x), uint16 ([1 2 2 2]));
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
627 %! x = int16 ([1, 2, 3, 4]); y = fliplr (x);
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
628 %! assert (min (x, y), int16 ([1 2 2 1]));
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
629 %! assert (min (x, 3), int16 ([1 2 3 3]));
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
630 %! assert (min (2, x), int16 ([1 2 2 2]));
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
631 %! x = uint32 ([1, 2, 3, 4]); y = fliplr (x);
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
632 %! assert (min (x, y), uint32 ([1 2 2 1]));
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
633 %! assert (min (x, 3), uint32 ([1 2 3 3]));
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
634 %! assert (min (2, x), uint32 ([1 2 2 2]));
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
635 %! x = int32 ([1, 2, 3, 4]); y = fliplr (x);
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
636 %! assert (min (x, y), int32 ([1 2 2 1]));
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
637 %! assert (min (x, 3), int32 ([1 2 3 3]));
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
638 %! assert (min (2, x), int32 ([1 2 2 2]));
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
639 %! x = uint64 ([1, 2, 3, 4]); y = fliplr (x);
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
640 %! assert (min (x, y), uint64 ([1 2 2 1]));
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
641 %! assert (min (x, 3), uint64 ([1 2 3 3]));
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
642 %! assert (min (2, x), uint64 ([1 2 2 2]));
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
643 %! x = int64 ([1, 2, 3, 4]); y = fliplr (x);
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
644 %! assert (min (x, y), int64 ([1 2 2 1]));
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
645 %! assert (min (x, 3), int64 ([1 2 3 3]));
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
646 %! assert (min (2, x), int64 ([1 2 2 2]));
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
647 ## Sparse double values
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
648 %!test
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
649 %! x = sparse ([1, 2, 3, 4]); y = fliplr (x);
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
650 %! assert (min (x, y), sparse ([1 2 2 1]));
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
651 %! assert (min (x, 3), sparse ([1 2 3 3]));
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
652 %! assert (min (2, x), sparse ([1 2 2 2]));
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
653 %! assert (min (x, 2.1i), sparse ([1 2 2.1i 2.1i]));
7600
24abf5a702d9 Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents: 7505
diff changeset
654
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
655 %!error min ()
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
656 %!error min (1, 2, 3, 4)
19412
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
657 %!error <DIM must be a valid dimension> min ([1 2; 3 4], [], -3)
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
658 %!warning <second argument is ignored> min ([1 2 3 4], 2, 2);
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
659 %!error <wrong type argument 'cell'> min ({1 2 3 4})
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
660 %!error <cannot compute min \(cell, scalar\)> min ({1, 2, 3}, 2)
7600
24abf5a702d9 Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents: 7505
diff changeset
661 */
24abf5a702d9 Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents: 7505
diff changeset
662
15039
e753177cde93 maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents: 14501
diff changeset
663 DEFUN (max, args, nargout,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
664 doc: /* -*- texinfo -*-
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30565
diff changeset
665 @deftypefn {} {@var{m} =} max (@var{x})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30565
diff changeset
666 @deftypefnx {} {@var{m} =} max (@var{x}, [], @var{dim})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30565
diff changeset
667 @deftypefnx {} {[@var{m}, @var{im}] =} max (@var{x})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30565
diff changeset
668 @deftypefnx {} {@var{m} =} max (@var{x}, @var{y})
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
669 Find maximum values in the array @var{x}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
670
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
671 For a vector argument, return the maximum value. For a matrix argument,
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
672 return a row vector with the maximum value of each column. For a
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
673 multi-dimensional array, @code{max} operates along the first non-singleton
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
674 dimension.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
675
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
676 If the optional third argument @var{dim} is present then operate along
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
677 this dimension. In this case the second argument is ignored and should be
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
678 set to the empty matrix.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
679
27955
179ece36a2eb doc: Clarify two-input argument form for max() and min() (bug #57573).
Rik <rik@octave.org>
parents: 27923
diff changeset
680 For two inputs (@var{x} and @var{y}), return the pairwise maximum according to
179ece36a2eb doc: Clarify two-input argument form for max() and min() (bug #57573).
Rik <rik@octave.org>
parents: 27923
diff changeset
681 the rules for @ref{Broadcasting}.
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
682
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
683 Thus,
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
684
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
685 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
686 max (max (@var{x}))
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
687 @end example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
688
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
689 @noindent
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
690 returns the largest element of the 2-D matrix @var{x}, and
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
691
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
692 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
693 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
694 max (2:5, pi)
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
695 @result{} 3.1416 3.1416 4.0000 5.0000
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
696 @end group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
697 @end example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
698
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
699 @noindent
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
700 compares each element of the range @code{2:5} with @code{pi}, and returns a
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
701 row vector of the maximum values.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
702
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
703 For complex arguments, the magnitude of the elements are used for
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
704 comparison. If the magnitudes are identical, then the results are ordered
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
705 by phase angle in the range (-pi, pi]. Hence,
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
706
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
707 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
708 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
709 max ([-1 i 1 -i])
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
710 @result{} -1
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
711 @end group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
712 @end example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
713
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
714 @noindent
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
715 because all entries have magnitude 1, but -1 has the largest phase angle
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
716 with value pi.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
717
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
718 If called with one input and two output arguments, @code{max} also returns
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
719 the first index of the maximum value(s). Thus,
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
720
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
721 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
722 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
723 [x, ix] = max ([1, 3, 5, 2, 5])
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
724 @result{} x = 5
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
725 ix = 3
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
726 @end group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
727 @end example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
728 @seealso{min, cummax, cummin}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
729 @end deftypefn */)
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
730 {
9790
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
731 return do_minmax_body (args, nargout, false);
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
732 }
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
733
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11553
diff changeset
734 /*
19412
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
735 ## Test generic double class
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
736 %!assert (max ([1, 4, 2, 3]), 4)
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
737 %!assert (max ([1; -10; 5; -2]), 5)
19412
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
738 %!assert (max ([4, 2i 4.999; -2, 2, 3+4i]), [4, 2i, 3+4i])
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
739 ## Special routines for char arrays
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
740 %!assert (max (["abc", "ABC"]), 99)
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
741 %!assert (max (["abc"; "CBA"]), [97 98 99])
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
742 ## Special routines for logical arrays
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
743 %!assert (max (logical ([])), logical ([]))
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
744 %!assert (max (logical ([0 0 1 0])), true)
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
745 %!assert (max (logical ([0 0 1 0; 0 1 0 0])), logical ([0 1 1 0]))
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
746 ## Single values
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
747 %!assert (max (single ([1, 4, 2, 3])), single (4))
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
748 %!assert (max (single ([1; -10; 5; -2])), single (5))
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
749 %!assert (max (single ([4, 2i 4.999; -2, 2, 3+4i])), single ([4, 2i, 3+4i]))
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
750 ## Integer values
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
751 %!assert (max (uint8 ([1, 4, 2, 3])), uint8 (4))
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
752 %!assert (max (uint8 ([1; -10; 5; -2])), uint8 (5))
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
753 %!assert (max (int8 ([1, 4, 2, 3])), int8 (4))
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
754 %!assert (max (int8 ([1; -10; 5; -2])), int8 (5))
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
755 %!assert (max (uint16 ([1, 4, 2, 3])), uint16 (4))
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
756 %!assert (max (uint16 ([1; -10; 5; -2])), uint16 (5))
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
757 %!assert (max (int16 ([1, 4, 2, 3])), int16 (4))
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
758 %!assert (max (int16 ([1; -10; 5; -2])), int16 (5))
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
759 %!assert (max (uint32 ([1, 4, 2, 3])), uint32 (4))
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
760 %!assert (max (uint32 ([1; -10; 5; -2])), uint32 (5))
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
761 %!assert (max (int32 ([1, 4, 2, 3])), int32 (4))
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
762 %!assert (max (int32 ([1; -10; 5; -2])), int32 (5))
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
763 %!assert (max (uint64 ([1, 4, 2, 3])), uint64 (4))
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
764 %!assert (max (uint64 ([1; -10; 5; -2])), uint64 (5))
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
765 %!assert (max (int64 ([1, 4, 2, 3])), int64 (4))
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
766 %!assert (max (int64 ([1; -10; 5; -2])), int64 (5))
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
767 ## Sparse double values
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
768 %!assert (max (sparse ([1, 4, 2, 3])), sparse (4))
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
769 %!assert (max (sparse ([1; -10; 5; -2])), sparse(5))
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
770 %!assert (max (sparse ([4, 2i 4.999; -2, 2, 3+4i])), sparse ([4, 2i, 3+4i]))
7600
24abf5a702d9 Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents: 7505
diff changeset
771
19412
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
772 ## Test dimension argument
7600
24abf5a702d9 Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents: 7505
diff changeset
773 %!test
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
774 %! x = reshape (1:8, [2,2,2]);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
775 %! assert (min (x, [], 1), reshape ([1, 3, 5, 7], [1,2,2]));
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
776 %! assert (min (x, [], 2), reshape ([1, 2, 5, 6], [2,1,2]));
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
777 %! [y, i] = min (x, [], 3);
19412
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
778 %! assert (ndims (y), 2);
7600
24abf5a702d9 Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents: 7505
diff changeset
779 %! assert (y, [1, 3; 2, 4]);
19412
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
780 %! assert (ndims (i), 2);
7600
24abf5a702d9 Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents: 7505
diff changeset
781 %! assert (i, [1, 1; 1, 1]);
24abf5a702d9 Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents: 7505
diff changeset
782
19412
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
783 ## Test 2-output forms for various arg types
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
784 ## Special routines for char arrays
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
785 %!test
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
786 %! [y, i] = max (["abc", "ABC"]);
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
787 %! assert (y, 99);
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
788 %! assert (i, 3);
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
789 ## Special routines for logical arrays
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
790 %!test
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
791 %! x = logical ([0 0 1 0]);
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
792 %! [y, i] = max (x);
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
793 %! assert (y, true);
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
794 %! assert (i, 3);
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
795 ## Special handling of ranges
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
796 %!test
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
797 %! rng = 1:2:10;
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
798 %! [y, i] = max (rng);
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
799 %! assert (y, 9);
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
800 %! assert (i, 5);
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
801 %! rng = 10:-2:1;
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
802 %! [y, i] = max (rng);
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
803 %! assert (y, 10);
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
804 %! assert (i, 1);
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
805
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
806 ## Test 2-input calling form for various arg types
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
807 ## Test generic double class
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
808 %!test
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
809 %! x = [1, 2, 3, 4]; y = fliplr (x);
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
810 %! assert (max (x, y), [4 3 3 4]);
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
811 %! assert (max (x, 3), [3 3 3 4]);
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
812 %! assert (max (2, x), [2 2 3 4]);
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
813 %! assert (max (x, 2.1i), [2.1i 2.1i 3 4]);
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
814 ## FIXME: Ordering of complex results with equal magnitude is not by phase
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
815 ## angle in the 2-input form. Instead, it is in the order in which it
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
816 ## appears in the argument list.
23690
8bba52bd04d2 * max.cc: Tag %!xtest tests with bug number.
John W. Eaton <jwe@octave.org>
parents: 23662
diff changeset
817 %!test <51307>
19412
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
818 %! x = [1, 2, 3, 4]; y = fliplr (x);
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
819 %! assert (max (x, 2i), [2i 2i 3 4]);
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
820 ## Special routines for char arrays
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
821 %!assert (max ("abc", "b"), [98 98 99])
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
822 %!assert (max ("b", "cba"), [99 98 98])
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
823 ## Special handling for logical arrays
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
824 %!assert (max ([true false], false), [true false])
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
825 %!assert (max (true, [false false]), [true true])
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
826 ## Single values
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
827 %!test
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
828 %! x = single ([1, 2, 3, 4]); y = fliplr (x);
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
829 %! assert (max (x, y), single ([4 3 3 4]));
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
830 %! assert (max (x, 3), single ([3 3 3 4]));
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
831 %! assert (max (2, x), single ([2 2 3 4]));
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
832 %! assert (max (x, 2.1i), single ([2.1i 2.1i 3 4]));
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
833 ## Integer values
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
834 %!test
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
835 %! x = uint8 ([1, 2, 3, 4]); y = fliplr (x);
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
836 %! assert (max (x, y), uint8 ([4 3 3 4]));
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
837 %! assert (max (x, 3), uint8 ([3 3 3 4]));
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
838 %! assert (max (2, x), uint8 ([2 2 3 4]));
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
839 %! x = int8 ([1, 2, 3, 4]); y = fliplr (x);
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
840 %! assert (max (x, y), int8 ([4 3 3 4]));
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
841 %! assert (max (x, 3), int8 ([3 3 3 4]));
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
842 %! assert (max (2, x), int8 ([2 2 3 4]));
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
843 %! x = uint16 ([1, 2, 3, 4]); y = fliplr (x);
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
844 %! assert (max (x, y), uint16 ([4 3 3 4]));
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
845 %! assert (max (x, 3), uint16 ([3 3 3 4]));
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
846 %! assert (max (2, x), uint16 ([2 2 3 4]));
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
847 %! x = int16 ([1, 2, 3, 4]); y = fliplr (x);
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
848 %! assert (max (x, y), int16 ([4 3 3 4]));
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
849 %! assert (max (x, 3), int16 ([3 3 3 4]));
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
850 %! assert (max (2, x), int16 ([2 2 3 4]));
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
851 %! x = uint32 ([1, 2, 3, 4]); y = fliplr (x);
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
852 %! assert (max (x, y), uint32 ([4 3 3 4]));
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
853 %! assert (max (x, 3), uint32 ([3 3 3 4]));
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
854 %! assert (max (2, x), uint32 ([2 2 3 4]));
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
855 %! x = int32 ([1, 2, 3, 4]); y = fliplr (x);
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
856 %! assert (max (x, y), int32 ([4 3 3 4]));
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
857 %! assert (max (x, 3), int32 ([3 3 3 4]));
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
858 %! assert (max (2, x), int32 ([2 2 3 4]));
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
859 %! x = uint64 ([1, 2, 3, 4]); y = fliplr (x);
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
860 %! assert (max (x, y), uint64 ([4 3 3 4]));
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
861 %! assert (max (x, 3), uint64 ([3 3 3 4]));
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
862 %! assert (max (2, x), uint64 ([2 2 3 4]));
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
863 %! x = int64 ([1, 2, 3, 4]); y = fliplr (x);
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
864 %! assert (max (x, y), int64 ([4 3 3 4]));
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
865 %! assert (max (x, 3), int64 ([3 3 3 4]));
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
866 %! assert (max (2, x), int64 ([2 2 3 4]));
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
867 ## Sparse double values
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
868 %!test
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
869 %! x = sparse ([1, 2, 3, 4]); y = fliplr (x);
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
870 %! assert (max (x, y), sparse ([4 3 3 4]));
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
871 %! assert (max (x, 3), sparse ([3 3 3 4]));
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
872 %! assert (max (2, x), sparse ([2 2 3 4]));
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
873 %! assert (max (x, 2.1i), sparse ([2.1i 2.1i 3 4]));
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
874
18076
42e6cdc76f4b max.cc: Add %!test for bug #40743.
Rik <rik@octave.org>
parents: 17787
diff changeset
875 ## Test for bug #40743
23573
1b4f4ec53b4a use new script to tag fixed bugs in tests
John W. Eaton <jwe@octave.org>
parents: 23572
diff changeset
876 %!assert <*40743> (max (zeros (1,0), ones (1,1)), zeros (1,0))
1b4f4ec53b4a use new script to tag fixed bugs in tests
John W. Eaton <jwe@octave.org>
parents: 23572
diff changeset
877 %!assert <*40743> (max (sparse (zeros (1,0)), sparse (ones (1,1))),
23552
654661539e20 * max.cc: Fix typo in test.
John W. Eaton <jwe@octave.org>
parents: 23450
diff changeset
878 %! sparse (zeros (1,0)))
18076
42e6cdc76f4b max.cc: Add %!test for bug #40743.
Rik <rik@octave.org>
parents: 17787
diff changeset
879
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
880 %!error max ()
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
881 %!error max (1, 2, 3, 4)
19412
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
882 %!error <DIM must be a valid dimension> max ([1 2; 3 4], [], -3)
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
883 %!warning <second argument is ignored> max ([1 2 3 4], 2, 2);
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
884 %!error <wrong type argument 'cell'> max ({1 2 3 4})
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
885 %!error <cannot compute max \(cell, scalar\)> max ({1, 2, 3}, 2)
78e424d31596 Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents: 18227
diff changeset
886
7600
24abf5a702d9 Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents: 7505
diff changeset
887 */
24abf5a702d9 Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents: 7505
diff changeset
888
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21100
diff changeset
889 template <typename ArrayType>
9790
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
890 static octave_value_list
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
891 do_cumminmax_red_op (const octave_value& arg,
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
892 int nargout, int dim, bool ismin)
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
893 {
20892
c07bee629973 2015 Code Sprint: use ovl ().
Rik <rik@octave.org>
parents: 20853
diff changeset
894 octave_value_list retval (nargout > 1 ? 2 : 1);
9790
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
895 ArrayType array = octave_value_extract<ArrayType> (arg);
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
896
20892
c07bee629973 2015 Code Sprint: use ovl ().
Rik <rik@octave.org>
parents: 20853
diff changeset
897 if (nargout <= 1)
c07bee629973 2015 Code Sprint: use ovl ().
Rik <rik@octave.org>
parents: 20853
diff changeset
898 {
c07bee629973 2015 Code Sprint: use ovl ().
Rik <rik@octave.org>
parents: 20853
diff changeset
899 if (ismin)
c07bee629973 2015 Code Sprint: use ovl ().
Rik <rik@octave.org>
parents: 20853
diff changeset
900 retval(0) = array.cummin (dim);
c07bee629973 2015 Code Sprint: use ovl ().
Rik <rik@octave.org>
parents: 20853
diff changeset
901 else
c07bee629973 2015 Code Sprint: use ovl ().
Rik <rik@octave.org>
parents: 20853
diff changeset
902 retval(0) = array.cummax (dim);
c07bee629973 2015 Code Sprint: use ovl ().
Rik <rik@octave.org>
parents: 20853
diff changeset
903 }
c07bee629973 2015 Code Sprint: use ovl ().
Rik <rik@octave.org>
parents: 20853
diff changeset
904 else
9790
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
905 {
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
906 retval.resize (2);
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
907 Array<octave_idx_type> idx;
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
908 if (ismin)
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
909 retval(0) = array.cummin (idx, dim);
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
910 else
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
911 retval(0) = array.cummax (idx, dim);
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
912
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
913 retval(1) = octave_value (idx, true, true);
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
914 }
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
915
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
916 return retval;
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
917 }
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
918
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
919 static octave_value_list
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
920 do_cumminmax_body (const octave_value_list& args,
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
921 int nargout, bool ismin)
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
922 {
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
923 int nargin = args.length ();
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
924
20802
8bb38ba1bad6 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20743
diff changeset
925 if (nargin < 1 || nargin > 2)
8bb38ba1bad6 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20743
diff changeset
926 print_usage ();
20743
b6408331bfa2 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20555
diff changeset
927
30896
c9788d7f6e65 maint: Use "fcn" as preferred abbreviation for "function" in libinterp/.
Rik <rik@octave.org>
parents: 30888
diff changeset
928 const char *fcn = (ismin ? "cummin" : "cummax");
20892
c07bee629973 2015 Code Sprint: use ovl ().
Rik <rik@octave.org>
parents: 20853
diff changeset
929
20802
8bb38ba1bad6 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20743
diff changeset
930 octave_value arg = args(0);
8bb38ba1bad6 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20743
diff changeset
931 int dim = -1;
8bb38ba1bad6 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20743
diff changeset
932 if (nargin == 2)
8bb38ba1bad6 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20743
diff changeset
933 {
8bb38ba1bad6 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20743
diff changeset
934 dim = args(1).int_value (true) - 1;
9790
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
935
20802
8bb38ba1bad6 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20743
diff changeset
936 if (dim < 0)
30896
c9788d7f6e65 maint: Use "fcn" as preferred abbreviation for "function" in libinterp/.
Rik <rik@octave.org>
parents: 30888
diff changeset
937 error ("%s: DIM must be a valid dimension", fcn);
9790
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
938 }
20802
8bb38ba1bad6 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20743
diff changeset
939
20892
c07bee629973 2015 Code Sprint: use ovl ().
Rik <rik@octave.org>
parents: 20853
diff changeset
940 octave_value_list retval;
c07bee629973 2015 Code Sprint: use ovl ().
Rik <rik@octave.org>
parents: 20853
diff changeset
941
20802
8bb38ba1bad6 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20743
diff changeset
942 switch (arg.builtin_type ())
8bb38ba1bad6 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20743
diff changeset
943 {
8bb38ba1bad6 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20743
diff changeset
944 case btyp_double:
8bb38ba1bad6 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20743
diff changeset
945 retval = do_cumminmax_red_op<NDArray> (arg, nargout, dim, ismin);
8bb38ba1bad6 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20743
diff changeset
946 break;
8bb38ba1bad6 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20743
diff changeset
947
8bb38ba1bad6 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20743
diff changeset
948 case btyp_complex:
8bb38ba1bad6 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20743
diff changeset
949 retval = do_cumminmax_red_op<ComplexNDArray> (arg, nargout, dim,
8bb38ba1bad6 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20743
diff changeset
950 ismin);
8bb38ba1bad6 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20743
diff changeset
951 break;
8bb38ba1bad6 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20743
diff changeset
952
8bb38ba1bad6 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20743
diff changeset
953 case btyp_float:
8bb38ba1bad6 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20743
diff changeset
954 retval = do_cumminmax_red_op<FloatNDArray> (arg, nargout, dim, ismin);
8bb38ba1bad6 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20743
diff changeset
955 break;
8bb38ba1bad6 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20743
diff changeset
956
8bb38ba1bad6 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20743
diff changeset
957 case btyp_float_complex:
8bb38ba1bad6 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20743
diff changeset
958 retval = do_cumminmax_red_op<FloatComplexNDArray> (arg, nargout, dim,
8bb38ba1bad6 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20743
diff changeset
959 ismin);
8bb38ba1bad6 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20743
diff changeset
960 break;
8bb38ba1bad6 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20743
diff changeset
961
22407
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22323
diff changeset
962 #define MAKE_INT_BRANCH(X) \
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22323
diff changeset
963 case btyp_ ## X: \
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22323
diff changeset
964 retval = do_cumminmax_red_op<X ## NDArray> (arg, nargout, dim, ismin); \
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22323
diff changeset
965 break;
20802
8bb38ba1bad6 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20743
diff changeset
966
8bb38ba1bad6 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20743
diff changeset
967 MAKE_INT_BRANCH (int8);
8bb38ba1bad6 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20743
diff changeset
968 MAKE_INT_BRANCH (int16);
8bb38ba1bad6 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20743
diff changeset
969 MAKE_INT_BRANCH (int32);
8bb38ba1bad6 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20743
diff changeset
970 MAKE_INT_BRANCH (int64);
8bb38ba1bad6 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20743
diff changeset
971 MAKE_INT_BRANCH (uint8);
8bb38ba1bad6 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20743
diff changeset
972 MAKE_INT_BRANCH (uint16);
8bb38ba1bad6 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20743
diff changeset
973 MAKE_INT_BRANCH (uint32);
8bb38ba1bad6 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20743
diff changeset
974 MAKE_INT_BRANCH (uint64);
8bb38ba1bad6 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20743
diff changeset
975
8bb38ba1bad6 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20743
diff changeset
976 #undef MAKE_INT_BRANCH
8bb38ba1bad6 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20743
diff changeset
977
8bb38ba1bad6 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20743
diff changeset
978 case btyp_bool:
8bb38ba1bad6 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20743
diff changeset
979 {
8bb38ba1bad6 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20743
diff changeset
980 retval = do_cumminmax_red_op<int8NDArray> (arg, nargout, dim,
8bb38ba1bad6 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20743
diff changeset
981 ismin);
8bb38ba1bad6 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20743
diff changeset
982 if (retval.length () > 0)
8bb38ba1bad6 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20743
diff changeset
983 retval(0) = retval(0).bool_array_value ();
8bb38ba1bad6 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20743
diff changeset
984 }
8bb38ba1bad6 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20743
diff changeset
985 break;
8bb38ba1bad6 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20743
diff changeset
986
8bb38ba1bad6 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20743
diff changeset
987 default:
30896
c9788d7f6e65 maint: Use "fcn" as preferred abbreviation for "function" in libinterp/.
Rik <rik@octave.org>
parents: 30888
diff changeset
988 err_wrong_type_arg (fcn, arg);
20802
8bb38ba1bad6 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20743
diff changeset
989 }
9790
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
990
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
991 return retval;
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
992 }
8777
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 7919
diff changeset
993
15039
e753177cde93 maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents: 14501
diff changeset
994 DEFUN (cummin, args, nargout,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
995 doc: /* -*- texinfo -*-
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30565
diff changeset
996 @deftypefn {} {@var{M} =} cummin (@var{x})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30565
diff changeset
997 @deftypefnx {} {@var{M} =} cummin (@var{x}, @var{dim})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30565
diff changeset
998 @deftypefnx {} {[@var{M}, @var{IM}] =} cummin (@var{x})
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
999 Return the cumulative minimum values along dimension @var{dim}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
1000
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
1001 If @var{dim} is unspecified it defaults to column-wise operation. For
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
1002 example:
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
1003
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
1004 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
1005 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
1006 cummin ([5 4 6 2 3 1])
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
1007 @result{} 5 4 4 2 2 1
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
1008 @end group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
1009 @end example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
1010
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
1011 If called with two output arguments the index of the minimum value is also
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
1012 returned.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
1013
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
1014 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
1015 @group
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30565
diff changeset
1016 [M, IM] = cummin ([5 4 6 2 3 1])
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
1017 @result{}
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30565
diff changeset
1018 M = 5 4 4 2 2 1
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30565
diff changeset
1019 IM = 1 2 2 4 4 6
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
1020 @end group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
1021 @end example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
1022
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
1023 @seealso{cummax, min, max}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
1024 @end deftypefn */)
8777
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 7919
diff changeset
1025 {
9790
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
1026 return do_cumminmax_body (args, nargout, true);
8777
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 7919
diff changeset
1027 }
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 7919
diff changeset
1028
17403
db8b90a56298 doc: Reword docstrings for cummax, cummin.
Rik <rik@octave.org>
parents: 16370
diff changeset
1029 /*
db8b90a56298 doc: Reword docstrings for cummax, cummin.
Rik <rik@octave.org>
parents: 16370
diff changeset
1030 %!assert (cummin ([1, 4, 2, 3]), [1 1 1 1])
db8b90a56298 doc: Reword docstrings for cummax, cummin.
Rik <rik@octave.org>
parents: 16370
diff changeset
1031 %!assert (cummin ([1; -10; 5; -2]), [1; -10; -10; -10])
db8b90a56298 doc: Reword docstrings for cummax, cummin.
Rik <rik@octave.org>
parents: 16370
diff changeset
1032 %!assert (cummin ([4, i; -2, 2]), [4, i; -2, i])
19591
6b09dd576521 Fix cummin/cummax operations on rows when NaN element present (bug #44009).
Lachlan Andrew <lachlanbis@gmail.com>
parents: 19412
diff changeset
1033 %!assert (cummin ([1 2; NaN 1], 2), [1 1; NaN 1])
17403
db8b90a56298 doc: Reword docstrings for cummax, cummin.
Rik <rik@octave.org>
parents: 16370
diff changeset
1034
db8b90a56298 doc: Reword docstrings for cummax, cummin.
Rik <rik@octave.org>
parents: 16370
diff changeset
1035 %!test
db8b90a56298 doc: Reword docstrings for cummax, cummin.
Rik <rik@octave.org>
parents: 16370
diff changeset
1036 %! x = reshape (1:8, [2,2,2]);
db8b90a56298 doc: Reword docstrings for cummax, cummin.
Rik <rik@octave.org>
parents: 16370
diff changeset
1037 %! assert (cummin (x, 1), reshape ([1 1 3 3 5 5 7 7], [2,2,2]));
db8b90a56298 doc: Reword docstrings for cummax, cummin.
Rik <rik@octave.org>
parents: 16370
diff changeset
1038 %! assert (cummin (x, 2), reshape ([1 2 1 2 5 6 5 6], [2,2,2]));
db8b90a56298 doc: Reword docstrings for cummax, cummin.
Rik <rik@octave.org>
parents: 16370
diff changeset
1039 %! [w, iw] = cummin (x, 3);
db8b90a56298 doc: Reword docstrings for cummax, cummin.
Rik <rik@octave.org>
parents: 16370
diff changeset
1040 %! assert (ndims (w), 3);
db8b90a56298 doc: Reword docstrings for cummax, cummin.
Rik <rik@octave.org>
parents: 16370
diff changeset
1041 %! assert (w, repmat ([1 3; 2 4], [1 1 2]));
db8b90a56298 doc: Reword docstrings for cummax, cummin.
Rik <rik@octave.org>
parents: 16370
diff changeset
1042 %! assert (ndims (iw), 3);
db8b90a56298 doc: Reword docstrings for cummax, cummin.
Rik <rik@octave.org>
parents: 16370
diff changeset
1043 %! assert (iw, ones (2,2,2));
db8b90a56298 doc: Reword docstrings for cummax, cummin.
Rik <rik@octave.org>
parents: 16370
diff changeset
1044
db8b90a56298 doc: Reword docstrings for cummax, cummin.
Rik <rik@octave.org>
parents: 16370
diff changeset
1045 %!error cummin ()
db8b90a56298 doc: Reword docstrings for cummax, cummin.
Rik <rik@octave.org>
parents: 16370
diff changeset
1046 %!error cummin (1, 2, 3)
db8b90a56298 doc: Reword docstrings for cummax, cummin.
Rik <rik@octave.org>
parents: 16370
diff changeset
1047 */
db8b90a56298 doc: Reword docstrings for cummax, cummin.
Rik <rik@octave.org>
parents: 16370
diff changeset
1048
15039
e753177cde93 maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents: 14501
diff changeset
1049 DEFUN (cummax, args, nargout,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
1050 doc: /* -*- texinfo -*-
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30565
diff changeset
1051 @deftypefn {} {@var{M} =} cummax (@var{x})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30565
diff changeset
1052 @deftypefnx {} {@var{M} =} cummax (@var{x}, @var{dim})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30565
diff changeset
1053 @deftypefnx {} {[@var{M}, @var{IM}] =} cummax (@dots{})
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
1054 Return the cumulative maximum values along dimension @var{dim}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
1055
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
1056 If @var{dim} is unspecified it defaults to column-wise operation. For
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
1057 example:
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
1058
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
1059 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
1060 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
1061 cummax ([1 3 2 6 4 5])
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
1062 @result{} 1 3 3 6 6 6
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
1063 @end group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
1064 @end example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
1065
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
1066 If called with two output arguments the index of the maximum value is also
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
1067 returned.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
1068
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
1069 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
1070 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
1071 [w, iw] = cummax ([1 3 2 6 4 5])
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
1072 @result{}
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30565
diff changeset
1073 M = 1 3 3 6 6 6
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30565
diff changeset
1074 IM = 1 2 2 4 4 4
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
1075 @end group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
1076 @end example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
1077
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
1078 @seealso{cummin, max, min}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
1079 @end deftypefn */)
8777
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 7919
diff changeset
1080 {
9790
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9732
diff changeset
1081 return do_cumminmax_body (args, nargout, false);
8777
724c0f46d9d4 implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents: 7919
diff changeset
1082 }
17403
db8b90a56298 doc: Reword docstrings for cummax, cummin.
Rik <rik@octave.org>
parents: 16370
diff changeset
1083
db8b90a56298 doc: Reword docstrings for cummax, cummin.
Rik <rik@octave.org>
parents: 16370
diff changeset
1084 /*
db8b90a56298 doc: Reword docstrings for cummax, cummin.
Rik <rik@octave.org>
parents: 16370
diff changeset
1085 %!assert (cummax ([1, 4, 2, 3]), [1 4 4 4])
db8b90a56298 doc: Reword docstrings for cummax, cummin.
Rik <rik@octave.org>
parents: 16370
diff changeset
1086 %!assert (cummax ([1; -10; 5; -2]), [1; 1; 5; 5])
db8b90a56298 doc: Reword docstrings for cummax, cummin.
Rik <rik@octave.org>
parents: 16370
diff changeset
1087 %!assert (cummax ([4, i 4.9, -2, 2, 3+4i]), [4, 4, 4.9, 4.9, 4.9, 3+4i])
19591
6b09dd576521 Fix cummin/cummax operations on rows when NaN element present (bug #44009).
Lachlan Andrew <lachlanbis@gmail.com>
parents: 19412
diff changeset
1088 %!assert (cummax ([1 NaN 0; NaN NaN 1], 2), [1 1 1; NaN NaN 1])
17403
db8b90a56298 doc: Reword docstrings for cummax, cummin.
Rik <rik@octave.org>
parents: 16370
diff changeset
1089
db8b90a56298 doc: Reword docstrings for cummax, cummin.
Rik <rik@octave.org>
parents: 16370
diff changeset
1090 %!test
db8b90a56298 doc: Reword docstrings for cummax, cummin.
Rik <rik@octave.org>
parents: 16370
diff changeset
1091 %! x = reshape (8:-1:1, [2,2,2]);
db8b90a56298 doc: Reword docstrings for cummax, cummin.
Rik <rik@octave.org>
parents: 16370
diff changeset
1092 %! assert (cummax (x, 1), reshape ([8 8 6 6 4 4 2 2], [2,2,2]));
db8b90a56298 doc: Reword docstrings for cummax, cummin.
Rik <rik@octave.org>
parents: 16370
diff changeset
1093 %! assert (cummax (x, 2), reshape ([8 7 8 7 4 3 4 3], [2,2,2]));
db8b90a56298 doc: Reword docstrings for cummax, cummin.
Rik <rik@octave.org>
parents: 16370
diff changeset
1094 %! [w, iw] = cummax (x, 3);
db8b90a56298 doc: Reword docstrings for cummax, cummin.
Rik <rik@octave.org>
parents: 16370
diff changeset
1095 %! assert (ndims (w), 3);
db8b90a56298 doc: Reword docstrings for cummax, cummin.
Rik <rik@octave.org>
parents: 16370
diff changeset
1096 %! assert (w, repmat ([8 6; 7 5], [1 1 2]));
db8b90a56298 doc: Reword docstrings for cummax, cummin.
Rik <rik@octave.org>
parents: 16370
diff changeset
1097 %! assert (ndims (iw), 3);
db8b90a56298 doc: Reword docstrings for cummax, cummin.
Rik <rik@octave.org>
parents: 16370
diff changeset
1098 %! assert (iw, ones (2,2,2));
db8b90a56298 doc: Reword docstrings for cummax, cummin.
Rik <rik@octave.org>
parents: 16370
diff changeset
1099
db8b90a56298 doc: Reword docstrings for cummax, cummin.
Rik <rik@octave.org>
parents: 16370
diff changeset
1100 %!error cummax ()
db8b90a56298 doc: Reword docstrings for cummax, cummin.
Rik <rik@octave.org>
parents: 16370
diff changeset
1101 %!error cummax (1, 2, 3)
db8b90a56298 doc: Reword docstrings for cummax, cummin.
Rik <rik@octave.org>
parents: 16370
diff changeset
1102 */
29958
32c3a5805893 move DEFUN and DEFMETHOD functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29359
diff changeset
1103
31605
e88a07dec498 maint: Use macros to begin/end C++ namespaces.
Rik <rik@octave.org>
parents: 30896
diff changeset
1104 OCTAVE_END_NAMESPACE(octave)