Mercurial > hg > octave-lyh
annotate liboctave/CNDArray.cc @ 9721:192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Tue, 13 Oct 2009 12:22:50 +0200 |
parents | 66970dd627f6 |
children | b4fdfee405b5 |
rev | line source |
---|---|
4514 | 1 // N-D Array manipulations. |
2 /* | |
3 | |
8920 | 4 Copyright (C) 1996, 1997, 2003, 2004, 2005, 2006, 2007, 2008, |
5 2009 John W. Eaton | |
9601
a9b37bae1802
add a couple of missing copyright statements
Jaroslav Hajek <highegg@gmail.com>
parents:
9578
diff
changeset
|
6 Copyright (C) 2009 VZLU Prague, a.s. |
4514 | 7 |
8 This file is part of Octave. | |
9 | |
10 Octave is free software; you can redistribute it and/or modify it | |
11 under the terms of the GNU General Public License as published by the | |
7016 | 12 Free Software Foundation; either version 3 of the License, or (at your |
13 option) any later version. | |
4514 | 14 |
15 Octave is distributed in the hope that it will be useful, but WITHOUT | |
16 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
17 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
18 for more details. | |
19 | |
20 You should have received a copy of the GNU General Public License | |
7016 | 21 along with Octave; see the file COPYING. If not, see |
22 <http://www.gnu.org/licenses/>. | |
4514 | 23 |
24 */ | |
25 | |
26 #ifdef HAVE_CONFIG_H | |
27 #include <config.h> | |
28 #endif | |
29 | |
4687 | 30 #include <cfloat> |
5164 | 31 |
4780 | 32 #include <vector> |
4687 | 33 |
4588 | 34 #include "Array-util.h" |
4514 | 35 #include "CNDArray.h" |
4773 | 36 #include "f77-fcn.h" |
7503
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
37 #include "functor.h" |
4514 | 38 #include "lo-ieee.h" |
4687 | 39 #include "lo-mappers.h" |
9546
1beb23d2b892
optimize op= in common cases
Jaroslav Hajek <highegg@gmail.com>
parents:
9523
diff
changeset
|
40 #include "MArray-defs.h" |
9523
0ce82753dd72
more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents:
9513
diff
changeset
|
41 #include "mx-base.h" |
8774
b756ce0002db
split implementation and interface in mx-op-defs and MArray-defs
Jaroslav Hajek <highegg@gmail.com>
parents:
8751
diff
changeset
|
42 #include "mx-op-defs.h" |
4780 | 43 #include "oct-fftw.h" |
9523
0ce82753dd72
more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents:
9513
diff
changeset
|
44 #include "oct-locbuf.h" |
4773 | 45 |
8956
d91fa4b20bbb
ensure nonnegative char -> real conversion
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
46 ComplexNDArray::ComplexNDArray (const charNDArray& a) |
d91fa4b20bbb
ensure nonnegative char -> real conversion
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
47 : MArrayN<Complex> (a.dims ()) |
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 | |
61 if (dim > dv.length () || dim < 0) | |
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 | |
5275 | 70 octave_idx_type howmany = numel () / dv (dim); |
4773 | 71 howmany = (stride == 1 ? howmany : (howmany > stride ? stride : howmany)); |
5275 | 72 octave_idx_type nloop = (stride == 1 ? 1 : numel () / dv (dim) / stride); |
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++) |
4773 | 81 octave_fftw::fft (in + k * stride * n, out + k * stride * n, |
82 n, howmany, stride, dist); | |
83 | |
84 return retval; | |
85 } | |
86 | |
87 ComplexNDArray | |
4816 | 88 ComplexNDArray::ifourier (int dim) const |
4773 | 89 { |
90 dim_vector dv = dims (); | |
91 | |
92 if (dim > dv.length () || dim < 0) | |
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 | |
5275 | 101 octave_idx_type howmany = numel () / dv (dim); |
4773 | 102 howmany = (stride == 1 ? howmany : (howmany > stride ? stride : howmany)); |
5275 | 103 octave_idx_type nloop = (stride == 1 ? 1 : numel () / dv (dim) / stride); |
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++) |
4773 | 112 octave_fftw::ifft (in + k * stride * n, out + k * stride * n, |
113 n, howmany, stride, dist); | |
114 | |
115 return retval; | |
116 } | |
117 | |
118 ComplexNDArray | |
119 ComplexNDArray::fourier2d (void) const | |
120 { | |
121 dim_vector dv = dims(); | |
122 if (dv.length () < 2) | |
123 return ComplexNDArray (); | |
124 | |
125 dim_vector dv2(dv(0), dv(1)); | |
126 const Complex *in = fortran_vec (); | |
127 ComplexNDArray retval (dv); | |
128 Complex *out = retval.fortran_vec (); | |
5275 | 129 octave_idx_type howmany = numel() / dv(0) / dv(1); |
130 octave_idx_type dist = dv(0) * dv(1); | |
4773 | 131 |
5275 | 132 for (octave_idx_type i=0; i < howmany; i++) |
4773 | 133 octave_fftw::fftNd (in + i*dist, out + i*dist, 2, dv2); |
134 | |
135 return retval; | |
136 } | |
137 | |
138 ComplexNDArray | |
139 ComplexNDArray::ifourier2d (void) const | |
140 { | |
141 dim_vector dv = dims(); | |
142 if (dv.length () < 2) | |
143 return ComplexNDArray (); | |
144 | |
145 dim_vector dv2(dv(0), dv(1)); | |
146 const Complex *in = fortran_vec (); | |
147 ComplexNDArray retval (dv); | |
148 Complex *out = retval.fortran_vec (); | |
5275 | 149 octave_idx_type howmany = numel() / dv(0) / dv(1); |
150 octave_idx_type dist = dv(0) * dv(1); | |
4773 | 151 |
5275 | 152 for (octave_idx_type i=0; i < howmany; i++) |
4773 | 153 octave_fftw::ifftNd (in + i*dist, out + i*dist, 2, dv2); |
154 | |
155 return retval; | |
156 } | |
157 | |
158 ComplexNDArray | |
159 ComplexNDArray::fourierNd (void) const | |
160 { | |
161 dim_vector dv = dims (); | |
162 int rank = dv.length (); | |
163 | |
164 const Complex *in (fortran_vec ()); | |
165 ComplexNDArray retval (dv); | |
166 Complex *out (retval.fortran_vec ()); | |
167 | |
168 octave_fftw::fftNd (in, out, rank, dv); | |
169 | |
170 return retval; | |
171 } | |
172 | |
173 ComplexNDArray | |
174 ComplexNDArray::ifourierNd (void) const | |
175 { | |
176 dim_vector dv = dims (); | |
177 int rank = dv.length (); | |
178 | |
179 const Complex *in (fortran_vec ()); | |
180 ComplexNDArray retval (dv); | |
181 Complex *out (retval.fortran_vec ()); | |
182 | |
183 octave_fftw::ifftNd (in, out, rank, dv); | |
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 |
0ce82753dd72
more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents:
9513
diff
changeset
|
190 extern "C" |
0ce82753dd72
more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents:
9513
diff
changeset
|
191 { |
0ce82753dd72
more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents:
9513
diff
changeset
|
192 // Note that the original complex fft routines were not written for |
0ce82753dd72
more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents:
9513
diff
changeset
|
193 // double complex arguments. They have been modified by adding an |
0ce82753dd72
more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents:
9513
diff
changeset
|
194 // implicit double precision (a-h,o-z) statement at the beginning of |
0ce82753dd72
more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents:
9513
diff
changeset
|
195 // each subroutine. |
0ce82753dd72
more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents:
9513
diff
changeset
|
196 |
0ce82753dd72
more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents:
9513
diff
changeset
|
197 F77_RET_T |
0ce82753dd72
more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents:
9513
diff
changeset
|
198 F77_FUNC (zffti, ZFFTI) (const octave_idx_type&, Complex*); |
0ce82753dd72
more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents:
9513
diff
changeset
|
199 |
0ce82753dd72
more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents:
9513
diff
changeset
|
200 F77_RET_T |
0ce82753dd72
more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents:
9513
diff
changeset
|
201 F77_FUNC (zfftf, ZFFTF) (const octave_idx_type&, Complex*, Complex*); |
0ce82753dd72
more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents:
9513
diff
changeset
|
202 |
0ce82753dd72
more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents:
9513
diff
changeset
|
203 F77_RET_T |
0ce82753dd72
more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents:
9513
diff
changeset
|
204 F77_FUNC (zfftb, ZFFTB) (const octave_idx_type&, Complex*, Complex*); |
0ce82753dd72
more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents:
9513
diff
changeset
|
205 } |
0ce82753dd72
more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents:
9513
diff
changeset
|
206 |
4773 | 207 ComplexNDArray |
208 ComplexNDArray::fourier (int dim) const | |
209 { | |
210 dim_vector dv = dims (); | |
211 | |
212 if (dim > dv.length () || dim < 0) | |
213 return ComplexNDArray (); | |
214 | |
215 ComplexNDArray retval (dv); | |
5275 | 216 octave_idx_type npts = dv(dim); |
217 octave_idx_type nn = 4*npts+15; | |
4773 | 218 Array<Complex> wsave (nn); |
219 Complex *pwsave = wsave.fortran_vec (); | |
220 | |
221 OCTAVE_LOCAL_BUFFER (Complex, tmp, npts); | |
222 | |
5275 | 223 octave_idx_type stride = 1; |
4773 | 224 |
225 for (int i = 0; i < dim; i++) | |
226 stride *= dv(i); | |
227 | |
5275 | 228 octave_idx_type howmany = numel () / npts; |
4773 | 229 howmany = (stride == 1 ? howmany : (howmany > stride ? stride : howmany)); |
5275 | 230 octave_idx_type nloop = (stride == 1 ? 1 : numel () / npts / stride); |
231 octave_idx_type dist = (stride == 1 ? npts : 1); | |
4773 | 232 |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7620
diff
changeset
|
233 F77_FUNC (zffti, ZFFTI) (npts, pwsave); |
4773 | 234 |
5275 | 235 for (octave_idx_type k = 0; k < nloop; k++) |
4773 | 236 { |
5275 | 237 for (octave_idx_type j = 0; j < howmany; j++) |
4773 | 238 { |
239 OCTAVE_QUIT; | |
240 | |
5275 | 241 for (octave_idx_type i = 0; i < npts; i++) |
4773 | 242 tmp[i] = elem((i + k*npts)*stride + j*dist); |
243 | |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7620
diff
changeset
|
244 F77_FUNC (zfftf, ZFFTF) (npts, tmp, pwsave); |
4773 | 245 |
5275 | 246 for (octave_idx_type i = 0; i < npts; i++) |
4773 | 247 retval ((i + k*npts)*stride + j*dist) = tmp[i]; |
248 } | |
249 } | |
250 | |
251 return retval; | |
252 } | |
253 | |
254 ComplexNDArray | |
255 ComplexNDArray::ifourier (int dim) const | |
256 { | |
257 dim_vector dv = dims (); | |
258 | |
259 if (dim > dv.length () || dim < 0) | |
260 return ComplexNDArray (); | |
261 | |
262 ComplexNDArray retval (dv); | |
5275 | 263 octave_idx_type npts = dv(dim); |
264 octave_idx_type nn = 4*npts+15; | |
4773 | 265 Array<Complex> wsave (nn); |
266 Complex *pwsave = wsave.fortran_vec (); | |
267 | |
268 OCTAVE_LOCAL_BUFFER (Complex, tmp, npts); | |
269 | |
5275 | 270 octave_idx_type stride = 1; |
4773 | 271 |
272 for (int i = 0; i < dim; i++) | |
273 stride *= dv(i); | |
274 | |
5275 | 275 octave_idx_type howmany = numel () / npts; |
4773 | 276 howmany = (stride == 1 ? howmany : (howmany > stride ? stride : howmany)); |
5275 | 277 octave_idx_type nloop = (stride == 1 ? 1 : numel () / npts / stride); |
278 octave_idx_type dist = (stride == 1 ? npts : 1); | |
4773 | 279 |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7620
diff
changeset
|
280 F77_FUNC (zffti, ZFFTI) (npts, pwsave); |
4773 | 281 |
5275 | 282 for (octave_idx_type k = 0; k < nloop; k++) |
4773 | 283 { |
5275 | 284 for (octave_idx_type j = 0; j < howmany; j++) |
4773 | 285 { |
286 OCTAVE_QUIT; | |
287 | |
5275 | 288 for (octave_idx_type i = 0; i < npts; i++) |
4773 | 289 tmp[i] = elem((i + k*npts)*stride + j*dist); |
290 | |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7620
diff
changeset
|
291 F77_FUNC (zfftb, ZFFTB) (npts, tmp, pwsave); |
4773 | 292 |
5275 | 293 for (octave_idx_type i = 0; i < npts; i++) |
4773 | 294 retval ((i + k*npts)*stride + j*dist) = tmp[i] / |
295 static_cast<double> (npts); | |
296 } | |
297 } | |
298 | |
299 return retval; | |
300 } | |
301 | |
302 ComplexNDArray | |
303 ComplexNDArray::fourier2d (void) const | |
304 { | |
305 dim_vector dv = dims (); | |
306 dim_vector dv2 (dv(0), dv(1)); | |
307 int rank = 2; | |
308 ComplexNDArray retval (*this); | |
5275 | 309 octave_idx_type stride = 1; |
4773 | 310 |
311 for (int i = 0; i < rank; i++) | |
312 { | |
5275 | 313 octave_idx_type npts = dv2(i); |
314 octave_idx_type nn = 4*npts+15; | |
4773 | 315 Array<Complex> wsave (nn); |
316 Complex *pwsave = wsave.fortran_vec (); | |
317 Array<Complex> row (npts); | |
318 Complex *prow = row.fortran_vec (); | |
319 | |
5275 | 320 octave_idx_type howmany = numel () / npts; |
4773 | 321 howmany = (stride == 1 ? howmany : |
322 (howmany > stride ? stride : howmany)); | |
5275 | 323 octave_idx_type nloop = (stride == 1 ? 1 : numel () / npts / stride); |
324 octave_idx_type dist = (stride == 1 ? npts : 1); | |
4773 | 325 |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7620
diff
changeset
|
326 F77_FUNC (zffti, ZFFTI) (npts, pwsave); |
4773 | 327 |
5275 | 328 for (octave_idx_type k = 0; k < nloop; k++) |
4773 | 329 { |
5275 | 330 for (octave_idx_type j = 0; j < howmany; j++) |
4773 | 331 { |
332 OCTAVE_QUIT; | |
333 | |
5275 | 334 for (octave_idx_type l = 0; l < npts; l++) |
4773 | 335 prow[l] = retval ((l + k*npts)*stride + j*dist); |
336 | |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7620
diff
changeset
|
337 F77_FUNC (zfftf, ZFFTF) (npts, prow, pwsave); |
4773 | 338 |
5275 | 339 for (octave_idx_type l = 0; l < npts; l++) |
4773 | 340 retval ((l + k*npts)*stride + j*dist) = prow[l]; |
341 } | |
342 } | |
343 | |
344 stride *= dv2(i); | |
345 } | |
346 | |
347 return retval; | |
348 } | |
349 | |
350 ComplexNDArray | |
351 ComplexNDArray::ifourier2d (void) const | |
352 { | |
353 dim_vector dv = dims(); | |
354 dim_vector dv2 (dv(0), dv(1)); | |
355 int rank = 2; | |
356 ComplexNDArray retval (*this); | |
5275 | 357 octave_idx_type stride = 1; |
4773 | 358 |
359 for (int i = 0; i < rank; i++) | |
360 { | |
5275 | 361 octave_idx_type npts = dv2(i); |
362 octave_idx_type nn = 4*npts+15; | |
4773 | 363 Array<Complex> wsave (nn); |
364 Complex *pwsave = wsave.fortran_vec (); | |
365 Array<Complex> row (npts); | |
366 Complex *prow = row.fortran_vec (); | |
367 | |
5275 | 368 octave_idx_type howmany = numel () / npts; |
4773 | 369 howmany = (stride == 1 ? howmany : |
370 (howmany > stride ? stride : howmany)); | |
5275 | 371 octave_idx_type nloop = (stride == 1 ? 1 : numel () / npts / stride); |
372 octave_idx_type dist = (stride == 1 ? npts : 1); | |
4773 | 373 |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7620
diff
changeset
|
374 F77_FUNC (zffti, ZFFTI) (npts, pwsave); |
4773 | 375 |
5275 | 376 for (octave_idx_type k = 0; k < nloop; k++) |
4773 | 377 { |
5275 | 378 for (octave_idx_type j = 0; j < howmany; j++) |
4773 | 379 { |
380 OCTAVE_QUIT; | |
381 | |
5275 | 382 for (octave_idx_type l = 0; l < npts; l++) |
4773 | 383 prow[l] = retval ((l + k*npts)*stride + j*dist); |
384 | |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7620
diff
changeset
|
385 F77_FUNC (zfftb, ZFFTB) (npts, prow, pwsave); |
4773 | 386 |
5275 | 387 for (octave_idx_type l = 0; l < npts; l++) |
4773 | 388 retval ((l + k*npts)*stride + j*dist) = prow[l] / |
389 static_cast<double> (npts); | |
390 } | |
391 } | |
392 | |
393 stride *= dv2(i); | |
394 } | |
395 | |
396 return retval; | |
397 } | |
398 | |
399 ComplexNDArray | |
400 ComplexNDArray::fourierNd (void) const | |
401 { | |
402 dim_vector dv = dims (); | |
403 int rank = dv.length (); | |
404 ComplexNDArray retval (*this); | |
5275 | 405 octave_idx_type stride = 1; |
4773 | 406 |
407 for (int i = 0; i < rank; i++) | |
408 { | |
5275 | 409 octave_idx_type npts = dv(i); |
410 octave_idx_type nn = 4*npts+15; | |
4773 | 411 Array<Complex> wsave (nn); |
412 Complex *pwsave = wsave.fortran_vec (); | |
413 Array<Complex> row (npts); | |
414 Complex *prow = row.fortran_vec (); | |
415 | |
5275 | 416 octave_idx_type howmany = numel () / npts; |
4773 | 417 howmany = (stride == 1 ? howmany : |
418 (howmany > stride ? stride : howmany)); | |
5275 | 419 octave_idx_type nloop = (stride == 1 ? 1 : numel () / npts / stride); |
420 octave_idx_type dist = (stride == 1 ? npts : 1); | |
4773 | 421 |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7620
diff
changeset
|
422 F77_FUNC (zffti, ZFFTI) (npts, pwsave); |
4773 | 423 |
5275 | 424 for (octave_idx_type k = 0; k < nloop; k++) |
4773 | 425 { |
5275 | 426 for (octave_idx_type j = 0; j < howmany; j++) |
4773 | 427 { |
428 OCTAVE_QUIT; | |
429 | |
5275 | 430 for (octave_idx_type l = 0; l < npts; l++) |
4773 | 431 prow[l] = retval ((l + k*npts)*stride + j*dist); |
432 | |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7620
diff
changeset
|
433 F77_FUNC (zfftf, ZFFTF) (npts, prow, pwsave); |
4773 | 434 |
5275 | 435 for (octave_idx_type l = 0; l < npts; l++) |
4773 | 436 retval ((l + k*npts)*stride + j*dist) = prow[l]; |
437 } | |
438 } | |
439 | |
440 stride *= dv(i); | |
441 } | |
442 | |
443 return retval; | |
444 } | |
445 | |
446 ComplexNDArray | |
447 ComplexNDArray::ifourierNd (void) const | |
448 { | |
449 dim_vector dv = dims (); | |
450 int rank = dv.length (); | |
451 ComplexNDArray retval (*this); | |
5275 | 452 octave_idx_type stride = 1; |
4773 | 453 |
454 for (int i = 0; i < rank; i++) | |
455 { | |
5275 | 456 octave_idx_type npts = dv(i); |
457 octave_idx_type nn = 4*npts+15; | |
4773 | 458 Array<Complex> wsave (nn); |
459 Complex *pwsave = wsave.fortran_vec (); | |
460 Array<Complex> row (npts); | |
461 Complex *prow = row.fortran_vec (); | |
462 | |
5275 | 463 octave_idx_type howmany = numel () / npts; |
4773 | 464 howmany = (stride == 1 ? howmany : |
465 (howmany > stride ? stride : howmany)); | |
5275 | 466 octave_idx_type nloop = (stride == 1 ? 1 : numel () / npts / stride); |
467 octave_idx_type dist = (stride == 1 ? npts : 1); | |
4773 | 468 |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7620
diff
changeset
|
469 F77_FUNC (zffti, ZFFTI) (npts, pwsave); |
4773 | 470 |
5275 | 471 for (octave_idx_type k = 0; k < nloop; k++) |
4773 | 472 { |
5275 | 473 for (octave_idx_type j = 0; j < howmany; j++) |
4773 | 474 { |
475 OCTAVE_QUIT; | |
476 | |
5275 | 477 for (octave_idx_type l = 0; l < npts; l++) |
4773 | 478 prow[l] = retval ((l + k*npts)*stride + j*dist); |
479 | |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7620
diff
changeset
|
480 F77_FUNC (zfftb, ZFFTB) (npts, prow, pwsave); |
4773 | 481 |
5275 | 482 for (octave_idx_type l = 0; l < npts; l++) |
4773 | 483 retval ((l + k*npts)*stride + j*dist) = prow[l] / |
484 static_cast<double> (npts); | |
485 } | |
486 } | |
487 | |
488 stride *= dv(i); | |
489 } | |
490 | |
491 return retval; | |
492 } | |
493 | |
494 #endif | |
495 | |
4543 | 496 // unary operations |
497 | |
498 boolNDArray | |
499 ComplexNDArray::operator ! (void) const | |
500 { | |
9553
0c72d9284087
further bool ops tweaks
Jaroslav Hajek <highegg@gmail.com>
parents:
9551
diff
changeset
|
501 return do_mx_unary_op<boolNDArray, ComplexNDArray> (*this, mx_inline_not); |
4543 | 502 } |
503 | |
5775 | 504 // FIXME -- this is not quite the right thing. |
4514 | 505 |
4687 | 506 bool |
7922
935be827eaf8
error for NaN values in & and | expressions
John W. Eaton <jwe@octave.org>
parents:
7789
diff
changeset
|
507 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
|
508 { |
935be827eaf8
error for NaN values in & and | expressions
John W. Eaton <jwe@octave.org>
parents:
7789
diff
changeset
|
509 octave_idx_type nel = nelem (); |
935be827eaf8
error for NaN values in & and | expressions
John W. Eaton <jwe@octave.org>
parents:
7789
diff
changeset
|
510 |
935be827eaf8
error for NaN values in & and | expressions
John W. Eaton <jwe@octave.org>
parents:
7789
diff
changeset
|
511 for (octave_idx_type i = 0; i < nel; i++) |
935be827eaf8
error for NaN values in & and | expressions
John W. Eaton <jwe@octave.org>
parents:
7789
diff
changeset
|
512 { |
935be827eaf8
error for NaN values in & and | expressions
John W. Eaton <jwe@octave.org>
parents:
7789
diff
changeset
|
513 Complex val = elem (i); |
935be827eaf8
error for NaN values in & and | expressions
John W. Eaton <jwe@octave.org>
parents:
7789
diff
changeset
|
514 if (xisnan (val)) |
935be827eaf8
error for NaN values in & and | expressions
John W. Eaton <jwe@octave.org>
parents:
7789
diff
changeset
|
515 return true; |
935be827eaf8
error for NaN values in & and | expressions
John W. Eaton <jwe@octave.org>
parents:
7789
diff
changeset
|
516 } |
935be827eaf8
error for NaN values in & and | expressions
John W. Eaton <jwe@octave.org>
parents:
7789
diff
changeset
|
517 return false; |
935be827eaf8
error for NaN values in & and | expressions
John W. Eaton <jwe@octave.org>
parents:
7789
diff
changeset
|
518 } |
935be827eaf8
error for NaN values in & and | expressions
John W. Eaton <jwe@octave.org>
parents:
7789
diff
changeset
|
519 |
935be827eaf8
error for NaN values in & and | expressions
John W. Eaton <jwe@octave.org>
parents:
7789
diff
changeset
|
520 bool |
4687 | 521 ComplexNDArray::any_element_is_inf_or_nan (void) const |
522 { | |
5275 | 523 octave_idx_type nel = nelem (); |
4687 | 524 |
5275 | 525 for (octave_idx_type i = 0; i < nel; i++) |
4687 | 526 { |
527 Complex val = elem (i); | |
528 if (xisinf (val) || xisnan (val)) | |
529 return true; | |
530 } | |
531 return false; | |
532 } | |
533 | |
534 // Return true if no elements have imaginary components. | |
535 | |
536 bool | |
537 ComplexNDArray::all_elements_are_real (void) const | |
538 { | |
5275 | 539 octave_idx_type nel = nelem (); |
4687 | 540 |
5275 | 541 for (octave_idx_type i = 0; i < nel; i++) |
4687 | 542 { |
5260 | 543 double ip = std::imag (elem (i)); |
4687 | 544 |
545 if (ip != 0.0 || lo_ieee_signbit (ip)) | |
546 return false; | |
547 } | |
548 | |
549 return true; | |
550 } | |
551 | |
552 // Return nonzero if any element of CM has a non-integer real or | |
553 // imaginary part. Also extract the largest and smallest (real or | |
554 // imaginary) values and return them in MAX_VAL and MIN_VAL. | |
555 | |
556 bool | |
557 ComplexNDArray::all_integers (double& max_val, double& min_val) const | |
558 { | |
5275 | 559 octave_idx_type nel = nelem (); |
4687 | 560 |
561 if (nel > 0) | |
562 { | |
563 Complex val = elem (0); | |
564 | |
5260 | 565 double r_val = std::real (val); |
566 double i_val = std::imag (val); | |
4687 | 567 |
568 max_val = r_val; | |
569 min_val = r_val; | |
570 | |
571 if (i_val > max_val) | |
572 max_val = i_val; | |
573 | |
574 if (i_val < max_val) | |
575 min_val = i_val; | |
576 } | |
577 else | |
578 return false; | |
579 | |
5275 | 580 for (octave_idx_type i = 0; i < nel; i++) |
4687 | 581 { |
582 Complex val = elem (i); | |
583 | |
5260 | 584 double r_val = std::real (val); |
585 double i_val = std::imag (val); | |
4687 | 586 |
587 if (r_val > max_val) | |
588 max_val = r_val; | |
589 | |
590 if (i_val > max_val) | |
591 max_val = i_val; | |
592 | |
593 if (r_val < min_val) | |
594 min_val = r_val; | |
595 | |
596 if (i_val < min_val) | |
597 min_val = i_val; | |
598 | |
599 if (D_NINT (r_val) != r_val || D_NINT (i_val) != i_val) | |
600 return false; | |
601 } | |
602 | |
603 return true; | |
604 } | |
605 | |
606 bool | |
607 ComplexNDArray::too_large_for_float (void) const | |
608 { | |
5275 | 609 octave_idx_type nel = nelem (); |
4687 | 610 |
5275 | 611 for (octave_idx_type i = 0; i < nel; i++) |
4687 | 612 { |
613 Complex val = elem (i); | |
614 | |
5260 | 615 double r_val = std::real (val); |
616 double i_val = std::imag (val); | |
4687 | 617 |
5389 | 618 if ((! (xisnan (r_val) || xisinf (r_val)) |
5387 | 619 && fabs (r_val) > FLT_MAX) |
5389 | 620 || (! (xisnan (i_val) || xisinf (i_val)) |
5387 | 621 && fabs (i_val) > FLT_MAX)) |
4687 | 622 return true; |
623 } | |
624 | |
625 return false; | |
626 } | |
627 | |
4556 | 628 boolNDArray |
4514 | 629 ComplexNDArray::all (int dim) const |
630 { | |
9227
8145f2255276
use explicit template qualifs to please Intel C++ and MSVC++
Jaroslav Hajek <highegg@gmail.com>
parents:
8999
diff
changeset
|
631 return do_mx_red_op<boolNDArray, Complex> (*this, dim, mx_inline_all); |
4514 | 632 } |
633 | |
4556 | 634 boolNDArray |
4514 | 635 ComplexNDArray::any (int dim) const |
636 { | |
9227
8145f2255276
use explicit template qualifs to please Intel C++ and MSVC++
Jaroslav Hajek <highegg@gmail.com>
parents:
8999
diff
changeset
|
637 return do_mx_red_op<boolNDArray, Complex> (*this, dim, mx_inline_any); |
4569 | 638 } |
639 | |
4584 | 640 ComplexNDArray |
4569 | 641 ComplexNDArray::cumprod (int dim) const |
642 { | |
9227
8145f2255276
use explicit template qualifs to please Intel C++ and MSVC++
Jaroslav Hajek <highegg@gmail.com>
parents:
8999
diff
changeset
|
643 return do_mx_cum_op<ComplexNDArray, Complex> (*this, dim, mx_inline_cumprod); |
4569 | 644 } |
645 | |
4584 | 646 ComplexNDArray |
4569 | 647 ComplexNDArray::cumsum (int dim) const |
648 { | |
9227
8145f2255276
use explicit template qualifs to please Intel C++ and MSVC++
Jaroslav Hajek <highegg@gmail.com>
parents:
8999
diff
changeset
|
649 return do_mx_cum_op<ComplexNDArray, Complex> (*this, dim, mx_inline_cumsum); |
4569 | 650 } |
651 | |
652 ComplexNDArray | |
653 ComplexNDArray::prod (int dim) const | |
654 { | |
9227
8145f2255276
use explicit template qualifs to please Intel C++ and MSVC++
Jaroslav Hajek <highegg@gmail.com>
parents:
8999
diff
changeset
|
655 return do_mx_red_op<ComplexNDArray, Complex> (*this, dim, mx_inline_prod); |
8736
53b4fdeacc2e
improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8650
diff
changeset
|
656 } |
53b4fdeacc2e
improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8650
diff
changeset
|
657 |
53b4fdeacc2e
improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8650
diff
changeset
|
658 ComplexNDArray |
53b4fdeacc2e
improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8650
diff
changeset
|
659 ComplexNDArray::sum (int dim) const |
53b4fdeacc2e
improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8650
diff
changeset
|
660 { |
9227
8145f2255276
use explicit template qualifs to please Intel C++ and MSVC++
Jaroslav Hajek <highegg@gmail.com>
parents:
8999
diff
changeset
|
661 return do_mx_red_op<ComplexNDArray, Complex> (*this, dim, mx_inline_sum); |
4569 | 662 } |
663 | |
664 ComplexNDArray | |
9721
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9612
diff
changeset
|
665 ComplexNDArray::xsum (int dim) const |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9612
diff
changeset
|
666 { |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9612
diff
changeset
|
667 return do_mx_red_op<ComplexNDArray, Complex> (*this, dim, mx_inline_xsum); |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9612
diff
changeset
|
668 } |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9612
diff
changeset
|
669 |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9612
diff
changeset
|
670 ComplexNDArray |
4569 | 671 ComplexNDArray::sumsq (int dim) const |
672 { | |
9227
8145f2255276
use explicit template qualifs to please Intel C++ and MSVC++
Jaroslav Hajek <highegg@gmail.com>
parents:
8999
diff
changeset
|
673 return do_mx_red_op<NDArray, Complex> (*this, dim, mx_inline_sumsq); |
4569 | 674 } |
675 | |
4915 | 676 ComplexNDArray |
9513
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9469
diff
changeset
|
677 ComplexNDArray::diff (octave_idx_type order, int dim) const |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9469
diff
changeset
|
678 { |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9469
diff
changeset
|
679 return do_mx_diff_op<ComplexNDArray> (*this, dim, order, mx_inline_diff); |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9469
diff
changeset
|
680 } |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9469
diff
changeset
|
681 |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9469
diff
changeset
|
682 ComplexNDArray |
5275 | 683 ComplexNDArray::concat (const ComplexNDArray& rb, const Array<octave_idx_type>& ra_idx) |
4915 | 684 { |
4940 | 685 if (rb.numel () > 0) |
5073 | 686 insert (rb, ra_idx); |
687 return *this; | |
4915 | 688 } |
689 | |
690 ComplexNDArray | |
5275 | 691 ComplexNDArray::concat (const NDArray& rb, const Array<octave_idx_type>& ra_idx) |
4758 | 692 { |
4915 | 693 ComplexNDArray tmp (rb); |
4940 | 694 if (rb.numel () > 0) |
5073 | 695 insert (tmp, ra_idx); |
696 return *this; | |
4915 | 697 } |
698 | |
699 ComplexNDArray | |
5275 | 700 concat (NDArray& ra, ComplexNDArray& rb, const Array<octave_idx_type>& ra_idx) |
4915 | 701 { |
702 ComplexNDArray retval (ra); | |
4940 | 703 if (rb.numel () > 0) |
4915 | 704 retval.insert (rb, ra_idx); |
705 return retval; | |
4758 | 706 } |
707 | |
4844 | 708 static const Complex Complex_NaN_result (octave_NaN, octave_NaN); |
709 | |
710 ComplexNDArray | |
711 ComplexNDArray::max (int dim) const | |
712 { | |
8751
9f7ce4bf7650
optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8743
diff
changeset
|
713 return do_mx_minmax_op<ComplexNDArray> (*this, dim, mx_inline_max); |
4844 | 714 } |
715 | |
716 ComplexNDArray | |
5275 | 717 ComplexNDArray::max (ArrayN<octave_idx_type>& idx_arg, int dim) const |
4844 | 718 { |
8751
9f7ce4bf7650
optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8743
diff
changeset
|
719 return do_mx_minmax_op<ComplexNDArray> (*this, idx_arg, dim, mx_inline_max); |
4844 | 720 } |
721 | |
722 ComplexNDArray | |
723 ComplexNDArray::min (int dim) const | |
724 { | |
8751
9f7ce4bf7650
optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8743
diff
changeset
|
725 return do_mx_minmax_op<ComplexNDArray> (*this, dim, mx_inline_min); |
4844 | 726 } |
727 | |
728 ComplexNDArray | |
5275 | 729 ComplexNDArray::min (ArrayN<octave_idx_type>& idx_arg, int dim) const |
4844 | 730 { |
8751
9f7ce4bf7650
optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8743
diff
changeset
|
731 return do_mx_minmax_op<ComplexNDArray> (*this, idx_arg, dim, mx_inline_min); |
4844 | 732 } |
733 | |
8777
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8774
diff
changeset
|
734 ComplexNDArray |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8774
diff
changeset
|
735 ComplexNDArray::cummax (int dim) const |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8774
diff
changeset
|
736 { |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8774
diff
changeset
|
737 return do_mx_cumminmax_op<ComplexNDArray> (*this, dim, mx_inline_cummax); |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8774
diff
changeset
|
738 } |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8774
diff
changeset
|
739 |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8774
diff
changeset
|
740 ComplexNDArray |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8774
diff
changeset
|
741 ComplexNDArray::cummax (ArrayN<octave_idx_type>& idx_arg, int dim) const |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8774
diff
changeset
|
742 { |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8774
diff
changeset
|
743 return do_mx_cumminmax_op<ComplexNDArray> (*this, idx_arg, dim, mx_inline_cummax); |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8774
diff
changeset
|
744 } |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8774
diff
changeset
|
745 |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8774
diff
changeset
|
746 ComplexNDArray |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8774
diff
changeset
|
747 ComplexNDArray::cummin (int dim) const |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8774
diff
changeset
|
748 { |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8774
diff
changeset
|
749 return do_mx_cumminmax_op<ComplexNDArray> (*this, dim, mx_inline_cummin); |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8774
diff
changeset
|
750 } |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8774
diff
changeset
|
751 |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8774
diff
changeset
|
752 ComplexNDArray |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8774
diff
changeset
|
753 ComplexNDArray::cummin (ArrayN<octave_idx_type>& idx_arg, int dim) const |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8774
diff
changeset
|
754 { |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8774
diff
changeset
|
755 return do_mx_cumminmax_op<ComplexNDArray> (*this, idx_arg, dim, mx_inline_cummin); |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8774
diff
changeset
|
756 } |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8774
diff
changeset
|
757 |
4634 | 758 NDArray |
4569 | 759 ComplexNDArray::abs (void) const |
760 { | |
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
|
761 return NDArray (mx_inline_cabs_dup (data (), length ()), |
a1ae2aae903e
abs,real,imag,conj: use code from mx-inlines rather than the generic map
Jaroslav Hajek <highegg@gmail.com>
parents:
8377
diff
changeset
|
762 dims ()); |
a1ae2aae903e
abs,real,imag,conj: use code from mx-inlines rather than the generic map
Jaroslav Hajek <highegg@gmail.com>
parents:
8377
diff
changeset
|
763 } |
4634 | 764 |
8998
a48fba01e4ac
optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents:
8981
diff
changeset
|
765 boolNDArray |
a48fba01e4ac
optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents:
8981
diff
changeset
|
766 ComplexNDArray::isnan (void) const |
a48fba01e4ac
optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents:
8981
diff
changeset
|
767 { |
a48fba01e4ac
optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents:
8981
diff
changeset
|
768 return ArrayN<bool> (fastmap<bool> (xisnan)); |
a48fba01e4ac
optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents:
8981
diff
changeset
|
769 } |
a48fba01e4ac
optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents:
8981
diff
changeset
|
770 |
a48fba01e4ac
optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents:
8981
diff
changeset
|
771 boolNDArray |
a48fba01e4ac
optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents:
8981
diff
changeset
|
772 ComplexNDArray::isinf (void) const |
a48fba01e4ac
optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents:
8981
diff
changeset
|
773 { |
a48fba01e4ac
optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents:
8981
diff
changeset
|
774 return ArrayN<bool> (fastmap<bool> (xisinf)); |
a48fba01e4ac
optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents:
8981
diff
changeset
|
775 } |
a48fba01e4ac
optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents:
8981
diff
changeset
|
776 |
a48fba01e4ac
optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents:
8981
diff
changeset
|
777 boolNDArray |
a48fba01e4ac
optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents:
8981
diff
changeset
|
778 ComplexNDArray::isfinite (void) const |
a48fba01e4ac
optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents:
8981
diff
changeset
|
779 { |
a48fba01e4ac
optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents:
8981
diff
changeset
|
780 return ArrayN<bool> (fastmap<bool> (xfinite)); |
a48fba01e4ac
optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents:
8981
diff
changeset
|
781 } |
a48fba01e4ac
optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents:
8981
diff
changeset
|
782 |
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
|
783 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
|
784 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
|
785 { |
a1ae2aae903e
abs,real,imag,conj: use code from mx-inlines rather than the generic map
Jaroslav Hajek <highegg@gmail.com>
parents:
8377
diff
changeset
|
786 return ComplexNDArray (mx_inline_conj_dup (a.data (), a.length ()), |
a1ae2aae903e
abs,real,imag,conj: use code from mx-inlines rather than the generic map
Jaroslav Hajek <highegg@gmail.com>
parents:
8377
diff
changeset
|
787 a.dims ()); |
4514 | 788 } |
789 | |
4765 | 790 ComplexNDArray& |
5275 | 791 ComplexNDArray::insert (const NDArray& a, octave_idx_type r, octave_idx_type c) |
4765 | 792 { |
793 dim_vector a_dv = a.dims (); | |
794 | |
795 int n = a_dv.length (); | |
796 | |
797 if (n == dimensions.length ()) | |
798 { | |
5275 | 799 Array<octave_idx_type> a_ra_idx (a_dv.length (), 0); |
4765 | 800 |
801 a_ra_idx.elem (0) = r; | |
802 a_ra_idx.elem (1) = c; | |
803 | |
804 for (int i = 0; i < n; i++) | |
805 { | |
806 if (a_ra_idx (i) < 0 || (a_ra_idx (i) + a_dv (i)) > dimensions (i)) | |
807 { | |
808 (*current_liboctave_error_handler) | |
809 ("Array<T>::insert: range error for insert"); | |
810 return *this; | |
811 } | |
812 } | |
813 | |
814 a_ra_idx.elem (0) = 0; | |
815 a_ra_idx.elem (1) = 0; | |
816 | |
5275 | 817 octave_idx_type n_elt = a.numel (); |
4765 | 818 |
819 // IS make_unique () NECCESSARY HERE?? | |
820 | |
5275 | 821 for (octave_idx_type i = 0; i < n_elt; i++) |
4765 | 822 { |
5275 | 823 Array<octave_idx_type> ra_idx = a_ra_idx; |
4765 | 824 |
825 ra_idx.elem (0) = a_ra_idx (0) + r; | |
826 ra_idx.elem (1) = a_ra_idx (1) + c; | |
827 | |
828 elem (ra_idx) = a.elem (a_ra_idx); | |
829 | |
830 increment_index (a_ra_idx, a_dv); | |
831 } | |
832 } | |
833 else | |
834 (*current_liboctave_error_handler) | |
835 ("Array<T>::insert: invalid indexing operation"); | |
836 | |
837 return *this; | |
838 } | |
839 | |
840 ComplexNDArray& | |
5275 | 841 ComplexNDArray::insert (const ComplexNDArray& a, octave_idx_type r, octave_idx_type c) |
4765 | 842 { |
843 Array<Complex>::insert (a, r, c); | |
844 return *this; | |
845 } | |
846 | |
4915 | 847 ComplexNDArray& |
5275 | 848 ComplexNDArray::insert (const ComplexNDArray& a, const Array<octave_idx_type>& ra_idx) |
4915 | 849 { |
850 Array<Complex>::insert (a, ra_idx); | |
851 return *this; | |
852 } | |
853 | |
4514 | 854 ComplexMatrix |
855 ComplexNDArray::matrix_value (void) const | |
856 { | |
857 ComplexMatrix retval; | |
858 | |
8981
ed5055b0a476
fix & simplify ndarray->matrix conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
8956
diff
changeset
|
859 if (ndims () == 2) |
ed5055b0a476
fix & simplify ndarray->matrix conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
8956
diff
changeset
|
860 retval = ComplexMatrix (Array2<Complex> (*this)); |
ed5055b0a476
fix & simplify ndarray->matrix conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
8956
diff
changeset
|
861 else |
ed5055b0a476
fix & simplify ndarray->matrix conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
8956
diff
changeset
|
862 (*current_liboctave_error_handler) |
ed5055b0a476
fix & simplify ndarray->matrix conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
8956
diff
changeset
|
863 ("invalid conversion of ComplexNDArray to ComplexMatrix"); |
4514 | 864 |
865 return retval; | |
866 } | |
867 | |
4532 | 868 void |
5275 | 869 ComplexNDArray::increment_index (Array<octave_idx_type>& ra_idx, |
4532 | 870 const dim_vector& dimensions, |
871 int start_dimension) | |
872 { | |
873 ::increment_index (ra_idx, dimensions, start_dimension); | |
874 } | |
875 | |
5275 | 876 octave_idx_type |
877 ComplexNDArray::compute_index (Array<octave_idx_type>& ra_idx, | |
4556 | 878 const dim_vector& dimensions) |
879 { | |
880 return ::compute_index (ra_idx, dimensions); | |
881 } | |
882 | |
7620
36594d5bbe13
Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents:
7600
diff
changeset
|
883 ComplexNDArray |
36594d5bbe13
Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents:
7600
diff
changeset
|
884 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
|
885 { |
36594d5bbe13
Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents:
7600
diff
changeset
|
886 return MArrayN<Complex>::diag (k); |
36594d5bbe13
Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents:
7600
diff
changeset
|
887 } |
36594d5bbe13
Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents:
7600
diff
changeset
|
888 |
7503
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
889 NDArray |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
890 ComplexNDArray::map (dmapper fcn) const |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
891 { |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
892 return MArrayN<Complex>::map<double> (func_ptr (fcn)); |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
893 } |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
894 |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
895 ComplexNDArray |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
896 ComplexNDArray::map (cmapper fcn) const |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
897 { |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
898 return MArrayN<Complex>::map<Complex> (func_ptr (fcn)); |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
899 } |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
900 |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
901 boolNDArray |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
902 ComplexNDArray::map (bmapper fcn) const |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
903 { |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
904 return MArrayN<Complex>::map<bool> (func_ptr (fcn)); |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
905 } |
4687 | 906 |
907 // This contains no information on the array structure !!! | |
908 std::ostream& | |
909 operator << (std::ostream& os, const ComplexNDArray& a) | |
910 { | |
5275 | 911 octave_idx_type nel = a.nelem (); |
4687 | 912 |
5275 | 913 for (octave_idx_type i = 0; i < nel; i++) |
4687 | 914 { |
915 os << " "; | |
916 octave_write_complex (os, a.elem (i)); | |
917 os << "\n"; | |
918 } | |
919 return os; | |
920 } | |
921 | |
922 std::istream& | |
923 operator >> (std::istream& is, ComplexNDArray& a) | |
924 { | |
5275 | 925 octave_idx_type nel = a.nelem (); |
4687 | 926 |
8999
dc07bc4157b8
allow empty matrices in stream input operators
Jaroslav Hajek <highegg@gmail.com>
parents:
8998
diff
changeset
|
927 if (nel > 0) |
4687 | 928 { |
929 Complex tmp; | |
5275 | 930 for (octave_idx_type i = 0; i < nel; i++) |
4687 | 931 { |
9469
c6edba80dfae
sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents:
9227
diff
changeset
|
932 tmp = octave_read_value<Complex> (is); |
4687 | 933 if (is) |
934 a.elem (i) = tmp; | |
935 else | |
936 goto done; | |
937 } | |
938 } | |
939 | |
940 done: | |
941 | |
942 return is; | |
943 } | |
944 | |
5775 | 945 // FIXME -- it would be nice to share code among the min/max |
4844 | 946 // functions below. |
947 | |
948 #define EMPTY_RETURN_CHECK(T) \ | |
949 if (nel == 0) \ | |
950 return T (dv); | |
951 | |
952 ComplexNDArray | |
953 min (const Complex& c, const ComplexNDArray& m) | |
954 { | |
955 dim_vector dv = m.dims (); | |
956 int nel = dv.numel (); | |
957 | |
958 EMPTY_RETURN_CHECK (ComplexNDArray); | |
959 | |
960 ComplexNDArray result (dv); | |
961 | |
962 for (int i = 0; i < nel; i++) | |
963 { | |
964 OCTAVE_QUIT; | |
965 result (i) = xmin (c, m (i)); | |
966 } | |
967 | |
968 return result; | |
969 } | |
970 | |
971 ComplexNDArray | |
972 min (const ComplexNDArray& m, const Complex& c) | |
973 { | |
974 dim_vector dv = m.dims (); | |
975 int nel = dv.numel (); | |
976 | |
977 EMPTY_RETURN_CHECK (ComplexNDArray); | |
978 | |
979 ComplexNDArray result (dv); | |
980 | |
981 for (int i = 0; i < nel; i++) | |
982 { | |
983 OCTAVE_QUIT; | |
984 result (i) = xmin (c, m (i)); | |
985 } | |
986 | |
987 return result; | |
988 } | |
989 | |
990 ComplexNDArray | |
991 min (const ComplexNDArray& a, const ComplexNDArray& b) | |
992 { | |
993 dim_vector dv = a.dims (); | |
994 int nel = dv.numel (); | |
995 | |
996 if (dv != b.dims ()) | |
997 { | |
998 (*current_liboctave_error_handler) | |
999 ("two-arg min expecting args of same size"); | |
1000 return ComplexNDArray (); | |
1001 } | |
1002 | |
1003 EMPTY_RETURN_CHECK (ComplexNDArray); | |
1004 | |
1005 ComplexNDArray result (dv); | |
1006 | |
1007 for (int i = 0; i < nel; i++) | |
1008 { | |
1009 OCTAVE_QUIT; | |
1010 result (i) = xmin (a (i), b (i)); | |
1011 } | |
1012 | |
1013 return result; | |
1014 } | |
1015 | |
1016 ComplexNDArray | |
1017 max (const Complex& c, const ComplexNDArray& m) | |
1018 { | |
1019 dim_vector dv = m.dims (); | |
1020 int nel = dv.numel (); | |
1021 | |
1022 EMPTY_RETURN_CHECK (ComplexNDArray); | |
1023 | |
1024 ComplexNDArray result (dv); | |
1025 | |
1026 for (int i = 0; i < nel; i++) | |
1027 { | |
1028 OCTAVE_QUIT; | |
1029 result (i) = xmax (c, m (i)); | |
1030 } | |
1031 | |
1032 return result; | |
1033 } | |
1034 | |
1035 ComplexNDArray | |
1036 max (const ComplexNDArray& m, const Complex& c) | |
1037 { | |
1038 dim_vector dv = m.dims (); | |
1039 int nel = dv.numel (); | |
1040 | |
1041 EMPTY_RETURN_CHECK (ComplexNDArray); | |
1042 | |
1043 ComplexNDArray result (dv); | |
1044 | |
1045 for (int i = 0; i < nel; i++) | |
1046 { | |
1047 OCTAVE_QUIT; | |
1048 result (i) = xmax (c, m (i)); | |
1049 } | |
1050 | |
1051 return result; | |
1052 } | |
1053 | |
1054 ComplexNDArray | |
1055 max (const ComplexNDArray& a, const ComplexNDArray& b) | |
1056 { | |
1057 dim_vector dv = a.dims (); | |
1058 int nel = dv.numel (); | |
1059 | |
1060 if (dv != b.dims ()) | |
1061 { | |
1062 (*current_liboctave_error_handler) | |
1063 ("two-arg max expecting args of same size"); | |
1064 return ComplexNDArray (); | |
1065 } | |
1066 | |
1067 EMPTY_RETURN_CHECK (ComplexNDArray); | |
1068 | |
1069 ComplexNDArray result (dv); | |
1070 | |
1071 for (int i = 0; i < nel; i++) | |
1072 { | |
1073 OCTAVE_QUIT; | |
1074 result (i) = xmax (a (i), b (i)); | |
1075 } | |
1076 | |
1077 return result; | |
1078 } | |
1079 | |
9578
7dafdb8b062f
refactor comparison ops implementations
Jaroslav Hajek <highegg@gmail.com>
parents:
9553
diff
changeset
|
1080 NDS_CMP_OPS (ComplexNDArray, Complex) |
9550
3d6a9aea2aea
refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
9546
diff
changeset
|
1081 NDS_BOOL_OPS (ComplexNDArray, Complex) |
4543 | 1082 |
9578
7dafdb8b062f
refactor comparison ops implementations
Jaroslav Hajek <highegg@gmail.com>
parents:
9553
diff
changeset
|
1083 SND_CMP_OPS (Complex, ComplexNDArray) |
9550
3d6a9aea2aea
refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
9546
diff
changeset
|
1084 SND_BOOL_OPS (Complex, ComplexNDArray) |
4543 | 1085 |
9578
7dafdb8b062f
refactor comparison ops implementations
Jaroslav Hajek <highegg@gmail.com>
parents:
9553
diff
changeset
|
1086 NDND_CMP_OPS (ComplexNDArray, ComplexNDArray) |
9550
3d6a9aea2aea
refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
9546
diff
changeset
|
1087 NDND_BOOL_OPS (ComplexNDArray, ComplexNDArray) |
4543 | 1088 |
9546
1beb23d2b892
optimize op= in common cases
Jaroslav Hajek <highegg@gmail.com>
parents:
9523
diff
changeset
|
1089 ComplexNDArray& operator *= (ComplexNDArray& a, double s) |
1beb23d2b892
optimize op= in common cases
Jaroslav Hajek <highegg@gmail.com>
parents:
9523
diff
changeset
|
1090 { |
1beb23d2b892
optimize op= in common cases
Jaroslav Hajek <highegg@gmail.com>
parents:
9523
diff
changeset
|
1091 if (a.is_shared ()) |
9612
66970dd627f6
further liboctave design improvements
Jaroslav Hajek <highegg@gmail.com>
parents:
9601
diff
changeset
|
1092 a = a * s; |
66970dd627f6
further liboctave design improvements
Jaroslav Hajek <highegg@gmail.com>
parents:
9601
diff
changeset
|
1093 else |
66970dd627f6
further liboctave design improvements
Jaroslav Hajek <highegg@gmail.com>
parents:
9601
diff
changeset
|
1094 do_ms_inplace_op<ComplexNDArray, double> (a, s, mx_inline_mul2); |
9546
1beb23d2b892
optimize op= in common cases
Jaroslav Hajek <highegg@gmail.com>
parents:
9523
diff
changeset
|
1095 return a; |
1beb23d2b892
optimize op= in common cases
Jaroslav Hajek <highegg@gmail.com>
parents:
9523
diff
changeset
|
1096 } |
1beb23d2b892
optimize op= in common cases
Jaroslav Hajek <highegg@gmail.com>
parents:
9523
diff
changeset
|
1097 |
1beb23d2b892
optimize op= in common cases
Jaroslav Hajek <highegg@gmail.com>
parents:
9523
diff
changeset
|
1098 ComplexNDArray& operator /= (ComplexNDArray& a, double s) |
1beb23d2b892
optimize op= in common cases
Jaroslav Hajek <highegg@gmail.com>
parents:
9523
diff
changeset
|
1099 { |
1beb23d2b892
optimize op= in common cases
Jaroslav Hajek <highegg@gmail.com>
parents:
9523
diff
changeset
|
1100 if (a.is_shared ()) |
1beb23d2b892
optimize op= in common cases
Jaroslav Hajek <highegg@gmail.com>
parents:
9523
diff
changeset
|
1101 return a = a / s; |
9612
66970dd627f6
further liboctave design improvements
Jaroslav Hajek <highegg@gmail.com>
parents:
9601
diff
changeset
|
1102 else |
66970dd627f6
further liboctave design improvements
Jaroslav Hajek <highegg@gmail.com>
parents:
9601
diff
changeset
|
1103 do_ms_inplace_op<ComplexNDArray, double> (a, s, mx_inline_div2); |
9546
1beb23d2b892
optimize op= in common cases
Jaroslav Hajek <highegg@gmail.com>
parents:
9523
diff
changeset
|
1104 return a; |
1beb23d2b892
optimize op= in common cases
Jaroslav Hajek <highegg@gmail.com>
parents:
9523
diff
changeset
|
1105 } |
1beb23d2b892
optimize op= in common cases
Jaroslav Hajek <highegg@gmail.com>
parents:
9523
diff
changeset
|
1106 |
4514 | 1107 /* |
1108 ;;; Local Variables: *** | |
1109 ;;; mode: C++ *** | |
1110 ;;; End: *** | |
1111 */ |