839
|
1 // f-minmax.cc -*- C++ -*- |
515
|
2 /* |
|
3 |
1009
|
4 Copyright (C) 1994, 1995 John W. Eaton |
515
|
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 |
|
10 Free Software Foundation; either version 2, or (at your option) any |
|
11 later version. |
|
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 |
|
19 along with Octave; see the file COPYING. If not, write to the Free |
1315
|
20 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
515
|
21 |
|
22 */ |
|
23 |
|
24 #ifdef HAVE_CONFIG_H |
1192
|
25 #include <config.h> |
515
|
26 #endif |
|
27 |
1342
|
28 #include <cmath> |
515
|
29 |
|
30 #include "tree-const.h" |
|
31 #include "error.h" |
777
|
32 #include "gripes.h" |
544
|
33 #include "help.h" |
519
|
34 #include "defun-dld.h" |
515
|
35 |
|
36 #ifndef MAX |
|
37 #define MAX(a,b) ((a) > (b) ? (a) : (b)) |
|
38 #endif |
|
39 |
|
40 #ifndef MIN |
|
41 #define MIN(a,b) ((a) < (b) ? (a) : (b)) |
|
42 #endif |
|
43 |
891
|
44 // XXX FIXME XXX -- it would be nice to share code among the min/max |
|
45 // functions below. |
839
|
46 |
|
47 static Matrix |
|
48 min (double d, const Matrix& m) |
|
49 { |
|
50 int nr = m.rows (); |
|
51 int nc = m.columns (); |
|
52 |
|
53 Matrix result (nr, nc); |
|
54 |
|
55 for (int j = 0; j < nc; j++) |
|
56 for (int i = 0; i < nr; i++) |
|
57 { |
|
58 double m_elem = m.elem (i, j); |
|
59 result.elem (i, j) = MIN (d, m_elem); |
|
60 } |
|
61 |
|
62 return result; |
|
63 } |
|
64 |
|
65 static Matrix |
|
66 min (const Matrix& m, double d) |
|
67 { |
|
68 int nr = m.rows (); |
|
69 int nc = m.columns (); |
|
70 |
|
71 Matrix result (nr, nc); |
|
72 |
|
73 for (int j = 0; j < nc; j++) |
|
74 for (int i = 0; i < nr; i++) |
|
75 { |
|
76 double m_elem = m.elem (i, j); |
|
77 result.elem (i, j) = MIN (m_elem, d); |
|
78 } |
|
79 |
|
80 return result; |
|
81 } |
|
82 |
|
83 static ComplexMatrix |
|
84 min (const Complex& c, const ComplexMatrix& m) |
|
85 { |
|
86 int nr = m.rows (); |
|
87 int nc = m.columns (); |
|
88 |
|
89 ComplexMatrix result (nr, nc); |
|
90 |
|
91 double abs_c = abs (c); |
|
92 |
|
93 for (int j = 0; j < nc; j++) |
891
|
94 { |
|
95 for (int i = 0; i < nr; i++) |
|
96 { |
|
97 double abs_m_elem = abs (m.elem (i, j)); |
|
98 if (abs_c < abs_m_elem) |
|
99 result.elem (i, j) = c; |
|
100 else |
|
101 result.elem (i, j) = m.elem (i, j); |
|
102 } |
|
103 } |
839
|
104 |
|
105 return result; |
|
106 } |
|
107 |
|
108 static ComplexMatrix |
|
109 min (const ComplexMatrix& m, const Complex& c) |
|
110 { |
|
111 int nr = m.rows (); |
|
112 int nc = m.columns (); |
|
113 |
|
114 ComplexMatrix result (nr, nc); |
|
115 |
|
116 double abs_c = abs (c); |
|
117 |
|
118 for (int j = 0; j < nc; j++) |
|
119 for (int i = 0; i < nr; i++) |
|
120 { |
|
121 double abs_m_elem = abs (m.elem (i, j)); |
|
122 if (abs_m_elem < abs_c) |
|
123 result.elem (i, j) = m.elem (i, j); |
|
124 else |
|
125 result.elem (i, j) = c; |
|
126 } |
|
127 |
|
128 return result; |
|
129 } |
|
130 |
515
|
131 static Matrix |
|
132 min (const Matrix& a, const Matrix& b) |
|
133 { |
|
134 int nr = a.rows (); |
|
135 int nc = a.columns (); |
|
136 if (nr != b.rows () || nc != b.columns ()) |
|
137 { |
|
138 error ("two-arg min expecting args of same size"); |
|
139 return Matrix (); |
|
140 } |
|
141 |
|
142 Matrix result (nr, nc); |
|
143 |
|
144 for (int j = 0; j < nc; j++) |
|
145 for (int i = 0; i < nr; i++) |
|
146 { |
|
147 double a_elem = a.elem (i, j); |
|
148 double b_elem = b.elem (i, j); |
|
149 result.elem (i, j) = MIN (a_elem, b_elem); |
|
150 } |
|
151 |
|
152 return result; |
|
153 } |
|
154 |
|
155 static ComplexMatrix |
|
156 min (const ComplexMatrix& a, const ComplexMatrix& b) |
|
157 { |
|
158 int nr = a.rows (); |
|
159 int nc = a.columns (); |
|
160 if (nr != b.rows () || nc != b.columns ()) |
|
161 { |
|
162 error ("two-arg min expecting args of same size"); |
|
163 return ComplexMatrix (); |
|
164 } |
|
165 |
|
166 ComplexMatrix result (nr, nc); |
|
167 |
|
168 for (int j = 0; j < nc; j++) |
891
|
169 { |
|
170 int columns_are_real_only = 1; |
|
171 for (int i = 0; i < nr; i++) |
|
172 if (imag (a.elem (i, j)) != 0.0 && imag (b.elem (i, j)) != 0.0) |
|
173 { |
|
174 columns_are_real_only = 0; |
|
175 break; |
|
176 } |
|
177 |
|
178 if (columns_are_real_only) |
|
179 { |
|
180 for (int i = 0; i < nr; i++) |
|
181 { |
|
182 double a_elem = real (a.elem (i, j)); |
|
183 double b_elem = real (b.elem (i, j)); |
|
184 if (a_elem < b_elem) |
|
185 result.elem (i, j) = a_elem; |
|
186 else |
|
187 result.elem (i, j) = b_elem; |
|
188 } |
|
189 } |
|
190 else |
|
191 { |
|
192 for (int i = 0; i < nr; i++) |
|
193 { |
|
194 double abs_a_elem = abs (a.elem (i, j)); |
|
195 double abs_b_elem = abs (b.elem (i, j)); |
|
196 if (abs_a_elem < abs_b_elem) |
|
197 result.elem (i, j) = a.elem (i, j); |
|
198 else |
|
199 result.elem (i, j) = b.elem (i, j); |
|
200 } |
|
201 } |
|
202 } |
839
|
203 |
|
204 return result; |
|
205 } |
|
206 |
|
207 static Matrix |
|
208 max (double d, const Matrix& m) |
|
209 { |
|
210 int nr = m.rows (); |
|
211 int nc = m.columns (); |
|
212 |
|
213 Matrix result (nr, nc); |
|
214 |
|
215 for (int j = 0; j < nc; j++) |
|
216 for (int i = 0; i < nr; i++) |
|
217 { |
|
218 double m_elem = m.elem (i, j); |
|
219 result.elem (i, j) = MAX (d, m_elem); |
|
220 } |
|
221 |
|
222 return result; |
|
223 } |
|
224 |
|
225 static Matrix |
|
226 max (const Matrix& m, double d) |
|
227 { |
|
228 int nr = m.rows (); |
|
229 int nc = m.columns (); |
|
230 |
|
231 Matrix result (nr, nc); |
|
232 |
|
233 for (int j = 0; j < nc; j++) |
|
234 for (int i = 0; i < nr; i++) |
|
235 { |
|
236 double m_elem = m.elem (i, j); |
|
237 result.elem (i, j) = MAX (m_elem, d); |
|
238 } |
|
239 |
|
240 return result; |
|
241 } |
|
242 |
|
243 static ComplexMatrix |
|
244 max (const Complex& c, const ComplexMatrix& m) |
|
245 { |
|
246 int nr = m.rows (); |
|
247 int nc = m.columns (); |
|
248 |
|
249 ComplexMatrix result (nr, nc); |
|
250 |
|
251 double abs_c = abs (c); |
|
252 |
|
253 for (int j = 0; j < nc; j++) |
|
254 for (int i = 0; i < nr; i++) |
|
255 { |
|
256 double abs_m_elem = abs (m.elem (i, j)); |
|
257 if (abs_c > abs_m_elem) |
|
258 result.elem (i, j) = c; |
|
259 else |
|
260 result.elem (i, j) = m.elem (i, j); |
|
261 } |
|
262 |
|
263 return result; |
|
264 } |
|
265 |
|
266 static ComplexMatrix |
|
267 max (const ComplexMatrix& m, const Complex& c) |
|
268 { |
|
269 int nr = m.rows (); |
|
270 int nc = m.columns (); |
|
271 |
|
272 ComplexMatrix result (nr, nc); |
|
273 |
|
274 double abs_c = abs (c); |
|
275 |
|
276 for (int j = 0; j < nc; j++) |
|
277 for (int i = 0; i < nr; i++) |
|
278 { |
|
279 double abs_m_elem = abs (m.elem (i, j)); |
|
280 if (abs_m_elem > abs_c) |
|
281 result.elem (i, j) = m.elem (i, j); |
|
282 else |
|
283 result.elem (i, j) = c; |
515
|
284 } |
|
285 |
|
286 return result; |
|
287 } |
|
288 |
|
289 static Matrix |
|
290 max (const Matrix& a, const Matrix& b) |
|
291 { |
|
292 int nr = a.rows (); |
|
293 int nc = a.columns (); |
|
294 if (nr != b.rows () || nc != b.columns ()) |
|
295 { |
|
296 error ("two-arg max expecting args of same size"); |
|
297 return Matrix (); |
|
298 } |
|
299 |
|
300 Matrix result (nr, nc); |
|
301 |
|
302 for (int j = 0; j < nc; j++) |
|
303 for (int i = 0; i < nr; i++) |
|
304 { |
|
305 double a_elem = a.elem (i, j); |
|
306 double b_elem = b.elem (i, j); |
|
307 result.elem (i, j) = MAX (a_elem, b_elem); |
|
308 } |
|
309 |
|
310 return result; |
|
311 } |
|
312 |
|
313 static ComplexMatrix |
|
314 max (const ComplexMatrix& a, const ComplexMatrix& b) |
|
315 { |
|
316 int nr = a.rows (); |
|
317 int nc = a.columns (); |
|
318 if (nr != b.rows () || nc != b.columns ()) |
|
319 { |
|
320 error ("two-arg max expecting args of same size"); |
|
321 return ComplexMatrix (); |
|
322 } |
|
323 |
|
324 ComplexMatrix result (nr, nc); |
|
325 |
|
326 for (int j = 0; j < nc; j++) |
891
|
327 { |
|
328 int columns_are_real_only = 1; |
|
329 for (int i = 0; i < nr; i++) |
|
330 if (imag (a.elem (i, j)) != 0.0 && imag (b.elem (i, j)) != 0.0) |
|
331 { |
|
332 columns_are_real_only = 0; |
|
333 break; |
|
334 } |
|
335 |
|
336 if (columns_are_real_only) |
|
337 { |
|
338 for (int i = 0; i < nr; i++) |
|
339 { |
|
340 double a_elem = real (a.elem (i, j)); |
|
341 double b_elem = real (b.elem (i, j)); |
|
342 if (a_elem > b_elem) |
|
343 result.elem (i, j) = a_elem; |
|
344 else |
|
345 result.elem (i, j) = b_elem; |
|
346 } |
|
347 } |
|
348 else |
|
349 { |
|
350 for (int i = 0; i < nr; i++) |
|
351 { |
|
352 double abs_a_elem = abs (a.elem (i, j)); |
|
353 double abs_b_elem = abs (b.elem (i, j)); |
|
354 if (abs_a_elem > abs_b_elem) |
|
355 result.elem (i, j) = a.elem (i, j); |
|
356 else |
|
357 result.elem (i, j) = b.elem (i, j); |
|
358 } |
|
359 } |
|
360 } |
515
|
361 |
|
362 return result; |
|
363 } |
|
364 |
701
|
365 DEFUN_DLD_BUILTIN ("min", Fmin, Smin, 3, 2, |
519
|
366 "min (X): minimum value(s) of a vector (matrix)") |
515
|
367 { |
|
368 Octave_object retval; |
|
369 |
519
|
370 int nargin = args.length (); |
|
371 |
712
|
372 if (nargin < 1 || nargin > 2 || nargout > 2) |
519
|
373 { |
|
374 print_usage ("min"); |
|
375 return retval; |
|
376 } |
|
377 |
515
|
378 tree_constant arg1; |
|
379 tree_constant arg2; |
|
380 |
|
381 switch (nargin) |
|
382 { |
712
|
383 case 2: |
|
384 arg2 = args(1); |
515
|
385 // Fall through... |
777
|
386 |
712
|
387 case 1: |
|
388 arg1 = args(0); |
515
|
389 break; |
777
|
390 |
515
|
391 default: |
|
392 panic_impossible (); |
|
393 break; |
|
394 } |
|
395 |
712
|
396 if (nargin == 1 && (nargout == 1 || nargout == 0)) |
515
|
397 { |
620
|
398 if (arg1.is_real_scalar ()) |
515
|
399 { |
|
400 retval(0) = arg1.double_value (); |
620
|
401 } |
|
402 else if (arg1.is_complex_scalar ()) |
|
403 { |
839
|
404 retval(0) = arg1.complex_value (); |
620
|
405 } |
636
|
406 else if (arg1.is_real_type ()) |
620
|
407 { |
|
408 Matrix m = arg1.matrix_value (); |
636
|
409 |
|
410 if (! error_state) |
|
411 { |
|
412 if (m.rows () == 1) |
|
413 retval(0) = m.row_min (); |
|
414 else |
|
415 retval(0) = tree_constant (m.column_min (), 0); |
|
416 } |
620
|
417 } |
636
|
418 else if (arg1.is_complex_type ()) |
620
|
419 { |
|
420 ComplexMatrix m = arg1.complex_matrix_value (); |
636
|
421 |
|
422 if (! error_state) |
|
423 { |
|
424 if (m.rows () == 1) |
|
425 retval(0) = m.row_min (); |
|
426 else |
|
427 retval(0) = tree_constant (m.column_min (), 0); |
|
428 } |
620
|
429 } |
|
430 else |
|
431 { |
|
432 gripe_wrong_type_arg ("min", arg1); |
|
433 return retval; |
515
|
434 } |
|
435 } |
712
|
436 else if (nargin == 1 && nargout == 2) |
515
|
437 { |
620
|
438 if (arg1.is_real_scalar ()) |
839
|
439 { |
620
|
440 retval(1) = 1; |
|
441 retval(0) = arg1.double_value (); |
|
442 } |
|
443 else if (arg1.is_complex_scalar ()) |
|
444 { |
|
445 retval(1) = 1; |
|
446 retval(0) = arg1.complex_value (); |
|
447 } |
636
|
448 else if (arg1.is_real_type ()) |
620
|
449 { |
|
450 Matrix m = arg1.matrix_value (); |
636
|
451 |
|
452 if (! error_state) |
620
|
453 { |
636
|
454 if (m.rows () == 1) |
|
455 { |
|
456 retval(1) = m.row_min_loc (); |
|
457 retval(0) = m.row_min (); |
|
458 } |
|
459 else |
|
460 { |
|
461 retval(1) = tree_constant (m.column_min_loc (), 0); |
|
462 retval(0) = tree_constant (m.column_min (), 0); |
|
463 } |
620
|
464 } |
|
465 } |
636
|
466 else if (arg1.is_complex_type ()) |
620
|
467 { |
|
468 ComplexMatrix m = arg1.complex_matrix_value (); |
636
|
469 |
|
470 if (! error_state) |
620
|
471 { |
636
|
472 if (m.rows () == 1) |
|
473 { |
|
474 retval(1) = m.row_min_loc (); |
|
475 retval(0) = m.row_min (); |
|
476 } |
|
477 else |
|
478 { |
|
479 retval(1) = tree_constant (m.column_min_loc (), 0); |
|
480 retval(0) = tree_constant (m.column_min (), 0); |
|
481 } |
620
|
482 } |
|
483 } |
|
484 else |
|
485 { |
|
486 gripe_wrong_type_arg ("min", arg1); |
|
487 return retval; |
839
|
488 } |
515
|
489 } |
712
|
490 else if (nargin == 2) |
515
|
491 { |
839
|
492 int arg1_is_scalar = arg1.is_scalar_type (); |
|
493 int arg2_is_scalar = arg2.is_scalar_type (); |
|
494 |
|
495 int arg1_is_complex = arg1.is_complex_type (); |
|
496 int arg2_is_complex = arg2.is_complex_type (); |
|
497 |
|
498 if (arg1_is_scalar) |
515
|
499 { |
839
|
500 if (arg1_is_complex || arg2_is_complex) |
|
501 { |
|
502 Complex c1 = arg1.complex_value (); |
|
503 ComplexMatrix m2 = arg2.complex_matrix_value (); |
|
504 if (! error_state) |
|
505 { |
|
506 ComplexMatrix result = min (c1, m2); |
|
507 if (! error_state) |
|
508 retval(0) = result; |
|
509 } |
|
510 } |
|
511 else |
|
512 { |
|
513 double d1 = arg1.double_value (); |
|
514 Matrix m2 = arg2.matrix_value (); |
|
515 |
|
516 if (! error_state) |
|
517 { |
|
518 Matrix result = min (d1, m2); |
|
519 if (! error_state) |
|
520 retval(0) = result; |
|
521 } |
|
522 } |
|
523 } |
|
524 else if (arg2_is_scalar) |
|
525 { |
|
526 if (arg1_is_complex || arg2_is_complex) |
|
527 { |
|
528 ComplexMatrix m1 = arg1.complex_matrix_value (); |
|
529 |
|
530 if (! error_state) |
|
531 { |
|
532 Complex c2 = arg2.complex_value (); |
|
533 ComplexMatrix result = min (m1, c2); |
|
534 if (! error_state) |
|
535 retval(0) = result; |
|
536 } |
|
537 } |
|
538 else |
620
|
539 { |
636
|
540 Matrix m1 = arg1.matrix_value (); |
|
541 |
|
542 if (! error_state) |
|
543 { |
839
|
544 double d2 = arg2.double_value (); |
|
545 Matrix result = min (m1, d2); |
636
|
546 if (! error_state) |
839
|
547 retval(0) = result; |
636
|
548 } |
620
|
549 } |
839
|
550 } |
|
551 else |
|
552 { |
|
553 if (arg1_is_complex || arg2_is_complex) |
620
|
554 { |
636
|
555 ComplexMatrix m1 = arg1.complex_matrix_value (); |
|
556 |
|
557 if (! error_state) |
|
558 { |
|
559 ComplexMatrix m2 = arg2.complex_matrix_value (); |
|
560 |
|
561 if (! error_state) |
|
562 { |
|
563 ComplexMatrix result = min (m1, m2); |
|
564 if (! error_state) |
|
565 retval(0) = result; |
|
566 } |
|
567 } |
620
|
568 } |
|
569 else |
|
570 { |
839
|
571 Matrix m1 = arg1.matrix_value (); |
|
572 |
|
573 if (! error_state) |
|
574 { |
|
575 Matrix m2 = arg2.matrix_value (); |
|
576 |
|
577 if (! error_state) |
|
578 { |
|
579 Matrix result = min (m1, m2); |
|
580 if (! error_state) |
|
581 retval(0) = result; |
|
582 } |
|
583 } |
515
|
584 } |
|
585 } |
|
586 } |
|
587 else |
|
588 panic_impossible (); |
|
589 |
|
590 return retval; |
|
591 } |
|
592 |
701
|
593 DEFUN_DLD_BUILTIN ("max", Fmax, Smax, 3, 2, |
519
|
594 "max (X): maximum value(s) of a vector (matrix)") |
515
|
595 { |
|
596 Octave_object retval; |
|
597 |
519
|
598 int nargin = args.length (); |
|
599 |
712
|
600 if (nargin < 1 || nargin > 2 || nargout > 2) |
519
|
601 { |
|
602 print_usage ("max"); |
|
603 return retval; |
|
604 } |
|
605 |
515
|
606 tree_constant arg1; |
|
607 tree_constant arg2; |
|
608 |
|
609 switch (nargin) |
|
610 { |
712
|
611 case 2: |
|
612 arg2 = args(1); |
515
|
613 // Fall through... |
777
|
614 |
712
|
615 case 1: |
|
616 arg1 = args(0); |
515
|
617 break; |
777
|
618 |
515
|
619 default: |
|
620 panic_impossible (); |
|
621 break; |
|
622 } |
|
623 |
712
|
624 if (nargin == 1 && (nargout == 1 || nargout == 0)) |
515
|
625 { |
620
|
626 if (arg1.is_real_scalar ()) |
515
|
627 { |
|
628 retval(0) = arg1.double_value (); |
620
|
629 } |
|
630 else if (arg1.is_complex_scalar ()) |
|
631 { |
839
|
632 retval(0) = arg1.complex_value (); |
620
|
633 } |
785
|
634 else if (arg1.is_real_type ()) |
620
|
635 { |
|
636 Matrix m = arg1.matrix_value (); |
839
|
637 |
|
638 if (! error_state) |
|
639 { |
|
640 if (m.rows () == 1) |
|
641 retval(0) = m.row_max (); |
|
642 else |
|
643 retval(0) = tree_constant (m.column_max (), 0); |
|
644 } |
620
|
645 } |
785
|
646 else if (arg1.is_complex_type ()) |
620
|
647 { |
|
648 ComplexMatrix m = arg1.complex_matrix_value (); |
839
|
649 |
|
650 if (! error_state) |
|
651 { |
|
652 if (m.rows () == 1) |
|
653 retval(0) = m.row_max (); |
|
654 else |
|
655 retval(0) = tree_constant (m.column_max (), 0); |
|
656 } |
620
|
657 } |
|
658 else |
|
659 { |
|
660 gripe_wrong_type_arg ("max", arg1); |
|
661 return retval; |
515
|
662 } |
|
663 } |
712
|
664 else if (nargin == 1 && nargout == 2) |
515
|
665 { |
620
|
666 if (arg1.is_real_scalar ()) |
|
667 { |
|
668 retval(1) = 1; |
|
669 retval(0) = arg1.double_value (); |
|
670 } |
|
671 else if (arg1.is_complex_scalar ()) |
|
672 { |
|
673 retval(1) = 1; |
|
674 retval(0) = arg1.complex_value (); |
|
675 } |
785
|
676 else if (arg1.is_real_type ()) |
620
|
677 { |
|
678 Matrix m = arg1.matrix_value (); |
839
|
679 |
|
680 if (! error_state) |
620
|
681 { |
839
|
682 if (m.rows () == 1) |
|
683 { |
|
684 retval(1) = m.row_max_loc (); |
|
685 retval(0) = m.row_max (); |
|
686 } |
|
687 else |
|
688 { |
|
689 retval(1) = tree_constant (m.column_max_loc (), 0); |
|
690 retval(0) = tree_constant (m.column_max (), 0); |
|
691 } |
620
|
692 } |
|
693 } |
785
|
694 else if (arg1.is_complex_type ()) |
620
|
695 { |
|
696 ComplexMatrix m = arg1.complex_matrix_value (); |
839
|
697 |
|
698 if (! error_state) |
620
|
699 { |
839
|
700 if (m.rows () == 1) |
|
701 { |
|
702 retval(1) = m.row_max_loc (); |
|
703 retval(0) = m.row_max (); |
|
704 } |
|
705 else |
|
706 { |
|
707 retval(1) = tree_constant (m.column_max_loc (), 0); |
|
708 retval(0) = tree_constant (m.column_max (), 0); |
|
709 } |
620
|
710 } |
|
711 } |
|
712 else |
|
713 { |
|
714 gripe_wrong_type_arg ("max", arg1); |
|
715 return retval; |
|
716 } |
515
|
717 } |
712
|
718 else if (nargin == 2) |
515
|
719 { |
839
|
720 int arg1_is_scalar = arg1.is_scalar_type (); |
|
721 int arg2_is_scalar = arg2.is_scalar_type (); |
|
722 |
|
723 int arg1_is_complex = arg1.is_complex_type (); |
|
724 int arg2_is_complex = arg2.is_complex_type (); |
|
725 |
|
726 if (arg1_is_scalar) |
515
|
727 { |
839
|
728 if (arg1_is_complex || arg2_is_complex) |
|
729 { |
|
730 Complex c1 = arg1.complex_value (); |
|
731 ComplexMatrix m2 = arg2.complex_matrix_value (); |
|
732 if (! error_state) |
|
733 { |
|
734 ComplexMatrix result = max (c1, m2); |
|
735 if (! error_state) |
|
736 retval(0) = result; |
|
737 } |
620
|
738 } |
839
|
739 else |
620
|
740 { |
839
|
741 double d1 = arg1.double_value (); |
|
742 Matrix m2 = arg2.matrix_value (); |
|
743 |
|
744 if (! error_state) |
|
745 { |
|
746 Matrix result = max (d1, m2); |
|
747 if (! error_state) |
|
748 retval(0) = result; |
|
749 } |
620
|
750 } |
839
|
751 } |
|
752 else if (arg2_is_scalar) |
|
753 { |
|
754 if (arg1_is_complex || arg2_is_complex) |
620
|
755 { |
839
|
756 ComplexMatrix m1 = arg1.complex_matrix_value (); |
|
757 |
|
758 if (! error_state) |
|
759 { |
|
760 Complex c2 = arg2.complex_value (); |
|
761 ComplexMatrix result = max (m1, c2); |
|
762 if (! error_state) |
|
763 retval(0) = result; |
|
764 } |
620
|
765 } |
839
|
766 else |
620
|
767 { |
839
|
768 Matrix m1 = arg1.matrix_value (); |
|
769 |
|
770 if (! error_state) |
|
771 { |
|
772 double d2 = arg2.double_value (); |
|
773 Matrix result = max (m1, d2); |
|
774 if (! error_state) |
|
775 retval(0) = result; |
|
776 } |
515
|
777 } |
|
778 } |
|
779 else |
839
|
780 { |
|
781 if (arg1_is_complex || arg2_is_complex) |
|
782 { |
|
783 ComplexMatrix m1 = arg1.complex_matrix_value (); |
|
784 |
|
785 if (! error_state) |
|
786 { |
|
787 ComplexMatrix m2 = arg2.complex_matrix_value (); |
|
788 |
|
789 if (! error_state) |
|
790 { |
|
791 ComplexMatrix result = max (m1, m2); |
|
792 if (! error_state) |
|
793 retval(0) = result; |
|
794 } |
|
795 } |
|
796 } |
|
797 else |
|
798 { |
|
799 Matrix m1 = arg1.matrix_value (); |
|
800 |
|
801 if (! error_state) |
|
802 { |
|
803 Matrix m2 = arg2.matrix_value (); |
|
804 |
|
805 if (! error_state) |
|
806 { |
|
807 Matrix result = max (m1, m2); |
|
808 if (! error_state) |
|
809 retval(0) = result; |
|
810 } |
|
811 } |
|
812 } |
|
813 } |
515
|
814 } |
|
815 else |
|
816 panic_impossible (); |
|
817 |
|
818 return retval; |
|
819 } |
|
820 |
|
821 /* |
|
822 ;;; Local Variables: *** |
|
823 ;;; mode: C++ *** |
|
824 ;;; page-delimiter: "^/\\*" *** |
|
825 ;;; End: *** |
|
826 */ |