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