Mercurial > octave
annotate liboctave/array/CNDArray.cc @ 25586:59f4fda5c548
remove fftpack sources
We now require FFTW to perform FFT calculations.
* liboctave/external/fftpack: Delete directory and all files.
* liboctave/external/module.mk: Update.
* lo-fftpack-proto.h: Delete.
* liboctave/numeric/module.mk: Update.
* CMatrix.cc, CNDArray.cc, dMatrix.cc, dNDArray.cc, fCMatrix.cc,
fCNDArray.cc, fMatrix.cc, fNDArray.cc: Require FFTW to compute FFT.
* interpft.m, fftconv.m, fftfilt.m, freqz.m, fft.cc, fft2.cc, fftn.cc:
Use TESTIF HAVE_FFTW as needed.
* NEWS: Note change.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Wed, 11 Jul 2018 17:41:36 -0400 |
parents | cb1606f78f6b |
children | 00f796120a6d |
rev | line source |
---|---|
4514 | 1 /* |
2 | |
25054
6652d3823428
maint: Update copyright dates in all source files.
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
3 Copyright (C) 1996-2018 John W. Eaton |
9601
a9b37bae1802
add a couple of missing copyright statements
Jaroslav Hajek <highegg@gmail.com>
parents:
9578
diff
changeset
|
4 Copyright (C) 2009 VZLU Prague, a.s. |
4514 | 5 |
6 This file is part of Octave. | |
7 | |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
23807
diff
changeset
|
8 Octave is free software: you can redistribute it and/or modify it |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22402
diff
changeset
|
9 under the terms of the GNU General Public License as published by |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
23807
diff
changeset
|
10 the Free Software Foundation, either version 3 of the License, or |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22402
diff
changeset
|
11 (at your option) any later version. |
4514 | 12 |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22402
diff
changeset
|
13 Octave is distributed in the hope that it will be useful, but |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22402
diff
changeset
|
14 WITHOUT ANY WARRANTY; without even the implied warranty of |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22402
diff
changeset
|
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22402
diff
changeset
|
16 GNU General Public License for more details. |
4514 | 17 |
18 You should have received a copy of the GNU General Public License | |
7016 | 19 along with Octave; see the file COPYING. If not, see |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
23807
diff
changeset
|
20 <https://www.gnu.org/licenses/>. |
4514 | 21 |
22 */ | |
23 | |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21723
diff
changeset
|
24 #if defined (HAVE_CONFIG_H) |
21301
40de9f8f23a6
Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents:
21202
diff
changeset
|
25 # include "config.h" |
4514 | 26 #endif |
27 | |
23443
3f1bf237908b
maint: Eliminate <cfloat.h> header from liboctave files.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
28 #include <complex> |
25438
cb1606f78f6b
prefer <istream>, <ostream>, or <iosfwd> to <iostream> where possible
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
29 #include <istream> |
cb1606f78f6b
prefer <istream>, <ostream>, or <iosfwd> to <iostream> where possible
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
30 #include <ostream> |
4687 | 31 |
4588 | 32 #include "Array-util.h" |
4514 | 33 #include "CNDArray.h" |
4773 | 34 #include "f77-fcn.h" |
7503
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
35 #include "functor.h" |
4514 | 36 #include "lo-ieee.h" |
4687 | 37 #include "lo-mappers.h" |
9523
0ce82753dd72
more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents:
9513
diff
changeset
|
38 #include "mx-base.h" |
23443
3f1bf237908b
maint: Eliminate <cfloat.h> header from liboctave files.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
39 #include "mx-cnda-s.h" |
8774
b756ce0002db
split implementation and interface in mx-op-defs and MArray-defs
Jaroslav Hajek <highegg@gmail.com>
parents:
8751
diff
changeset
|
40 #include "mx-op-defs.h" |
4780 | 41 #include "oct-fftw.h" |
9523
0ce82753dd72
more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents:
9513
diff
changeset
|
42 #include "oct-locbuf.h" |
4773 | 43 |
9743
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
44 #include "bsxfun-defs.cc" |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
45 |
8956
d91fa4b20bbb
ensure nonnegative char -> real conversion
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
46 ComplexNDArray::ComplexNDArray (const charNDArray& a) |
10350
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10329
diff
changeset
|
47 : MArray<Complex> (a.dims ()) |
8956
d91fa4b20bbb
ensure nonnegative char -> real conversion
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
48 { |
d91fa4b20bbb
ensure nonnegative char -> real conversion
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
49 octave_idx_type n = a.numel (); |
d91fa4b20bbb
ensure nonnegative char -> real conversion
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
50 for (octave_idx_type i = 0; i < n; i++) |
d91fa4b20bbb
ensure nonnegative char -> real conversion
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
51 xelem (i) = static_cast<unsigned char> (a(i)); |
d91fa4b20bbb
ensure nonnegative char -> real conversion
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
52 } |
d91fa4b20bbb
ensure nonnegative char -> real conversion
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
53 |
9523
0ce82753dd72
more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents:
9513
diff
changeset
|
54 #if defined (HAVE_FFTW) |
0ce82753dd72
more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents:
9513
diff
changeset
|
55 |
4773 | 56 ComplexNDArray |
57 ComplexNDArray::fourier (int dim) const | |
58 { | |
59 dim_vector dv = dims (); | |
60 | |
21660
53728df3e4c9
maint: for clarity, call ndims() rather than length() on dimension vectors.
Rik <rik@octave.org>
parents:
21562
diff
changeset
|
61 if (dim > dv.ndims () || dim < 0) |
4773 | 62 return ComplexNDArray (); |
63 | |
5275 | 64 octave_idx_type stride = 1; |
65 octave_idx_type n = dv(dim); | |
4773 | 66 |
67 for (int i = 0; i < dim; i++) | |
68 stride *= dv(i); | |
69 | |
20218
b2100e1659ac
maint: Use cuddled parentheses when indexing dimension_vectors.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
70 octave_idx_type howmany = numel () / dv(dim); |
4773 | 71 howmany = (stride == 1 ? howmany : (howmany > stride ? stride : howmany)); |
20218
b2100e1659ac
maint: Use cuddled parentheses when indexing dimension_vectors.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
72 octave_idx_type nloop = (stride == 1 ? 1 : numel () / dv(dim) / stride); |
5275 | 73 octave_idx_type dist = (stride == 1 ? n : 1); |
4773 | 74 |
75 const Complex *in (fortran_vec ()); | |
76 ComplexNDArray retval (dv); | |
77 Complex *out (retval.fortran_vec ()); | |
78 | |
79 // Need to be careful here about the distance between fft's | |
5275 | 80 for (octave_idx_type k = 0; k < nloop; k++) |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
81 octave::fftw::fft (in + k * stride * n, out + k * stride * n, |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
82 n, howmany, stride, dist); |
4773 | 83 |
84 return retval; | |
85 } | |
86 | |
87 ComplexNDArray | |
4816 | 88 ComplexNDArray::ifourier (int dim) const |
4773 | 89 { |
90 dim_vector dv = dims (); | |
91 | |
21660
53728df3e4c9
maint: for clarity, call ndims() rather than length() on dimension vectors.
Rik <rik@octave.org>
parents:
21562
diff
changeset
|
92 if (dim > dv.ndims () || dim < 0) |
4773 | 93 return ComplexNDArray (); |
94 | |
5275 | 95 octave_idx_type stride = 1; |
96 octave_idx_type n = dv(dim); | |
4773 | 97 |
98 for (int i = 0; i < dim; i++) | |
99 stride *= dv(i); | |
100 | |
20218
b2100e1659ac
maint: Use cuddled parentheses when indexing dimension_vectors.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
101 octave_idx_type howmany = numel () / dv(dim); |
4773 | 102 howmany = (stride == 1 ? howmany : (howmany > stride ? stride : howmany)); |
20218
b2100e1659ac
maint: Use cuddled parentheses when indexing dimension_vectors.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
103 octave_idx_type nloop = (stride == 1 ? 1 : numel () / dv(dim) / stride); |
5275 | 104 octave_idx_type dist = (stride == 1 ? n : 1); |
4773 | 105 |
106 const Complex *in (fortran_vec ()); | |
107 ComplexNDArray retval (dv); | |
108 Complex *out (retval.fortran_vec ()); | |
109 | |
110 // Need to be careful here about the distance between fft's | |
5275 | 111 for (octave_idx_type k = 0; k < nloop; k++) |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
112 octave::fftw::ifft (in + k * stride * n, out + k * stride * n, |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
113 n, howmany, stride, dist); |
4773 | 114 |
115 return retval; | |
116 } | |
117 | |
118 ComplexNDArray | |
119 ComplexNDArray::fourier2d (void) const | |
120 { | |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14844
diff
changeset
|
121 dim_vector dv = dims (); |
21660
53728df3e4c9
maint: for clarity, call ndims() rather than length() on dimension vectors.
Rik <rik@octave.org>
parents:
21562
diff
changeset
|
122 if (dv.ndims () < 2) |
4773 | 123 return ComplexNDArray (); |
124 | |
20218
b2100e1659ac
maint: Use cuddled parentheses when indexing dimension_vectors.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
125 dim_vector dv2 (dv(0), dv(1)); |
4773 | 126 const Complex *in = fortran_vec (); |
127 ComplexNDArray retval (dv); | |
128 Complex *out = retval.fortran_vec (); | |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14844
diff
changeset
|
129 octave_idx_type howmany = numel () / dv(0) / dv(1); |
5275 | 130 octave_idx_type dist = dv(0) * dv(1); |
4773 | 131 |
5275 | 132 for (octave_idx_type i=0; i < howmany; i++) |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
133 octave::fftw::fftNd (in + i*dist, out + i*dist, 2, dv2); |
4773 | 134 |
135 return retval; | |
136 } | |
137 | |
138 ComplexNDArray | |
139 ComplexNDArray::ifourier2d (void) const | |
140 { | |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14844
diff
changeset
|
141 dim_vector dv = dims (); |
21660
53728df3e4c9
maint: for clarity, call ndims() rather than length() on dimension vectors.
Rik <rik@octave.org>
parents:
21562
diff
changeset
|
142 if (dv.ndims () < 2) |
4773 | 143 return ComplexNDArray (); |
144 | |
20218
b2100e1659ac
maint: Use cuddled parentheses when indexing dimension_vectors.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
145 dim_vector dv2 (dv(0), dv(1)); |
4773 | 146 const Complex *in = fortran_vec (); |
147 ComplexNDArray retval (dv); | |
148 Complex *out = retval.fortran_vec (); | |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14844
diff
changeset
|
149 octave_idx_type howmany = numel () / dv(0) / dv(1); |
5275 | 150 octave_idx_type dist = dv(0) * dv(1); |
4773 | 151 |
5275 | 152 for (octave_idx_type i=0; i < howmany; i++) |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
153 octave::fftw::ifftNd (in + i*dist, out + i*dist, 2, dv2); |
4773 | 154 |
155 return retval; | |
156 } | |
157 | |
158 ComplexNDArray | |
159 ComplexNDArray::fourierNd (void) const | |
160 { | |
161 dim_vector dv = dims (); | |
21660
53728df3e4c9
maint: for clarity, call ndims() rather than length() on dimension vectors.
Rik <rik@octave.org>
parents:
21562
diff
changeset
|
162 int rank = dv.ndims (); |
4773 | 163 |
164 const Complex *in (fortran_vec ()); | |
165 ComplexNDArray retval (dv); | |
166 Complex *out (retval.fortran_vec ()); | |
167 | |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
168 octave::fftw::fftNd (in, out, rank, dv); |
4773 | 169 |
170 return retval; | |
171 } | |
172 | |
173 ComplexNDArray | |
174 ComplexNDArray::ifourierNd (void) const | |
175 { | |
176 dim_vector dv = dims (); | |
21660
53728df3e4c9
maint: for clarity, call ndims() rather than length() on dimension vectors.
Rik <rik@octave.org>
parents:
21562
diff
changeset
|
177 int rank = dv.ndims (); |
4773 | 178 |
179 const Complex *in (fortran_vec ()); | |
180 ComplexNDArray retval (dv); | |
181 Complex *out (retval.fortran_vec ()); | |
182 | |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
183 octave::fftw::ifftNd (in, out, rank, dv); |
4773 | 184 |
185 return retval; | |
186 } | |
187 | |
188 #else | |
9523
0ce82753dd72
more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents:
9513
diff
changeset
|
189 |
4773 | 190 ComplexNDArray |
191 ComplexNDArray::fourier (int dim) const | |
192 { | |
25586 | 193 (*current_liboctave_error_handler) |
194 ("support for FFTW was unavailable or disabled when liboctave was built"); | |
4773 | 195 |
25586 | 196 return ComplexNDArray (); |
4773 | 197 } |
198 | |
199 ComplexNDArray | |
200 ComplexNDArray::ifourier (int dim) const | |
201 { | |
25586 | 202 (*current_liboctave_error_handler) |
203 ("support for FFTW was unavailable or disabled when liboctave was built"); | |
4773 | 204 |
25586 | 205 return ComplexNDArray (); |
4773 | 206 } |
207 | |
208 ComplexNDArray | |
209 ComplexNDArray::fourier2d (void) const | |
210 { | |
25586 | 211 (*current_liboctave_error_handler) |
212 ("support for FFTW was unavailable or disabled when liboctave was built"); | |
4773 | 213 |
25586 | 214 return ComplexNDArray (); |
4773 | 215 } |
216 | |
217 ComplexNDArray | |
218 ComplexNDArray::ifourier2d (void) const | |
219 { | |
25586 | 220 (*current_liboctave_error_handler) |
221 ("support for FFTW was unavailable or disabled when liboctave was built"); | |
4773 | 222 |
25586 | 223 return ComplexNDArray (); |
4773 | 224 } |
225 | |
226 ComplexNDArray | |
227 ComplexNDArray::fourierNd (void) const | |
228 { | |
25586 | 229 (*current_liboctave_error_handler) |
230 ("support for FFTW was unavailable or disabled when liboctave was built"); | |
4773 | 231 |
25586 | 232 return ComplexNDArray (); |
4773 | 233 } |
234 | |
235 ComplexNDArray | |
236 ComplexNDArray::ifourierNd (void) const | |
237 { | |
25586 | 238 (*current_liboctave_error_handler) |
239 ("support for FFTW was unavailable or disabled when liboctave was built"); | |
4773 | 240 |
25586 | 241 return ComplexNDArray (); |
4773 | 242 } |
243 | |
244 #endif | |
245 | |
4543 | 246 // unary operations |
247 | |
248 boolNDArray | |
249 ComplexNDArray::operator ! (void) const | |
250 { | |
11130
7c573eb981eb
consistently give error for operator not applied to NaN values
John W. Eaton <jwe@octave.org>
parents:
11008
diff
changeset
|
251 if (any_element_is_nan ()) |
22327
d0562b3159c7
move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
252 octave::err_nan_to_logical_conversion (); |
11130
7c573eb981eb
consistently give error for operator not applied to NaN values
John W. Eaton <jwe@octave.org>
parents:
11008
diff
changeset
|
253 |
10362
b47ab50a6aa8
simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
254 return do_mx_unary_op<bool, Complex> (*this, mx_inline_not); |
4543 | 255 } |
256 | |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
257 // FIXME: this is not quite the right thing. |
4514 | 258 |
4687 | 259 bool |
7922
935be827eaf8
error for NaN values in & and | expressions
John W. Eaton <jwe@octave.org>
parents:
7789
diff
changeset
|
260 ComplexNDArray::any_element_is_nan (void) const |
935be827eaf8
error for NaN values in & and | expressions
John W. Eaton <jwe@octave.org>
parents:
7789
diff
changeset
|
261 { |
11008
3622db30ff05
simplify some array tests in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10362
diff
changeset
|
262 return do_mx_check<Complex> (*this, mx_inline_any_nan); |
7922
935be827eaf8
error for NaN values in & and | expressions
John W. Eaton <jwe@octave.org>
parents:
7789
diff
changeset
|
263 } |
935be827eaf8
error for NaN values in & and | expressions
John W. Eaton <jwe@octave.org>
parents:
7789
diff
changeset
|
264 |
935be827eaf8
error for NaN values in & and | expressions
John W. Eaton <jwe@octave.org>
parents:
7789
diff
changeset
|
265 bool |
4687 | 266 ComplexNDArray::any_element_is_inf_or_nan (void) const |
267 { | |
11008
3622db30ff05
simplify some array tests in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10362
diff
changeset
|
268 return ! do_mx_check<Complex> (*this, mx_inline_all_finite); |
4687 | 269 } |
270 | |
271 // Return true if no elements have imaginary components. | |
272 | |
273 bool | |
274 ComplexNDArray::all_elements_are_real (void) const | |
275 { | |
11008
3622db30ff05
simplify some array tests in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10362
diff
changeset
|
276 return do_mx_check<Complex> (*this, mx_inline_all_real); |
4687 | 277 } |
278 | |
279 // Return nonzero if any element of CM has a non-integer real or | |
280 // imaginary part. Also extract the largest and smallest (real or | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
281 // imaginary) values and return them in MAX_VAL and MIN_VAL. |
4687 | 282 |
283 bool | |
284 ComplexNDArray::all_integers (double& max_val, double& min_val) const | |
285 { | |
20228
00cf2847355d
Deprecate Array::nelem() and Range::nelem() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20218
diff
changeset
|
286 octave_idx_type nel = numel (); |
4687 | 287 |
288 if (nel > 0) | |
289 { | |
290 Complex val = elem (0); | |
291 | |
22274
edcad35c364f
don't rely on std:: overloads of arg, conj, imag, and real for real args
John W. Eaton <jwe@octave.org>
parents:
22261
diff
changeset
|
292 double r_val = val.real (); |
edcad35c364f
don't rely on std:: overloads of arg, conj, imag, and real for real args
John W. Eaton <jwe@octave.org>
parents:
22261
diff
changeset
|
293 double i_val = val.imag (); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
294 |
4687 | 295 max_val = r_val; |
296 min_val = r_val; | |
297 | |
298 if (i_val > max_val) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
299 max_val = i_val; |
4687 | 300 |
301 if (i_val < max_val) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
302 min_val = i_val; |
4687 | 303 } |
304 else | |
305 return false; | |
306 | |
5275 | 307 for (octave_idx_type i = 0; i < nel; i++) |
4687 | 308 { |
309 Complex val = elem (i); | |
310 | |
22274
edcad35c364f
don't rely on std:: overloads of arg, conj, imag, and real for real args
John W. Eaton <jwe@octave.org>
parents:
22261
diff
changeset
|
311 double r_val = val.real (); |
edcad35c364f
don't rely on std:: overloads of arg, conj, imag, and real for real args
John W. Eaton <jwe@octave.org>
parents:
22261
diff
changeset
|
312 double i_val = val.imag (); |
4687 | 313 |
314 if (r_val > max_val) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
315 max_val = r_val; |
4687 | 316 |
317 if (i_val > max_val) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
318 max_val = i_val; |
4687 | 319 |
320 if (r_val < min_val) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
321 min_val = r_val; |
4687 | 322 |
323 if (i_val < min_val) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
324 min_val = i_val; |
4687 | 325 |
22402
4caa7b28d183
maint: Style check C++ code in liboctave/
Rik <rik@octave.org>
parents:
22327
diff
changeset
|
326 if (octave::math::x_nint (r_val) != r_val |
4caa7b28d183
maint: Style check C++ code in liboctave/
Rik <rik@octave.org>
parents:
22327
diff
changeset
|
327 || octave::math::x_nint (i_val) != i_val) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
328 return false; |
4687 | 329 } |
330 | |
331 return true; | |
332 } | |
333 | |
334 bool | |
335 ComplexNDArray::too_large_for_float (void) const | |
336 { | |
15212
4bbd3bbb8912
reduce code duplication in too_large_for_float array functions
John W. Eaton <jwe@octave.org>
parents:
15018
diff
changeset
|
337 return test_any (xtoo_large_for_float); |
4687 | 338 } |
339 | |
4556 | 340 boolNDArray |
4514 | 341 ComplexNDArray::all (int dim) const |
342 { | |
10362
b47ab50a6aa8
simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
343 return do_mx_red_op<bool, Complex> (*this, dim, mx_inline_all); |
4514 | 344 } |
345 | |
4556 | 346 boolNDArray |
4514 | 347 ComplexNDArray::any (int dim) const |
348 { | |
10362
b47ab50a6aa8
simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
349 return do_mx_red_op<bool, Complex> (*this, dim, mx_inline_any); |
4569 | 350 } |
351 | |
4584 | 352 ComplexNDArray |
4569 | 353 ComplexNDArray::cumprod (int dim) const |
354 { | |
10362
b47ab50a6aa8
simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
355 return do_mx_cum_op<Complex, Complex> (*this, dim, mx_inline_cumprod); |
4569 | 356 } |
357 | |
4584 | 358 ComplexNDArray |
4569 | 359 ComplexNDArray::cumsum (int dim) const |
360 { | |
10362
b47ab50a6aa8
simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
361 return do_mx_cum_op<Complex, Complex> (*this, dim, mx_inline_cumsum); |
4569 | 362 } |
363 | |
364 ComplexNDArray | |
365 ComplexNDArray::prod (int dim) const | |
366 { | |
10362
b47ab50a6aa8
simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
367 return do_mx_red_op<Complex, Complex> (*this, dim, mx_inline_prod); |
8736
53b4fdeacc2e
improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8650
diff
changeset
|
368 } |
53b4fdeacc2e
improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8650
diff
changeset
|
369 |
53b4fdeacc2e
improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8650
diff
changeset
|
370 ComplexNDArray |
53b4fdeacc2e
improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8650
diff
changeset
|
371 ComplexNDArray::sum (int dim) const |
53b4fdeacc2e
improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8650
diff
changeset
|
372 { |
10362
b47ab50a6aa8
simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
373 return do_mx_red_op<Complex, Complex> (*this, dim, mx_inline_sum); |
4569 | 374 } |
375 | |
376 ComplexNDArray | |
9721
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9612
diff
changeset
|
377 ComplexNDArray::xsum (int dim) const |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9612
diff
changeset
|
378 { |
10362
b47ab50a6aa8
simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
379 return do_mx_red_op<Complex, Complex> (*this, dim, mx_inline_xsum); |
9721
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9612
diff
changeset
|
380 } |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9612
diff
changeset
|
381 |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9612
diff
changeset
|
382 ComplexNDArray |
4569 | 383 ComplexNDArray::sumsq (int dim) const |
384 { | |
10362
b47ab50a6aa8
simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
385 return do_mx_red_op<double, Complex> (*this, dim, mx_inline_sumsq); |
4569 | 386 } |
387 | |
4915 | 388 ComplexNDArray |
9513
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9469
diff
changeset
|
389 ComplexNDArray::diff (octave_idx_type order, int dim) const |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9469
diff
changeset
|
390 { |
10362
b47ab50a6aa8
simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
391 return do_mx_diff_op<Complex> (*this, dim, order, mx_inline_diff); |
9513
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9469
diff
changeset
|
392 } |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9469
diff
changeset
|
393 |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9469
diff
changeset
|
394 ComplexNDArray |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
395 ComplexNDArray::concat (const ComplexNDArray& rb, |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
396 const Array<octave_idx_type>& ra_idx) |
4915 | 397 { |
4940 | 398 if (rb.numel () > 0) |
5073 | 399 insert (rb, ra_idx); |
400 return *this; | |
4915 | 401 } |
402 | |
403 ComplexNDArray | |
5275 | 404 ComplexNDArray::concat (const NDArray& rb, const Array<octave_idx_type>& ra_idx) |
4758 | 405 { |
4915 | 406 ComplexNDArray tmp (rb); |
4940 | 407 if (rb.numel () > 0) |
5073 | 408 insert (tmp, ra_idx); |
409 return *this; | |
4915 | 410 } |
411 | |
412 ComplexNDArray | |
5275 | 413 concat (NDArray& ra, ComplexNDArray& rb, const Array<octave_idx_type>& ra_idx) |
4915 | 414 { |
415 ComplexNDArray retval (ra); | |
4940 | 416 if (rb.numel () > 0) |
4915 | 417 retval.insert (rb, ra_idx); |
418 return retval; | |
4758 | 419 } |
420 | |
21723
bae585228161
use namespace for numeric_limits
John W. Eaton <jwe@octave.org>
parents:
21721
diff
changeset
|
421 static const Complex Complex_NaN_result (octave::numeric_limits<double>::NaN (), |
bae585228161
use namespace for numeric_limits
John W. Eaton <jwe@octave.org>
parents:
21721
diff
changeset
|
422 octave::numeric_limits<double>::NaN ()); |
4844 | 423 |
424 ComplexNDArray | |
425 ComplexNDArray::max (int dim) const | |
426 { | |
10362
b47ab50a6aa8
simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
427 return do_mx_minmax_op<Complex> (*this, dim, mx_inline_max); |
4844 | 428 } |
429 | |
430 ComplexNDArray | |
9732
b4fdfee405b5
remove ArrayN<T> + fix nonhom. diag-scalar ops
Jaroslav Hajek <highegg@gmail.com>
parents:
9721
diff
changeset
|
431 ComplexNDArray::max (Array<octave_idx_type>& idx_arg, int dim) const |
4844 | 432 { |
10362
b47ab50a6aa8
simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
433 return do_mx_minmax_op<Complex> (*this, idx_arg, dim, mx_inline_max); |
4844 | 434 } |
435 | |
436 ComplexNDArray | |
437 ComplexNDArray::min (int dim) const | |
438 { | |
10362
b47ab50a6aa8
simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
439 return do_mx_minmax_op<Complex> (*this, dim, mx_inline_min); |
4844 | 440 } |
441 | |
442 ComplexNDArray | |
9732
b4fdfee405b5
remove ArrayN<T> + fix nonhom. diag-scalar ops
Jaroslav Hajek <highegg@gmail.com>
parents:
9721
diff
changeset
|
443 ComplexNDArray::min (Array<octave_idx_type>& idx_arg, int dim) const |
4844 | 444 { |
10362
b47ab50a6aa8
simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
445 return do_mx_minmax_op<Complex> (*this, idx_arg, dim, mx_inline_min); |
4844 | 446 } |
447 | |
8777
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8774
diff
changeset
|
448 ComplexNDArray |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8774
diff
changeset
|
449 ComplexNDArray::cummax (int dim) const |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8774
diff
changeset
|
450 { |
10362
b47ab50a6aa8
simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
451 return do_mx_cumminmax_op<Complex> (*this, dim, mx_inline_cummax); |
8777
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8774
diff
changeset
|
452 } |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8774
diff
changeset
|
453 |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8774
diff
changeset
|
454 ComplexNDArray |
9732
b4fdfee405b5
remove ArrayN<T> + fix nonhom. diag-scalar ops
Jaroslav Hajek <highegg@gmail.com>
parents:
9721
diff
changeset
|
455 ComplexNDArray::cummax (Array<octave_idx_type>& idx_arg, int dim) const |
8777
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8774
diff
changeset
|
456 { |
10362
b47ab50a6aa8
simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
457 return do_mx_cumminmax_op<Complex> (*this, idx_arg, dim, mx_inline_cummax); |
8777
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8774
diff
changeset
|
458 } |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8774
diff
changeset
|
459 |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8774
diff
changeset
|
460 ComplexNDArray |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8774
diff
changeset
|
461 ComplexNDArray::cummin (int dim) const |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8774
diff
changeset
|
462 { |
10362
b47ab50a6aa8
simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
463 return do_mx_cumminmax_op<Complex> (*this, dim, mx_inline_cummin); |
8777
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8774
diff
changeset
|
464 } |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8774
diff
changeset
|
465 |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8774
diff
changeset
|
466 ComplexNDArray |
9732
b4fdfee405b5
remove ArrayN<T> + fix nonhom. diag-scalar ops
Jaroslav Hajek <highegg@gmail.com>
parents:
9721
diff
changeset
|
467 ComplexNDArray::cummin (Array<octave_idx_type>& idx_arg, int dim) const |
8777
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8774
diff
changeset
|
468 { |
10362
b47ab50a6aa8
simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
469 return do_mx_cumminmax_op<Complex> (*this, idx_arg, dim, mx_inline_cummin); |
8777
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8774
diff
changeset
|
470 } |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8774
diff
changeset
|
471 |
4634 | 472 NDArray |
4569 | 473 ComplexNDArray::abs (void) const |
474 { | |
10362
b47ab50a6aa8
simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
475 return do_mx_unary_map<double, Complex, std::abs> (*this); |
8650
a1ae2aae903e
abs,real,imag,conj: use code from mx-inlines rather than the generic map
Jaroslav Hajek <highegg@gmail.com>
parents:
8377
diff
changeset
|
476 } |
4634 | 477 |
8998
a48fba01e4ac
optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents:
8981
diff
changeset
|
478 boolNDArray |
a48fba01e4ac
optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents:
8981
diff
changeset
|
479 ComplexNDArray::isnan (void) const |
a48fba01e4ac
optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents:
8981
diff
changeset
|
480 { |
21782
2aef506f3fec
use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
481 return do_mx_unary_map<bool, Complex, octave::math::isnan> (*this); |
8998
a48fba01e4ac
optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents:
8981
diff
changeset
|
482 } |
a48fba01e4ac
optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents:
8981
diff
changeset
|
483 |
a48fba01e4ac
optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents:
8981
diff
changeset
|
484 boolNDArray |
a48fba01e4ac
optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents:
8981
diff
changeset
|
485 ComplexNDArray::isinf (void) const |
a48fba01e4ac
optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents:
8981
diff
changeset
|
486 { |
21782
2aef506f3fec
use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
487 return do_mx_unary_map<bool, Complex, octave::math::isinf> (*this); |
8998
a48fba01e4ac
optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents:
8981
diff
changeset
|
488 } |
a48fba01e4ac
optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents:
8981
diff
changeset
|
489 |
a48fba01e4ac
optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents:
8981
diff
changeset
|
490 boolNDArray |
a48fba01e4ac
optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents:
8981
diff
changeset
|
491 ComplexNDArray::isfinite (void) const |
a48fba01e4ac
optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents:
8981
diff
changeset
|
492 { |
23564
7049da1648c0
Deprecate octave::math::finite in favor of octave::math::isfinite.
Rik <rik@octave.org>
parents:
23534
diff
changeset
|
493 return do_mx_unary_map<bool, Complex, octave::math::isfinite> (*this); |
8998
a48fba01e4ac
optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents:
8981
diff
changeset
|
494 } |
a48fba01e4ac
optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents:
8981
diff
changeset
|
495 |
8650
a1ae2aae903e
abs,real,imag,conj: use code from mx-inlines rather than the generic map
Jaroslav Hajek <highegg@gmail.com>
parents:
8377
diff
changeset
|
496 ComplexNDArray |
a1ae2aae903e
abs,real,imag,conj: use code from mx-inlines rather than the generic map
Jaroslav Hajek <highegg@gmail.com>
parents:
8377
diff
changeset
|
497 conj (const ComplexNDArray& a) |
a1ae2aae903e
abs,real,imag,conj: use code from mx-inlines rather than the generic map
Jaroslav Hajek <highegg@gmail.com>
parents:
8377
diff
changeset
|
498 { |
23534
b6498c088fca
maint: Don't write '> >' for declaration of templates that use templates.
Rik <rik@octave.org>
parents:
23461
diff
changeset
|
499 return do_mx_unary_map<Complex, Complex, std::conj<double>> (a); |
4514 | 500 } |
501 | |
4765 | 502 ComplexNDArray& |
5275 | 503 ComplexNDArray::insert (const NDArray& a, octave_idx_type r, octave_idx_type c) |
4765 | 504 { |
505 dim_vector a_dv = a.dims (); | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
506 |
21660
53728df3e4c9
maint: for clarity, call ndims() rather than length() on dimension vectors.
Rik <rik@octave.org>
parents:
21562
diff
changeset
|
507 int n = a_dv.ndims (); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
508 |
21660
53728df3e4c9
maint: for clarity, call ndims() rather than length() on dimension vectors.
Rik <rik@octave.org>
parents:
21562
diff
changeset
|
509 if (n != dimensions.ndims ()) |
4765 | 510 (*current_liboctave_error_handler) |
511 ("Array<T>::insert: invalid indexing operation"); | |
512 | |
21660
53728df3e4c9
maint: for clarity, call ndims() rather than length() on dimension vectors.
Rik <rik@octave.org>
parents:
21562
diff
changeset
|
513 Array<octave_idx_type> a_ra_idx (dim_vector (a_dv.ndims (), 1), 0); |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
514 |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
515 a_ra_idx.elem (0) = r; |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
516 a_ra_idx.elem (1) = c; |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
517 |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
518 for (int i = 0; i < n; i++) |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
519 { |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
520 if (a_ra_idx(i) < 0 || (a_ra_idx(i) + a_dv(i)) > dimensions(i)) |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
521 (*current_liboctave_error_handler) |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
522 ("Array<T>::insert: range error for insert"); |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
523 } |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
524 |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
525 a_ra_idx.elem (0) = 0; |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
526 a_ra_idx.elem (1) = 0; |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
527 |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
528 octave_idx_type n_elt = a.numel (); |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
529 |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
530 // IS make_unique () NECESSARY HERE? |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
531 |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
532 for (octave_idx_type i = 0; i < n_elt; i++) |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
533 { |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
534 Array<octave_idx_type> ra_idx = a_ra_idx; |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
535 |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
536 ra_idx.elem (0) = a_ra_idx(0) + r; |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
537 ra_idx.elem (1) = a_ra_idx(1) + c; |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
538 |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
539 elem (ra_idx) = a.elem (a_ra_idx); |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
540 |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
541 increment_index (a_ra_idx, a_dv); |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
542 } |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
543 |
4765 | 544 return *this; |
545 } | |
546 | |
547 ComplexNDArray& | |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
548 ComplexNDArray::insert (const ComplexNDArray& a, |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
549 octave_idx_type r, octave_idx_type c) |
4765 | 550 { |
551 Array<Complex>::insert (a, r, c); | |
552 return *this; | |
553 } | |
554 | |
4915 | 555 ComplexNDArray& |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
556 ComplexNDArray::insert (const ComplexNDArray& a, |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
557 const Array<octave_idx_type>& ra_idx) |
4915 | 558 { |
559 Array<Complex>::insert (a, ra_idx); | |
560 return *this; | |
561 } | |
562 | |
4532 | 563 void |
5275 | 564 ComplexNDArray::increment_index (Array<octave_idx_type>& ra_idx, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
565 const dim_vector& dimensions, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
566 int start_dimension) |
4532 | 567 { |
568 ::increment_index (ra_idx, dimensions, start_dimension); | |
569 } | |
570 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
571 octave_idx_type |
5275 | 572 ComplexNDArray::compute_index (Array<octave_idx_type>& ra_idx, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
573 const dim_vector& dimensions) |
4556 | 574 { |
575 return ::compute_index (ra_idx, dimensions); | |
576 } | |
577 | |
7620
36594d5bbe13
Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents:
7600
diff
changeset
|
578 ComplexNDArray |
36594d5bbe13
Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents:
7600
diff
changeset
|
579 ComplexNDArray::diag (octave_idx_type k) const |
36594d5bbe13
Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents:
7600
diff
changeset
|
580 { |
10350
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10329
diff
changeset
|
581 return MArray<Complex>::diag (k); |
7620
36594d5bbe13
Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents:
7600
diff
changeset
|
582 } |
36594d5bbe13
Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents:
7600
diff
changeset
|
583 |
14557
e8e86ae3abbc
make diag (x, m, n) return a proper diagonal matrix object (bug #36099)
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
584 ComplexNDArray |
e8e86ae3abbc
make diag (x, m, n) return a proper diagonal matrix object (bug #36099)
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
585 ComplexNDArray::diag (octave_idx_type m, octave_idx_type n) const |
e8e86ae3abbc
make diag (x, m, n) return a proper diagonal matrix object (bug #36099)
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
586 { |
e8e86ae3abbc
make diag (x, m, n) return a proper diagonal matrix object (bug #36099)
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
587 return MArray<Complex>::diag (m, n); |
e8e86ae3abbc
make diag (x, m, n) return a proper diagonal matrix object (bug #36099)
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
588 } |
e8e86ae3abbc
make diag (x, m, n) return a proper diagonal matrix object (bug #36099)
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
589 |
4687 | 590 // This contains no information on the array structure !!! |
591 std::ostream& | |
592 operator << (std::ostream& os, const ComplexNDArray& a) | |
593 { | |
20228
00cf2847355d
Deprecate Array::nelem() and Range::nelem() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20218
diff
changeset
|
594 octave_idx_type nel = a.numel (); |
4687 | 595 |
5275 | 596 for (octave_idx_type i = 0; i < nel; i++) |
4687 | 597 { |
23807
336f89b6208b
Use character literals 'c' rather than string literals "c" when possible.
Rik <rik@octave.org>
parents:
23564
diff
changeset
|
598 os << ' '; |
4687 | 599 octave_write_complex (os, a.elem (i)); |
600 os << "\n"; | |
601 } | |
602 return os; | |
603 } | |
604 | |
605 std::istream& | |
606 operator >> (std::istream& is, ComplexNDArray& a) | |
607 { | |
20228
00cf2847355d
Deprecate Array::nelem() and Range::nelem() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20218
diff
changeset
|
608 octave_idx_type nel = a.numel (); |
4687 | 609 |
8999
dc07bc4157b8
allow empty matrices in stream input operators
Jaroslav Hajek <highegg@gmail.com>
parents:
8998
diff
changeset
|
610 if (nel > 0) |
4687 | 611 { |
612 Complex tmp; | |
5275 | 613 for (octave_idx_type i = 0; i < nel; i++) |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
614 { |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
615 tmp = octave_read_value<Complex> (is); |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
616 if (is) |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
617 a.elem (i) = tmp; |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
618 else |
21168
26f85aa072de
maint: Replace instances of goto in liboctave where convenient.
Rik <rik@octave.org>
parents:
21136
diff
changeset
|
619 return is; |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
620 } |
4687 | 621 } |
622 | |
623 return is; | |
624 } | |
625 | |
10329
83fa590b8a09
simplify min/max definitions in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10314
diff
changeset
|
626 MINMAX_FCNS (ComplexNDArray, Complex) |
4844 | 627 |
9578
7dafdb8b062f
refactor comparison ops implementations
Jaroslav Hajek <highegg@gmail.com>
parents:
9553
diff
changeset
|
628 NDS_CMP_OPS (ComplexNDArray, Complex) |
9550
3d6a9aea2aea
refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
9546
diff
changeset
|
629 NDS_BOOL_OPS (ComplexNDArray, Complex) |
4543 | 630 |
9578
7dafdb8b062f
refactor comparison ops implementations
Jaroslav Hajek <highegg@gmail.com>
parents:
9553
diff
changeset
|
631 SND_CMP_OPS (Complex, ComplexNDArray) |
9550
3d6a9aea2aea
refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
9546
diff
changeset
|
632 SND_BOOL_OPS (Complex, ComplexNDArray) |
4543 | 633 |
9578
7dafdb8b062f
refactor comparison ops implementations
Jaroslav Hajek <highegg@gmail.com>
parents:
9553
diff
changeset
|
634 NDND_CMP_OPS (ComplexNDArray, ComplexNDArray) |
9550
3d6a9aea2aea
refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
9546
diff
changeset
|
635 NDND_BOOL_OPS (ComplexNDArray, ComplexNDArray) |
4543 | 636 |
9546
1beb23d2b892
optimize op= in common cases
Jaroslav Hajek <highegg@gmail.com>
parents:
9523
diff
changeset
|
637 ComplexNDArray& operator *= (ComplexNDArray& a, double s) |
1beb23d2b892
optimize op= in common cases
Jaroslav Hajek <highegg@gmail.com>
parents:
9523
diff
changeset
|
638 { |
1beb23d2b892
optimize op= in common cases
Jaroslav Hajek <highegg@gmail.com>
parents:
9523
diff
changeset
|
639 if (a.is_shared ()) |
9612
66970dd627f6
further liboctave design improvements
Jaroslav Hajek <highegg@gmail.com>
parents:
9601
diff
changeset
|
640 a = a * s; |
66970dd627f6
further liboctave design improvements
Jaroslav Hajek <highegg@gmail.com>
parents:
9601
diff
changeset
|
641 else |
10362
b47ab50a6aa8
simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
642 do_ms_inplace_op<Complex, double> (a, s, mx_inline_mul2); |
9546
1beb23d2b892
optimize op= in common cases
Jaroslav Hajek <highegg@gmail.com>
parents:
9523
diff
changeset
|
643 return a; |
1beb23d2b892
optimize op= in common cases
Jaroslav Hajek <highegg@gmail.com>
parents:
9523
diff
changeset
|
644 } |
1beb23d2b892
optimize op= in common cases
Jaroslav Hajek <highegg@gmail.com>
parents:
9523
diff
changeset
|
645 |
1beb23d2b892
optimize op= in common cases
Jaroslav Hajek <highegg@gmail.com>
parents:
9523
diff
changeset
|
646 ComplexNDArray& operator /= (ComplexNDArray& a, double s) |
1beb23d2b892
optimize op= in common cases
Jaroslav Hajek <highegg@gmail.com>
parents:
9523
diff
changeset
|
647 { |
1beb23d2b892
optimize op= in common cases
Jaroslav Hajek <highegg@gmail.com>
parents:
9523
diff
changeset
|
648 if (a.is_shared ()) |
1beb23d2b892
optimize op= in common cases
Jaroslav Hajek <highegg@gmail.com>
parents:
9523
diff
changeset
|
649 return a = a / s; |
9612
66970dd627f6
further liboctave design improvements
Jaroslav Hajek <highegg@gmail.com>
parents:
9601
diff
changeset
|
650 else |
10362
b47ab50a6aa8
simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
651 do_ms_inplace_op<Complex, double> (a, s, mx_inline_div2); |
9546
1beb23d2b892
optimize op= in common cases
Jaroslav Hajek <highegg@gmail.com>
parents:
9523
diff
changeset
|
652 return a; |
1beb23d2b892
optimize op= in common cases
Jaroslav Hajek <highegg@gmail.com>
parents:
9523
diff
changeset
|
653 } |
1beb23d2b892
optimize op= in common cases
Jaroslav Hajek <highegg@gmail.com>
parents:
9523
diff
changeset
|
654 |
9743
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
655 BSXFUN_STDOP_DEFS_MXLOOP (ComplexNDArray) |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
656 BSXFUN_STDREL_DEFS_MXLOOP (ComplexNDArray) |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
657 |
9827
c15a5ed0da58
optimize bsxfun (@power, ...)
Jaroslav Hajek <highegg@gmail.com>
parents:
9825
diff
changeset
|
658 BSXFUN_OP_DEF_MXLOOP (pow, ComplexNDArray, mx_inline_pow) |