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