Mercurial > octave
annotate src/DLD-FUNCTIONS/max.cc @ 9732:b4fdfee405b5
remove ArrayN<T> + fix nonhom. diag-scalar ops
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Fri, 16 Oct 2009 13:12:31 +0200 |
parents | e2344f4af0cb |
children | a5035bc7fbfb |
rev | line source |
---|---|
2928 | 1 /* |
2 | |
7017 | 3 Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, |
8920 | 4 2005, 2006, 2007, 2008 John W. Eaton |
8777
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7919
diff
changeset
|
5 Copyright (C) 2009 VZLU Prague |
2928 | 6 |
7 This file is part of Octave. | |
8 | |
9 Octave is free software; you can redistribute it and/or modify it | |
10 under the terms of the GNU General Public License as published by the | |
7016 | 11 Free Software Foundation; either version 3 of the License, or (at your |
12 option) any later version. | |
2928 | 13 |
14 Octave is distributed in the hope that it will be useful, but WITHOUT | |
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
17 for more details. | |
18 | |
19 You should have received a copy of the GNU General Public License | |
7016 | 20 along with Octave; see the file COPYING. If not, see |
21 <http://www.gnu.org/licenses/>. | |
2928 | 22 |
23 */ | |
24 | |
25 #ifdef HAVE_CONFIG_H | |
26 #include <config.h> | |
27 #endif | |
28 | |
29 #include "lo-ieee.h" | |
3248 | 30 #include "lo-mappers.h" |
7231 | 31 #include "lo-math.h" |
4844 | 32 #include "dNDArray.h" |
33 #include "CNDArray.h" | |
4153 | 34 #include "quit.h" |
2928 | 35 |
36 #include "defun-dld.h" | |
37 #include "error.h" | |
38 #include "gripes.h" | |
39 #include "oct-obj.h" | |
40 | |
4844 | 41 #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
|
42 #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
|
43 #include "ov-cx-sparse.h" |
4844 | 44 |
8777
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7919
diff
changeset
|
45 #define MINMAX_DOUBLE_SBODY(FCN) \ |
7189 | 46 { \ |
8777
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7919
diff
changeset
|
47 if (nargout == 1 || nargout == 0) \ |
3747 | 48 { \ |
49 if (arg1.is_real_type ()) \ | |
50 { \ | |
4844 | 51 NDArray m = arg1.array_value (); \ |
3747 | 52 \ |
53 if (! error_state) \ | |
54 { \ | |
4844 | 55 NDArray n = m. FCN (dim); \ |
56 retval(0) = n; \ | |
3747 | 57 } \ |
58 } \ | |
59 else if (arg1.is_complex_type ()) \ | |
60 { \ | |
4844 | 61 ComplexNDArray m = arg1.complex_array_value (); \ |
3747 | 62 \ |
63 if (! error_state) \ | |
64 { \ | |
4844 | 65 ComplexNDArray n = m. FCN (dim); \ |
66 retval(0) = n; \ | |
3747 | 67 } \ |
68 } \ | |
69 else \ | |
70 gripe_wrong_type_arg (#FCN, arg1); \ | |
71 } \ | |
8777
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7919
diff
changeset
|
72 else if (nargout == 2) \ |
3747 | 73 { \ |
9732
b4fdfee405b5
remove ArrayN<T> + fix nonhom. diag-scalar ops
Jaroslav Hajek <highegg@gmail.com>
parents:
9351
diff
changeset
|
74 Array<octave_idx_type> index; \ |
3747 | 75 \ |
76 if (arg1.is_real_type ()) \ | |
77 { \ | |
4844 | 78 NDArray m = arg1.array_value (); \ |
3747 | 79 \ |
80 if (! error_state) \ | |
81 { \ | |
4844 | 82 NDArray n = m. FCN (index, dim); \ |
83 retval(0) = n; \ | |
3747 | 84 } \ |
85 } \ | |
86 else if (arg1.is_complex_type ()) \ | |
87 { \ | |
4844 | 88 ComplexNDArray m = arg1.complex_array_value (); \ |
3747 | 89 \ |
90 if (! error_state) \ | |
91 { \ | |
4844 | 92 ComplexNDArray n = m. FCN (index, dim); \ |
93 retval(0) = n; \ | |
3747 | 94 } \ |
95 } \ | |
96 else \ | |
97 gripe_wrong_type_arg (#FCN, arg1); \ | |
98 \ | |
5275 | 99 octave_idx_type len = index.numel (); \ |
3747 | 100 \ |
101 if (len > 0) \ | |
9351
e2344f4af0cb
autocache indices returned from find et al.
Jaroslav Hajek <highegg@gmail.com>
parents:
9165
diff
changeset
|
102 retval(1) = octave_value (index, true, true); \ |
3747 | 103 else \ |
4844 | 104 retval(1) = NDArray (); \ |
3747 | 105 } \ |
8777
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7919
diff
changeset
|
106 } |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7919
diff
changeset
|
107 |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7919
diff
changeset
|
108 #define MINMAX_DOUBLE_BODY(FCN) \ |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7919
diff
changeset
|
109 { \ |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7919
diff
changeset
|
110 bool single_arg = (nargin == 1) || (arg2.is_empty() && nargin == 3); \ |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7919
diff
changeset
|
111 if (single_arg) \ |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7919
diff
changeset
|
112 MINMAX_DOUBLE_SBODY (FCN) \ |
4844 | 113 else \ |
3747 | 114 { \ |
115 int arg1_is_scalar = arg1.is_scalar_type (); \ | |
116 int arg2_is_scalar = arg2.is_scalar_type (); \ | |
117 \ | |
118 int arg1_is_complex = arg1.is_complex_type (); \ | |
119 int arg2_is_complex = arg2.is_complex_type (); \ | |
120 \ | |
121 if (arg1_is_scalar) \ | |
122 { \ | |
123 if (arg1_is_complex || arg2_is_complex) \ | |
124 { \ | |
125 Complex c1 = arg1.complex_value (); \ | |
4844 | 126 ComplexNDArray m2 = arg2.complex_array_value (); \ |
3747 | 127 if (! error_state) \ |
128 { \ | |
4844 | 129 ComplexNDArray result = FCN (c1, m2); \ |
3747 | 130 if (! error_state) \ |
131 retval(0) = result; \ | |
132 } \ | |
133 } \ | |
134 else \ | |
135 { \ | |
136 double d1 = arg1.double_value (); \ | |
4844 | 137 NDArray m2 = arg2.array_value (); \ |
3747 | 138 \ |
139 if (! error_state) \ | |
140 { \ | |
4844 | 141 NDArray result = FCN (d1, m2); \ |
3747 | 142 if (! error_state) \ |
143 retval(0) = result; \ | |
144 } \ | |
145 } \ | |
146 } \ | |
147 else if (arg2_is_scalar) \ | |
148 { \ | |
149 if (arg1_is_complex || arg2_is_complex) \ | |
150 { \ | |
4844 | 151 ComplexNDArray m1 = arg1.complex_array_value (); \ |
3747 | 152 \ |
153 if (! error_state) \ | |
154 { \ | |
155 Complex c2 = arg2.complex_value (); \ | |
4844 | 156 ComplexNDArray result = FCN (m1, c2); \ |
3747 | 157 if (! error_state) \ |
158 retval(0) = result; \ | |
159 } \ | |
160 } \ | |
161 else \ | |
162 { \ | |
4844 | 163 NDArray m1 = arg1.array_value (); \ |
3747 | 164 \ |
165 if (! error_state) \ | |
166 { \ | |
167 double d2 = arg2.double_value (); \ | |
4844 | 168 NDArray result = FCN (m1, d2); \ |
3747 | 169 if (! error_state) \ |
170 retval(0) = result; \ | |
171 } \ | |
172 } \ | |
173 } \ | |
174 else \ | |
175 { \ | |
176 if (arg1_is_complex || arg2_is_complex) \ | |
177 { \ | |
4844 | 178 ComplexNDArray m1 = arg1.complex_array_value (); \ |
3747 | 179 \ |
180 if (! error_state) \ | |
181 { \ | |
4844 | 182 ComplexNDArray m2 = arg2.complex_array_value (); \ |
3747 | 183 \ |
184 if (! error_state) \ | |
185 { \ | |
4844 | 186 ComplexNDArray result = FCN (m1, m2); \ |
3747 | 187 if (! error_state) \ |
188 retval(0) = result; \ | |
189 } \ | |
190 } \ | |
191 } \ | |
192 else \ | |
193 { \ | |
4844 | 194 NDArray m1 = arg1.array_value (); \ |
3747 | 195 \ |
196 if (! error_state) \ | |
197 { \ | |
4844 | 198 NDArray m2 = arg2.array_value (); \ |
3747 | 199 \ |
200 if (! error_state) \ | |
201 { \ | |
4844 | 202 NDArray result = FCN (m1, m2); \ |
3747 | 203 if (! error_state) \ |
204 retval(0) = result; \ | |
205 } \ | |
206 } \ | |
207 } \ | |
208 } \ | |
209 } \ | |
7189 | 210 } |
211 | |
8777
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7919
diff
changeset
|
212 #define MINMAX_SINGLE_SBODY(FCN) \ |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
213 { \ |
8777
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7919
diff
changeset
|
214 if (nargout == 1 || nargout == 0) \ |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
215 { \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
216 if (arg1.is_real_type ()) \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
217 { \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
218 FloatNDArray m = arg1.float_array_value (); \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
219 \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
220 if (! error_state) \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
221 { \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
222 FloatNDArray n = m. FCN (dim); \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
223 retval(0) = n; \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
224 } \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
225 } \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
226 else if (arg1.is_complex_type ()) \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
227 { \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
228 FloatComplexNDArray m = arg1.float_complex_array_value (); \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
229 \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
230 if (! error_state) \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
231 { \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
232 FloatComplexNDArray n = m. FCN (dim); \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
233 retval(0) = n; \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
234 } \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
235 } \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
236 else \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
237 gripe_wrong_type_arg (#FCN, arg1); \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
238 } \ |
8777
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7919
diff
changeset
|
239 else if (nargout == 2) \ |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
240 { \ |
9732
b4fdfee405b5
remove ArrayN<T> + fix nonhom. diag-scalar ops
Jaroslav Hajek <highegg@gmail.com>
parents:
9351
diff
changeset
|
241 Array<octave_idx_type> index; \ |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
242 \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
243 if (arg1.is_real_type ()) \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
244 { \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
245 FloatNDArray m = arg1.float_array_value (); \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
246 \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
247 if (! error_state) \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
248 { \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
249 FloatNDArray n = m. FCN (index, dim); \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
250 retval(0) = n; \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
251 } \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
252 } \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
253 else if (arg1.is_complex_type ()) \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
254 { \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
255 FloatComplexNDArray m = arg1.float_complex_array_value (); \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
256 \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
257 if (! error_state) \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
258 { \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
259 FloatComplexNDArray n = m. FCN (index, dim); \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
260 retval(0) = n; \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
261 } \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
262 } \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
263 else \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
264 gripe_wrong_type_arg (#FCN, arg1); \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
265 \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
266 octave_idx_type len = index.numel (); \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
267 \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
268 if (len > 0) \ |
9351
e2344f4af0cb
autocache indices returned from find et al.
Jaroslav Hajek <highegg@gmail.com>
parents:
9165
diff
changeset
|
269 retval(1) = octave_value (index, true, true); \ |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
270 else \ |
7919
9d080df0c843
new NDArray constructor for ArrayN<octave_idx_type>
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
271 retval(1) = NDArray (); \ |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
272 } \ |
8777
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7919
diff
changeset
|
273 } |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7919
diff
changeset
|
274 |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7919
diff
changeset
|
275 #define MINMAX_SINGLE_BODY(FCN) \ |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7919
diff
changeset
|
276 { \ |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7919
diff
changeset
|
277 bool single_arg = (nargin == 1) || (arg2.is_empty() && nargin == 3); \ |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7919
diff
changeset
|
278 if (single_arg) \ |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7919
diff
changeset
|
279 MINMAX_SINGLE_SBODY(FCN) \ |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
280 else \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
281 { \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
282 int arg1_is_scalar = arg1.is_scalar_type (); \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
283 int arg2_is_scalar = arg2.is_scalar_type (); \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
284 \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
285 int arg1_is_complex = arg1.is_complex_type (); \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
286 int arg2_is_complex = arg2.is_complex_type (); \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
287 \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
288 if (arg1_is_scalar) \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
289 { \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
290 if (arg1_is_complex || arg2_is_complex) \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
291 { \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
292 FloatComplex c1 = arg1.float_complex_value (); \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
293 FloatComplexNDArray m2 = arg2.float_complex_array_value (); \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
294 if (! error_state) \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
295 { \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
296 FloatComplexNDArray result = FCN (c1, m2); \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
297 if (! error_state) \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
298 retval(0) = result; \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
299 } \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
300 } \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
301 else \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
302 { \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
303 float d1 = arg1.float_value (); \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
304 FloatNDArray m2 = arg2.float_array_value (); \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
305 \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
306 if (! error_state) \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
307 { \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
308 FloatNDArray result = FCN (d1, m2); \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
309 if (! error_state) \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
310 retval(0) = result; \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
311 } \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
312 } \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
313 } \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
314 else if (arg2_is_scalar) \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
315 { \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
316 if (arg1_is_complex || arg2_is_complex) \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
317 { \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
318 FloatComplexNDArray m1 = arg1.float_complex_array_value (); \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
319 \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
320 if (! error_state) \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
321 { \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
322 FloatComplex c2 = arg2.float_complex_value (); \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
323 FloatComplexNDArray result = FCN (m1, c2); \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
324 if (! error_state) \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
325 retval(0) = result; \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
326 } \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
327 } \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
328 else \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
329 { \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
330 FloatNDArray m1 = arg1.float_array_value (); \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
331 \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
332 if (! error_state) \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
333 { \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
334 float d2 = arg2.float_value (); \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
335 FloatNDArray result = FCN (m1, d2); \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
336 if (! error_state) \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
337 retval(0) = result; \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
338 } \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
339 } \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
340 } \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
341 else \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
342 { \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
343 if (arg1_is_complex || arg2_is_complex) \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
344 { \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
345 FloatComplexNDArray m1 = arg1.float_complex_array_value (); \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
346 \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
347 if (! error_state) \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
348 { \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
349 FloatComplexNDArray m2 = arg2.float_complex_array_value (); \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
350 \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
351 if (! error_state) \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
352 { \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
353 FloatComplexNDArray result = FCN (m1, m2); \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
354 if (! error_state) \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
355 retval(0) = result; \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
356 } \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
357 } \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
358 } \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
359 else \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
360 { \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
361 FloatNDArray m1 = arg1.float_array_value (); \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
362 \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
363 if (! error_state) \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
364 { \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
365 FloatNDArray m2 = arg2.float_array_value (); \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
366 \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
367 if (! error_state) \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
368 { \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
369 FloatNDArray result = FCN (m1, m2); \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
370 if (! error_state) \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
371 retval(0) = result; \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
372 } \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
373 } \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
374 } \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
375 } \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
376 } \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
377 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
378 |
8777
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7919
diff
changeset
|
379 #define MINMAX_INT_SBODY(FCN, TYP) \ |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7919
diff
changeset
|
380 { \ |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7919
diff
changeset
|
381 if (nargout == 1 || nargout == 0) \ |
7189 | 382 { \ |
383 TYP ## NDArray m = arg1. TYP ## _array_value (); \ | |
384 \ | |
385 if (! error_state) \ | |
386 { \ | |
387 TYP ## NDArray n = m. FCN (dim); \ | |
388 retval(0) = n; \ | |
389 } \ | |
390 } \ | |
8777
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7919
diff
changeset
|
391 else if (nargout == 2) \ |
7189 | 392 { \ |
9732
b4fdfee405b5
remove ArrayN<T> + fix nonhom. diag-scalar ops
Jaroslav Hajek <highegg@gmail.com>
parents:
9351
diff
changeset
|
393 Array<octave_idx_type> index; \ |
7189 | 394 \ |
395 TYP ## NDArray m = arg1. TYP ## _array_value (); \ | |
396 \ | |
397 if (! error_state) \ | |
398 { \ | |
399 TYP ## NDArray n = m. FCN (index, dim); \ | |
400 retval(0) = n; \ | |
401 } \ | |
402 \ | |
403 octave_idx_type len = index.numel (); \ | |
404 \ | |
405 if (len > 0) \ | |
9351
e2344f4af0cb
autocache indices returned from find et al.
Jaroslav Hajek <highegg@gmail.com>
parents:
9165
diff
changeset
|
406 retval(1) = octave_value (index, true, true); \ |
7189 | 407 else \ |
408 retval(1) = NDArray (); \ | |
409 } \ | |
8777
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7919
diff
changeset
|
410 } |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7919
diff
changeset
|
411 |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7919
diff
changeset
|
412 #define MINMAX_INT_BODY(FCN, TYP) \ |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7919
diff
changeset
|
413 { \ |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7919
diff
changeset
|
414 bool single_arg = (nargin == 1) || (arg2.is_empty() && nargin == 3); \ |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7919
diff
changeset
|
415 if (single_arg) \ |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7919
diff
changeset
|
416 MINMAX_INT_SBODY (FCN, TYP) \ |
7189 | 417 else \ |
418 { \ | |
419 int arg1_is_scalar = arg1.is_scalar_type (); \ | |
420 int arg2_is_scalar = arg2.is_scalar_type (); \ | |
421 \ | |
422 if (arg1_is_scalar) \ | |
423 { \ | |
424 octave_ ## TYP d1 = arg1. TYP ## _scalar_value (); \ | |
425 TYP ## NDArray m2 = arg2. TYP ## _array_value (); \ | |
426 \ | |
427 if (! error_state) \ | |
428 { \ | |
429 TYP ## NDArray result = FCN (d1, m2); \ | |
430 if (! error_state) \ | |
431 retval(0) = result; \ | |
432 } \ | |
433 } \ | |
434 else if (arg2_is_scalar) \ | |
435 { \ | |
436 TYP ## NDArray m1 = arg1. TYP ## _array_value (); \ | |
437 \ | |
438 if (! error_state) \ | |
439 { \ | |
440 octave_ ## TYP d2 = arg2. TYP ## _scalar_value (); \ | |
441 TYP ## NDArray result = FCN (m1, d2); \ | |
442 if (! error_state) \ | |
443 retval(0) = result; \ | |
444 } \ | |
445 } \ | |
446 else \ | |
447 { \ | |
448 TYP ## NDArray m1 = arg1. TYP ## _array_value (); \ | |
449 \ | |
450 if (! error_state) \ | |
451 { \ | |
452 TYP ## NDArray m2 = arg2. TYP ## _array_value (); \ | |
453 \ | |
454 if (! error_state) \ | |
455 { \ | |
456 TYP ## NDArray result = FCN (m1, m2); \ | |
457 if (! error_state) \ | |
458 retval(0) = result; \ | |
459 } \ | |
460 } \ | |
461 } \ | |
462 } \ | |
463 } | |
464 | |
7505
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
465 #define MINMAX_SPARSE_BODY(FCN) \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
466 { \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
467 bool single_arg = (nargin == 1) || arg2.is_empty(); \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
468 \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
469 if (single_arg && (nargout == 1 || nargout == 0)) \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
470 { \ |
9086
4218f9515258
Allow sparse logical max/min
David Bateman <dbateman@free.fr>
parents:
9065
diff
changeset
|
471 if (arg1.is_real_type ()) \ |
7505
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
472 retval(0) = arg1.sparse_matrix_value () .FCN (dim); \ |
9086
4218f9515258
Allow sparse logical max/min
David Bateman <dbateman@free.fr>
parents:
9065
diff
changeset
|
473 else if (arg1.is_complex_type ()) \ |
7505
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
474 retval(0) = arg1.sparse_complex_matrix_value () .FCN (dim); \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
475 else \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
476 gripe_wrong_type_arg (#FCN, arg1); \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
477 } \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
478 else if (single_arg && nargout == 2) \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
479 { \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
480 Array2<octave_idx_type> index; \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
481 \ |
9086
4218f9515258
Allow sparse logical max/min
David Bateman <dbateman@free.fr>
parents:
9065
diff
changeset
|
482 if (arg1.is_real_type ()) \ |
7505
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
483 retval(0) = arg1.sparse_matrix_value () .FCN (index, dim); \ |
9086
4218f9515258
Allow sparse logical max/min
David Bateman <dbateman@free.fr>
parents:
9065
diff
changeset
|
484 else if (arg1.is_complex_type ()) \ |
7505
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
485 retval(0) = arg1.sparse_complex_matrix_value () .FCN (index, dim); \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
486 else \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
487 gripe_wrong_type_arg (#FCN, arg1); \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
488 \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
489 octave_idx_type len = index.numel (); \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
490 \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
491 if (len > 0) \ |
9351
e2344f4af0cb
autocache indices returned from find et al.
Jaroslav Hajek <highegg@gmail.com>
parents:
9165
diff
changeset
|
492 retval(1) = octave_value (index, true, true); \ |
7505
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
493 else \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
494 retval(1) = NDArray (); \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
495 } \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
496 else \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
497 { \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
498 int arg1_is_scalar = arg1.is_scalar_type (); \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
499 int arg2_is_scalar = arg2.is_scalar_type (); \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
500 \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
501 int arg1_is_complex = arg1.is_complex_type (); \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
502 int arg2_is_complex = arg2.is_complex_type (); \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
503 \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
504 if (arg1_is_scalar) \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
505 { \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
506 if (arg1_is_complex || arg2_is_complex) \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
507 { \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
508 Complex c1 = arg1.complex_value (); \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
509 \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
510 SparseComplexMatrix m2 = arg2.sparse_complex_matrix_value (); \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
511 \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
512 if (! error_state) \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
513 { \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
514 SparseComplexMatrix result = FCN (c1, m2); \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
515 if (! error_state) \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
516 retval(0) = result; \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
517 } \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
518 } \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
519 else \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
520 { \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
521 double d1 = arg1.double_value (); \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
522 SparseMatrix m2 = arg2.sparse_matrix_value (); \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
523 \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
524 if (! error_state) \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
525 { \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
526 SparseMatrix result = FCN (d1, m2); \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
527 if (! error_state) \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
528 retval(0) = result; \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
529 } \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
530 } \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
531 } \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
532 else if (arg2_is_scalar) \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
533 { \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
534 if (arg1_is_complex || arg2_is_complex) \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
535 { \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
536 SparseComplexMatrix m1 = arg1.sparse_complex_matrix_value (); \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
537 \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
538 if (! error_state) \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
539 { \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
540 Complex c2 = arg2.complex_value (); \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
541 SparseComplexMatrix result = FCN (m1, c2); \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
542 if (! error_state) \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
543 retval(0) = result; \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
544 } \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
545 } \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
546 else \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
547 { \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
548 SparseMatrix m1 = arg1.sparse_matrix_value (); \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
549 \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
550 if (! error_state) \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
551 { \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
552 double d2 = arg2.double_value (); \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
553 SparseMatrix result = FCN (m1, d2); \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
554 if (! error_state) \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
555 retval(0) = result; \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
556 } \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
557 } \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
558 } \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
559 else \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
560 { \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
561 if (arg1_is_complex || arg2_is_complex) \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
562 { \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
563 SparseComplexMatrix m1 = arg1.sparse_complex_matrix_value (); \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
564 \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
565 if (! error_state) \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
566 { \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
567 SparseComplexMatrix m2 = arg2.sparse_complex_matrix_value (); \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
568 \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
569 if (! error_state) \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
570 { \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
571 SparseComplexMatrix result = FCN (m1, m2); \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
572 if (! error_state) \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
573 retval(0) = result; \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
574 } \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
575 } \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
576 } \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
577 else \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
578 { \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
579 SparseMatrix m1 = arg1.sparse_matrix_value (); \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
580 \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
581 if (! error_state) \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
582 { \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
583 SparseMatrix m2 = arg2.sparse_matrix_value (); \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
584 \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
585 if (! error_state) \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
586 { \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
587 SparseMatrix result = FCN (m1, m2); \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
588 if (! error_state) \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
589 retval(0) = result; \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
590 } \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
591 } \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
592 } \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
593 } \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
594 } \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
595 } |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
596 |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
597 |
7189 | 598 #define MINMAX_BODY(FCN) \ |
599 \ | |
600 octave_value_list retval; \ | |
601 \ | |
602 int nargin = args.length (); \ | |
603 \ | |
604 if (nargin < 1 || nargin > 3 || nargout > 2) \ | |
605 { \ | |
606 print_usage (); \ | |
607 return retval; \ | |
608 } \ | |
609 \ | |
610 octave_value arg1; \ | |
611 octave_value arg2; \ | |
612 octave_value arg3; \ | |
613 \ | |
614 switch (nargin) \ | |
615 { \ | |
616 case 3: \ | |
617 arg3 = args(2); \ | |
618 \ | |
619 case 2: \ | |
620 arg2 = args(1); \ | |
621 \ | |
622 case 1: \ | |
623 arg1 = args(0); \ | |
624 break; \ | |
625 \ | |
626 default: \ | |
627 panic_impossible (); \ | |
628 break; \ | |
629 } \ | |
630 \ | |
631 int dim; \ | |
632 dim_vector dv = arg1.dims (); \ | |
633 if (error_state) \ | |
634 { \ | |
635 gripe_wrong_type_arg (#FCN, arg1); \ | |
636 return retval; \ | |
637 } \ | |
638 \ | |
639 if (nargin == 3) \ | |
640 { \ | |
641 dim = arg3.nint_value () - 1; \ | |
642 if (dim < 0 || dim >= dv.length ()) \ | |
643 { \ | |
644 error ("%s: invalid dimension", #FCN); \ | |
645 return retval; \ | |
646 } \ | |
647 } \ | |
648 else \ | |
649 { \ | |
650 dim = 0; \ | |
651 while ((dim < dv.length ()) && (dv (dim) <= 1)) \ | |
652 dim++; \ | |
653 if (dim == dv.length ()) \ | |
654 dim = 0; \ | |
655 } \ | |
656 \ | |
657 if (arg1.is_integer_type ()) \ | |
658 { \ | |
659 if (arg1.is_uint8_type ()) \ | |
660 MINMAX_INT_BODY (FCN, uint8) \ | |
661 else if (arg1.is_uint16_type ()) \ | |
662 MINMAX_INT_BODY (FCN, uint16) \ | |
663 else if (arg1.is_uint32_type ()) \ | |
664 MINMAX_INT_BODY (FCN, uint32) \ | |
665 else if (arg1.is_uint64_type ()) \ | |
666 MINMAX_INT_BODY (FCN, uint64) \ | |
667 else if (arg1.is_int8_type ()) \ | |
668 MINMAX_INT_BODY (FCN, int8) \ | |
669 else if (arg1.is_int16_type ()) \ | |
670 MINMAX_INT_BODY (FCN, int16) \ | |
671 else if (arg1.is_int32_type ()) \ | |
672 MINMAX_INT_BODY (FCN, int32) \ | |
673 else if (arg1.is_int64_type ()) \ | |
674 MINMAX_INT_BODY (FCN, int64) \ | |
675 } \ | |
7505
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
676 else if (arg1.is_sparse_type ()) \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
677 MINMAX_SPARSE_BODY (FCN) \ |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
678 else if (arg1.is_single_type ()) \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
679 MINMAX_SINGLE_BODY (FCN) \ |
7189 | 680 else \ |
681 MINMAX_DOUBLE_BODY (FCN) \ | |
682 \ | |
683 return retval; | |
3747 | 684 |
2928 | 685 DEFUN_DLD (min, args, nargout, |
3443 | 686 "-*- texinfo -*-\n\ |
9141
c1fff751b5a8
Update section 17.1 (Utility Functions) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents:
9086
diff
changeset
|
687 @deftypefn {Loadable Function} {} min (@var{x})\n\ |
c1fff751b5a8
Update section 17.1 (Utility Functions) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents:
9086
diff
changeset
|
688 @deftypefnx {Loadable Function} {} min (@var{x}, @var{y})\n\ |
c1fff751b5a8
Update section 17.1 (Utility Functions) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents:
9086
diff
changeset
|
689 @deftypefnx {Loadable Function} {} min (@var{x}, @var{y}, @var{dim})\n\ |
8780
ea76466605ba
support native cumsum, gripe on overflow in sum/cumsum
Jaroslav Hajek <highegg@gmail.com>
parents:
8778
diff
changeset
|
690 @deftypefnx {Loadable Function} {[@var{w}, @var{iw}] =} min (@var{x})\n\ |
3443 | 691 For a vector argument, return the minimum value. For a matrix\n\ |
692 argument, return the minimum value from each column, as a row\n\ | |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
8949
diff
changeset
|
693 vector, or over the dimension @var{dim} if defined. For two matrices\n\ |
4844 | 694 (or a matrix and scalar), return the pair-wise minimum.\n\ |
4522 | 695 Thus,\n\ |
3443 | 696 \n\ |
697 @example\n\ | |
698 min (min (@var{x}))\n\ | |
699 @end example\n\ | |
700 \n\ | |
701 @noindent\n\ | |
4522 | 702 returns the smallest element of @var{x}, and\n\ |
703 \n\ | |
704 @example\n\ | |
705 @group\n\ | |
706 min (2:5, pi)\n\ | |
707 @result{} 2.0000 3.0000 3.1416 3.1416\n\ | |
708 @end group\n\ | |
709 @end example\n\ | |
710 @noindent\n\ | |
711 compares each element of the range @code{2:5} with @code{pi}, and\n\ | |
712 returns a row vector of the minimum values.\n\ | |
3443 | 713 \n\ |
714 For complex arguments, the magnitude of the elements are used for\n\ | |
3657 | 715 comparison.\n\ |
716 \n\ | |
4522 | 717 If called with one input and two output arguments,\n\ |
718 @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
|
719 minimum value(s). Thus,\n\ |
4522 | 720 \n\ |
3775 | 721 @example\n\ |
4522 | 722 @group\n\ |
9165
8c71a86c4bf4
Update section 17.5 (Utility Functions) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents:
9141
diff
changeset
|
723 [x, ix] = min ([1, 3, 0, 2, 0])\n\ |
4522 | 724 @result{} x = 0\n\ |
725 ix = 3\n\ | |
726 @end group\n\ | |
3657 | 727 @end example\n\ |
9141
c1fff751b5a8
Update section 17.1 (Utility Functions) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents:
9086
diff
changeset
|
728 @seealso{max, cummin, cummax}\n\ |
4522 | 729 @end deftypefn") |
2928 | 730 { |
3747 | 731 MINMAX_BODY (min); |
2928 | 732 } |
733 | |
7600
24abf5a702d9
Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
734 /* |
24abf5a702d9
Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
735 |
24abf5a702d9
Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
736 %% test/octave.test/arith/min-1.m |
24abf5a702d9
Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
737 %!assert (min ([1, 4, 2, 3]) == 1); |
24abf5a702d9
Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
738 %!assert (min ([1; -10; 5; -2]) == -10); |
24abf5a702d9
Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
739 |
24abf5a702d9
Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
740 %% test/octave.test/arith/min-2.m |
24abf5a702d9
Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
741 %!assert(all (min ([4, i; -2, 2]) == [-2, i])); |
24abf5a702d9
Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
742 |
24abf5a702d9
Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
743 %% test/octave.test/arith/min-3.m |
24abf5a702d9
Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
744 %!error <Invalid call to min.*> min (); |
24abf5a702d9
Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
745 |
24abf5a702d9
Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
746 %% test/octave.test/arith/min-4.m |
24abf5a702d9
Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
747 %!error <Invalid call to min.*> min (1, 2, 3, 4); |
24abf5a702d9
Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
748 |
24abf5a702d9
Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
749 %!test |
24abf5a702d9
Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
750 %! x = reshape (1:8,[2,2,2]); |
24abf5a702d9
Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
751 %! assert (max (x,[],1), reshape ([2, 4, 6, 8], [1,2,2])); |
24abf5a702d9
Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
752 %! assert (max (x,[],2), reshape ([3, 4, 7, 8], [2,1,2])); |
24abf5a702d9
Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
753 %! [y, i ] = max (x, [], 3); |
24abf5a702d9
Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
754 %! assert (y, [5, 7; 6, 8]); |
24abf5a702d9
Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
755 %! assert (ndims(y), 2); |
24abf5a702d9
Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
756 %! assert (i, [2, 2; 2, 2]); |
24abf5a702d9
Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
757 %! assert (ndims(i), 2); |
24abf5a702d9
Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
758 |
24abf5a702d9
Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
759 */ |
24abf5a702d9
Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
760 |
2928 | 761 DEFUN_DLD (max, args, nargout, |
3443 | 762 "-*- texinfo -*-\n\ |
9141
c1fff751b5a8
Update section 17.1 (Utility Functions) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents:
9086
diff
changeset
|
763 @deftypefn {Loadable Function} {} max (@var{x})\n\ |
c1fff751b5a8
Update section 17.1 (Utility Functions) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents:
9086
diff
changeset
|
764 @deftypefnx {Loadable Function} {} max (@var{x}, @var{y})\n\ |
c1fff751b5a8
Update section 17.1 (Utility Functions) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents:
9086
diff
changeset
|
765 @deftypefnx {Loadable Function} {} max (@var{x}, @var{y}, @var{dim})\n\ |
8780
ea76466605ba
support native cumsum, gripe on overflow in sum/cumsum
Jaroslav Hajek <highegg@gmail.com>
parents:
8778
diff
changeset
|
766 @deftypefnx {Loadable Function} {[@var{w}, @var{iw}] =} max (@var{x})\n\ |
3443 | 767 For a vector argument, return the maximum value. For a matrix\n\ |
768 argument, return the maximum value from each column, as a row\n\ | |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
8949
diff
changeset
|
769 vector, or over the dimension @var{dim} if defined. For two matrices\n\ |
4844 | 770 (or a matrix and scalar), return the pair-wise maximum.\n\ |
4522 | 771 Thus,\n\ |
3443 | 772 \n\ |
773 @example\n\ | |
774 max (max (@var{x}))\n\ | |
775 @end example\n\ | |
776 \n\ | |
777 @noindent\n\ | |
9141
c1fff751b5a8
Update section 17.1 (Utility Functions) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents:
9086
diff
changeset
|
778 returns the largest element of the matrix @var{x}, and\n\ |
4522 | 779 \n\ |
780 @example\n\ | |
781 @group\n\ | |
782 max (2:5, pi)\n\ | |
783 @result{} 3.1416 3.1416 4.0000 5.0000\n\ | |
784 @end group\n\ | |
785 @end example\n\ | |
786 @noindent\n\ | |
787 compares each element of the range @code{2:5} with @code{pi}, and\n\ | |
788 returns a row vector of the maximum values.\n\ | |
3443 | 789 \n\ |
790 For complex arguments, the magnitude of the elements are used for\n\ | |
3775 | 791 comparison.\n\ |
3657 | 792 \n\ |
4522 | 793 If called with one input and two output arguments,\n\ |
794 @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
|
795 maximum value(s). Thus,\n\ |
4522 | 796 \n\ |
3775 | 797 @example\n\ |
4522 | 798 @group\n\ |
799 [x, ix] = max ([1, 3, 5, 2, 5])\n\ | |
800 @result{} x = 5\n\ | |
801 ix = 3\n\ | |
802 @end group\n\ | |
3657 | 803 @end example\n\ |
9141
c1fff751b5a8
Update section 17.1 (Utility Functions) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents:
9086
diff
changeset
|
804 @seealso{min, cummax, cummin}\n\ |
4522 | 805 @end deftypefn") |
2928 | 806 { |
3747 | 807 MINMAX_BODY (max); |
2928 | 808 } |
809 | |
7600
24abf5a702d9
Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
810 /* |
24abf5a702d9
Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
811 |
24abf5a702d9
Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
812 %% test/octave.test/arith/max-1.m |
24abf5a702d9
Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
813 %!assert (max ([1, 4, 2, 3]) == 4); |
24abf5a702d9
Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
814 %!assert (max ([1; -10; 5; -2]) == 5); |
24abf5a702d9
Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
815 |
24abf5a702d9
Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
816 %% test/octave.test/arith/max-2.m |
24abf5a702d9
Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
817 %!assert(all (max ([4, i 4.999; -2, 2, 3+4i]) == [4, 2, 3+4i])); |
24abf5a702d9
Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
818 |
24abf5a702d9
Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
819 %% test/octave.test/arith/max-3.m |
24abf5a702d9
Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
820 %!error <Invalid call to max.*> max (); |
24abf5a702d9
Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
821 |
24abf5a702d9
Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
822 %% test/octave.test/arith/max-4.m |
24abf5a702d9
Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
823 %!error <Invalid call to max.*> max (1, 2, 3, 4); |
24abf5a702d9
Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
824 |
24abf5a702d9
Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
825 %!test |
24abf5a702d9
Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
826 %! x = reshape (1:8,[2,2,2]); |
24abf5a702d9
Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
827 %! assert (min (x,[],1), reshape ([1, 3, 5, 7], [1,2,2])); |
24abf5a702d9
Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
828 %! assert (min (x,[],2), reshape ([1, 2, 5, 6], [2,1,2])); |
24abf5a702d9
Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
829 %! [y, i ] = min (x, [], 3); |
24abf5a702d9
Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
830 %! assert (y, [1, 3; 2, 4]); |
24abf5a702d9
Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
831 %! assert (ndims(y), 2); |
24abf5a702d9
Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
832 %! assert (i, [1, 1; 1, 1]); |
24abf5a702d9
Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
833 %! assert (ndims(i), 2); |
24abf5a702d9
Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
834 |
24abf5a702d9
Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
835 |
24abf5a702d9
Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
836 */ |
24abf5a702d9
Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
837 |
8777
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7919
diff
changeset
|
838 #define CUMMINMAX_BODY(FCN) \ |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7919
diff
changeset
|
839 \ |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7919
diff
changeset
|
840 octave_value_list retval; \ |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7919
diff
changeset
|
841 \ |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7919
diff
changeset
|
842 int nargin = args.length (); \ |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7919
diff
changeset
|
843 \ |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7919
diff
changeset
|
844 if (nargin < 1 || nargin > 2 || nargout > 2) \ |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7919
diff
changeset
|
845 { \ |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7919
diff
changeset
|
846 print_usage (); \ |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7919
diff
changeset
|
847 return retval; \ |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7919
diff
changeset
|
848 } \ |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7919
diff
changeset
|
849 \ |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7919
diff
changeset
|
850 octave_value arg1; \ |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7919
diff
changeset
|
851 octave_value arg2; \ |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7919
diff
changeset
|
852 \ |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7919
diff
changeset
|
853 switch (nargin) \ |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7919
diff
changeset
|
854 { \ |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7919
diff
changeset
|
855 case 2: \ |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7919
diff
changeset
|
856 arg2 = args(1); \ |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7919
diff
changeset
|
857 \ |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7919
diff
changeset
|
858 case 1: \ |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7919
diff
changeset
|
859 arg1 = args(0); \ |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7919
diff
changeset
|
860 break; \ |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7919
diff
changeset
|
861 \ |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7919
diff
changeset
|
862 default: \ |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7919
diff
changeset
|
863 panic_impossible (); \ |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7919
diff
changeset
|
864 break; \ |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7919
diff
changeset
|
865 } \ |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7919
diff
changeset
|
866 \ |
8949
e31d47f2c9bb
fixes to row-reducing cummin/cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
8948
diff
changeset
|
867 int dim; \ |
8777
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7919
diff
changeset
|
868 dim_vector dv = arg1.dims (); \ |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7919
diff
changeset
|
869 if (error_state) \ |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7919
diff
changeset
|
870 { \ |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7919
diff
changeset
|
871 gripe_wrong_type_arg (#FCN, arg1); \ |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7919
diff
changeset
|
872 return retval; \ |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7919
diff
changeset
|
873 } \ |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7919
diff
changeset
|
874 \ |
8949
e31d47f2c9bb
fixes to row-reducing cummin/cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
8948
diff
changeset
|
875 if (nargin == 2) \ |
e31d47f2c9bb
fixes to row-reducing cummin/cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
8948
diff
changeset
|
876 { \ |
e31d47f2c9bb
fixes to row-reducing cummin/cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
8948
diff
changeset
|
877 dim = arg2.nint_value () - 1; \ |
e31d47f2c9bb
fixes to row-reducing cummin/cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
8948
diff
changeset
|
878 if (dim < 0 || dim >= dv.length ()) \ |
e31d47f2c9bb
fixes to row-reducing cummin/cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
8948
diff
changeset
|
879 { \ |
e31d47f2c9bb
fixes to row-reducing cummin/cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
8948
diff
changeset
|
880 error ("%s: invalid dimension", #FCN); \ |
e31d47f2c9bb
fixes to row-reducing cummin/cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
8948
diff
changeset
|
881 return retval; \ |
e31d47f2c9bb
fixes to row-reducing cummin/cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
8948
diff
changeset
|
882 } \ |
e31d47f2c9bb
fixes to row-reducing cummin/cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
8948
diff
changeset
|
883 } \ |
e31d47f2c9bb
fixes to row-reducing cummin/cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
8948
diff
changeset
|
884 else \ |
e31d47f2c9bb
fixes to row-reducing cummin/cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
8948
diff
changeset
|
885 { \ |
e31d47f2c9bb
fixes to row-reducing cummin/cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
8948
diff
changeset
|
886 dim = 0; \ |
e31d47f2c9bb
fixes to row-reducing cummin/cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
8948
diff
changeset
|
887 while ((dim < dv.length ()) && (dv (dim) <= 1)) \ |
e31d47f2c9bb
fixes to row-reducing cummin/cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
8948
diff
changeset
|
888 dim++; \ |
e31d47f2c9bb
fixes to row-reducing cummin/cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
8948
diff
changeset
|
889 if (dim == dv.length ()) \ |
e31d47f2c9bb
fixes to row-reducing cummin/cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
8948
diff
changeset
|
890 dim = 0; \ |
e31d47f2c9bb
fixes to row-reducing cummin/cummax
Jaroslav Hajek <highegg@gmail.com>
parents:
8948
diff
changeset
|
891 } \ |
8777
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7919
diff
changeset
|
892 \ |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7919
diff
changeset
|
893 if (arg1.is_integer_type ()) \ |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7919
diff
changeset
|
894 { \ |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7919
diff
changeset
|
895 if (arg1.is_uint8_type ()) \ |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7919
diff
changeset
|
896 MINMAX_INT_SBODY (FCN, uint8) \ |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7919
diff
changeset
|
897 else if (arg1.is_uint16_type ()) \ |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7919
diff
changeset
|
898 MINMAX_INT_SBODY (FCN, uint16) \ |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7919
diff
changeset
|
899 else if (arg1.is_uint32_type ()) \ |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7919
diff
changeset
|
900 MINMAX_INT_SBODY (FCN, uint32) \ |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7919
diff
changeset
|
901 else if (arg1.is_uint64_type ()) \ |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7919
diff
changeset
|
902 MINMAX_INT_SBODY (FCN, uint64) \ |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7919
diff
changeset
|
903 else if (arg1.is_int8_type ()) \ |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7919
diff
changeset
|
904 MINMAX_INT_SBODY (FCN, int8) \ |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7919
diff
changeset
|
905 else if (arg1.is_int16_type ()) \ |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7919
diff
changeset
|
906 MINMAX_INT_SBODY (FCN, int16) \ |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7919
diff
changeset
|
907 else if (arg1.is_int32_type ()) \ |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7919
diff
changeset
|
908 MINMAX_INT_SBODY (FCN, int32) \ |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7919
diff
changeset
|
909 else if (arg1.is_int64_type ()) \ |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7919
diff
changeset
|
910 MINMAX_INT_SBODY (FCN, int64) \ |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7919
diff
changeset
|
911 } \ |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7919
diff
changeset
|
912 else if (arg1.is_single_type ()) \ |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7919
diff
changeset
|
913 MINMAX_SINGLE_SBODY (FCN) \ |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7919
diff
changeset
|
914 else \ |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7919
diff
changeset
|
915 MINMAX_DOUBLE_SBODY (FCN) \ |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7919
diff
changeset
|
916 \ |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7919
diff
changeset
|
917 return retval; |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7919
diff
changeset
|
918 |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7919
diff
changeset
|
919 DEFUN_DLD (cummin, args, nargout, |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7919
diff
changeset
|
920 "-*- texinfo -*-\n\ |
9141
c1fff751b5a8
Update section 17.1 (Utility Functions) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents:
9086
diff
changeset
|
921 @deftypefn {Loadable Function} {} cummin (@var{x})\n\ |
c1fff751b5a8
Update section 17.1 (Utility Functions) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents:
9086
diff
changeset
|
922 @deftypefnx {Loadable Function} {} cummin (@var{x}, @var{dim})\n\ |
8780
ea76466605ba
support native cumsum, gripe on overflow in sum/cumsum
Jaroslav Hajek <highegg@gmail.com>
parents:
8778
diff
changeset
|
923 @deftypefnx {Loadable Function} {[@var{w}, @var{iw}] =} cummin (@var{x})\n\ |
9141
c1fff751b5a8
Update section 17.1 (Utility Functions) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents:
9086
diff
changeset
|
924 Return the cumulative minimum values along dimension @var{dim}. If @var{dim}\n\ |
c1fff751b5a8
Update section 17.1 (Utility Functions) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents:
9086
diff
changeset
|
925 is unspecified it defaults to column-wise operation. For example,\n\ |
c1fff751b5a8
Update section 17.1 (Utility Functions) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents:
9086
diff
changeset
|
926 \n\ |
c1fff751b5a8
Update section 17.1 (Utility Functions) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents:
9086
diff
changeset
|
927 @example\n\ |
c1fff751b5a8
Update section 17.1 (Utility Functions) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents:
9086
diff
changeset
|
928 @group\n\ |
c1fff751b5a8
Update section 17.1 (Utility Functions) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents:
9086
diff
changeset
|
929 cummin ([5 4 6 2 3 1])\n\ |
c1fff751b5a8
Update section 17.1 (Utility Functions) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents:
9086
diff
changeset
|
930 @result{} 5 4 4 2 2 1\n\ |
c1fff751b5a8
Update section 17.1 (Utility Functions) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents:
9086
diff
changeset
|
931 @end group\n\ |
c1fff751b5a8
Update section 17.1 (Utility Functions) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents:
9086
diff
changeset
|
932 @end example\n\ |
c1fff751b5a8
Update section 17.1 (Utility Functions) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents:
9086
diff
changeset
|
933 \n\ |
c1fff751b5a8
Update section 17.1 (Utility Functions) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents:
9086
diff
changeset
|
934 \n\ |
c1fff751b5a8
Update section 17.1 (Utility Functions) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents:
9086
diff
changeset
|
935 The call\n\ |
8777
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7919
diff
changeset
|
936 @example\n\ |
8948
3e161cae0bc6
update cummin, cummax docs
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
937 [w, iw] = cummin (x, dim)\n\ |
8777
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7919
diff
changeset
|
938 @end example\n\ |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7919
diff
changeset
|
939 \n\ |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7919
diff
changeset
|
940 @noindent\n\ |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7919
diff
changeset
|
941 is equivalent to the following code:\n\ |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7919
diff
changeset
|
942 @example\n\ |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
8949
diff
changeset
|
943 @group\n\ |
9141
c1fff751b5a8
Update section 17.1 (Utility Functions) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents:
9086
diff
changeset
|
944 w = iw = zeros (size (x));\n\ |
c1fff751b5a8
Update section 17.1 (Utility Functions) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents:
9086
diff
changeset
|
945 idxw = idxx = repmat (@{':'@}, 1, ndims (x));\n\ |
c1fff751b5a8
Update section 17.1 (Utility Functions) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents:
9086
diff
changeset
|
946 for i = 1:size (x, dim)\n\ |
c1fff751b5a8
Update section 17.1 (Utility Functions) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents:
9086
diff
changeset
|
947 idxw@{dim@} = i; idxx@{dim@} = 1:i;\n\ |
c1fff751b5a8
Update section 17.1 (Utility Functions) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents:
9086
diff
changeset
|
948 [w(idxw@{:@}), iw(idxw@{:@})] = min(x(idxx@{:@}), [], dim);\n\ |
c1fff751b5a8
Update section 17.1 (Utility Functions) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents:
9086
diff
changeset
|
949 endfor\n\ |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
8949
diff
changeset
|
950 @end group\n\ |
8777
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7919
diff
changeset
|
951 @end example\n\ |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7919
diff
changeset
|
952 \n\ |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7919
diff
changeset
|
953 @noindent\n\ |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7919
diff
changeset
|
954 but computed in a much faster manner.\n\ |
9141
c1fff751b5a8
Update section 17.1 (Utility Functions) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents:
9086
diff
changeset
|
955 @seealso{cummax, min, max}\n\ |
8777
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7919
diff
changeset
|
956 @end deftypefn") |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7919
diff
changeset
|
957 { |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7919
diff
changeset
|
958 CUMMINMAX_BODY (cummin); |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7919
diff
changeset
|
959 } |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7919
diff
changeset
|
960 |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7919
diff
changeset
|
961 DEFUN_DLD (cummax, args, nargout, |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7919
diff
changeset
|
962 "-*- texinfo -*-\n\ |
9141
c1fff751b5a8
Update section 17.1 (Utility Functions) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents:
9086
diff
changeset
|
963 @deftypefn {Loadable Function} {} cummax (@var{x})\n\ |
c1fff751b5a8
Update section 17.1 (Utility Functions) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents:
9086
diff
changeset
|
964 @deftypefnx {Loadable Function} {} cummax (@var{x}, @var{dim})\n\ |
8780
ea76466605ba
support native cumsum, gripe on overflow in sum/cumsum
Jaroslav Hajek <highegg@gmail.com>
parents:
8778
diff
changeset
|
965 @deftypefnx {Loadable Function} {[@var{w}, @var{iw}] =} cummax (@var{x})\n\ |
9141
c1fff751b5a8
Update section 17.1 (Utility Functions) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents:
9086
diff
changeset
|
966 Return the cumulative maximum values along dimension @var{dim}. If @var{dim}\n\ |
c1fff751b5a8
Update section 17.1 (Utility Functions) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents:
9086
diff
changeset
|
967 is unspecified it defaults to column-wise operation. For example,\n\ |
c1fff751b5a8
Update section 17.1 (Utility Functions) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents:
9086
diff
changeset
|
968 \n\ |
8777
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7919
diff
changeset
|
969 @example\n\ |
9141
c1fff751b5a8
Update section 17.1 (Utility Functions) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents:
9086
diff
changeset
|
970 @group\n\ |
c1fff751b5a8
Update section 17.1 (Utility Functions) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents:
9086
diff
changeset
|
971 cummax ([1 3 2 6 4 5])\n\ |
c1fff751b5a8
Update section 17.1 (Utility Functions) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents:
9086
diff
changeset
|
972 @result{} 1 3 3 6 6 6\n\ |
c1fff751b5a8
Update section 17.1 (Utility Functions) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents:
9086
diff
changeset
|
973 @end group\n\ |
c1fff751b5a8
Update section 17.1 (Utility Functions) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents:
9086
diff
changeset
|
974 @end example\n\ |
c1fff751b5a8
Update section 17.1 (Utility Functions) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents:
9086
diff
changeset
|
975 \n\ |
c1fff751b5a8
Update section 17.1 (Utility Functions) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents:
9086
diff
changeset
|
976 The call\n\ |
c1fff751b5a8
Update section 17.1 (Utility Functions) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents:
9086
diff
changeset
|
977 @example\n\ |
c1fff751b5a8
Update section 17.1 (Utility Functions) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents:
9086
diff
changeset
|
978 [w, iw] = cummax (x, dim)\n\ |
8777
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7919
diff
changeset
|
979 @end example\n\ |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7919
diff
changeset
|
980 \n\ |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7919
diff
changeset
|
981 @noindent\n\ |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7919
diff
changeset
|
982 is equivalent to the following code:\n\ |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7919
diff
changeset
|
983 @example\n\ |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
8949
diff
changeset
|
984 @group\n\ |
9141
c1fff751b5a8
Update section 17.1 (Utility Functions) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents:
9086
diff
changeset
|
985 w = iw = zeros (size (x));\n\ |
c1fff751b5a8
Update section 17.1 (Utility Functions) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents:
9086
diff
changeset
|
986 idxw = idxx = repmat (@{':'@}, 1, ndims (x));\n\ |
c1fff751b5a8
Update section 17.1 (Utility Functions) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents:
9086
diff
changeset
|
987 for i = 1:size (x, dim)\n\ |
c1fff751b5a8
Update section 17.1 (Utility Functions) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents:
9086
diff
changeset
|
988 idxw@{dim@} = i; idxx@{dim@} = 1:i;\n\ |
c1fff751b5a8
Update section 17.1 (Utility Functions) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents:
9086
diff
changeset
|
989 [w(idxw@{:@}), iw(idxw@{:@})] = max(x(idxx@{:@}), [], dim);\n\ |
c1fff751b5a8
Update section 17.1 (Utility Functions) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents:
9086
diff
changeset
|
990 endfor\n\ |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
8949
diff
changeset
|
991 @end group\n\ |
8777
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7919
diff
changeset
|
992 @end example\n\ |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7919
diff
changeset
|
993 \n\ |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7919
diff
changeset
|
994 @noindent\n\ |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7919
diff
changeset
|
995 but computed in a much faster manner.\n\ |
9141
c1fff751b5a8
Update section 17.1 (Utility Functions) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents:
9086
diff
changeset
|
996 @seealso{cummin, max, min}\n\ |
8777
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7919
diff
changeset
|
997 @end deftypefn") |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7919
diff
changeset
|
998 { |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7919
diff
changeset
|
999 CUMMINMAX_BODY (cummax); |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7919
diff
changeset
|
1000 } |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7919
diff
changeset
|
1001 |
2928 | 1002 /* |
1003 ;;; Local Variables: *** | |
1004 ;;; mode: C++ *** | |
1005 ;;; End: *** | |
1006 */ |