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