Mercurial > octave
annotate libinterp/corefcn/max.cc @ 19591:6b09dd576521
Fix cummin/cummax operations on rows when NaN element present (bug #44009).
* mx-inlines.cc (OP_CUMMINMAX_FCN2): Add missing else clauses.
* max.cc (Fcummin, Fcummax): Add BIST tests for cummin and cummax to
verify fix.
* contributors.in: Add Lachlan Andrew to list of contributors.
author | Lachlan Andrew <lachlanbis@gmail.com> |
---|---|
date | Mon, 19 Jan 2015 21:05:39 -0800 |
parents | 78e424d31596 |
children | 4197fc428c7d |
rev | line source |
---|---|
2928 | 1 /* |
2 | |
17744
d63878346099
maint: Update copyright notices for release.
John W. Eaton <jwe@octave.org>
parents:
17403
diff
changeset
|
3 Copyright (C) 1996-2013 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 | |
24 #ifdef HAVE_CONFIG_H | |
25 #include <config.h> | |
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" |
37 #include "gripes.h" | |
38 #include "oct-obj.h" | |
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 |
9790
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
44 template <class ArrayType> |
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 { |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
49 octave_value_list retval; |
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 |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
52 if (error_state) |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
53 return retval; |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
54 |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
55 if (nargout == 2) |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
56 { |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
57 retval.resize (2); |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
58 Array<octave_idx_type> idx; |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
59 if (ismin) |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
60 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
|
61 else |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
62 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
|
63 |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
64 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
|
65 } |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
66 else |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
67 { |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
68 if (ismin) |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
69 retval(0) = array.min (dim); |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
70 else |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
71 retval(0) = array.max (dim); |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
72 } |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
73 |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
74 return retval; |
8777
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7919
diff
changeset
|
75 } |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7919
diff
changeset
|
76 |
16370
7ce21619a4b9
min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents:
15195
diff
changeset
|
77 // 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
|
78 // 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
|
79 // 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
|
80 // 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
|
81 // 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
|
82 // 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
|
83 // functions work. |
7ce21619a4b9
min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents:
15195
diff
changeset
|
84 |
7ce21619a4b9
min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents:
15195
diff
changeset
|
85 template <> |
7ce21619a4b9
min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents:
15195
diff
changeset
|
86 octave_value_list |
7ce21619a4b9
min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents:
15195
diff
changeset
|
87 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
|
88 int nargout, int dim, bool ismin) |
7ce21619a4b9
min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents:
15195
diff
changeset
|
89 { |
7ce21619a4b9
min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents:
15195
diff
changeset
|
90 octave_value_list retval; |
7ce21619a4b9
min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents:
15195
diff
changeset
|
91 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
|
92 |
7ce21619a4b9
min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents:
15195
diff
changeset
|
93 if (error_state) |
7ce21619a4b9
min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents:
15195
diff
changeset
|
94 return retval; |
7ce21619a4b9
min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents:
15195
diff
changeset
|
95 |
7ce21619a4b9
min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents:
15195
diff
changeset
|
96 if (nargout == 2) |
7ce21619a4b9
min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents:
15195
diff
changeset
|
97 { |
7ce21619a4b9
min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents:
15195
diff
changeset
|
98 retval.resize (2); |
7ce21619a4b9
min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents:
15195
diff
changeset
|
99 Array<octave_idx_type> idx; |
7ce21619a4b9
min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents:
15195
diff
changeset
|
100 if (ismin) |
7ce21619a4b9
min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents:
15195
diff
changeset
|
101 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
|
102 else |
7ce21619a4b9
min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents:
15195
diff
changeset
|
103 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
|
104 |
7ce21619a4b9
min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents:
15195
diff
changeset
|
105 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
|
106 } |
7ce21619a4b9
min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents:
15195
diff
changeset
|
107 else |
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 if (ismin) |
7ce21619a4b9
min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents:
15195
diff
changeset
|
110 retval(0) = NDArray (array.min (dim)); |
7ce21619a4b9
min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents:
15195
diff
changeset
|
111 else |
7ce21619a4b9
min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents:
15195
diff
changeset
|
112 retval(0) = NDArray (array.max (dim)); |
7ce21619a4b9
min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents:
15195
diff
changeset
|
113 } |
7ce21619a4b9
min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents:
15195
diff
changeset
|
114 |
7ce21619a4b9
min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents:
15195
diff
changeset
|
115 return retval; |
7ce21619a4b9
min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents:
15195
diff
changeset
|
116 } |
7ce21619a4b9
min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents:
15195
diff
changeset
|
117 |
9993
b22a2f4b34aa
support min/max with logical arrays
Jaroslav Hajek <highegg@gmail.com>
parents:
9791
diff
changeset
|
118 // Specialization for bool arrays. |
b22a2f4b34aa
support min/max with logical arrays
Jaroslav Hajek <highegg@gmail.com>
parents:
9791
diff
changeset
|
119 template <> |
b22a2f4b34aa
support min/max with logical arrays
Jaroslav Hajek <highegg@gmail.com>
parents:
9791
diff
changeset
|
120 octave_value_list |
b22a2f4b34aa
support min/max with logical arrays
Jaroslav Hajek <highegg@gmail.com>
parents:
9791
diff
changeset
|
121 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
|
122 int nargout, int dim, bool ismin) |
b22a2f4b34aa
support min/max with logical arrays
Jaroslav Hajek <highegg@gmail.com>
parents:
9791
diff
changeset
|
123 { |
b22a2f4b34aa
support min/max with logical arrays
Jaroslav Hajek <highegg@gmail.com>
parents:
9791
diff
changeset
|
124 octave_value_list retval; |
b22a2f4b34aa
support min/max with logical arrays
Jaroslav Hajek <highegg@gmail.com>
parents:
9791
diff
changeset
|
125 |
b22a2f4b34aa
support min/max with logical arrays
Jaroslav Hajek <highegg@gmail.com>
parents:
9791
diff
changeset
|
126 if (nargout <= 1) |
b22a2f4b34aa
support min/max with logical arrays
Jaroslav Hajek <highegg@gmail.com>
parents:
9791
diff
changeset
|
127 { |
b22a2f4b34aa
support min/max with logical arrays
Jaroslav Hajek <highegg@gmail.com>
parents:
9791
diff
changeset
|
128 // This case can be handled using any/all. |
b22a2f4b34aa
support min/max with logical arrays
Jaroslav Hajek <highegg@gmail.com>
parents:
9791
diff
changeset
|
129 boolNDArray array = arg.bool_array_value (); |
b22a2f4b34aa
support min/max with logical arrays
Jaroslav Hajek <highegg@gmail.com>
parents:
9791
diff
changeset
|
130 |
b22a2f4b34aa
support min/max with logical arrays
Jaroslav Hajek <highegg@gmail.com>
parents:
9791
diff
changeset
|
131 if (array.is_empty ()) |
b22a2f4b34aa
support min/max with logical arrays
Jaroslav Hajek <highegg@gmail.com>
parents:
9791
diff
changeset
|
132 retval(0) = array; |
b22a2f4b34aa
support min/max with logical arrays
Jaroslav Hajek <highegg@gmail.com>
parents:
9791
diff
changeset
|
133 else if (ismin) |
b22a2f4b34aa
support min/max with logical arrays
Jaroslav Hajek <highegg@gmail.com>
parents:
9791
diff
changeset
|
134 retval(0) = array.all (dim); |
b22a2f4b34aa
support min/max with logical arrays
Jaroslav Hajek <highegg@gmail.com>
parents:
9791
diff
changeset
|
135 else |
b22a2f4b34aa
support min/max with logical arrays
Jaroslav Hajek <highegg@gmail.com>
parents:
9791
diff
changeset
|
136 retval(0) = array.any (dim); |
b22a2f4b34aa
support min/max with logical arrays
Jaroslav Hajek <highegg@gmail.com>
parents:
9791
diff
changeset
|
137 } |
b22a2f4b34aa
support min/max with logical arrays
Jaroslav Hajek <highegg@gmail.com>
parents:
9791
diff
changeset
|
138 else |
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 // any/all don't have indexed versions, so do it via a conversion. |
b22a2f4b34aa
support min/max with logical arrays
Jaroslav Hajek <highegg@gmail.com>
parents:
9791
diff
changeset
|
141 retval = do_minmax_red_op<int8NDArray> (arg, nargout, dim, ismin); |
b22a2f4b34aa
support min/max with logical arrays
Jaroslav Hajek <highegg@gmail.com>
parents:
9791
diff
changeset
|
142 if (! error_state) |
b22a2f4b34aa
support min/max with logical arrays
Jaroslav Hajek <highegg@gmail.com>
parents:
9791
diff
changeset
|
143 retval(0) = retval(0).bool_array_value (); |
b22a2f4b34aa
support min/max with logical arrays
Jaroslav Hajek <highegg@gmail.com>
parents:
9791
diff
changeset
|
144 } |
b22a2f4b34aa
support min/max with logical arrays
Jaroslav Hajek <highegg@gmail.com>
parents:
9791
diff
changeset
|
145 |
b22a2f4b34aa
support min/max with logical arrays
Jaroslav Hajek <highegg@gmail.com>
parents:
9791
diff
changeset
|
146 return retval; |
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 |
9790
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
149 template <class ArrayType> |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
150 static octave_value |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
151 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
|
152 bool ismin) |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
153 { |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
154 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
|
155 |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
156 octave_value retval; |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
157 |
19412
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
158 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
|
159 { |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
160 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
|
161 ArrayType y = octave_value_extract<ArrayType> (argy); |
7189 | 162 |
9790
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
163 if (error_state) |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
164 ; |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
165 else if (ismin) |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
166 retval = min (x, y); |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
167 else |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
168 retval = max (x, y); |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
169 } |
19412
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
170 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
|
171 { |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
172 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
|
173 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
|
174 |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
175 if (error_state) |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
176 ; |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
177 else if (ismin) |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
178 retval = min (x, y); |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
179 else |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
180 retval = max (x, y); |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
181 } |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
182 else |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
183 { |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
184 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
|
185 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
|
186 |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
187 if (error_state) |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
188 ; |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
189 else if (ismin) |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
190 retval = min (x, y); |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
191 else |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
192 retval = max (x, y); |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
193 } |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
194 |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
195 return retval; |
8777
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7919
diff
changeset
|
196 } |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7919
diff
changeset
|
197 |
16370
7ce21619a4b9
min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents:
15195
diff
changeset
|
198 // 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
|
199 // 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
|
200 // 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
|
201 // 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
|
202 // 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
|
203 // 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
|
204 // functions work. |
7ce21619a4b9
min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents:
15195
diff
changeset
|
205 |
7ce21619a4b9
min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents:
15195
diff
changeset
|
206 template <> |
7ce21619a4b9
min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents:
15195
diff
changeset
|
207 octave_value |
7ce21619a4b9
min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents:
15195
diff
changeset
|
208 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
|
209 const octave_value& argy, bool ismin) |
7ce21619a4b9
min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents:
15195
diff
changeset
|
210 { |
7ce21619a4b9
min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents:
15195
diff
changeset
|
211 octave_value retval; |
7ce21619a4b9
min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents:
15195
diff
changeset
|
212 |
19412
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
213 charNDArray x = octave_value_extract<charNDArray> (argx); |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
214 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
|
215 |
19412
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
216 if (error_state) |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
217 ; |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
218 else if (ismin) |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
219 { |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
220 if (x.numel () == 1) |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
221 retval = NDArray (min (x(0), y)); |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
222 else if (y.numel () == 1) |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
223 retval = NDArray (min (x, y(0))); |
16370
7ce21619a4b9
min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents:
15195
diff
changeset
|
224 else |
7ce21619a4b9
min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents:
15195
diff
changeset
|
225 retval = NDArray (min (x, y)); |
7ce21619a4b9
min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents:
15195
diff
changeset
|
226 } |
7ce21619a4b9
min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents:
15195
diff
changeset
|
227 else |
7ce21619a4b9
min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents:
15195
diff
changeset
|
228 { |
19412
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
229 if (x.numel () == 1) |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
230 retval = NDArray (max (x(0), y)); |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
231 else if (y.numel () == 1) |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
232 retval = NDArray (max (x, y(0))); |
16370
7ce21619a4b9
min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents:
15195
diff
changeset
|
233 else |
7ce21619a4b9
min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents:
15195
diff
changeset
|
234 retval = NDArray (max (x, y)); |
7ce21619a4b9
min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents:
15195
diff
changeset
|
235 } |
7ce21619a4b9
min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents:
15195
diff
changeset
|
236 |
7ce21619a4b9
min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents:
15195
diff
changeset
|
237 return retval; |
7ce21619a4b9
min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents:
15195
diff
changeset
|
238 } |
7ce21619a4b9
min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents:
15195
diff
changeset
|
239 |
9790
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
240 static octave_value_list |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
241 do_minmax_body (const octave_value_list& args, |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
242 int nargout, bool ismin) |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
243 { |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
244 octave_value_list retval; |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
245 |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
246 const char *func = ismin ? "min" : "max"; |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
247 |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
248 int nargin = args.length (); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
249 |
9790
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
250 if (nargin == 3 || nargin == 1) |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
251 { |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
252 octave_value arg = args(0); |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
253 int dim = -1; |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
254 if (nargin == 3) |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
255 { |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
256 dim = args(2).int_value (true) - 1; |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
257 if (error_state || dim < 0) |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
258 { |
11553
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
259 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
|
260 return retval; |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
261 } |
8777
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7919
diff
changeset
|
262 |
9790
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
263 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
|
264 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
|
265 } |
7189 | 266 |
9790
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
267 switch (arg.builtin_type ()) |
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 case btyp_double: |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
270 { |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
271 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
|
272 { |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
273 Range range = arg.range_value (); |
19412
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
274 if (range.nelem () < 1) |
9790
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 retval(0) = arg; |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
277 if (nargout > 1) |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
278 retval(1) = arg; |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
279 } |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
280 else if (ismin) |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
281 { |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
282 retval(0) = range.min (); |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
283 if (nargout > 1) |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
284 retval(1) = static_cast<double> |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
285 (range.inc () < 0 ? range.nelem () : 1); |
9790
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
286 } |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
287 else |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
288 { |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
289 retval(0) = range.max (); |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
290 if (nargout > 1) |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
291 retval(1) = static_cast<double> |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
292 (range.inc () >= 0 ? range.nelem () : 1); |
9790
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
293 } |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
294 } |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
295 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
|
296 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
|
297 ismin); |
9790
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
298 else |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
299 retval = do_minmax_red_op<NDArray> (arg, nargout, dim, ismin); |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
300 break; |
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 case btyp_complex: |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
303 { |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
304 if (arg.is_sparse_type ()) |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
305 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
|
306 ismin); |
9790
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
307 else |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
308 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
|
309 ismin); |
9790
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
310 break; |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
311 } |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
312 case btyp_float: |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
313 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
|
314 break; |
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; |
16370
7ce21619a4b9
min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents:
15195
diff
changeset
|
319 case btyp_char: |
7ce21619a4b9
min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents:
15195
diff
changeset
|
320 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
|
321 break; |
9790
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
322 #define MAKE_INT_BRANCH(X) \ |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
323 case btyp_ ## X: \ |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
324 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
|
325 break; |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
326 MAKE_INT_BRANCH (int8); |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
327 MAKE_INT_BRANCH (int16); |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
328 MAKE_INT_BRANCH (int32); |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
329 MAKE_INT_BRANCH (int64); |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
330 MAKE_INT_BRANCH (uint8); |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
331 MAKE_INT_BRANCH (uint16); |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
332 MAKE_INT_BRANCH (uint32); |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
333 MAKE_INT_BRANCH (uint64); |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
334 #undef MAKE_INT_BRANCH |
9993
b22a2f4b34aa
support min/max with logical arrays
Jaroslav Hajek <highegg@gmail.com>
parents:
9791
diff
changeset
|
335 case btyp_bool: |
b22a2f4b34aa
support min/max with logical arrays
Jaroslav Hajek <highegg@gmail.com>
parents:
9791
diff
changeset
|
336 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
|
337 break; |
9790
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
338 default: |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
339 gripe_wrong_type_arg (func, arg); |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
340 } |
9790
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
341 } |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
342 else if (nargin == 2) |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
343 { |
18100
6a71e5030df5
Follow coding convention of defining and initializing only 1 variable per line in liboctinterp.
Rik <rik@octave.org>
parents:
18076
diff
changeset
|
344 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
|
345 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
|
346 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
|
347 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
|
348 builtin_type_t rtyp; |
7ce21619a4b9
min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents:
15195
diff
changeset
|
349 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
|
350 rtyp = btyp_char; |
19412
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
351 /* |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
352 FIXME: This is what should happen when boolNDArray has max() |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
353 else if (xtyp == btyp_bool && ytyp == btyp_bool) |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
354 rtyp = btyp_bool; |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
355 */ |
16370
7ce21619a4b9
min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents:
15195
diff
changeset
|
356 else |
7ce21619a4b9
min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents:
15195
diff
changeset
|
357 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
|
358 |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
359 switch (rtyp) |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
360 { |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
361 case btyp_double: |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
362 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
363 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
|
364 && (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
|
365 || (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
|
366 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
|
367 else |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
368 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
|
369 break; |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
370 } |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
371 case btyp_complex: |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
372 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
373 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
|
374 && (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
|
375 || (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
|
376 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
|
377 ismin); |
9790
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
378 else |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
379 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
|
380 break; |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
381 } |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
382 case btyp_float: |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
383 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
|
384 break; |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
385 case btyp_float_complex: |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
386 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
|
387 break; |
16370
7ce21619a4b9
min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents:
15195
diff
changeset
|
388 case btyp_char: |
7ce21619a4b9
min Matlab compatibility issue (bug #33530)
Axel Mathéi <axel.mathei@gmail.com>
parents:
15195
diff
changeset
|
389 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
|
390 break; |
9790
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
391 #define MAKE_INT_BRANCH(X) \ |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
392 case btyp_ ## X: \ |
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<X ## NDArray> (argx, argy, ismin); \ |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
394 break; |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
395 MAKE_INT_BRANCH (int8); |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
396 MAKE_INT_BRANCH (int16); |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
397 MAKE_INT_BRANCH (int32); |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
398 MAKE_INT_BRANCH (int64); |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
399 MAKE_INT_BRANCH (uint8); |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
400 MAKE_INT_BRANCH (uint16); |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
401 MAKE_INT_BRANCH (uint32); |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
402 MAKE_INT_BRANCH (uint64); |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
403 #undef MAKE_INT_BRANCH |
19412
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
404 /* |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
405 FIXME: This is what should happen when boolNDArray has max() |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
406 case btyp_bool: |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
407 retval = do_minmax_bin_op<boolNDArray> (argx, argy, ismin); |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
408 break; |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
409 */ |
9790
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
410 default: |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
411 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
|
412 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
|
413 } |
19412
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
414 |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
415 // FIXME: Delete when boolNDArray has max() |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
416 if (xtyp == btyp_bool && ytyp == btyp_bool) |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
417 retval(0) = retval(0).bool_array_value (); |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
418 |
9790
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
419 } |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
420 else |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
421 print_usage (); |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
422 |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
423 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
|
424 } |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
425 |
15039
e753177cde93
maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents:
14501
diff
changeset
|
426 DEFUN (min, args, nargout, |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
427 "-*- texinfo -*-\n\ |
15039
e753177cde93
maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents:
14501
diff
changeset
|
428 @deftypefn {Built-in Function} {} min (@var{x})\n\ |
e753177cde93
maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents:
14501
diff
changeset
|
429 @deftypefnx {Built-in Function} {} min (@var{x}, [], @var{dim})\n\ |
e753177cde93
maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents:
14501
diff
changeset
|
430 @deftypefnx {Built-in Function} {[@var{w}, @var{iw}] =} min (@var{x})\n\ |
19412
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
431 @deftypefnx {Built-in Function} {} min (@var{x}, @var{y})\n\ |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
432 Find minimum values in the array @var{x}.\n\ |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
433 \n\ |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
434 For a vector argument, return the minimum value.\n\ |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
435 For a matrix argument, return a row vector with the minimum value of each\n\ |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
436 column.\n\ |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
437 For a multi-dimensional array, @code{min} operates along the first\n\ |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
438 non-singleton dimension.\n\ |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
439 \n\ |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
440 If the optional third argument @var{dim} is present then operate along\n\ |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
441 this dimension. In this case the second argument is ignored and should be\n\ |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
442 set to the empty matrix.\n\ |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
443 \n\ |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
444 For two matrices (or a matrix and a scalar), return the pairwise minimum.\n\ |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
445 \n\ |
4522 | 446 Thus,\n\ |
3443 | 447 \n\ |
448 @example\n\ | |
449 min (min (@var{x}))\n\ | |
450 @end example\n\ | |
451 \n\ | |
452 @noindent\n\ | |
19412
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
453 returns the smallest element of the 2-D matrix @var{x}, and\n\ |
4522 | 454 \n\ |
455 @example\n\ | |
456 @group\n\ | |
457 min (2:5, pi)\n\ | |
458 @result{} 2.0000 3.0000 3.1416 3.1416\n\ | |
459 @end group\n\ | |
460 @end example\n\ | |
10840 | 461 \n\ |
4522 | 462 @noindent\n\ |
463 compares each element of the range @code{2:5} with @code{pi}, and\n\ | |
464 returns a row vector of the minimum values.\n\ | |
3443 | 465 \n\ |
466 For complex arguments, the magnitude of the elements are used for\n\ | |
19412
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
467 comparison. If the magnitudes are identical, then the results are ordered\n\ |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
468 by phase angle in the range (-pi, pi]. Hence,\n\ |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
469 \n\ |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
470 @example\n\ |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
471 @group\n\ |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
472 min ([-1 i 1 -i])\n\ |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
473 @result{} -i\n\ |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
474 @end group\n\ |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
475 @end example\n\ |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
476 \n\ |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
477 @noindent\n\ |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
478 because all entries have magnitude 1, but -i has the smallest phase angle\n\ |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
479 with value -pi/2.\n\ |
3657 | 480 \n\ |
4522 | 481 If called with one input and two output arguments,\n\ |
482 @code{min} also returns the first index of the\n\ | |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
8949
diff
changeset
|
483 minimum value(s). Thus,\n\ |
4522 | 484 \n\ |
3775 | 485 @example\n\ |
4522 | 486 @group\n\ |
9165
8c71a86c4bf4
Update section 17.5 (Utility Functions) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents:
9141
diff
changeset
|
487 [x, ix] = min ([1, 3, 0, 2, 0])\n\ |
4522 | 488 @result{} x = 0\n\ |
489 ix = 3\n\ | |
490 @end group\n\ | |
3657 | 491 @end example\n\ |
9141
c1fff751b5a8
Update section 17.1 (Utility Functions) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents:
9086
diff
changeset
|
492 @seealso{max, cummin, cummax}\n\ |
4522 | 493 @end deftypefn") |
2928 | 494 { |
9790
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
495 return do_minmax_body (args, nargout, true); |
2928 | 496 } |
497 | |
7600
24abf5a702d9
Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
498 /* |
19412
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
499 ## 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
|
500 %!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
|
501 %!assert (min ([1; -10; 5; -2]), -10) |
19412
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
502 %!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
|
503 ## Special routines for char arrays |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
504 %!assert (min (["abc", "ABC"]), 65) |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
505 %!assert (min (["abc"; "CBA"]), [67 66 65]) |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
506 ## Special routines for logical arrays |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
507 %!assert (min (logical ([])), logical ([])) |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
508 %!assert (min (logical ([0 0 1 0])), false) |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
509 %!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
|
510 ## Single values |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
511 %!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
|
512 %!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
|
513 %!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
|
514 ## Integer values |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
515 %!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
|
516 %!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
|
517 %!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
|
518 %!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
|
519 %!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
|
520 %!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
|
521 %!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
|
522 %!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
|
523 %!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
|
524 %!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
|
525 %!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
|
526 %!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
|
527 %!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
|
528 %!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
|
529 %!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
|
530 %!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
|
531 ## Sparse double values |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
532 %!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
|
533 %!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
|
534 ## 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
|
535 %!xtest |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
536 %! 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
|
537 |
19412
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
538 ## Test dimension argument |
7600
24abf5a702d9
Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
539 %!test |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14360
diff
changeset
|
540 %! x = reshape (1:8, [2,2,2]); |
19412
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
541 %! 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
|
542 %! 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
|
543 %! [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
|
544 %! assert (ndims (y), 2); |
19412
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
545 %! 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
|
546 %! assert (ndims (i), 2); |
19412
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
547 %! assert (i, [1, 1; 1, 1]); |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
548 |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
549 ## Test 2-output forms for various arg types |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
550 ## Special routines for char arrays |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
551 %!test |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
552 %! [y, i] = min (["abc", "ABC"]); |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
553 %! assert (y, 65); |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
554 %! assert (i, 4); |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
555 ## Special routines for logical arrays |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
556 %!test |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
557 %! x = logical ([0 0 1 0]); |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
558 %! [y, i] = min (x); |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
559 %! assert (y, false); |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
560 %! assert (i, 1); |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
561 ## Special handling of ranges |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
562 %!test |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
563 %! rng = 1:2:10; |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
564 %! [y, i] = min (rng); |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
565 %! assert (y, 1); |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
566 %! assert (i, 1); |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
567 %! rng = 10:-2:1; |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
568 %! [y, i] = min (rng); |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
569 %! assert (y, 2); |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
570 %! assert (i, 5); |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
571 |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
572 ## 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
|
573 ## Test generic double class |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
574 %!test |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
575 %! x = [1, 2, 3, 4]; y = fliplr (x); |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
576 %! assert (min (x, y), [1 2 2 1]); |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
577 %! assert (min (x, 3), [1 2 3 3]); |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
578 %! assert (min (2, x), [1 2 2 2]); |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
579 %! 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
|
580 ## 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
|
581 ## 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
|
582 ## appears in the argument list. |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
583 %!xtest |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
584 %! x = [1, 2, 3, 4]; y = fliplr (x); |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
585 %! assert (min (x, 2i), [2i 2i 3 4]); |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
586 ## Special routines for char arrays |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
587 %!assert (min ("abc", "b"), [97 98 98]) |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
588 %!assert (min ("b", "cba"), [98 98 97]) |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
589 ## Special handling for logical arrays |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
590 %!assert (min ([true false], false), [false false]) |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
591 %!assert (min (true, [true false]), [true false]) |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
592 ## Single values |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
593 %!test |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
594 %! 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
|
595 %! 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
|
596 %! 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
|
597 %! 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
|
598 %! 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
|
599 ## Integer 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 = uint8 ([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), uint8 ([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), uint8 ([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), uint8 ([1 2 2 2])); |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
605 %! 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
|
606 %! 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
|
607 %! 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
|
608 %! 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
|
609 %! 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
|
610 %! 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
|
611 %! 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
|
612 %! 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
|
613 %! 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
|
614 %! 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
|
615 %! 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
|
616 %! 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
|
617 %! 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
|
618 %! 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
|
619 %! 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
|
620 %! 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
|
621 %! 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
|
622 %! 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
|
623 %! 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
|
624 %! 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
|
625 %! 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
|
626 %! 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
|
627 %! 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
|
628 %! 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
|
629 %! 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
|
630 %! 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
|
631 %! 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
|
632 %! 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
|
633 ## Sparse double values |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
634 %!test |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
635 %! 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
|
636 %! 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
|
637 %! 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
|
638 %! 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
|
639 %! 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
|
640 |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14360
diff
changeset
|
641 %!error min () |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14360
diff
changeset
|
642 %!error min (1, 2, 3, 4) |
19412
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
643 %!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
|
644 %!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
|
645 %!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
|
646 %!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
|
647 */ |
24abf5a702d9
Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
648 |
15039
e753177cde93
maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents:
14501
diff
changeset
|
649 DEFUN (max, args, nargout, |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
650 "-*- texinfo -*-\n\ |
15039
e753177cde93
maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents:
14501
diff
changeset
|
651 @deftypefn {Built-in Function} {} max (@var{x})\n\ |
e753177cde93
maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents:
14501
diff
changeset
|
652 @deftypefnx {Built-in Function} {} max (@var{x}, [], @var{dim})\n\ |
e753177cde93
maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents:
14501
diff
changeset
|
653 @deftypefnx {Built-in Function} {[@var{w}, @var{iw}] =} max (@var{x})\n\ |
19412
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
654 @deftypefnx {Built-in Function} {} max (@var{x}, @var{y})\n\ |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
655 Find maximum values in the array @var{x}.\n\ |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
656 \n\ |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
657 For a vector argument, return the maximum value.\n\ |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
658 For a matrix argument, return a row vector with the maximum value of each\n\ |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
659 column.\n\ |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
660 For a multi-dimensional array, @code{max} operates along the first\n\ |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
661 non-singleton dimension.\n\ |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
662 \n\ |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
663 If the optional third argument @var{dim} is present then operate along\n\ |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
664 this dimension. In this case the second argument is ignored and should be\n\ |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
665 set to the empty matrix.\n\ |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
666 \n\ |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
667 For two matrices (or a matrix and a scalar), return the pairwise maximum.\n\ |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
668 \n\ |
4522 | 669 Thus,\n\ |
3443 | 670 \n\ |
671 @example\n\ | |
672 max (max (@var{x}))\n\ | |
673 @end example\n\ | |
674 \n\ | |
675 @noindent\n\ | |
19412
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
676 returns the largest element of the 2-D matrix @var{x}, and\n\ |
4522 | 677 \n\ |
678 @example\n\ | |
679 @group\n\ | |
680 max (2:5, pi)\n\ | |
681 @result{} 3.1416 3.1416 4.0000 5.0000\n\ | |
682 @end group\n\ | |
683 @end example\n\ | |
10840 | 684 \n\ |
4522 | 685 @noindent\n\ |
19412
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
686 compares each element of the range @code{2:5} with @code{pi}, and returns a\n\ |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
687 row vector of the maximum values.\n\ |
3443 | 688 \n\ |
689 For complex arguments, the magnitude of the elements are used for\n\ | |
19412
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
690 comparison. If the magnitudes are identical, then the results are ordered\n\ |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
691 by phase angle in the range (-pi, pi]. Hence,\n\ |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
692 \n\ |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
693 @example\n\ |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
694 @group\n\ |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
695 max ([-1 i 1 -i])\n\ |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
696 @result{} -1\n\ |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
697 @end group\n\ |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
698 @end example\n\ |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
699 \n\ |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
700 @noindent\n\ |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
701 because all entries have magnitude 1, but -1 has the largest phase angle\n\ |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
702 with value pi.\n\ |
3657 | 703 \n\ |
4522 | 704 If called with one input and two output arguments,\n\ |
705 @code{max} also returns the first index of the\n\ | |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
8949
diff
changeset
|
706 maximum value(s). Thus,\n\ |
4522 | 707 \n\ |
3775 | 708 @example\n\ |
4522 | 709 @group\n\ |
710 [x, ix] = max ([1, 3, 5, 2, 5])\n\ | |
711 @result{} x = 5\n\ | |
712 ix = 3\n\ | |
713 @end group\n\ | |
3657 | 714 @end example\n\ |
9141
c1fff751b5a8
Update section 17.1 (Utility Functions) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents:
9086
diff
changeset
|
715 @seealso{min, cummax, cummin}\n\ |
4522 | 716 @end deftypefn") |
2928 | 717 { |
9790
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
718 return do_minmax_body (args, nargout, false); |
2928 | 719 } |
720 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
721 /* |
19412
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
722 ## 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
|
723 %!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
|
724 %!assert (max ([1; -10; 5; -2]), 5) |
19412
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
725 %!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
|
726 ## Special routines for char arrays |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
727 %!assert (max (["abc", "ABC"]), 99) |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
728 %!assert (max (["abc"; "CBA"]), [97 98 99]) |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
729 ## Special routines for logical arrays |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
730 %!assert (max (logical ([])), logical ([])) |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
731 %!assert (max (logical ([0 0 1 0])), true) |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
732 %!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
|
733 ## Single values |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
734 %!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
|
735 %!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
|
736 %!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
|
737 ## Integer values |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
738 %!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
|
739 %!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
|
740 %!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
|
741 %!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
|
742 %!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
|
743 %!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
|
744 %!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
|
745 %!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
|
746 %!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
|
747 %!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
|
748 %!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
|
749 %!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
|
750 %!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
|
751 %!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
|
752 %!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
|
753 %!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
|
754 ## Sparse double values |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
755 %!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
|
756 %!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
|
757 %!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
|
758 |
19412
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
759 ## Test dimension argument |
7600
24abf5a702d9
Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
760 %!test |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14360
diff
changeset
|
761 %! 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
|
762 %! 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
|
763 %! 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
|
764 %! [y, i] = min (x, [], 3); |
19412
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
765 %! assert (ndims (y), 2); |
7600
24abf5a702d9
Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
766 %! assert (y, [1, 3; 2, 4]); |
19412
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
767 %! assert (ndims (i), 2); |
7600
24abf5a702d9
Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
768 %! assert (i, [1, 1; 1, 1]); |
24abf5a702d9
Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
769 |
19412
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
770 ## Test 2-output forms for various arg types |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
771 ## Special routines for char arrays |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
772 %!test |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
773 %! [y, i] = max (["abc", "ABC"]); |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
774 %! assert (y, 99); |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
775 %! assert (i, 3); |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
776 ## Special routines for logical 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 %! x = logical ([0 0 1 0]); |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
779 %! [y, i] = max (x); |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
780 %! assert (y, true); |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
781 %! assert (i, 3); |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
782 ## Special handling of ranges |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
783 %!test |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
784 %! rng = 1:2:10; |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
785 %! [y, i] = max (rng); |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
786 %! assert (y, 9); |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
787 %! assert (i, 5); |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
788 %! rng = 10:-2:1; |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
789 %! [y, i] = max (rng); |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
790 %! assert (y, 10); |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
791 %! assert (i, 1); |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
792 |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
793 ## 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
|
794 ## Test generic double class |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
795 %!test |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
796 %! x = [1, 2, 3, 4]; y = fliplr (x); |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
797 %! assert (max (x, y), [4 3 3 4]); |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
798 %! assert (max (x, 3), [3 3 3 4]); |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
799 %! assert (max (2, x), [2 2 3 4]); |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
800 %! 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
|
801 ## 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
|
802 ## 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
|
803 ## appears in the argument list. |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
804 %!xtest |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
805 %! x = [1, 2, 3, 4]; y = fliplr (x); |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
806 %! assert (max (x, 2i), [2i 2i 3 4]); |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
807 ## Special routines for char arrays |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
808 %!assert (max ("abc", "b"), [98 98 99]) |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
809 %!assert (max ("b", "cba"), [99 98 98]) |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
810 ## Special handling for logical arrays |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
811 %!assert (max ([true false], false), [true false]) |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
812 %!assert (max (true, [false false]), [true true]) |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
813 ## Single values |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
814 %!test |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
815 %! 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
|
816 %! 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
|
817 %! 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
|
818 %! 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
|
819 %! 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
|
820 ## Integer values |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
821 %!test |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
822 %! 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
|
823 %! 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
|
824 %! 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
|
825 %! 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
|
826 %! 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
|
827 %! 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
|
828 %! 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
|
829 %! 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
|
830 %! 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
|
831 %! 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
|
832 %! 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
|
833 %! 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
|
834 %! 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
|
835 %! 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
|
836 %! 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
|
837 %! 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
|
838 %! 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
|
839 %! 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
|
840 %! 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
|
841 %! 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
|
842 %! 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
|
843 %! 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
|
844 %! 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
|
845 %! 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
|
846 %! 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
|
847 %! 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
|
848 %! 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
|
849 %! 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
|
850 %! 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
|
851 %! 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
|
852 %! 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
|
853 %! 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
|
854 ## Sparse double values |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
855 %!test |
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
856 %! 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
|
857 %! 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
|
858 %! 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
|
859 %! 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
|
860 %! 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
|
861 |
18076 | 862 ## Test for bug #40743 |
863 %!assert (max (zeros (1,0), ones (1,1)), zeros (1,0)) | |
864 %!assert (max (sparse (zeros (1,0)), sparse (ones (1,1))), sparse (zeros (1,0))) | |
865 | |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14360
diff
changeset
|
866 %!error max () |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14360
diff
changeset
|
867 %!error max (1, 2, 3, 4) |
19412
78e424d31596
Overhaul max/min functions (fixes bug #43712).
Rik <rik@octave.org>
parents:
18227
diff
changeset
|
868 %!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
|
869 %!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
|
870 %!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
|
871 %!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
|
872 |
7600
24abf5a702d9
Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
873 */ |
24abf5a702d9
Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
874 |
9790
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
875 template <class ArrayType> |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
876 static octave_value_list |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
877 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
|
878 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
|
879 { |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
880 octave_value_list retval; |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
881 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
|
882 |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
883 if (error_state) |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
884 return retval; |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
885 |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
886 if (nargout == 2) |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
887 { |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
888 retval.resize (2); |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
889 Array<octave_idx_type> idx; |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
890 if (ismin) |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
891 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
|
892 else |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
893 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
|
894 |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
895 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
|
896 } |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
897 else |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
898 { |
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 (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 (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 |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
905 return retval; |
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 |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
908 static octave_value_list |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
909 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
|
910 int nargout, bool ismin) |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
911 { |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
912 octave_value_list retval; |
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 const char *func = ismin ? "cummin" : "cummax"; |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
915 |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
916 int nargin = args.length (); |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
917 |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
918 if (nargin == 1 || nargin == 2) |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
919 { |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
920 octave_value arg = args(0); |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
921 int dim = -1; |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
922 if (nargin == 2) |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
923 { |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
924 dim = args(1).int_value (true) - 1; |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
925 if (error_state || dim < 0) |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
926 { |
11553
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
927 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
|
928 return retval; |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
929 } |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
930 } |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
931 |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
932 switch (arg.builtin_type ()) |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
933 { |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
934 case btyp_double: |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
935 retval = do_cumminmax_red_op<NDArray> (arg, nargout, dim, ismin); |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
936 break; |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
937 case btyp_complex: |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
938 retval = do_cumminmax_red_op<ComplexNDArray> (arg, nargout, dim, |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
939 ismin); |
9790
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
940 break; |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
941 case btyp_float: |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
942 retval = do_cumminmax_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
|
943 break; |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
944 case btyp_float_complex: |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
945 retval = do_cumminmax_red_op<FloatComplexNDArray> (arg, nargout, dim, |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
946 ismin); |
9790
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
947 break; |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
948 #define MAKE_INT_BRANCH(X) \ |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
949 case btyp_ ## X: \ |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
950 retval = do_cumminmax_red_op<X ## NDArray> (arg, nargout, dim, \ |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
951 ismin); \ |
9790
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
952 break; |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
953 MAKE_INT_BRANCH (int8); |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
954 MAKE_INT_BRANCH (int16); |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
955 MAKE_INT_BRANCH (int32); |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
956 MAKE_INT_BRANCH (int64); |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
957 MAKE_INT_BRANCH (uint8); |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
958 MAKE_INT_BRANCH (uint16); |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
959 MAKE_INT_BRANCH (uint32); |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
960 MAKE_INT_BRANCH (uint64); |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
961 #undef MAKE_INT_BRANCH |
10017
1ce1ae448572
support cummin/cummax for bools
Jaroslav Hajek <highegg@gmail.com>
parents:
9993
diff
changeset
|
962 case btyp_bool: |
1ce1ae448572
support cummin/cummax for bools
Jaroslav Hajek <highegg@gmail.com>
parents:
9993
diff
changeset
|
963 { |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
964 retval = do_cumminmax_red_op<int8NDArray> (arg, nargout, dim, |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
965 ismin); |
10017
1ce1ae448572
support cummin/cummax for bools
Jaroslav Hajek <highegg@gmail.com>
parents:
9993
diff
changeset
|
966 if (retval.length () > 0) |
1ce1ae448572
support cummin/cummax for bools
Jaroslav Hajek <highegg@gmail.com>
parents:
9993
diff
changeset
|
967 retval(0) = retval(0).bool_array_value (); |
1ce1ae448572
support cummin/cummax for bools
Jaroslav Hajek <highegg@gmail.com>
parents:
9993
diff
changeset
|
968 break; |
1ce1ae448572
support cummin/cummax for bools
Jaroslav Hajek <highegg@gmail.com>
parents:
9993
diff
changeset
|
969 } |
9790
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
970 default: |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
971 gripe_wrong_type_arg (func, arg); |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
972 } |
9790
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
973 } |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
974 else |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
975 print_usage (); |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
976 |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
977 return retval; |
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
978 } |
8777
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7919
diff
changeset
|
979 |
15039
e753177cde93
maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents:
14501
diff
changeset
|
980 DEFUN (cummin, args, nargout, |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
981 "-*- texinfo -*-\n\ |
15039
e753177cde93
maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents:
14501
diff
changeset
|
982 @deftypefn {Built-in Function} {} cummin (@var{x})\n\ |
e753177cde93
maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents:
14501
diff
changeset
|
983 @deftypefnx {Built-in Function} {} cummin (@var{x}, @var{dim})\n\ |
e753177cde93
maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents:
14501
diff
changeset
|
984 @deftypefnx {Built-in Function} {[@var{w}, @var{iw}] =} cummin (@var{x})\n\ |
17403
db8b90a56298
doc: Reword docstrings for cummax, cummin.
Rik <rik@octave.org>
parents:
16370
diff
changeset
|
985 Return the cumulative minimum values along dimension @var{dim}.\n\ |
db8b90a56298
doc: Reword docstrings for cummax, cummin.
Rik <rik@octave.org>
parents:
16370
diff
changeset
|
986 \n\ |
db8b90a56298
doc: Reword docstrings for cummax, cummin.
Rik <rik@octave.org>
parents:
16370
diff
changeset
|
987 If @var{dim} is unspecified it defaults to column-wise operation. For\n\ |
db8b90a56298
doc: Reword docstrings for cummax, cummin.
Rik <rik@octave.org>
parents:
16370
diff
changeset
|
988 example:\n\ |
9141
c1fff751b5a8
Update section 17.1 (Utility Functions) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents:
9086
diff
changeset
|
989 \n\ |
c1fff751b5a8
Update section 17.1 (Utility Functions) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents:
9086
diff
changeset
|
990 @example\n\ |
c1fff751b5a8
Update section 17.1 (Utility Functions) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents:
9086
diff
changeset
|
991 @group\n\ |
c1fff751b5a8
Update section 17.1 (Utility Functions) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents:
9086
diff
changeset
|
992 cummin ([5 4 6 2 3 1])\n\ |
14360
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
993 @result{} 5 4 4 2 2 1\n\ |
9141
c1fff751b5a8
Update section 17.1 (Utility Functions) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents:
9086
diff
changeset
|
994 @end group\n\ |
c1fff751b5a8
Update section 17.1 (Utility Functions) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents:
9086
diff
changeset
|
995 @end example\n\ |
c1fff751b5a8
Update section 17.1 (Utility Functions) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents:
9086
diff
changeset
|
996 \n\ |
17403
db8b90a56298
doc: Reword docstrings for cummax, cummin.
Rik <rik@octave.org>
parents:
16370
diff
changeset
|
997 If called with two output arguments the index of the minimum value is also\n\ |
db8b90a56298
doc: Reword docstrings for cummax, cummin.
Rik <rik@octave.org>
parents:
16370
diff
changeset
|
998 returned.\n\ |
10840 | 999 \n\ |
8777
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7919
diff
changeset
|
1000 @example\n\ |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
8949
diff
changeset
|
1001 @group\n\ |
17403
db8b90a56298
doc: Reword docstrings for cummax, cummin.
Rik <rik@octave.org>
parents:
16370
diff
changeset
|
1002 [w, iw] = cummin ([5 4 6 2 3 1])\n\ |
db8b90a56298
doc: Reword docstrings for cummax, cummin.
Rik <rik@octave.org>
parents:
16370
diff
changeset
|
1003 @result{}\n\ |
db8b90a56298
doc: Reword docstrings for cummax, cummin.
Rik <rik@octave.org>
parents:
16370
diff
changeset
|
1004 w = 5 4 4 2 2 1\n\ |
db8b90a56298
doc: Reword docstrings for cummax, cummin.
Rik <rik@octave.org>
parents:
16370
diff
changeset
|
1005 iw = 1 2 2 4 4 6\n\ |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
8949
diff
changeset
|
1006 @end group\n\ |
8777
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7919
diff
changeset
|
1007 @end example\n\ |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7919
diff
changeset
|
1008 \n\ |
9141
c1fff751b5a8
Update section 17.1 (Utility Functions) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents:
9086
diff
changeset
|
1009 @seealso{cummax, min, max}\n\ |
8777
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7919
diff
changeset
|
1010 @end deftypefn") |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7919
diff
changeset
|
1011 { |
9790
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
1012 return do_cumminmax_body (args, nargout, true); |
8777
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7919
diff
changeset
|
1013 } |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7919
diff
changeset
|
1014 |
17403
db8b90a56298
doc: Reword docstrings for cummax, cummin.
Rik <rik@octave.org>
parents:
16370
diff
changeset
|
1015 /* |
db8b90a56298
doc: Reword docstrings for cummax, cummin.
Rik <rik@octave.org>
parents:
16370
diff
changeset
|
1016 %!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
|
1017 %!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
|
1018 %!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
|
1019 %!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
|
1020 |
db8b90a56298
doc: Reword docstrings for cummax, cummin.
Rik <rik@octave.org>
parents:
16370
diff
changeset
|
1021 %!test |
db8b90a56298
doc: Reword docstrings for cummax, cummin.
Rik <rik@octave.org>
parents:
16370
diff
changeset
|
1022 %! x = reshape (1:8, [2,2,2]); |
db8b90a56298
doc: Reword docstrings for cummax, cummin.
Rik <rik@octave.org>
parents:
16370
diff
changeset
|
1023 %! 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
|
1024 %! 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
|
1025 %! [w, iw] = cummin (x, 3); |
db8b90a56298
doc: Reword docstrings for cummax, cummin.
Rik <rik@octave.org>
parents:
16370
diff
changeset
|
1026 %! assert (ndims (w), 3); |
db8b90a56298
doc: Reword docstrings for cummax, cummin.
Rik <rik@octave.org>
parents:
16370
diff
changeset
|
1027 %! 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
|
1028 %! assert (ndims (iw), 3); |
db8b90a56298
doc: Reword docstrings for cummax, cummin.
Rik <rik@octave.org>
parents:
16370
diff
changeset
|
1029 %! assert (iw, ones (2,2,2)); |
db8b90a56298
doc: Reword docstrings for cummax, cummin.
Rik <rik@octave.org>
parents:
16370
diff
changeset
|
1030 |
19591
6b09dd576521
Fix cummin/cummax operations on rows when NaN element present (bug #44009).
Lachlan Andrew <lachlanbis@gmail.com>
parents:
19412
diff
changeset
|
1031 |
17403
db8b90a56298
doc: Reword docstrings for cummax, cummin.
Rik <rik@octave.org>
parents:
16370
diff
changeset
|
1032 %!error cummin () |
db8b90a56298
doc: Reword docstrings for cummax, cummin.
Rik <rik@octave.org>
parents:
16370
diff
changeset
|
1033 %!error cummin (1, 2, 3) |
db8b90a56298
doc: Reword docstrings for cummax, cummin.
Rik <rik@octave.org>
parents:
16370
diff
changeset
|
1034 */ |
db8b90a56298
doc: Reword docstrings for cummax, cummin.
Rik <rik@octave.org>
parents:
16370
diff
changeset
|
1035 |
15039
e753177cde93
maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents:
14501
diff
changeset
|
1036 DEFUN (cummax, args, nargout, |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1037 "-*- texinfo -*-\n\ |
15039
e753177cde93
maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents:
14501
diff
changeset
|
1038 @deftypefn {Built-in Function} {} cummax (@var{x})\n\ |
e753177cde93
maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents:
14501
diff
changeset
|
1039 @deftypefnx {Built-in Function} {} cummax (@var{x}, @var{dim})\n\ |
17403
db8b90a56298
doc: Reword docstrings for cummax, cummin.
Rik <rik@octave.org>
parents:
16370
diff
changeset
|
1040 @deftypefnx {Built-in Function} {[@var{w}, @var{iw}] =} cummax (@dots{})\n\ |
db8b90a56298
doc: Reword docstrings for cummax, cummin.
Rik <rik@octave.org>
parents:
16370
diff
changeset
|
1041 Return the cumulative maximum values along dimension @var{dim}.\n\ |
db8b90a56298
doc: Reword docstrings for cummax, cummin.
Rik <rik@octave.org>
parents:
16370
diff
changeset
|
1042 \n\ |
db8b90a56298
doc: Reword docstrings for cummax, cummin.
Rik <rik@octave.org>
parents:
16370
diff
changeset
|
1043 If @var{dim} is unspecified it defaults to column-wise operation. For\n\ |
db8b90a56298
doc: Reword docstrings for cummax, cummin.
Rik <rik@octave.org>
parents:
16370
diff
changeset
|
1044 example:\n\ |
9141
c1fff751b5a8
Update section 17.1 (Utility Functions) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents:
9086
diff
changeset
|
1045 \n\ |
8777
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7919
diff
changeset
|
1046 @example\n\ |
9141
c1fff751b5a8
Update section 17.1 (Utility Functions) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents:
9086
diff
changeset
|
1047 @group\n\ |
c1fff751b5a8
Update section 17.1 (Utility Functions) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents:
9086
diff
changeset
|
1048 cummax ([1 3 2 6 4 5])\n\ |
14360
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
1049 @result{} 1 3 3 6 6 6\n\ |
9141
c1fff751b5a8
Update section 17.1 (Utility Functions) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents:
9086
diff
changeset
|
1050 @end group\n\ |
c1fff751b5a8
Update section 17.1 (Utility Functions) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents:
9086
diff
changeset
|
1051 @end example\n\ |
c1fff751b5a8
Update section 17.1 (Utility Functions) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents:
9086
diff
changeset
|
1052 \n\ |
17403
db8b90a56298
doc: Reword docstrings for cummax, cummin.
Rik <rik@octave.org>
parents:
16370
diff
changeset
|
1053 If called with two output arguments the index of the maximum value is also\n\ |
db8b90a56298
doc: Reword docstrings for cummax, cummin.
Rik <rik@octave.org>
parents:
16370
diff
changeset
|
1054 returned.\n\ |
10840 | 1055 \n\ |
8777
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7919
diff
changeset
|
1056 @example\n\ |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
8949
diff
changeset
|
1057 @group\n\ |
17403
db8b90a56298
doc: Reword docstrings for cummax, cummin.
Rik <rik@octave.org>
parents:
16370
diff
changeset
|
1058 [w, iw] = cummax ([1 3 2 6 4 5])\n\ |
db8b90a56298
doc: Reword docstrings for cummax, cummin.
Rik <rik@octave.org>
parents:
16370
diff
changeset
|
1059 @result{}\n\ |
db8b90a56298
doc: Reword docstrings for cummax, cummin.
Rik <rik@octave.org>
parents:
16370
diff
changeset
|
1060 w = 1 3 3 6 6 6\n\ |
db8b90a56298
doc: Reword docstrings for cummax, cummin.
Rik <rik@octave.org>
parents:
16370
diff
changeset
|
1061 iw = 1 2 2 4 4 4\n\ |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
8949
diff
changeset
|
1062 @end group\n\ |
8777
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7919
diff
changeset
|
1063 @end example\n\ |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7919
diff
changeset
|
1064 \n\ |
9141
c1fff751b5a8
Update section 17.1 (Utility Functions) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents:
9086
diff
changeset
|
1065 @seealso{cummin, max, min}\n\ |
8777
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7919
diff
changeset
|
1066 @end deftypefn") |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7919
diff
changeset
|
1067 { |
9790
a5035bc7fbfb
rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
1068 return do_cumminmax_body (args, nargout, false); |
8777
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7919
diff
changeset
|
1069 } |
17403
db8b90a56298
doc: Reword docstrings for cummax, cummin.
Rik <rik@octave.org>
parents:
16370
diff
changeset
|
1070 |
db8b90a56298
doc: Reword docstrings for cummax, cummin.
Rik <rik@octave.org>
parents:
16370
diff
changeset
|
1071 /* |
db8b90a56298
doc: Reword docstrings for cummax, cummin.
Rik <rik@octave.org>
parents:
16370
diff
changeset
|
1072 %!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
|
1073 %!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
|
1074 %!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
|
1075 %!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
|
1076 |
db8b90a56298
doc: Reword docstrings for cummax, cummin.
Rik <rik@octave.org>
parents:
16370
diff
changeset
|
1077 %!test |
db8b90a56298
doc: Reword docstrings for cummax, cummin.
Rik <rik@octave.org>
parents:
16370
diff
changeset
|
1078 %! x = reshape (8:-1:1, [2,2,2]); |
db8b90a56298
doc: Reword docstrings for cummax, cummin.
Rik <rik@octave.org>
parents:
16370
diff
changeset
|
1079 %! 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
|
1080 %! 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
|
1081 %! [w, iw] = cummax (x, 3); |
db8b90a56298
doc: Reword docstrings for cummax, cummin.
Rik <rik@octave.org>
parents:
16370
diff
changeset
|
1082 %! assert (ndims (w), 3); |
db8b90a56298
doc: Reword docstrings for cummax, cummin.
Rik <rik@octave.org>
parents:
16370
diff
changeset
|
1083 %! 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
|
1084 %! assert (ndims (iw), 3); |
db8b90a56298
doc: Reword docstrings for cummax, cummin.
Rik <rik@octave.org>
parents:
16370
diff
changeset
|
1085 %! assert (iw, ones (2,2,2)); |
db8b90a56298
doc: Reword docstrings for cummax, cummin.
Rik <rik@octave.org>
parents:
16370
diff
changeset
|
1086 |
db8b90a56298
doc: Reword docstrings for cummax, cummin.
Rik <rik@octave.org>
parents:
16370
diff
changeset
|
1087 %!error cummax () |
db8b90a56298
doc: Reword docstrings for cummax, cummin.
Rik <rik@octave.org>
parents:
16370
diff
changeset
|
1088 %!error cummax (1, 2, 3) |
db8b90a56298
doc: Reword docstrings for cummax, cummin.
Rik <rik@octave.org>
parents:
16370
diff
changeset
|
1089 */ |
db8b90a56298
doc: Reword docstrings for cummax, cummin.
Rik <rik@octave.org>
parents:
16370
diff
changeset
|
1090 |