Mercurial > octave
annotate src/DLD-FUNCTIONS/max.cc @ 7789:82be108cc558
First attempt at single precision tyeps
* * *
corrections to qrupdate single precision routines
* * *
prefer demotion to single over promotion to double
* * *
Add single precision support to log2 function
* * *
Trivial PROJECT file update
* * *
Cache optimized hermitian/transpose methods
* * *
Add tests for tranpose/hermitian and ChangeLog entry for new transpose code
author | David Bateman <dbateman@free.fr> |
---|---|
date | Sun, 27 Apr 2008 22:34:17 +0200 |
parents | a168157f08ee |
children | 9d080df0c843 |
rev | line source |
---|---|
2928 | 1 /* |
2 | |
7017 | 3 Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, |
4 2005, 2006, 2007 John W. Eaton | |
2928 | 5 |
6 This file is part of Octave. | |
7 | |
8 Octave is free software; you can redistribute it and/or modify it | |
9 under the terms of the GNU General Public License as published by the | |
7016 | 10 Free Software Foundation; either version 3 of the License, or (at your |
11 option) any later version. | |
2928 | 12 |
13 Octave is distributed in the hope that it will be useful, but WITHOUT | |
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
16 for more details. | |
17 | |
18 You should have received a copy of the GNU General Public License | |
7016 | 19 along with Octave; see the file COPYING. If not, see |
20 <http://www.gnu.org/licenses/>. | |
2928 | 21 |
22 */ | |
23 | |
24 #ifdef HAVE_CONFIG_H | |
25 #include <config.h> | |
26 #endif | |
27 | |
28 #include "lo-ieee.h" | |
3248 | 29 #include "lo-mappers.h" |
7231 | 30 #include "lo-math.h" |
4844 | 31 #include "dNDArray.h" |
32 #include "CNDArray.h" | |
4153 | 33 #include "quit.h" |
2928 | 34 |
35 #include "defun-dld.h" | |
36 #include "error.h" | |
37 #include "gripes.h" | |
38 #include "oct-obj.h" | |
39 | |
4844 | 40 #include "ov-cx-mat.h" |
7505
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
41 #include "ov-re-sparse.h" |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
42 #include "ov-cx-sparse.h" |
4844 | 43 |
7189 | 44 #define MINMAX_DOUBLE_BODY(FCN) \ |
45 { \ | |
6711 | 46 bool single_arg = (nargin == 1) || (arg2.is_empty() && nargin == 3); \ |
4844 | 47 \ |
48 if (single_arg && (nargout == 1 || nargout == 0)) \ | |
3747 | 49 { \ |
50 if (arg1.is_real_type ()) \ | |
51 { \ | |
4844 | 52 NDArray m = arg1.array_value (); \ |
3747 | 53 \ |
54 if (! error_state) \ | |
55 { \ | |
4844 | 56 NDArray n = m. FCN (dim); \ |
57 retval(0) = n; \ | |
3747 | 58 } \ |
59 } \ | |
60 else if (arg1.is_complex_type ()) \ | |
61 { \ | |
4844 | 62 ComplexNDArray m = arg1.complex_array_value (); \ |
3747 | 63 \ |
64 if (! error_state) \ | |
65 { \ | |
4844 | 66 ComplexNDArray n = m. FCN (dim); \ |
67 retval(0) = n; \ | |
3747 | 68 } \ |
69 } \ | |
70 else \ | |
71 gripe_wrong_type_arg (#FCN, arg1); \ | |
72 } \ | |
4844 | 73 else if (single_arg && nargout == 2) \ |
3747 | 74 { \ |
5275 | 75 ArrayN<octave_idx_type> index; \ |
3747 | 76 \ |
77 if (arg1.is_real_type ()) \ | |
78 { \ | |
4844 | 79 NDArray m = arg1.array_value (); \ |
3747 | 80 \ |
81 if (! error_state) \ | |
82 { \ | |
4844 | 83 NDArray n = m. FCN (index, dim); \ |
84 retval(0) = n; \ | |
3747 | 85 } \ |
86 } \ | |
87 else if (arg1.is_complex_type ()) \ | |
88 { \ | |
4844 | 89 ComplexNDArray m = arg1.complex_array_value (); \ |
3747 | 90 \ |
91 if (! error_state) \ | |
92 { \ | |
4844 | 93 ComplexNDArray n = m. FCN (index, dim); \ |
94 retval(0) = n; \ | |
3747 | 95 } \ |
96 } \ | |
97 else \ | |
98 gripe_wrong_type_arg (#FCN, arg1); \ | |
99 \ | |
5275 | 100 octave_idx_type len = index.numel (); \ |
3747 | 101 \ |
102 if (len > 0) \ | |
103 { \ | |
4102 | 104 double nan_val = lo_ieee_nan_value (); \ |
105 \ | |
4844 | 106 NDArray idx (index.dims ()); \ |
3747 | 107 \ |
5275 | 108 for (octave_idx_type i = 0; i < len; i++) \ |
3747 | 109 { \ |
4153 | 110 OCTAVE_QUIT; \ |
7600
24abf5a702d9
Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
111 octave_idx_type tmp = index.elem (i) + 1; \ |
3747 | 112 idx.elem (i) = (tmp <= 0) \ |
4102 | 113 ? nan_val : static_cast<double> (tmp); \ |
3747 | 114 } \ |
115 \ | |
116 retval(1) = idx; \ | |
117 } \ | |
118 else \ | |
4844 | 119 retval(1) = NDArray (); \ |
3747 | 120 } \ |
4844 | 121 else \ |
3747 | 122 { \ |
123 int arg1_is_scalar = arg1.is_scalar_type (); \ | |
124 int arg2_is_scalar = arg2.is_scalar_type (); \ | |
125 \ | |
126 int arg1_is_complex = arg1.is_complex_type (); \ | |
127 int arg2_is_complex = arg2.is_complex_type (); \ | |
128 \ | |
129 if (arg1_is_scalar) \ | |
130 { \ | |
131 if (arg1_is_complex || arg2_is_complex) \ | |
132 { \ | |
133 Complex c1 = arg1.complex_value (); \ | |
4844 | 134 ComplexNDArray m2 = arg2.complex_array_value (); \ |
3747 | 135 if (! error_state) \ |
136 { \ | |
4844 | 137 ComplexNDArray result = FCN (c1, m2); \ |
3747 | 138 if (! error_state) \ |
139 retval(0) = result; \ | |
140 } \ | |
141 } \ | |
142 else \ | |
143 { \ | |
144 double d1 = arg1.double_value (); \ | |
4844 | 145 NDArray m2 = arg2.array_value (); \ |
3747 | 146 \ |
147 if (! error_state) \ | |
148 { \ | |
4844 | 149 NDArray result = FCN (d1, m2); \ |
3747 | 150 if (! error_state) \ |
151 retval(0) = result; \ | |
152 } \ | |
153 } \ | |
154 } \ | |
155 else if (arg2_is_scalar) \ | |
156 { \ | |
157 if (arg1_is_complex || arg2_is_complex) \ | |
158 { \ | |
4844 | 159 ComplexNDArray m1 = arg1.complex_array_value (); \ |
3747 | 160 \ |
161 if (! error_state) \ | |
162 { \ | |
163 Complex c2 = arg2.complex_value (); \ | |
4844 | 164 ComplexNDArray result = FCN (m1, c2); \ |
3747 | 165 if (! error_state) \ |
166 retval(0) = result; \ | |
167 } \ | |
168 } \ | |
169 else \ | |
170 { \ | |
4844 | 171 NDArray m1 = arg1.array_value (); \ |
3747 | 172 \ |
173 if (! error_state) \ | |
174 { \ | |
175 double d2 = arg2.double_value (); \ | |
4844 | 176 NDArray result = FCN (m1, d2); \ |
3747 | 177 if (! error_state) \ |
178 retval(0) = result; \ | |
179 } \ | |
180 } \ | |
181 } \ | |
182 else \ | |
183 { \ | |
184 if (arg1_is_complex || arg2_is_complex) \ | |
185 { \ | |
4844 | 186 ComplexNDArray m1 = arg1.complex_array_value (); \ |
3747 | 187 \ |
188 if (! error_state) \ | |
189 { \ | |
4844 | 190 ComplexNDArray m2 = arg2.complex_array_value (); \ |
3747 | 191 \ |
192 if (! error_state) \ | |
193 { \ | |
4844 | 194 ComplexNDArray result = FCN (m1, m2); \ |
3747 | 195 if (! error_state) \ |
196 retval(0) = result; \ | |
197 } \ | |
198 } \ | |
199 } \ | |
200 else \ | |
201 { \ | |
4844 | 202 NDArray m1 = arg1.array_value (); \ |
3747 | 203 \ |
204 if (! error_state) \ | |
205 { \ | |
4844 | 206 NDArray m2 = arg2.array_value (); \ |
3747 | 207 \ |
208 if (! error_state) \ | |
209 { \ | |
4844 | 210 NDArray result = FCN (m1, m2); \ |
3747 | 211 if (! error_state) \ |
212 retval(0) = result; \ | |
213 } \ | |
214 } \ | |
215 } \ | |
216 } \ | |
217 } \ | |
7189 | 218 } |
219 | |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
220 #define MINMAX_SINGLE_BODY(FCN) \ |
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 bool single_arg = (nargin == 1) || (arg2.is_empty() && nargin == 3); \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
223 \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
224 if (single_arg && (nargout == 1 || nargout == 0)) \ |
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 if (arg1.is_real_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 FloatNDArray m = arg1.float_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 FloatNDArray 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 if (arg1.is_complex_type ()) \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
237 { \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
238 FloatComplexNDArray m = arg1.float_complex_array_value (); \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
239 \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
240 if (! error_state) \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
241 { \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
242 FloatComplexNDArray n = m. FCN (dim); \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
243 retval(0) = n; \ |
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 } \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
246 else \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
247 gripe_wrong_type_arg (#FCN, arg1); \ |
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 else if (single_arg && nargout == 2) \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
250 { \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
251 ArrayN<octave_idx_type> index; \ |
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 if (arg1.is_real_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 FloatNDArray m = arg1.float_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 FloatNDArray 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 if (arg1.is_complex_type ()) \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
264 { \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
265 FloatComplexNDArray m = arg1.float_complex_array_value (); \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
266 \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
267 if (! error_state) \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
268 { \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
269 FloatComplexNDArray n = m. FCN (index, dim); \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
270 retval(0) = n; \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
271 } \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
272 } \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
273 else \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
274 gripe_wrong_type_arg (#FCN, arg1); \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
275 \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
276 octave_idx_type len = index.numel (); \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
277 \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
278 if (len > 0) \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
279 { \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
280 float nan_val = lo_ieee_nan_value (); \ |
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 FloatNDArray idx (index.dims ()); \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
283 \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
284 for (octave_idx_type i = 0; i < len; i++) \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
285 { \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
286 OCTAVE_QUIT; \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
287 octave_idx_type tmp = index.elem (i) + 1; \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
288 idx.elem (i) = (tmp <= 0) \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
289 ? nan_val : static_cast<float> (tmp); \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
290 } \ |
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 retval(1) = idx; \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
293 } \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
294 else \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
295 retval(1) = FloatNDArray (); \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
296 } \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
297 else \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
298 { \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
299 int arg1_is_scalar = arg1.is_scalar_type (); \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
300 int arg2_is_scalar = arg2.is_scalar_type (); \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
301 \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
302 int arg1_is_complex = arg1.is_complex_type (); \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
303 int arg2_is_complex = arg2.is_complex_type (); \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
304 \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
305 if (arg1_is_scalar) \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
306 { \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
307 if (arg1_is_complex || arg2_is_complex) \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
308 { \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
309 FloatComplex c1 = arg1.float_complex_value (); \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
310 FloatComplexNDArray m2 = arg2.float_complex_array_value (); \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
311 if (! error_state) \ |
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 FloatComplexNDArray result = FCN (c1, m2); \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
314 if (! error_state) \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
315 retval(0) = result; \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
316 } \ |
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 else \ |
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 float d1 = arg1.float_value (); \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
321 FloatNDArray m2 = arg2.float_array_value (); \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
322 \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
323 if (! error_state) \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
324 { \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
325 FloatNDArray result = FCN (d1, m2); \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
326 if (! error_state) \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
327 retval(0) = result; \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
328 } \ |
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 } \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
331 else if (arg2_is_scalar) \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
332 { \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
333 if (arg1_is_complex || arg2_is_complex) \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
334 { \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
335 FloatComplexNDArray m1 = arg1.float_complex_array_value (); \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
336 \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
337 if (! error_state) \ |
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 FloatComplex c2 = arg2.float_complex_value (); \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
340 FloatComplexNDArray result = FCN (m1, c2); \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
341 if (! error_state) \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
342 retval(0) = result; \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
343 } \ |
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 else \ |
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 FloatNDArray m1 = arg1.float_array_value (); \ |
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 if (! error_state) \ |
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 float d2 = arg2.float_value (); \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
352 FloatNDArray result = FCN (m1, d2); \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
353 if (! error_state) \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
354 retval(0) = result; \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
355 } \ |
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 else \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
359 { \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
360 if (arg1_is_complex || arg2_is_complex) \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
361 { \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
362 FloatComplexNDArray m1 = arg1.float_complex_array_value (); \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
363 \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
364 if (! error_state) \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
365 { \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
366 FloatComplexNDArray m2 = arg2.float_complex_array_value (); \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
367 \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
368 if (! error_state) \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
369 { \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
370 FloatComplexNDArray result = FCN (m1, m2); \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
371 if (! error_state) \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
372 retval(0) = result; \ |
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 else \ |
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 FloatNDArray m1 = arg1.float_array_value (); \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
379 \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
380 if (! error_state) \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
381 { \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
382 FloatNDArray m2 = arg2.float_array_value (); \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
383 \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
384 if (! error_state) \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
385 { \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
386 FloatNDArray result = FCN (m1, m2); \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
387 if (! error_state) \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
388 retval(0) = result; \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
389 } \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
390 } \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
391 } \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
392 } \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
393 } \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
394 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
395 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
396 |
7189 | 397 #define MINMAX_INT_BODY(FCN, TYP) \ |
398 { \ | |
399 bool single_arg = (nargin == 1) || (arg2.is_empty() && nargin == 3); \ | |
3747 | 400 \ |
7189 | 401 if (single_arg && (nargout == 1 || nargout == 0)) \ |
402 { \ | |
403 TYP ## NDArray m = arg1. TYP ## _array_value (); \ | |
404 \ | |
405 if (! error_state) \ | |
406 { \ | |
407 TYP ## NDArray n = m. FCN (dim); \ | |
408 retval(0) = n; \ | |
409 } \ | |
410 } \ | |
411 else if (single_arg && nargout == 2) \ | |
412 { \ | |
413 ArrayN<octave_idx_type> index; \ | |
414 \ | |
415 TYP ## NDArray m = arg1. TYP ## _array_value (); \ | |
416 \ | |
417 if (! error_state) \ | |
418 { \ | |
419 TYP ## NDArray n = m. FCN (index, dim); \ | |
420 retval(0) = n; \ | |
421 } \ | |
422 \ | |
423 octave_idx_type len = index.numel (); \ | |
424 \ | |
425 if (len > 0) \ | |
426 { \ | |
427 double nan_val = lo_ieee_nan_value (); \ | |
428 \ | |
429 NDArray idx (index.dims ()); \ | |
430 \ | |
431 for (octave_idx_type i = 0; i < len; i++) \ | |
432 { \ | |
433 OCTAVE_QUIT; \ | |
7600
24abf5a702d9
Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
434 octave_idx_type tmp = index.elem (i) + 1; \ |
7189 | 435 idx.elem (i) = (tmp <= 0) \ |
436 ? nan_val : static_cast<double> (tmp); \ | |
437 } \ | |
438 \ | |
439 retval(1) = idx; \ | |
440 } \ | |
441 else \ | |
442 retval(1) = NDArray (); \ | |
443 } \ | |
444 else \ | |
445 { \ | |
446 int arg1_is_scalar = arg1.is_scalar_type (); \ | |
447 int arg2_is_scalar = arg2.is_scalar_type (); \ | |
448 \ | |
449 if (arg1_is_scalar) \ | |
450 { \ | |
451 octave_ ## TYP d1 = arg1. TYP ## _scalar_value (); \ | |
452 TYP ## NDArray m2 = arg2. TYP ## _array_value (); \ | |
453 \ | |
454 if (! error_state) \ | |
455 { \ | |
456 TYP ## NDArray result = FCN (d1, m2); \ | |
457 if (! error_state) \ | |
458 retval(0) = result; \ | |
459 } \ | |
460 } \ | |
461 else if (arg2_is_scalar) \ | |
462 { \ | |
463 TYP ## NDArray m1 = arg1. TYP ## _array_value (); \ | |
464 \ | |
465 if (! error_state) \ | |
466 { \ | |
467 octave_ ## TYP d2 = arg2. TYP ## _scalar_value (); \ | |
468 TYP ## NDArray result = FCN (m1, d2); \ | |
469 if (! error_state) \ | |
470 retval(0) = result; \ | |
471 } \ | |
472 } \ | |
473 else \ | |
474 { \ | |
475 TYP ## NDArray m1 = arg1. TYP ## _array_value (); \ | |
476 \ | |
477 if (! error_state) \ | |
478 { \ | |
479 TYP ## NDArray m2 = arg2. TYP ## _array_value (); \ | |
480 \ | |
481 if (! error_state) \ | |
482 { \ | |
483 TYP ## NDArray result = FCN (m1, m2); \ | |
484 if (! error_state) \ | |
485 retval(0) = result; \ | |
486 } \ | |
487 } \ | |
488 } \ | |
489 } \ | |
490 } | |
491 | |
7505
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
492 #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
|
493 { \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
494 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
|
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 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
|
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 if (arg1.type_id () == octave_sparse_matrix::static_type_id ()) \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
499 retval(0) = arg1.sparse_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
|
500 else if (arg1.type_id () == \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
501 octave_sparse_complex_matrix::static_type_id ()) \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
502 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
|
503 else \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
504 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
|
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 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
|
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 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
|
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 if (arg1.type_id () == octave_sparse_matrix::static_type_id ()) \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
511 retval(0) = arg1.sparse_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
|
512 else if (arg1.type_id () == \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
513 octave_sparse_complex_matrix::static_type_id ()) \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
514 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
|
515 else \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
516 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
|
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 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
|
519 \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
520 if (len > 0) \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
521 { \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
522 double nan_val = lo_ieee_nan_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 NDArray idx (index.dims ()); \ |
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 for (octave_idx_type i = 0; i < len; i++) \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
527 { \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
528 OCTAVE_QUIT; \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
529 octave_idx_type tmp = index.elem (i) + 1; \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
530 idx.elem (i) = (tmp <= 0) \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
531 ? nan_val : static_cast<double> (tmp); \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
532 } \ |
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 retval(1) = idx; \ |
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 else \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
537 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
|
538 } \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
539 else \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
540 { \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
541 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
|
542 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
|
543 \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
544 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
|
545 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
|
546 \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
547 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
|
548 { \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
549 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
|
550 { \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
551 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
|
552 \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
553 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
|
554 \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
555 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
|
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 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
|
558 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
|
559 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
|
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 } \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
562 else \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
563 { \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
564 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
|
565 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
|
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 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
|
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 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
|
570 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
|
571 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
|
572 } \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
573 } \ |
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 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
|
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 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
|
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 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
|
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 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
|
584 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
|
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 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
|
587 } \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
588 } \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
589 else \ |
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 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
|
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 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
|
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 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
|
596 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
|
597 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
|
598 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
|
599 } \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
600 } \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
601 } \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
602 else \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
603 { \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
604 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
|
605 { \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
606 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
|
607 \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
608 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
|
609 { \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
610 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
|
611 \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
612 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
|
613 { \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
614 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
|
615 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
|
616 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
|
617 } \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
618 } \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
619 } \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
620 else \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
621 { \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
622 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
|
623 \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
624 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
|
625 { \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
626 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
|
627 \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
628 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
|
629 { \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
630 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
|
631 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
|
632 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
|
633 } \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
634 } \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
635 } \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
636 } \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
637 } \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
638 } |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
639 |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
640 |
7189 | 641 #define MINMAX_BODY(FCN) \ |
642 \ | |
643 octave_value_list retval; \ | |
644 \ | |
645 int nargin = args.length (); \ | |
646 \ | |
647 if (nargin < 1 || nargin > 3 || nargout > 2) \ | |
648 { \ | |
649 print_usage (); \ | |
650 return retval; \ | |
651 } \ | |
652 \ | |
653 octave_value arg1; \ | |
654 octave_value arg2; \ | |
655 octave_value arg3; \ | |
656 \ | |
657 switch (nargin) \ | |
658 { \ | |
659 case 3: \ | |
660 arg3 = args(2); \ | |
661 \ | |
662 case 2: \ | |
663 arg2 = args(1); \ | |
664 \ | |
665 case 1: \ | |
666 arg1 = args(0); \ | |
667 break; \ | |
668 \ | |
669 default: \ | |
670 panic_impossible (); \ | |
671 break; \ | |
672 } \ | |
673 \ | |
674 int dim; \ | |
675 dim_vector dv = arg1.dims (); \ | |
676 if (error_state) \ | |
677 { \ | |
678 gripe_wrong_type_arg (#FCN, arg1); \ | |
679 return retval; \ | |
680 } \ | |
681 \ | |
682 if (nargin == 3) \ | |
683 { \ | |
684 dim = arg3.nint_value () - 1; \ | |
685 if (dim < 0 || dim >= dv.length ()) \ | |
686 { \ | |
687 error ("%s: invalid dimension", #FCN); \ | |
688 return retval; \ | |
689 } \ | |
690 } \ | |
691 else \ | |
692 { \ | |
693 dim = 0; \ | |
694 while ((dim < dv.length ()) && (dv (dim) <= 1)) \ | |
695 dim++; \ | |
696 if (dim == dv.length ()) \ | |
697 dim = 0; \ | |
698 } \ | |
699 \ | |
700 if (arg1.is_integer_type ()) \ | |
701 { \ | |
702 if (arg1.is_uint8_type ()) \ | |
703 MINMAX_INT_BODY (FCN, uint8) \ | |
704 else if (arg1.is_uint16_type ()) \ | |
705 MINMAX_INT_BODY (FCN, uint16) \ | |
706 else if (arg1.is_uint32_type ()) \ | |
707 MINMAX_INT_BODY (FCN, uint32) \ | |
708 else if (arg1.is_uint64_type ()) \ | |
709 MINMAX_INT_BODY (FCN, uint64) \ | |
710 else if (arg1.is_int8_type ()) \ | |
711 MINMAX_INT_BODY (FCN, int8) \ | |
712 else if (arg1.is_int16_type ()) \ | |
713 MINMAX_INT_BODY (FCN, int16) \ | |
714 else if (arg1.is_int32_type ()) \ | |
715 MINMAX_INT_BODY (FCN, int32) \ | |
716 else if (arg1.is_int64_type ()) \ | |
717 MINMAX_INT_BODY (FCN, int64) \ | |
718 } \ | |
7505
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
719 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
|
720 MINMAX_SPARSE_BODY (FCN) \ |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
721 else if (arg1.is_single_type ()) \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
722 MINMAX_SINGLE_BODY (FCN) \ |
7189 | 723 else \ |
724 MINMAX_DOUBLE_BODY (FCN) \ | |
725 \ | |
726 return retval; | |
3747 | 727 |
2928 | 728 DEFUN_DLD (min, args, nargout, |
3443 | 729 "-*- texinfo -*-\n\ |
4844 | 730 @deftypefn {Mapping Function} {} min (@var{x}, @var{y}, @var{dim})\n\ |
4522 | 731 @deftypefnx {Mapping Function} {[@var{w}, @var{iw}] =} min (@var{x})\n\ |
732 @cindex Utility Functions\n\ | |
3443 | 733 For a vector argument, return the minimum value. For a matrix\n\ |
734 argument, return the minimum value from each column, as a row\n\ | |
4844 | 735 vector, or over the dimension @var{dim} if defined. For two matrices\n\ |
736 (or a matrix and scalar), return the pair-wise minimum.\n\ | |
4522 | 737 Thus,\n\ |
3443 | 738 \n\ |
739 @example\n\ | |
740 min (min (@var{x}))\n\ | |
741 @end example\n\ | |
742 \n\ | |
743 @noindent\n\ | |
4522 | 744 returns the smallest element of @var{x}, and\n\ |
745 \n\ | |
746 @example\n\ | |
747 @group\n\ | |
748 min (2:5, pi)\n\ | |
749 @result{} 2.0000 3.0000 3.1416 3.1416\n\ | |
750 @end group\n\ | |
751 @end example\n\ | |
752 @noindent\n\ | |
753 compares each element of the range @code{2:5} with @code{pi}, and\n\ | |
754 returns a row vector of the minimum values.\n\ | |
3443 | 755 \n\ |
756 For complex arguments, the magnitude of the elements are used for\n\ | |
3657 | 757 comparison.\n\ |
758 \n\ | |
4522 | 759 If called with one input and two output arguments,\n\ |
760 @code{min} also returns the first index of the\n\ | |
3657 | 761 minimum value(s). Thus,\n\ |
4522 | 762 \n\ |
3775 | 763 @example\n\ |
4522 | 764 @group\n\ |
3657 | 765 [x, ix] = min ([1, 3, 0, 2, 5])\n\ |
4522 | 766 @result{} x = 0\n\ |
767 ix = 3\n\ | |
768 @end group\n\ | |
3657 | 769 @end example\n\ |
4522 | 770 @end deftypefn") |
2928 | 771 { |
3747 | 772 MINMAX_BODY (min); |
2928 | 773 } |
774 | |
7600
24abf5a702d9
Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
775 /* |
24abf5a702d9
Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
776 |
24abf5a702d9
Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
777 %% test/octave.test/arith/min-1.m |
24abf5a702d9
Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
778 %!assert (min ([1, 4, 2, 3]) == 1); |
24abf5a702d9
Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
779 %!assert (min ([1; -10; 5; -2]) == -10); |
24abf5a702d9
Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
780 |
24abf5a702d9
Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
781 %% test/octave.test/arith/min-2.m |
24abf5a702d9
Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
782 %!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
|
783 |
24abf5a702d9
Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
784 %% test/octave.test/arith/min-3.m |
24abf5a702d9
Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
785 %!error <Invalid call to min.*> min (); |
24abf5a702d9
Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
786 |
24abf5a702d9
Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
787 %% test/octave.test/arith/min-4.m |
24abf5a702d9
Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
788 %!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
|
789 |
24abf5a702d9
Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
790 %!test |
24abf5a702d9
Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
791 %! x = reshape (1:8,[2,2,2]); |
24abf5a702d9
Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
792 %! 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
|
793 %! 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
|
794 %! [y, i ] = max (x, [], 3); |
24abf5a702d9
Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
795 %! assert (y, [5, 7; 6, 8]); |
24abf5a702d9
Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
796 %! assert (ndims(y), 2); |
24abf5a702d9
Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
797 %! assert (i, [2, 2; 2, 2]); |
24abf5a702d9
Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
798 %! assert (ndims(i), 2); |
24abf5a702d9
Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
799 |
24abf5a702d9
Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
800 */ |
24abf5a702d9
Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
801 |
2928 | 802 DEFUN_DLD (max, args, nargout, |
3443 | 803 "-*- texinfo -*-\n\ |
4844 | 804 @deftypefn {Mapping Function} {} max (@var{x}, @var{y}, @var{dim})\n\ |
4522 | 805 @deftypefnx {Mapping Function} {[@var{w}, @var{iw}] =} max (@var{x})\n\ |
806 @cindex Utility Functions\n\ | |
3443 | 807 For a vector argument, return the maximum value. For a matrix\n\ |
808 argument, return the maximum value from each column, as a row\n\ | |
4844 | 809 vector, or over the dimension @var{dim} if defined. For two matrices\n\ |
810 (or a matrix and scalar), return the pair-wise maximum.\n\ | |
4522 | 811 Thus,\n\ |
3443 | 812 \n\ |
813 @example\n\ | |
814 max (max (@var{x}))\n\ | |
815 @end example\n\ | |
816 \n\ | |
817 @noindent\n\ | |
4522 | 818 returns the largest element of @var{x}, and\n\ |
819 \n\ | |
820 @example\n\ | |
821 @group\n\ | |
822 max (2:5, pi)\n\ | |
823 @result{} 3.1416 3.1416 4.0000 5.0000\n\ | |
824 @end group\n\ | |
825 @end example\n\ | |
826 @noindent\n\ | |
827 compares each element of the range @code{2:5} with @code{pi}, and\n\ | |
828 returns a row vector of the maximum values.\n\ | |
3443 | 829 \n\ |
830 For complex arguments, the magnitude of the elements are used for\n\ | |
3775 | 831 comparison.\n\ |
3657 | 832 \n\ |
4522 | 833 If called with one input and two output arguments,\n\ |
834 @code{max} also returns the first index of the\n\ | |
3657 | 835 maximum value(s). Thus,\n\ |
4522 | 836 \n\ |
3775 | 837 @example\n\ |
4522 | 838 @group\n\ |
839 [x, ix] = max ([1, 3, 5, 2, 5])\n\ | |
840 @result{} x = 5\n\ | |
841 ix = 3\n\ | |
842 @end group\n\ | |
3657 | 843 @end example\n\ |
4522 | 844 @end deftypefn") |
2928 | 845 { |
3747 | 846 MINMAX_BODY (max); |
2928 | 847 } |
848 | |
7600
24abf5a702d9
Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
849 /* |
24abf5a702d9
Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
850 |
24abf5a702d9
Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
851 %% test/octave.test/arith/max-1.m |
24abf5a702d9
Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
852 %!assert (max ([1, 4, 2, 3]) == 4); |
24abf5a702d9
Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
853 %!assert (max ([1; -10; 5; -2]) == 5); |
24abf5a702d9
Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
854 |
24abf5a702d9
Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
855 %% test/octave.test/arith/max-2.m |
24abf5a702d9
Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
856 %!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
|
857 |
24abf5a702d9
Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
858 %% test/octave.test/arith/max-3.m |
24abf5a702d9
Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
859 %!error <Invalid call to max.*> max (); |
24abf5a702d9
Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
860 |
24abf5a702d9
Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
861 %% test/octave.test/arith/max-4.m |
24abf5a702d9
Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
862 %!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
|
863 |
24abf5a702d9
Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
864 %!test |
24abf5a702d9
Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
865 %! x = reshape (1:8,[2,2,2]); |
24abf5a702d9
Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
866 %! 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
|
867 %! 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
|
868 %! [y, i ] = min (x, [], 3); |
24abf5a702d9
Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
869 %! assert (y, [1, 3; 2, 4]); |
24abf5a702d9
Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
870 %! assert (ndims(y), 2); |
24abf5a702d9
Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
871 %! assert (i, [1, 1; 1, 1]); |
24abf5a702d9
Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
872 %! assert (ndims(i), 2); |
24abf5a702d9
Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
873 |
24abf5a702d9
Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
874 |
24abf5a702d9
Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
875 */ |
24abf5a702d9
Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
876 |
2928 | 877 /* |
878 ;;; Local Variables: *** | |
879 ;;; mode: C++ *** | |
880 ;;; End: *** | |
881 */ |