annotate src/DLD-FUNCTIONS/max.cc @ 9732:b4fdfee405b5

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