Mercurial > octave
annotate libinterp/corefcn/max.cc @ 21966:112b20240c87
move docstrings in C++ files out of C strings and into comments
* __contourc__.cc, __dispatch__.cc, __dsearchn__.cc, __ichol__.cc,
__ilu__.cc, __lin_interpn__.cc, __luinc__.cc, __magick_read__.cc,
__pchip_deriv__.cc, __qp__.cc, balance.cc, besselj.cc, betainc.cc,
bitfcns.cc, bsxfun.cc, cellfun.cc, colloc.cc, conv2.cc, daspk.cc,
dasrt.cc, dassl.cc, data.cc, debug.cc, defaults.cc, det.cc, dirfns.cc,
dlmread.cc, dot.cc, eig.cc, ellipj.cc, error.cc, fft.cc, fft2.cc,
fftn.cc, file-io.cc, filter.cc, find.cc, gammainc.cc, gcd.cc,
getgrent.cc, getpwent.cc, getrusage.cc, givens.cc, graphics.cc,
hash.cc, help.cc, hess.cc, hex2num.cc, input.cc, inv.cc, kron.cc,
load-path.cc, load-save.cc, lookup.cc, ls-oct-text.cc, lsode.cc,
lu.cc, mappers.cc, matrix_type.cc, max.cc, mgorth.cc, nproc.cc,
oct-hist.cc, octave-link.cc, ordschur.cc, pager.cc, pinv.cc,
pr-output.cc, profiler.cc, psi.cc, pt-jit.cc, quad.cc, quadcc.cc,
qz.cc, rand.cc, rcond.cc, regexp.cc, schur.cc, sighandlers.cc,
sparse.cc, spparms.cc, sqrtm.cc, str2double.cc, strfind.cc, strfns.cc,
sub2ind.cc, svd.cc, sylvester.cc, symtab.cc, syscalls.cc, sysdep.cc,
time.cc, toplev.cc, tril.cc, tsearch.cc, typecast.cc, urlwrite.cc,
utils.cc, variables.cc, __delaunayn__.cc, __eigs__.cc,
__fltk_uigetfile__.cc, __glpk__.cc, __init_fltk__.cc,
__init_gnuplot__.cc, __osmesa_print__.cc, __voronoi__.cc, amd.cc,
audiodevinfo.cc, audioread.cc, ccolamd.cc, chol.cc, colamd.cc,
convhulln.cc, dmperm.cc, fftw.cc, qr.cc, symbfact.cc, symrcm.cc,
ov-base.cc, ov-bool-mat.cc, ov-cell.cc, ov-class.cc, ov-classdef.cc,
ov-fcn-handle.cc, ov-fcn-inline.cc, ov-flt-re-mat.cc, ov-int16.cc,
ov-int32.cc, ov-int64.cc, ov-int8.cc, ov-java.cc, ov-null-mat.cc,
ov-oncleanup.cc, ov-range.cc, ov-re-mat.cc, ov-struct.cc,
ov-typeinfo.cc, ov-uint16.cc, ov-uint32.cc, ov-uint64.cc, ov-uint8.cc,
ov-usr-fcn.cc, ov.cc, octave.cc, pt-arg-list.cc, pt-binop.cc,
pt-eval.cc, pt-mat.cc, lex.ll, oct-parse.in.yy:
Docstrings are now comments instead of C strings.
* build-aux/mk-opts.pl: Emit docstrings as comments instead of C
strings.
* DASPK-opts.in, LSODE-opts.in: Don't quote " in docstring fragments.
* builtins.h: Include builtin-defun-decls.h unconditionally.
* defun.h (DEFUN, DEFUNX, DEFCONSTFUN): Simply emit declaration.
(DEFALIAS): Always expand to nothing.
* defun-dld.h: No special macro expansions for MAKE_BUILTINS.
(DEFUN_DLD): Use FORWARD_DECLARE_FUN.
(DEFUNX_DLD): Use FORWARD_DECLARE_FUNX.
* defun-int.h: No special macro expansions for MAKE_BUILTINS.
(FORWARD_DECLARE_FUN, FORWARD_DECLARE_FUNX): New macros.
(DEFINE_FUN_INSTALLER_FUN): If compiling an Octave source file, pass
"external-doc" to DEFINE_FUNX_INSTALLER_FUN.
(DEFUN_INTERNAL, DEFCONSTFUN_INTERNAL, DEFUNX_INTERNAL,
DEFALIAS_INTERNAL): Delete.
* common.mk (move_if_change_rule): New macro.
(simple_move_if_change_rule): Define using move_if_change_rule.
* find-defun-files.sh (DEFUN_PATTERN): Update. Don't transform file
name extension to ".df".
* libinterp/mk-pkg-add, gendoc.pl: Operate directly on source files.
* mkbuiltins: New argument, SRCDIR. Operate directly on source files.
* mkdefs: Delete.
* libinterp/module.mk (BUILT_SOURCES): Update list to contain only
files included in other source files.
(GENERATED_MAKE_BUILTINS_INCS, DEF_FILES): Delete.
(LIBINTERP_BUILT_DISTFILES): Include $(OPT_HANDLERS) here.
(LIBINTERP_BUILT_NODISTFILES): Not here. Remove $(ALL_DEF_FILES from
the list.
(libinterp_EXTRA_DIST): Remove mkdefs from the list.
(FOUND_DEFUN_FILES): Rename from SRC_DEF_FILES.
(DLDFCN_DEFUN_FILES): Rename from DLDFCN_DEF_FILES.
(SRC_DEFUN_FILES): Rename from SRC_DEF_FILES.
(ALL_DEFUN_FILES): Rename from ALL_DEF_FILES.
(%.df: %.cc): Delete pattern rule.
(libinterp/build-env-features.cc, libinterp/builtins.cc,
libinterp/dldfcn/PKG_ADD): Use mv instead of move-if-change.
(libinterp/builtins.cc, libinterp/builtin-defun-decls.h):
Update mkbuiltins command.
($(srcdir)/libinterp/DOCSTRINGS): Update gendoc.pl command.
* liboctave/module.mk (BUILT_SOURCES): Don't include
liboctave-build-info.cc in the list.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Tue, 21 Jun 2016 16:07:51 -0400 |
parents | aba2e6293dd8 |
children | 278fc29b69ca |
rev | line source |
---|---|
2928 | 1 /* |
2 | |
19697
4197fc428c7d
maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents:
19591
diff
changeset
|
3 Copyright (C) 1996-2015 John W. Eaton |
8777
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7919
diff
changeset
|
4 Copyright (C) 2009 VZLU Prague |
2928 | 5 |
6 This file is part of Octave. | |
7 | |
8 Octave is free software; you can redistribute it and/or modify it | |
9 under the terms of the GNU General Public License as published by the | |
7016 | 10 Free Software Foundation; either version 3 of the License, or (at your |
11 option) any later version. | |
2928 | 12 |
13 Octave is distributed in the hope that it will be useful, but WITHOUT | |
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
16 for more details. | |
17 | |
18 You should have received a copy of the GNU General Public License | |
7016 | 19 along with Octave; see the file COPYING. If not, see |
20 <http://www.gnu.org/licenses/>. | |
2928 | 21 |
22 */ | |
23 | |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21604
diff
changeset
|
24 #if defined (HAVE_CONFIG_H) |
21301
40de9f8f23a6
Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents:
21265
diff
changeset
|
25 # include "config.h" |
2928 | 26 #endif |
27 | |
28 #include "lo-ieee.h" | |
3248 | 29 #include "lo-mappers.h" |
7231 | 30 #include "lo-math.h" |
4844 | 31 #include "dNDArray.h" |
32 #include "CNDArray.h" | |
4153 | 33 #include "quit.h" |
2928 | 34 |
15039
e753177cde93
maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents:
14501
diff
changeset
|
35 #include "defun.h" |
2928 | 36 #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
|
37 #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
|
38 #include "ovl.h" |
2928 | 39 |
4844 | 40 #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
|
41 #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
|
42 #include "ov-cx-sparse.h" |
4844 | 43 |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21100
diff
changeset
|
44 template <typename ArrayType> |
9790
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
45 static octave_value_list |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
46 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
|
47 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
|
48 { |
20892 | 49 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
|
50 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
|
51 |
20892 | 52 if (nargout <= 1) |
9790
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
53 { |
20892 | 54 if (ismin) |
55 retval(0) = array.min (dim); | |
56 else | |
57 retval(0) = array.max (dim); | |
58 } | |
59 else | |
60 { | |
9790
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
61 Array<octave_idx_type> idx; |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
62 if (ismin) |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
63 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
|
64 else |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
65 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
|
66 |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
67 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
|
68 } |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
69 |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
70 return retval; |
8777
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7919
diff
changeset
|
71 } |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7919
diff
changeset
|
72 |
16370
7ce21619a4b9
min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents:
15195
diff
changeset
|
73 // 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
|
74 // 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
|
75 // 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
|
76 // 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
|
77 // 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
|
78 // 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
|
79 // functions work. |
7ce21619a4b9
min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents:
15195
diff
changeset
|
80 |
7ce21619a4b9
min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents:
15195
diff
changeset
|
81 template <> |
7ce21619a4b9
min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents:
15195
diff
changeset
|
82 octave_value_list |
7ce21619a4b9
min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents:
15195
diff
changeset
|
83 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
|
84 int nargout, int dim, bool ismin) |
7ce21619a4b9
min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents:
15195
diff
changeset
|
85 { |
20892 | 86 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
|
87 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
|
88 |
20892 | 89 if (nargout <= 1) |
16370
7ce21619a4b9
min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents:
15195
diff
changeset
|
90 { |
20892 | 91 if (ismin) |
92 retval(0) = NDArray (array.min (dim)); | |
93 else | |
94 retval(0) = NDArray (array.max (dim)); | |
95 } | |
96 else | |
97 { | |
16370
7ce21619a4b9
min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents:
15195
diff
changeset
|
98 Array<octave_idx_type> idx; |
7ce21619a4b9
min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents:
15195
diff
changeset
|
99 if (ismin) |
7ce21619a4b9
min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents:
15195
diff
changeset
|
100 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
|
101 else |
7ce21619a4b9
min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents:
15195
diff
changeset
|
102 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
|
103 |
7ce21619a4b9
min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents:
15195
diff
changeset
|
104 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
|
105 } |
7ce21619a4b9
min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents:
15195
diff
changeset
|
106 |
7ce21619a4b9
min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents:
15195
diff
changeset
|
107 return retval; |
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 |
21265
f780d057a3ec
Let max/min return a second (index) value for sparse logicals (bug #41512).
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21200
diff
changeset
|
110 // Specialization for bool arrays (dense or sparse). |
9993
b22a2f4b34aa
support min/max with logical arrays
Jaroslav Hajek <highegg@gmail.com>
parents:
9791
diff
changeset
|
111 template <> |
b22a2f4b34aa
support min/max with logical arrays
Jaroslav Hajek <highegg@gmail.com>
parents:
9791
diff
changeset
|
112 octave_value_list |
b22a2f4b34aa
support min/max with logical arrays
Jaroslav Hajek <highegg@gmail.com>
parents:
9791
diff
changeset
|
113 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
|
114 int nargout, int dim, bool ismin) |
b22a2f4b34aa
support min/max with logical arrays
Jaroslav Hajek <highegg@gmail.com>
parents:
9791
diff
changeset
|
115 { |
b22a2f4b34aa
support min/max with logical arrays
Jaroslav Hajek <highegg@gmail.com>
parents:
9791
diff
changeset
|
116 octave_value_list retval; |
b22a2f4b34aa
support min/max with logical arrays
Jaroslav Hajek <highegg@gmail.com>
parents:
9791
diff
changeset
|
117 |
21265
f780d057a3ec
Let max/min return a second (index) value for sparse logicals (bug #41512).
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21200
diff
changeset
|
118 if (! arg.is_sparse_type ()) |
9993
b22a2f4b34aa
support min/max with logical arrays
Jaroslav Hajek <highegg@gmail.com>
parents:
9791
diff
changeset
|
119 { |
21265
f780d057a3ec
Let max/min return a second (index) value for sparse logicals (bug #41512).
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21200
diff
changeset
|
120 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
|
121 { |
f780d057a3ec
Let max/min return a second (index) value for sparse logicals (bug #41512).
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21200
diff
changeset
|
122 // 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
|
123 boolNDArray array = arg.bool_array_value (); |
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 (array.is_empty ()) |
f780d057a3ec
Let max/min return a second (index) value for sparse logicals (bug #41512).
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21200
diff
changeset
|
126 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
|
127 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
|
128 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
|
129 else |
f780d057a3ec
Let max/min return a second (index) value for sparse logicals (bug #41512).
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21200
diff
changeset
|
130 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
|
131 } |
9993
b22a2f4b34aa
support min/max with logical arrays
Jaroslav Hajek <highegg@gmail.com>
parents:
9791
diff
changeset
|
132 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
|
133 { |
f780d057a3ec
Let max/min return a second (index) value for sparse logicals (bug #41512).
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21200
diff
changeset
|
134 // 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
|
135 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
|
136 |
f780d057a3ec
Let max/min return a second (index) value for sparse logicals (bug #41512).
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21200
diff
changeset
|
137 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
|
138 } |
9993
b22a2f4b34aa
support min/max with logical arrays
Jaroslav Hajek <highegg@gmail.com>
parents:
9791
diff
changeset
|
139 } |
b22a2f4b34aa
support min/max with logical arrays
Jaroslav Hajek <highegg@gmail.com>
parents:
9791
diff
changeset
|
140 else |
b22a2f4b34aa
support min/max with logical arrays
Jaroslav Hajek <highegg@gmail.com>
parents:
9791
diff
changeset
|
141 { |
21604
d7a268e68e69
maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
142 // 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
|
143 // 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
|
144 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
|
145 |
21265
f780d057a3ec
Let max/min return a second (index) value for sparse logicals (bug #41512).
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21200
diff
changeset
|
146 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
|
147 } |
b22a2f4b34aa
support min/max with logical arrays
Jaroslav Hajek <highegg@gmail.com>
parents:
9791
diff
changeset
|
148 |
b22a2f4b34aa
support min/max with logical arrays
Jaroslav Hajek <highegg@gmail.com>
parents:
9791
diff
changeset
|
149 return retval; |
b22a2f4b34aa
support min/max with logical arrays
Jaroslav Hajek <highegg@gmail.com>
parents:
9791
diff
changeset
|
150 } |
b22a2f4b34aa
support min/max with logical arrays
Jaroslav Hajek <highegg@gmail.com>
parents:
9791
diff
changeset
|
151 |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21100
diff
changeset
|
152 template <typename ArrayType> |
9790
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
153 static octave_value |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
154 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
|
155 bool ismin) |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
156 { |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
157 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
|
158 |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
159 octave_value retval; |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
160 |
19412
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
161 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
|
162 { |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
163 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
|
164 ArrayType y = octave_value_extract<ArrayType> (argy); |
7189 | 165 |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20228
diff
changeset
|
166 if (ismin) |
9790
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
167 retval = min (x, y); |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
168 else |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
169 retval = max (x, y); |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
170 } |
19412
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
171 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
|
172 { |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
173 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
|
174 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
|
175 |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20228
diff
changeset
|
176 if (ismin) |
9790
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
177 retval = min (x, y); |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
178 else |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
179 retval = max (x, y); |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
180 } |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
181 else |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
182 { |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
183 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
|
184 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
|
185 |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20228
diff
changeset
|
186 if (ismin) |
9790
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
187 retval = min (x, y); |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
188 else |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
189 retval = max (x, y); |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
190 } |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
191 |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
192 return retval; |
8777
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7919
diff
changeset
|
193 } |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7919
diff
changeset
|
194 |
16370
7ce21619a4b9
min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents:
15195
diff
changeset
|
195 // 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
|
196 // 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
|
197 // 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
|
198 // 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
|
199 // 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
|
200 // 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
|
201 // functions work. |
7ce21619a4b9
min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents:
15195
diff
changeset
|
202 |
7ce21619a4b9
min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents:
15195
diff
changeset
|
203 template <> |
7ce21619a4b9
min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents:
15195
diff
changeset
|
204 octave_value |
7ce21619a4b9
min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents:
15195
diff
changeset
|
205 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
|
206 const octave_value& argy, bool ismin) |
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 octave_value retval; |
7ce21619a4b9
min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents:
15195
diff
changeset
|
209 |
19412
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
210 charNDArray x = octave_value_extract<charNDArray> (argx); |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
211 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
|
212 |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20228
diff
changeset
|
213 if (ismin) |
19412
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
214 { |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
215 if (x.numel () == 1) |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
216 retval = NDArray (min (x(0), y)); |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
217 else if (y.numel () == 1) |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
218 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
|
219 else |
7ce21619a4b9
min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents:
15195
diff
changeset
|
220 retval = NDArray (min (x, y)); |
7ce21619a4b9
min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents:
15195
diff
changeset
|
221 } |
7ce21619a4b9
min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents:
15195
diff
changeset
|
222 else |
7ce21619a4b9
min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents:
15195
diff
changeset
|
223 { |
19412
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
224 if (x.numel () == 1) |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
225 retval = NDArray (max (x(0), y)); |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
226 else if (y.numel () == 1) |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
227 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
|
228 else |
7ce21619a4b9
min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents:
15195
diff
changeset
|
229 retval = NDArray (max (x, y)); |
7ce21619a4b9
min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents:
15195
diff
changeset
|
230 } |
7ce21619a4b9
min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents:
15195
diff
changeset
|
231 |
7ce21619a4b9
min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents:
15195
diff
changeset
|
232 return retval; |
7ce21619a4b9
min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents:
15195
diff
changeset
|
233 } |
7ce21619a4b9
min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents:
15195
diff
changeset
|
234 |
9790
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
235 static octave_value_list |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
236 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
|
237 int nargout, bool ismin) |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
238 { |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
239 int nargin = args.length (); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
240 |
20802
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20743
diff
changeset
|
241 if (nargin < 1 || nargin > 3) |
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20743
diff
changeset
|
242 print_usage (); |
20921
4d3daf7e43f3
eliminate trailing whitespace in source files
John W. Eaton <jwe@octave.org>
parents:
20892
diff
changeset
|
243 |
20892 | 244 octave_value_list retval (nargout > 1 ? 2 : 1); |
245 | |
246 const char *func = ismin ? "min" : "max"; | |
247 | |
9790
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
248 if (nargin == 3 || nargin == 1) |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
249 { |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
250 octave_value arg = args(0); |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
251 int dim = -1; |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
252 if (nargin == 3) |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
253 { |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
254 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
|
255 |
b6408331bfa2
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20555
diff
changeset
|
256 if (dim < 0) |
20831
35241c4b696c
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20802
diff
changeset
|
257 error ("%s: DIM must be a valid dimension", func); |
8777
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7919
diff
changeset
|
258 |
9790
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
259 if (! args(1).is_empty ()) |
13717
fcdf0993b8c9
Fix segfault in do_minmax_bin_op (bug #34589)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
11586
diff
changeset
|
260 warning ("%s: second argument is ignored", func); |
9790
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
261 } |
7189 | 262 |
9790
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
263 switch (arg.builtin_type ()) |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
264 { |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
265 case btyp_double: |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
266 { |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
267 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
|
268 { |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
269 Range 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
|
270 if (range.numel () < 1) |
9790
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 retval(0) = arg; |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
273 if (nargout > 1) |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
274 retval(1) = arg; |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
275 } |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
276 else if (ismin) |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
277 { |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
278 retval(0) = range.min (); |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
279 if (nargout > 1) |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
280 retval(1) = static_cast<double> |
20228
00cf2847355d
Deprecate Array::nelem() and Range::nelem() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20172
diff
changeset
|
281 (range.inc () < 0 ? range.numel () : 1); |
9790
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 else |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
284 { |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
285 retval(0) = range.max (); |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
286 if (nargout > 1) |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
287 retval(1) = static_cast<double> |
20228
00cf2847355d
Deprecate Array::nelem() and Range::nelem() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20172
diff
changeset
|
288 (range.inc () >= 0 ? range.numel () : 1); |
9790
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 } |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
291 else if (arg.is_sparse_type ()) |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
292 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
|
293 ismin); |
9790
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
294 else |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
295 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
|
296 |
9790
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
297 } |
20802
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20743
diff
changeset
|
298 break; |
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20743
diff
changeset
|
299 |
9790
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
300 case btyp_complex: |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
301 { |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
302 if (arg.is_sparse_type ()) |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
303 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
|
304 ismin); |
9790
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
305 else |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
306 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
|
307 ismin); |
9790
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
308 } |
20802
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20743
diff
changeset
|
309 break; |
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20743
diff
changeset
|
310 |
9790
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
311 case btyp_float: |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
312 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
|
313 break; |
20802
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20743
diff
changeset
|
314 |
9790
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
315 case btyp_float_complex: |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
316 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
|
317 ismin); |
9790
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
318 break; |
20802
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20743
diff
changeset
|
319 |
16370
7ce21619a4b9
min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents:
15195
diff
changeset
|
320 case btyp_char: |
7ce21619a4b9
min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents:
15195
diff
changeset
|
321 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
|
322 break; |
20802
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20743
diff
changeset
|
323 |
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20743
diff
changeset
|
324 #define MAKE_INT_BRANCH(X) \ |
9790
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
325 case btyp_ ## X: \ |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
326 retval = do_minmax_red_op<X ## NDArray> (arg, nargout, dim, ismin); \ |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
327 break; |
20802
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20743
diff
changeset
|
328 |
9790
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
329 MAKE_INT_BRANCH (int8); |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
330 MAKE_INT_BRANCH (int16); |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
331 MAKE_INT_BRANCH (int32); |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
332 MAKE_INT_BRANCH (int64); |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
333 MAKE_INT_BRANCH (uint8); |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
334 MAKE_INT_BRANCH (uint16); |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
335 MAKE_INT_BRANCH (uint32); |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
336 MAKE_INT_BRANCH (uint64); |
20802
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20743
diff
changeset
|
337 |
9790
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
338 #undef MAKE_INT_BRANCH |
20802
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20743
diff
changeset
|
339 |
9993
b22a2f4b34aa
support min/max with logical arrays
Jaroslav Hajek <highegg@gmail.com>
parents:
9791
diff
changeset
|
340 case btyp_bool: |
b22a2f4b34aa
support min/max with logical arrays
Jaroslav Hajek <highegg@gmail.com>
parents:
9791
diff
changeset
|
341 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
|
342 break; |
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 default: |
21100
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
20946
diff
changeset
|
345 err_wrong_type_arg (func, arg); |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
346 } |
9790
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
347 } |
20802
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20743
diff
changeset
|
348 else |
9790
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
349 { |
18100
6a71e5030df5
Follow coding convention of defining and initializing only 1 variable per line in liboctinterp.
Rik <rik@octave.org>
parents:
18076
diff
changeset
|
350 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
|
351 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
|
352 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
|
353 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
|
354 builtin_type_t rtyp; |
7ce21619a4b9
min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents:
15195
diff
changeset
|
355 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
|
356 rtyp = btyp_char; |
20946 | 357 // FIXME: This is what should happen when boolNDArray has max() |
358 // else if (xtyp == btyp_bool && ytyp == btyp_bool) | |
359 // rtyp = btyp_bool; | |
16370
7ce21619a4b9
min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents:
15195
diff
changeset
|
360 else |
7ce21619a4b9
min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents:
15195
diff
changeset
|
361 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
|
362 |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
363 switch (rtyp) |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
364 { |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
365 case btyp_double: |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
366 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
367 if ((argx.is_sparse_type () |
9790
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
368 && (argy.is_sparse_type () || argy.is_scalar_type ())) |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
369 || (argy.is_sparse_type () && argx.is_scalar_type ())) |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
370 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
|
371 else |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
372 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
|
373 } |
20802
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20743
diff
changeset
|
374 break; |
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20743
diff
changeset
|
375 |
9790
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
376 case btyp_complex: |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
377 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
378 if ((argx.is_sparse_type () |
9790
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
379 && (argy.is_sparse_type () || argy.is_scalar_type ())) |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
380 || (argy.is_sparse_type () && argx.is_scalar_type ())) |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
381 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
|
382 ismin); |
9790
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
383 else |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
384 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
|
385 } |
20802
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20743
diff
changeset
|
386 break; |
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20743
diff
changeset
|
387 |
9790
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
388 case btyp_float: |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
389 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
|
390 break; |
20802
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20743
diff
changeset
|
391 |
9790
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
392 case btyp_float_complex: |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
393 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
|
394 break; |
20802
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20743
diff
changeset
|
395 |
16370
7ce21619a4b9
min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents:
15195
diff
changeset
|
396 case btyp_char: |
7ce21619a4b9
min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents:
15195
diff
changeset
|
397 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
|
398 break; |
20802
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20743
diff
changeset
|
399 |
9790
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
400 #define MAKE_INT_BRANCH(X) \ |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
401 case btyp_ ## X: \ |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
402 retval = do_minmax_bin_op<X ## NDArray> (argx, argy, ismin); \ |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
403 break; |
20802
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20743
diff
changeset
|
404 |
9790
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
405 MAKE_INT_BRANCH (int8); |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
406 MAKE_INT_BRANCH (int16); |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
407 MAKE_INT_BRANCH (int32); |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
408 MAKE_INT_BRANCH (int64); |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
409 MAKE_INT_BRANCH (uint8); |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
410 MAKE_INT_BRANCH (uint16); |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
411 MAKE_INT_BRANCH (uint32); |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
412 MAKE_INT_BRANCH (uint64); |
20802
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20743
diff
changeset
|
413 |
9790
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
414 #undef MAKE_INT_BRANCH |
20802
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20743
diff
changeset
|
415 |
20946 | 416 // FIXME: This is what should happen when boolNDArray has max() |
417 // case btyp_bool: | |
418 // retval = do_minmax_bin_op<boolNDArray> (argx, argy, ismin); | |
419 // break; | |
420 | |
9790
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
421 default: |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
422 error ("%s: cannot compute %s (%s, %s)", func, func, |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
423 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
|
424 } |
19412
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
425 |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
426 // FIXME: Delete when boolNDArray has max() |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
427 if (xtyp == btyp_bool && ytyp == btyp_bool) |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
428 retval(0) = retval(0).bool_array_value (); |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
429 |
9790
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
430 } |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
431 |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
432 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
|
433 } |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
434 |
15039
e753177cde93
maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents:
14501
diff
changeset
|
435 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
|
436 doc: /* -*- texinfo -*- |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
437 @deftypefn {} {} 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
|
438 @deftypefnx {} {} min (@var{x}, [], @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
|
439 @deftypefnx {} {[@var{w}, @var{iw}] =} 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
|
440 @deftypefnx {} {} min (@var{x}, @var{y}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
441 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
|
442 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
443 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
|
444 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
|
445 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
|
446 dimension. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
447 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
448 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
|
449 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
|
450 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
|
451 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
452 For two matrices (or a matrix and a scalar), return the pairwise minimum. |
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 Thus, |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
455 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
456 @example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
457 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
|
458 @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
|
459 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
460 @noindent |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
461 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
|
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 @group |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
465 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
|
466 @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
|
467 @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
|
468 @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
|
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 @noindent |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
471 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
|
472 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
|
473 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
474 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
|
475 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
|
476 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
|
477 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
478 @example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
479 @group |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
480 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
|
481 @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
|
482 @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
|
483 @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
|
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 @noindent |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
486 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
|
487 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
|
488 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
489 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
|
490 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
|
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 @example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
493 @group |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
494 [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
|
495 @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
|
496 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
|
497 @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
|
498 @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
|
499 @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
|
500 @end deftypefn */) |
2928 | 501 { |
9790
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
502 return do_minmax_body (args, nargout, true); |
2928 | 503 } |
504 | |
7600
24abf5a702d9
Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
505 /* |
19412
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
506 ## 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
|
507 %!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
|
508 %!assert (min ([1; -10; 5; -2]), -10) |
19412
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
509 %!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
|
510 ## Special routines for char arrays |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
511 %!assert (min (["abc", "ABC"]), 65) |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
512 %!assert (min (["abc"; "CBA"]), [67 66 65]) |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
513 ## Special routines for logical arrays |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
514 %!assert (min (logical ([])), logical ([])) |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
515 %!assert (min (logical ([0 0 1 0])), false) |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
516 %!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
|
517 ## Single values |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
518 %!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
|
519 %!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
|
520 %!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
|
521 ## Integer values |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
522 %!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
|
523 %!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
|
524 %!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
|
525 %!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
|
526 %!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
|
527 %!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
|
528 %!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
|
529 %!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
|
530 %!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
|
531 %!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
|
532 %!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
|
533 %!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
|
534 %!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
|
535 %!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
|
536 %!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
|
537 %!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
|
538 ## Sparse double values |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
539 %!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
|
540 %!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
|
541 ## FIXME: sparse doesn't order complex values by phase angle |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
542 %!xtest |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
543 %! 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
|
544 |
19412
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
545 ## Test dimension argument |
7600
24abf5a702d9
Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
546 %!test |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14360
diff
changeset
|
547 %! x = reshape (1:8, [2,2,2]); |
19412
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
548 %! 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
|
549 %! 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
|
550 %! [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
|
551 %! assert (ndims (y), 2); |
19412
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
552 %! 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
|
553 %! assert (ndims (i), 2); |
19412
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
554 %! assert (i, [1, 1; 1, 1]); |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
555 |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
556 ## Test 2-output forms for various arg types |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
557 ## Special routines for char arrays |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
558 %!test |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
559 %! [y, i] = min (["abc", "ABC"]); |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
560 %! assert (y, 65); |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
561 %! assert (i, 4); |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
562 ## Special routines for logical arrays |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
563 %!test |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
564 %! x = logical ([0 0 1 0]); |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
565 %! [y, i] = min (x); |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
566 %! assert (y, false); |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
567 %! assert (i, 1); |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
568 ## Special handling of ranges |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
569 %!test |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
570 %! rng = 1:2:10; |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
571 %! [y, i] = min (rng); |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
572 %! assert (y, 1); |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
573 %! assert (i, 1); |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
574 %! rng = 10:-2:1; |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
575 %! [y, i] = min (rng); |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
576 %! assert (y, 2); |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
577 %! assert (i, 5); |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
578 |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
579 ## 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
|
580 ## Test generic double class |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
581 %!test |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
582 %! x = [1, 2, 3, 4]; y = fliplr (x); |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
583 %! assert (min (x, y), [1 2 2 1]); |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
584 %! assert (min (x, 3), [1 2 3 3]); |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
585 %! assert (min (2, x), [1 2 2 2]); |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
586 %! 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
|
587 ## 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
|
588 ## 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
|
589 ## appears in the argument list. |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
590 %!xtest |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
591 %! x = [1, 2, 3, 4]; y = fliplr (x); |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
592 %! assert (min (x, 2i), [2i 2i 3 4]); |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
593 ## Special routines for char arrays |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
594 %!assert (min ("abc", "b"), [97 98 98]) |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
595 %!assert (min ("b", "cba"), [98 98 97]) |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
596 ## Special handling for logical arrays |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
597 %!assert (min ([true false], false), [false false]) |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
598 %!assert (min (true, [true false]), [true false]) |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
599 ## Single values |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
600 %!test |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
601 %! 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
|
602 %! 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
|
603 %! 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
|
604 %! 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
|
605 %! 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
|
606 ## Integer 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 = uint8 ([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), uint8 ([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), uint8 ([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), uint8 ([1 2 2 2])); |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
612 %! 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
|
613 %! 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
|
614 %! 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
|
615 %! 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
|
616 %! 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
|
617 %! 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
|
618 %! 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
|
619 %! 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
|
620 %! 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
|
621 %! 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
|
622 %! 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
|
623 %! 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
|
624 %! 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
|
625 %! 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
|
626 %! 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
|
627 %! 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
|
628 %! 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
|
629 %! 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
|
630 %! 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
|
631 %! 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
|
632 %! 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
|
633 %! 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
|
634 %! 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
|
635 %! 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
|
636 %! 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
|
637 %! 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
|
638 %! 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
|
639 %! 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
|
640 ## Sparse double values |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
641 %!test |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
642 %! 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
|
643 %! 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
|
644 %! 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
|
645 %! 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
|
646 %! 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
|
647 |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14360
diff
changeset
|
648 %!error min () |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14360
diff
changeset
|
649 %!error min (1, 2, 3, 4) |
19412
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
650 %!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
|
651 %!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
|
652 %!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
|
653 %!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
|
654 */ |
24abf5a702d9
Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
655 |
15039
e753177cde93
maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents:
14501
diff
changeset
|
656 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
|
657 doc: /* -*- texinfo -*- |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
658 @deftypefn {} {} 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
|
659 @deftypefnx {} {} max (@var{x}, [], @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
|
660 @deftypefnx {} {[@var{w}, @var{iw}] =} 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
|
661 @deftypefnx {} {} max (@var{x}, @var{y}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
662 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
|
663 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
664 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
|
665 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
|
666 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
|
667 dimension. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
668 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
669 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
|
670 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
|
671 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
|
672 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
673 For two matrices (or a matrix and a scalar), return the pairwise maximum. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
674 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
675 Thus, |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
676 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
677 @example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
678 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
|
679 @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
|
680 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
681 @noindent |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
682 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
|
683 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
684 @example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
685 @group |
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 (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
|
687 @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
|
688 @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
|
689 @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
|
690 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
691 @noindent |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
692 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
|
693 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
|
694 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
695 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
|
696 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
|
697 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
|
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 @example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
700 @group |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
701 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
|
702 @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
|
703 @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
|
704 @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
|
705 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
706 @noindent |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
707 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
|
708 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
|
709 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
710 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
|
711 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
|
712 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
713 @example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
714 @group |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
715 [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
|
716 @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
|
717 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
|
718 @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
|
719 @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
|
720 @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
|
721 @end deftypefn */) |
2928 | 722 { |
9790
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
723 return do_minmax_body (args, nargout, false); |
2928 | 724 } |
725 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
726 /* |
19412
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
727 ## 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
|
728 %!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
|
729 %!assert (max ([1; -10; 5; -2]), 5) |
19412
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
730 %!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
|
731 ## Special routines for char arrays |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
732 %!assert (max (["abc", "ABC"]), 99) |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
733 %!assert (max (["abc"; "CBA"]), [97 98 99]) |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
734 ## Special routines for logical arrays |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
735 %!assert (max (logical ([])), logical ([])) |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
736 %!assert (max (logical ([0 0 1 0])), true) |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
737 %!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
|
738 ## Single values |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
739 %!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
|
740 %!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
|
741 %!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
|
742 ## Integer values |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
743 %!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
|
744 %!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
|
745 %!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
|
746 %!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
|
747 %!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
|
748 %!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
|
749 %!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
|
750 %!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
|
751 %!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
|
752 %!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
|
753 %!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
|
754 %!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
|
755 %!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
|
756 %!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
|
757 %!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
|
758 %!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
|
759 ## Sparse double values |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
760 %!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
|
761 %!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
|
762 %!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
|
763 |
19412
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
764 ## Test dimension argument |
7600
24abf5a702d9
Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
765 %!test |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14360
diff
changeset
|
766 %! 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
|
767 %! 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
|
768 %! 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
|
769 %! [y, i] = min (x, [], 3); |
19412
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
770 %! assert (ndims (y), 2); |
7600
24abf5a702d9
Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
771 %! assert (y, [1, 3; 2, 4]); |
19412
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
772 %! assert (ndims (i), 2); |
7600
24abf5a702d9
Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
773 %! assert (i, [1, 1; 1, 1]); |
24abf5a702d9
Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
774 |
19412
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
775 ## Test 2-output forms for various arg types |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
776 ## Special routines for char arrays |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
777 %!test |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
778 %! [y, i] = max (["abc", "ABC"]); |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
779 %! assert (y, 99); |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
780 %! assert (i, 3); |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
781 ## Special routines for logical arrays |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
782 %!test |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
783 %! x = logical ([0 0 1 0]); |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
784 %! [y, i] = max (x); |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
785 %! assert (y, true); |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
786 %! assert (i, 3); |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
787 ## Special handling of ranges |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
788 %!test |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
789 %! rng = 1:2:10; |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
790 %! [y, i] = max (rng); |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
791 %! assert (y, 9); |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
792 %! assert (i, 5); |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
793 %! rng = 10:-2:1; |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
794 %! [y, i] = max (rng); |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
795 %! assert (y, 10); |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
796 %! assert (i, 1); |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
797 |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
798 ## 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
|
799 ## Test generic double class |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
800 %!test |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
801 %! x = [1, 2, 3, 4]; y = fliplr (x); |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
802 %! assert (max (x, y), [4 3 3 4]); |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
803 %! assert (max (x, 3), [3 3 3 4]); |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
804 %! assert (max (2, x), [2 2 3 4]); |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
805 %! 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
|
806 ## 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
|
807 ## 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
|
808 ## appears in the argument list. |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
809 %!xtest |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
810 %! x = [1, 2, 3, 4]; y = fliplr (x); |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
811 %! assert (max (x, 2i), [2i 2i 3 4]); |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
812 ## Special routines for char arrays |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
813 %!assert (max ("abc", "b"), [98 98 99]) |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
814 %!assert (max ("b", "cba"), [99 98 98]) |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
815 ## Special handling for logical arrays |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
816 %!assert (max ([true false], false), [true false]) |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
817 %!assert (max (true, [false false]), [true true]) |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
818 ## Single values |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
819 %!test |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
820 %! 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
|
821 %! 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
|
822 %! 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
|
823 %! 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
|
824 %! 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
|
825 ## Integer values |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
826 %!test |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
827 %! 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
|
828 %! 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
|
829 %! 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
|
830 %! 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
|
831 %! 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
|
832 %! 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
|
833 %! 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
|
834 %! 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
|
835 %! 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
|
836 %! 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
|
837 %! 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
|
838 %! 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
|
839 %! 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
|
840 %! 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
|
841 %! 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
|
842 %! 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
|
843 %! 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
|
844 %! 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
|
845 %! 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
|
846 %! 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
|
847 %! 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
|
848 %! 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
|
849 %! 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
|
850 %! 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
|
851 %! 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
|
852 %! 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
|
853 %! 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
|
854 %! 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
|
855 %! 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
|
856 %! 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
|
857 %! 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
|
858 %! 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
|
859 ## Sparse double values |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
860 %!test |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
861 %! 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
|
862 %! 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
|
863 %! 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
|
864 %! 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
|
865 %! 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
|
866 |
18076 | 867 ## Test for bug #40743 |
868 %!assert (max (zeros (1,0), ones (1,1)), zeros (1,0)) | |
869 %!assert (max (sparse (zeros (1,0)), sparse (ones (1,1))), sparse (zeros (1,0))) | |
870 | |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14360
diff
changeset
|
871 %!error max () |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14360
diff
changeset
|
872 %!error max (1, 2, 3, 4) |
19412
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
873 %!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
|
874 %!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
|
875 %!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
|
876 %!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
|
877 |
7600
24abf5a702d9
Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
878 */ |
24abf5a702d9
Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
879 |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21100
diff
changeset
|
880 template <typename ArrayType> |
9790
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
881 static octave_value_list |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
882 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
|
883 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
|
884 { |
20892 | 885 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
|
886 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
|
887 |
20892 | 888 if (nargout <= 1) |
889 { | |
890 if (ismin) | |
891 retval(0) = array.cummin (dim); | |
892 else | |
893 retval(0) = array.cummax (dim); | |
894 } | |
895 else | |
9790
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
896 { |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
897 retval.resize (2); |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
898 Array<octave_idx_type> idx; |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
899 if (ismin) |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
900 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
|
901 else |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
902 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
|
903 |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
904 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
|
905 } |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
906 |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
907 return retval; |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
908 } |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
909 |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
910 static octave_value_list |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
911 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
|
912 int nargout, bool ismin) |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
913 { |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
914 int nargin = args.length (); |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
915 |
20802
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20743
diff
changeset
|
916 if (nargin < 1 || nargin > 2) |
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20743
diff
changeset
|
917 print_usage (); |
20743
b6408331bfa2
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20555
diff
changeset
|
918 |
20892 | 919 const char *func = ismin ? "cummin" : "cummax"; |
920 | |
20802
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20743
diff
changeset
|
921 octave_value arg = args(0); |
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20743
diff
changeset
|
922 int dim = -1; |
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20743
diff
changeset
|
923 if (nargin == 2) |
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20743
diff
changeset
|
924 { |
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20743
diff
changeset
|
925 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
|
926 |
20802
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20743
diff
changeset
|
927 if (dim < 0) |
20831
35241c4b696c
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20802
diff
changeset
|
928 error ("%s: DIM must be a valid dimension", func); |
9790
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
929 } |
20802
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20743
diff
changeset
|
930 |
20892 | 931 octave_value_list retval; |
932 | |
20802
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20743
diff
changeset
|
933 switch (arg.builtin_type ()) |
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20743
diff
changeset
|
934 { |
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20743
diff
changeset
|
935 case btyp_double: |
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20743
diff
changeset
|
936 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
|
937 break; |
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20743
diff
changeset
|
938 |
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20743
diff
changeset
|
939 case btyp_complex: |
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20743
diff
changeset
|
940 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
|
941 ismin); |
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20743
diff
changeset
|
942 break; |
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_float: |
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<FloatNDArray> (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_float_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<FloatComplexNDArray> (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 #define MAKE_INT_BRANCH(X) \ |
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20743
diff
changeset
|
954 case btyp_ ## X: \ |
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20743
diff
changeset
|
955 retval = do_cumminmax_red_op<X ## NDArray> (arg, nargout, dim, \ |
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20743
diff
changeset
|
956 ismin); \ |
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20743
diff
changeset
|
957 break; |
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20743
diff
changeset
|
958 |
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20743
diff
changeset
|
959 MAKE_INT_BRANCH (int8); |
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20743
diff
changeset
|
960 MAKE_INT_BRANCH (int16); |
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20743
diff
changeset
|
961 MAKE_INT_BRANCH (int32); |
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20743
diff
changeset
|
962 MAKE_INT_BRANCH (int64); |
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20743
diff
changeset
|
963 MAKE_INT_BRANCH (uint8); |
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20743
diff
changeset
|
964 MAKE_INT_BRANCH (uint16); |
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20743
diff
changeset
|
965 MAKE_INT_BRANCH (uint32); |
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20743
diff
changeset
|
966 MAKE_INT_BRANCH (uint64); |
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20743
diff
changeset
|
967 |
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20743
diff
changeset
|
968 #undef MAKE_INT_BRANCH |
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20743
diff
changeset
|
969 |
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20743
diff
changeset
|
970 case btyp_bool: |
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20743
diff
changeset
|
971 { |
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20743
diff
changeset
|
972 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
|
973 ismin); |
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20743
diff
changeset
|
974 if (retval.length () > 0) |
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20743
diff
changeset
|
975 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
|
976 } |
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20743
diff
changeset
|
977 break; |
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20743
diff
changeset
|
978 |
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20743
diff
changeset
|
979 default: |
21100
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
20946
diff
changeset
|
980 err_wrong_type_arg (func, arg); |
20802
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20743
diff
changeset
|
981 } |
9790
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
982 |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
983 return retval; |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
984 } |
8777
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7919
diff
changeset
|
985 |
15039
e753177cde93
maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents:
14501
diff
changeset
|
986 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
|
987 doc: /* -*- texinfo -*- |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
988 @deftypefn {} {} cummin (@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
|
989 @deftypefnx {} {} cummin (@var{x}, @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
|
990 @deftypefnx {} {[@var{w}, @var{iw}] =} cummin (@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
|
991 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
|
992 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
993 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
|
994 example: |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
995 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
996 @example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
997 @group |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
998 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
|
999 @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
|
1000 @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
|
1001 @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
|
1002 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
1003 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
|
1004 returned. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
1005 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
1006 @example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
1007 @group |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
1008 [w, iw] = 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
|
1009 @result{} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
1010 w = 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
|
1011 iw = 1 2 2 4 4 6 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
1012 @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
|
1013 @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
|
1014 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
1015 @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
|
1016 @end deftypefn */) |
8777
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7919
diff
changeset
|
1017 { |
9790
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
1018 return do_cumminmax_body (args, nargout, true); |
8777
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7919
diff
changeset
|
1019 } |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7919
diff
changeset
|
1020 |
17403
db8b90a56298
doc: Reword docstrings for cummax, cummin.
Rik <rik@octave.org>
parents:
16370
diff
changeset
|
1021 /* |
db8b90a56298
doc: Reword docstrings for cummax, cummin.
Rik <rik@octave.org>
parents:
16370
diff
changeset
|
1022 %!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
|
1023 %!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
|
1024 %!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
|
1025 %!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
|
1026 |
db8b90a56298
doc: Reword docstrings for cummax, cummin.
Rik <rik@octave.org>
parents:
16370
diff
changeset
|
1027 %!test |
db8b90a56298
doc: Reword docstrings for cummax, cummin.
Rik <rik@octave.org>
parents:
16370
diff
changeset
|
1028 %! x = reshape (1:8, [2,2,2]); |
db8b90a56298
doc: Reword docstrings for cummax, cummin.
Rik <rik@octave.org>
parents:
16370
diff
changeset
|
1029 %! 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
|
1030 %! 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
|
1031 %! [w, iw] = cummin (x, 3); |
db8b90a56298
doc: Reword docstrings for cummax, cummin.
Rik <rik@octave.org>
parents:
16370
diff
changeset
|
1032 %! assert (ndims (w), 3); |
db8b90a56298
doc: Reword docstrings for cummax, cummin.
Rik <rik@octave.org>
parents:
16370
diff
changeset
|
1033 %! 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
|
1034 %! assert (ndims (iw), 3); |
db8b90a56298
doc: Reword docstrings for cummax, cummin.
Rik <rik@octave.org>
parents:
16370
diff
changeset
|
1035 %! assert (iw, ones (2,2,2)); |
db8b90a56298
doc: Reword docstrings for cummax, cummin.
Rik <rik@octave.org>
parents:
16370
diff
changeset
|
1036 |
19591
6b09dd576521
Fix cummin/cummax operations on rows when NaN element present (bug #44009).
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19412
diff
changeset
|
1037 |
17403
db8b90a56298
doc: Reword docstrings for cummax, cummin.
Rik <rik@octave.org>
parents:
16370
diff
changeset
|
1038 %!error cummin () |
db8b90a56298
doc: Reword docstrings for cummax, cummin.
Rik <rik@octave.org>
parents:
16370
diff
changeset
|
1039 %!error cummin (1, 2, 3) |
db8b90a56298
doc: Reword docstrings for cummax, cummin.
Rik <rik@octave.org>
parents:
16370
diff
changeset
|
1040 */ |
db8b90a56298
doc: Reword docstrings for cummax, cummin.
Rik <rik@octave.org>
parents:
16370
diff
changeset
|
1041 |
15039
e753177cde93
maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents:
14501
diff
changeset
|
1042 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
|
1043 doc: /* -*- texinfo -*- |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
1044 @deftypefn {} {} cummax (@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
|
1045 @deftypefnx {} {} cummax (@var{x}, @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
|
1046 @deftypefnx {} {[@var{w}, @var{iw}] =} cummax (@dots{}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
1047 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
|
1048 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
1049 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
|
1050 example: |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
1051 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
1052 @example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
1053 @group |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
1054 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
|
1055 @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
|
1056 @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
|
1057 @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
|
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 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
|
1060 returned. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
1061 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
1062 @example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
1063 @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 [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
|
1065 @result{} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
1066 w = 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
|
1067 iw = 1 2 2 4 4 4 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
1068 @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
|
1069 @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
|
1070 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
1071 @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
|
1072 @end deftypefn */) |
8777
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7919
diff
changeset
|
1073 { |
9790
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
1074 return do_cumminmax_body (args, nargout, false); |
8777
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7919
diff
changeset
|
1075 } |
17403
db8b90a56298
doc: Reword docstrings for cummax, cummin.
Rik <rik@octave.org>
parents:
16370
diff
changeset
|
1076 |
db8b90a56298
doc: Reword docstrings for cummax, cummin.
Rik <rik@octave.org>
parents:
16370
diff
changeset
|
1077 /* |
db8b90a56298
doc: Reword docstrings for cummax, cummin.
Rik <rik@octave.org>
parents:
16370
diff
changeset
|
1078 %!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
|
1079 %!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
|
1080 %!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
|
1081 %!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
|
1082 |
db8b90a56298
doc: Reword docstrings for cummax, cummin.
Rik <rik@octave.org>
parents:
16370
diff
changeset
|
1083 %!test |
db8b90a56298
doc: Reword docstrings for cummax, cummin.
Rik <rik@octave.org>
parents:
16370
diff
changeset
|
1084 %! x = reshape (8:-1:1, [2,2,2]); |
db8b90a56298
doc: Reword docstrings for cummax, cummin.
Rik <rik@octave.org>
parents:
16370
diff
changeset
|
1085 %! 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
|
1086 %! 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
|
1087 %! [w, iw] = cummax (x, 3); |
db8b90a56298
doc: Reword docstrings for cummax, cummin.
Rik <rik@octave.org>
parents:
16370
diff
changeset
|
1088 %! assert (ndims (w), 3); |
db8b90a56298
doc: Reword docstrings for cummax, cummin.
Rik <rik@octave.org>
parents:
16370
diff
changeset
|
1089 %! 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
|
1090 %! assert (ndims (iw), 3); |
db8b90a56298
doc: Reword docstrings for cummax, cummin.
Rik <rik@octave.org>
parents:
16370
diff
changeset
|
1091 %! assert (iw, ones (2,2,2)); |
db8b90a56298
doc: Reword docstrings for cummax, cummin.
Rik <rik@octave.org>
parents:
16370
diff
changeset
|
1092 |
db8b90a56298
doc: Reword docstrings for cummax, cummin.
Rik <rik@octave.org>
parents:
16370
diff
changeset
|
1093 %!error cummax () |
db8b90a56298
doc: Reword docstrings for cummax, cummin.
Rik <rik@octave.org>
parents:
16370
diff
changeset
|
1094 %!error cummax (1, 2, 3) |
db8b90a56298
doc: Reword docstrings for cummax, cummin.
Rik <rik@octave.org>
parents:
16370
diff
changeset
|
1095 */ |
db8b90a56298
doc: Reword docstrings for cummax, cummin.
Rik <rik@octave.org>
parents:
16370
diff
changeset
|
1096 |