Mercurial > octave
annotate src/DLD-FUNCTIONS/max.cc @ 7919:9d080df0c843
new NDArray constructor for ArrayN<octave_idx_type>
author | David Bateman <dbateman@free.fr> |
---|---|
date | Mon, 30 Jun 2008 15:51:31 +0200 |
parents | 82be108cc558 |
children | 724c0f46d9d4 |
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) \ | |
7919
9d080df0c843
new NDArray constructor for ArrayN<octave_idx_type>
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
103 retval(1) = NDArray (index, true, true); \ |
3747 | 104 else \ |
4844 | 105 retval(1) = NDArray (); \ |
3747 | 106 } \ |
4844 | 107 else \ |
3747 | 108 { \ |
109 int arg1_is_scalar = arg1.is_scalar_type (); \ | |
110 int arg2_is_scalar = arg2.is_scalar_type (); \ | |
111 \ | |
112 int arg1_is_complex = arg1.is_complex_type (); \ | |
113 int arg2_is_complex = arg2.is_complex_type (); \ | |
114 \ | |
115 if (arg1_is_scalar) \ | |
116 { \ | |
117 if (arg1_is_complex || arg2_is_complex) \ | |
118 { \ | |
119 Complex c1 = arg1.complex_value (); \ | |
4844 | 120 ComplexNDArray m2 = arg2.complex_array_value (); \ |
3747 | 121 if (! error_state) \ |
122 { \ | |
4844 | 123 ComplexNDArray result = FCN (c1, m2); \ |
3747 | 124 if (! error_state) \ |
125 retval(0) = result; \ | |
126 } \ | |
127 } \ | |
128 else \ | |
129 { \ | |
130 double d1 = arg1.double_value (); \ | |
4844 | 131 NDArray m2 = arg2.array_value (); \ |
3747 | 132 \ |
133 if (! error_state) \ | |
134 { \ | |
4844 | 135 NDArray result = FCN (d1, m2); \ |
3747 | 136 if (! error_state) \ |
137 retval(0) = result; \ | |
138 } \ | |
139 } \ | |
140 } \ | |
141 else if (arg2_is_scalar) \ | |
142 { \ | |
143 if (arg1_is_complex || arg2_is_complex) \ | |
144 { \ | |
4844 | 145 ComplexNDArray m1 = arg1.complex_array_value (); \ |
3747 | 146 \ |
147 if (! error_state) \ | |
148 { \ | |
149 Complex c2 = arg2.complex_value (); \ | |
4844 | 150 ComplexNDArray result = FCN (m1, c2); \ |
3747 | 151 if (! error_state) \ |
152 retval(0) = result; \ | |
153 } \ | |
154 } \ | |
155 else \ | |
156 { \ | |
4844 | 157 NDArray m1 = arg1.array_value (); \ |
3747 | 158 \ |
159 if (! error_state) \ | |
160 { \ | |
161 double d2 = arg2.double_value (); \ | |
4844 | 162 NDArray result = FCN (m1, d2); \ |
3747 | 163 if (! error_state) \ |
164 retval(0) = result; \ | |
165 } \ | |
166 } \ | |
167 } \ | |
168 else \ | |
169 { \ | |
170 if (arg1_is_complex || arg2_is_complex) \ | |
171 { \ | |
4844 | 172 ComplexNDArray m1 = arg1.complex_array_value (); \ |
3747 | 173 \ |
174 if (! error_state) \ | |
175 { \ | |
4844 | 176 ComplexNDArray m2 = arg2.complex_array_value (); \ |
3747 | 177 \ |
178 if (! error_state) \ | |
179 { \ | |
4844 | 180 ComplexNDArray result = FCN (m1, m2); \ |
3747 | 181 if (! error_state) \ |
182 retval(0) = result; \ | |
183 } \ | |
184 } \ | |
185 } \ | |
186 else \ | |
187 { \ | |
4844 | 188 NDArray m1 = arg1.array_value (); \ |
3747 | 189 \ |
190 if (! error_state) \ | |
191 { \ | |
4844 | 192 NDArray m2 = arg2.array_value (); \ |
3747 | 193 \ |
194 if (! error_state) \ | |
195 { \ | |
4844 | 196 NDArray result = FCN (m1, m2); \ |
3747 | 197 if (! error_state) \ |
198 retval(0) = result; \ | |
199 } \ | |
200 } \ | |
201 } \ | |
202 } \ | |
203 } \ | |
7189 | 204 } |
205 | |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
206 #define MINMAX_SINGLE_BODY(FCN) \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
207 { \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
208 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
|
209 \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
210 if (single_arg && (nargout == 1 || nargout == 0)) \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
211 { \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
212 if (arg1.is_real_type ()) \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
213 { \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
214 FloatNDArray m = arg1.float_array_value (); \ |
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 (! error_state) \ |
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 n = m. FCN (dim); \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
219 retval(0) = n; \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
220 } \ |
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 else if (arg1.is_complex_type ()) \ |
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 FloatComplexNDArray m = arg1.float_complex_array_value (); \ |
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 (! error_state) \ |
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 n = m. FCN (dim); \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
229 retval(0) = n; \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
230 } \ |
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 else \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
233 gripe_wrong_type_arg (#FCN, arg1); \ |
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 else if (single_arg && nargout == 2) \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
236 { \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
237 ArrayN<octave_idx_type> index; \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
238 \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
239 if (arg1.is_real_type ()) \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
240 { \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
241 FloatNDArray m = arg1.float_array_value (); \ |
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 (! error_state) \ |
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 n = m. FCN (index, dim); \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
246 retval(0) = n; \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
247 } \ |
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 (arg1.is_complex_type ()) \ |
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 FloatComplexNDArray m = arg1.float_complex_array_value (); \ |
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 (! error_state) \ |
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 n = m. FCN (index, dim); \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
256 retval(0) = n; \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
257 } \ |
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 else \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
260 gripe_wrong_type_arg (#FCN, arg1); \ |
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 octave_idx_type len = index.numel (); \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
263 \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
264 if (len > 0) \ |
7919
9d080df0c843
new NDArray constructor for ArrayN<octave_idx_type>
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
265 retval(1) = NDArray (index, true, true); \ |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
266 else \ |
7919
9d080df0c843
new NDArray constructor for ArrayN<octave_idx_type>
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
267 retval(1) = NDArray (); \ |
7789
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 else \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
270 { \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
271 int arg1_is_scalar = arg1.is_scalar_type (); \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
272 int arg2_is_scalar = arg2.is_scalar_type (); \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
273 \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
274 int arg1_is_complex = arg1.is_complex_type (); \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
275 int arg2_is_complex = arg2.is_complex_type (); \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
276 \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
277 if (arg1_is_scalar) \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
278 { \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
279 if (arg1_is_complex || arg2_is_complex) \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
280 { \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
281 FloatComplex c1 = arg1.float_complex_value (); \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
282 FloatComplexNDArray m2 = arg2.float_complex_array_value (); \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
283 if (! error_state) \ |
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 FloatComplexNDArray result = FCN (c1, m2); \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
286 if (! error_state) \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
287 retval(0) = result; \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
288 } \ |
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 else \ |
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 float d1 = arg1.float_value (); \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
293 FloatNDArray m2 = arg2.float_array_value (); \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
294 \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
295 if (! error_state) \ |
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 FloatNDArray result = FCN (d1, m2); \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
298 if (! error_state) \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
299 retval(0) = result; \ |
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 } \ |
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 else if (arg2_is_scalar) \ |
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_complex || arg2_is_complex) \ |
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 FloatComplexNDArray m1 = arg1.float_complex_array_value (); \ |
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 if (! error_state) \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
310 { \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
311 FloatComplex c2 = arg2.float_complex_value (); \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
312 FloatComplexNDArray result = FCN (m1, c2); \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
313 if (! error_state) \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
314 retval(0) = result; \ |
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 } \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
317 else \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
318 { \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
319 FloatNDArray m1 = arg1.float_array_value (); \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
320 \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
321 if (! error_state) \ |
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 float d2 = arg2.float_value (); \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
324 FloatNDArray result = FCN (m1, d2); \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
325 if (! error_state) \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
326 retval(0) = result; \ |
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 } \ |
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 else \ |
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 (arg1_is_complex || arg2_is_complex) \ |
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 FloatComplexNDArray m1 = arg1.float_complex_array_value (); \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
335 \ |
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 { \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
338 FloatComplexNDArray m2 = arg2.float_complex_array_value (); \ |
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 if (! error_state) \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
341 { \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
342 FloatComplexNDArray result = FCN (m1, m2); \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
343 if (! error_state) \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
344 retval(0) = result; \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
345 } \ |
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 } \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
348 else \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
349 { \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
350 FloatNDArray m1 = arg1.float_array_value (); \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
351 \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
352 if (! error_state) \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
353 { \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
354 FloatNDArray m2 = arg2.float_array_value (); \ |
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 if (! error_state) \ |
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 FloatNDArray result = FCN (m1, m2); \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
359 if (! error_state) \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
360 retval(0) = result; \ |
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 } \ |
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 } \ |
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 } |
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 |
7189 | 369 #define MINMAX_INT_BODY(FCN, TYP) \ |
370 { \ | |
371 bool single_arg = (nargin == 1) || (arg2.is_empty() && nargin == 3); \ | |
3747 | 372 \ |
7189 | 373 if (single_arg && (nargout == 1 || nargout == 0)) \ |
374 { \ | |
375 TYP ## NDArray m = arg1. TYP ## _array_value (); \ | |
376 \ | |
377 if (! error_state) \ | |
378 { \ | |
379 TYP ## NDArray n = m. FCN (dim); \ | |
380 retval(0) = n; \ | |
381 } \ | |
382 } \ | |
383 else if (single_arg && nargout == 2) \ | |
384 { \ | |
385 ArrayN<octave_idx_type> index; \ | |
386 \ | |
387 TYP ## NDArray m = arg1. TYP ## _array_value (); \ | |
388 \ | |
389 if (! error_state) \ | |
390 { \ | |
391 TYP ## NDArray n = m. FCN (index, dim); \ | |
392 retval(0) = n; \ | |
393 } \ | |
394 \ | |
395 octave_idx_type len = index.numel (); \ | |
396 \ | |
397 if (len > 0) \ | |
7919
9d080df0c843
new NDArray constructor for ArrayN<octave_idx_type>
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
398 retval(1) = NDArray (index, true, true); \ |
7189 | 399 else \ |
400 retval(1) = NDArray (); \ | |
401 } \ | |
402 else \ | |
403 { \ | |
404 int arg1_is_scalar = arg1.is_scalar_type (); \ | |
405 int arg2_is_scalar = arg2.is_scalar_type (); \ | |
406 \ | |
407 if (arg1_is_scalar) \ | |
408 { \ | |
409 octave_ ## TYP d1 = arg1. TYP ## _scalar_value (); \ | |
410 TYP ## NDArray m2 = arg2. TYP ## _array_value (); \ | |
411 \ | |
412 if (! error_state) \ | |
413 { \ | |
414 TYP ## NDArray result = FCN (d1, m2); \ | |
415 if (! error_state) \ | |
416 retval(0) = result; \ | |
417 } \ | |
418 } \ | |
419 else if (arg2_is_scalar) \ | |
420 { \ | |
421 TYP ## NDArray m1 = arg1. TYP ## _array_value (); \ | |
422 \ | |
423 if (! error_state) \ | |
424 { \ | |
425 octave_ ## TYP d2 = arg2. TYP ## _scalar_value (); \ | |
426 TYP ## NDArray result = FCN (m1, d2); \ | |
427 if (! error_state) \ | |
428 retval(0) = result; \ | |
429 } \ | |
430 } \ | |
431 else \ | |
432 { \ | |
433 TYP ## NDArray m1 = arg1. TYP ## _array_value (); \ | |
434 \ | |
435 if (! error_state) \ | |
436 { \ | |
437 TYP ## NDArray m2 = arg2. TYP ## _array_value (); \ | |
438 \ | |
439 if (! error_state) \ | |
440 { \ | |
441 TYP ## NDArray result = FCN (m1, m2); \ | |
442 if (! error_state) \ | |
443 retval(0) = result; \ | |
444 } \ | |
445 } \ | |
446 } \ | |
447 } \ | |
448 } | |
449 | |
7505
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
450 #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
|
451 { \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
452 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
|
453 \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
454 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
|
455 { \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
456 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
|
457 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
|
458 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
|
459 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
|
460 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
|
461 else \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
462 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
|
463 } \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
464 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
|
465 { \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
466 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
|
467 \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
468 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
|
469 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
|
470 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
|
471 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
|
472 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
|
473 else \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
474 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
|
475 \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
476 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
|
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 if (len > 0) \ |
7919
9d080df0c843
new NDArray constructor for ArrayN<octave_idx_type>
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
479 retval(1) = NDArray (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
|
480 else \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
481 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
|
482 } \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
483 else \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
484 { \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
485 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
|
486 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
|
487 \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
488 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
|
489 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
|
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 (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
|
492 { \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
493 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
|
494 { \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
495 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
|
496 \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
497 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
|
498 \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
499 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
|
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 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
|
502 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
|
503 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
|
504 } \ |
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 \ |
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 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
|
509 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
|
510 \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
511 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
|
512 { \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
513 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
|
514 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
|
515 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
|
516 } \ |
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 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
|
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 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
|
522 { \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
523 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
|
524 \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
525 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
|
526 { \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
527 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
|
528 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
|
529 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
|
530 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
|
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 } \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
533 else \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
534 { \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
535 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
|
536 \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
537 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
|
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 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
|
540 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
|
541 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
|
542 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
|
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 } \ |
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 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
|
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 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
|
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 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
|
553 { \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
554 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
|
555 \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
556 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
|
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 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
|
559 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
|
560 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
|
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 } \ |
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 else \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
565 { \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
566 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
|
567 \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
568 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
|
569 { \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
570 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
|
571 \ |
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 { \ |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
574 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
|
575 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
|
576 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
|
577 } \ |
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 } \ |
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 } \ |
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 |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
584 |
7189 | 585 #define MINMAX_BODY(FCN) \ |
586 \ | |
587 octave_value_list retval; \ | |
588 \ | |
589 int nargin = args.length (); \ | |
590 \ | |
591 if (nargin < 1 || nargin > 3 || nargout > 2) \ | |
592 { \ | |
593 print_usage (); \ | |
594 return retval; \ | |
595 } \ | |
596 \ | |
597 octave_value arg1; \ | |
598 octave_value arg2; \ | |
599 octave_value arg3; \ | |
600 \ | |
601 switch (nargin) \ | |
602 { \ | |
603 case 3: \ | |
604 arg3 = args(2); \ | |
605 \ | |
606 case 2: \ | |
607 arg2 = args(1); \ | |
608 \ | |
609 case 1: \ | |
610 arg1 = args(0); \ | |
611 break; \ | |
612 \ | |
613 default: \ | |
614 panic_impossible (); \ | |
615 break; \ | |
616 } \ | |
617 \ | |
618 int dim; \ | |
619 dim_vector dv = arg1.dims (); \ | |
620 if (error_state) \ | |
621 { \ | |
622 gripe_wrong_type_arg (#FCN, arg1); \ | |
623 return retval; \ | |
624 } \ | |
625 \ | |
626 if (nargin == 3) \ | |
627 { \ | |
628 dim = arg3.nint_value () - 1; \ | |
629 if (dim < 0 || dim >= dv.length ()) \ | |
630 { \ | |
631 error ("%s: invalid dimension", #FCN); \ | |
632 return retval; \ | |
633 } \ | |
634 } \ | |
635 else \ | |
636 { \ | |
637 dim = 0; \ | |
638 while ((dim < dv.length ()) && (dv (dim) <= 1)) \ | |
639 dim++; \ | |
640 if (dim == dv.length ()) \ | |
641 dim = 0; \ | |
642 } \ | |
643 \ | |
644 if (arg1.is_integer_type ()) \ | |
645 { \ | |
646 if (arg1.is_uint8_type ()) \ | |
647 MINMAX_INT_BODY (FCN, uint8) \ | |
648 else if (arg1.is_uint16_type ()) \ | |
649 MINMAX_INT_BODY (FCN, uint16) \ | |
650 else if (arg1.is_uint32_type ()) \ | |
651 MINMAX_INT_BODY (FCN, uint32) \ | |
652 else if (arg1.is_uint64_type ()) \ | |
653 MINMAX_INT_BODY (FCN, uint64) \ | |
654 else if (arg1.is_int8_type ()) \ | |
655 MINMAX_INT_BODY (FCN, int8) \ | |
656 else if (arg1.is_int16_type ()) \ | |
657 MINMAX_INT_BODY (FCN, int16) \ | |
658 else if (arg1.is_int32_type ()) \ | |
659 MINMAX_INT_BODY (FCN, int32) \ | |
660 else if (arg1.is_int64_type ()) \ | |
661 MINMAX_INT_BODY (FCN, int64) \ | |
662 } \ | |
7505
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
663 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
|
664 MINMAX_SPARSE_BODY (FCN) \ |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
665 else if (arg1.is_single_type ()) \ |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7662
diff
changeset
|
666 MINMAX_SINGLE_BODY (FCN) \ |
7189 | 667 else \ |
668 MINMAX_DOUBLE_BODY (FCN) \ | |
669 \ | |
670 return retval; | |
3747 | 671 |
2928 | 672 DEFUN_DLD (min, args, nargout, |
3443 | 673 "-*- texinfo -*-\n\ |
4844 | 674 @deftypefn {Mapping Function} {} min (@var{x}, @var{y}, @var{dim})\n\ |
4522 | 675 @deftypefnx {Mapping Function} {[@var{w}, @var{iw}] =} min (@var{x})\n\ |
676 @cindex Utility Functions\n\ | |
3443 | 677 For a vector argument, return the minimum value. For a matrix\n\ |
678 argument, return the minimum value from each column, as a row\n\ | |
4844 | 679 vector, or over the dimension @var{dim} if defined. For two matrices\n\ |
680 (or a matrix and scalar), return the pair-wise minimum.\n\ | |
4522 | 681 Thus,\n\ |
3443 | 682 \n\ |
683 @example\n\ | |
684 min (min (@var{x}))\n\ | |
685 @end example\n\ | |
686 \n\ | |
687 @noindent\n\ | |
4522 | 688 returns the smallest element of @var{x}, and\n\ |
689 \n\ | |
690 @example\n\ | |
691 @group\n\ | |
692 min (2:5, pi)\n\ | |
693 @result{} 2.0000 3.0000 3.1416 3.1416\n\ | |
694 @end group\n\ | |
695 @end example\n\ | |
696 @noindent\n\ | |
697 compares each element of the range @code{2:5} with @code{pi}, and\n\ | |
698 returns a row vector of the minimum values.\n\ | |
3443 | 699 \n\ |
700 For complex arguments, the magnitude of the elements are used for\n\ | |
3657 | 701 comparison.\n\ |
702 \n\ | |
4522 | 703 If called with one input and two output arguments,\n\ |
704 @code{min} also returns the first index of the\n\ | |
3657 | 705 minimum value(s). Thus,\n\ |
4522 | 706 \n\ |
3775 | 707 @example\n\ |
4522 | 708 @group\n\ |
3657 | 709 [x, ix] = min ([1, 3, 0, 2, 5])\n\ |
4522 | 710 @result{} x = 0\n\ |
711 ix = 3\n\ | |
712 @end group\n\ | |
3657 | 713 @end example\n\ |
4522 | 714 @end deftypefn") |
2928 | 715 { |
3747 | 716 MINMAX_BODY (min); |
2928 | 717 } |
718 | |
7600
24abf5a702d9
Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
719 /* |
24abf5a702d9
Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
720 |
24abf5a702d9
Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
721 %% test/octave.test/arith/min-1.m |
24abf5a702d9
Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
722 %!assert (min ([1, 4, 2, 3]) == 1); |
24abf5a702d9
Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
723 %!assert (min ([1; -10; 5; -2]) == -10); |
24abf5a702d9
Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
724 |
24abf5a702d9
Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
725 %% test/octave.test/arith/min-2.m |
24abf5a702d9
Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
726 %!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
|
727 |
24abf5a702d9
Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
728 %% test/octave.test/arith/min-3.m |
24abf5a702d9
Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
729 %!error <Invalid call to min.*> min (); |
24abf5a702d9
Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
730 |
24abf5a702d9
Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
731 %% test/octave.test/arith/min-4.m |
24abf5a702d9
Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
732 %!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
|
733 |
24abf5a702d9
Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
734 %!test |
24abf5a702d9
Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
735 %! x = reshape (1:8,[2,2,2]); |
24abf5a702d9
Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
736 %! 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
|
737 %! 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
|
738 %! [y, i ] = max (x, [], 3); |
24abf5a702d9
Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
739 %! assert (y, [5, 7; 6, 8]); |
24abf5a702d9
Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
740 %! assert (ndims(y), 2); |
24abf5a702d9
Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
741 %! assert (i, [2, 2; 2, 2]); |
24abf5a702d9
Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
742 %! assert (ndims(i), 2); |
24abf5a702d9
Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
743 |
24abf5a702d9
Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
744 */ |
24abf5a702d9
Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
745 |
2928 | 746 DEFUN_DLD (max, args, nargout, |
3443 | 747 "-*- texinfo -*-\n\ |
4844 | 748 @deftypefn {Mapping Function} {} max (@var{x}, @var{y}, @var{dim})\n\ |
4522 | 749 @deftypefnx {Mapping Function} {[@var{w}, @var{iw}] =} max (@var{x})\n\ |
750 @cindex Utility Functions\n\ | |
3443 | 751 For a vector argument, return the maximum value. For a matrix\n\ |
752 argument, return the maximum value from each column, as a row\n\ | |
4844 | 753 vector, or over the dimension @var{dim} if defined. For two matrices\n\ |
754 (or a matrix and scalar), return the pair-wise maximum.\n\ | |
4522 | 755 Thus,\n\ |
3443 | 756 \n\ |
757 @example\n\ | |
758 max (max (@var{x}))\n\ | |
759 @end example\n\ | |
760 \n\ | |
761 @noindent\n\ | |
4522 | 762 returns the largest element of @var{x}, and\n\ |
763 \n\ | |
764 @example\n\ | |
765 @group\n\ | |
766 max (2:5, pi)\n\ | |
767 @result{} 3.1416 3.1416 4.0000 5.0000\n\ | |
768 @end group\n\ | |
769 @end example\n\ | |
770 @noindent\n\ | |
771 compares each element of the range @code{2:5} with @code{pi}, and\n\ | |
772 returns a row vector of the maximum values.\n\ | |
3443 | 773 \n\ |
774 For complex arguments, the magnitude of the elements are used for\n\ | |
3775 | 775 comparison.\n\ |
3657 | 776 \n\ |
4522 | 777 If called with one input and two output arguments,\n\ |
778 @code{max} also returns the first index of the\n\ | |
3657 | 779 maximum value(s). Thus,\n\ |
4522 | 780 \n\ |
3775 | 781 @example\n\ |
4522 | 782 @group\n\ |
783 [x, ix] = max ([1, 3, 5, 2, 5])\n\ | |
784 @result{} x = 5\n\ | |
785 ix = 3\n\ | |
786 @end group\n\ | |
3657 | 787 @end example\n\ |
4522 | 788 @end deftypefn") |
2928 | 789 { |
3747 | 790 MINMAX_BODY (max); |
2928 | 791 } |
792 | |
7600
24abf5a702d9
Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
793 /* |
24abf5a702d9
Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
794 |
24abf5a702d9
Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
795 %% test/octave.test/arith/max-1.m |
24abf5a702d9
Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
796 %!assert (max ([1, 4, 2, 3]) == 4); |
24abf5a702d9
Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
797 %!assert (max ([1; -10; 5; -2]) == 5); |
24abf5a702d9
Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
798 |
24abf5a702d9
Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
799 %% test/octave.test/arith/max-2.m |
24abf5a702d9
Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
800 %!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
|
801 |
24abf5a702d9
Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
802 %% test/octave.test/arith/max-3.m |
24abf5a702d9
Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
803 %!error <Invalid call to max.*> max (); |
24abf5a702d9
Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
804 |
24abf5a702d9
Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
805 %% test/octave.test/arith/max-4.m |
24abf5a702d9
Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
806 %!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
|
807 |
24abf5a702d9
Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
808 %!test |
24abf5a702d9
Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
809 %! x = reshape (1:8,[2,2,2]); |
24abf5a702d9
Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
810 %! 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
|
811 %! 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
|
812 %! [y, i ] = min (x, [], 3); |
24abf5a702d9
Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
813 %! assert (y, [1, 3; 2, 4]); |
24abf5a702d9
Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
814 %! assert (ndims(y), 2); |
24abf5a702d9
Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
815 %! assert (i, [1, 1; 1, 1]); |
24abf5a702d9
Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
816 %! assert (ndims(i), 2); |
24abf5a702d9
Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
817 |
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 */ |
24abf5a702d9
Chop trailing singletons in min/max functions
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
820 |
2928 | 821 /* |
822 ;;; Local Variables: *** | |
823 ;;; mode: C++ *** | |
824 ;;; End: *** | |
825 */ |