Mercurial > octave
annotate liboctave/CNDArray.cc @ 9553:0c72d9284087
further bool ops tweaks
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Fri, 21 Aug 2009 12:12:25 +0200 |
parents | 19d298e6f7e5 |
children | 7dafdb8b062f |
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" |
4773 | 35 #include "f77-fcn.h" |
7503
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
36 #include "functor.h" |
4514 | 37 #include "lo-ieee.h" |
4687 | 38 #include "lo-mappers.h" |
9546
1beb23d2b892
optimize op= in common cases
Jaroslav Hajek <highegg@gmail.com>
parents:
9523
diff
changeset
|
39 #include "MArray-defs.h" |
9523
0ce82753dd72
more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents:
9513
diff
changeset
|
40 #include "mx-base.h" |
8774
b756ce0002db
split implementation and interface in mx-op-defs and MArray-defs
Jaroslav Hajek <highegg@gmail.com>
parents:
8751
diff
changeset
|
41 #include "mx-op-defs.h" |
4780 | 42 #include "oct-fftw.h" |
9523
0ce82753dd72
more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents:
9513
diff
changeset
|
43 #include "oct-locbuf.h" |
4773 | 44 |
8956
d91fa4b20bbb
ensure nonnegative char -> real conversion
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
45 ComplexNDArray::ComplexNDArray (const charNDArray& a) |
d91fa4b20bbb
ensure nonnegative char -> real conversion
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
46 : MArrayN<Complex> (a.dims ()) |
d91fa4b20bbb
ensure nonnegative char -> real conversion
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
47 { |
d91fa4b20bbb
ensure nonnegative char -> real conversion
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
48 octave_idx_type n = a.numel (); |
d91fa4b20bbb
ensure nonnegative char -> real conversion
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
49 for (octave_idx_type i = 0; i < n; i++) |
d91fa4b20bbb
ensure nonnegative char -> real conversion
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
50 xelem (i) = static_cast<unsigned char> (a(i)); |
d91fa4b20bbb
ensure nonnegative char -> real conversion
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
51 } |
d91fa4b20bbb
ensure nonnegative char -> real conversion
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
52 |
9523
0ce82753dd72
more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents:
9513
diff
changeset
|
53 #if defined (HAVE_FFTW) |
0ce82753dd72
more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents:
9513
diff
changeset
|
54 |
4773 | 55 ComplexNDArray |
56 ComplexNDArray::fourier (int dim) const | |
57 { | |
58 dim_vector dv = dims (); | |
59 | |
60 if (dim > dv.length () || dim < 0) | |
61 return ComplexNDArray (); | |
62 | |
5275 | 63 octave_idx_type stride = 1; |
64 octave_idx_type n = dv(dim); | |
4773 | 65 |
66 for (int i = 0; i < dim; i++) | |
67 stride *= dv(i); | |
68 | |
5275 | 69 octave_idx_type howmany = numel () / dv (dim); |
4773 | 70 howmany = (stride == 1 ? howmany : (howmany > stride ? stride : howmany)); |
5275 | 71 octave_idx_type nloop = (stride == 1 ? 1 : numel () / dv (dim) / stride); |
72 octave_idx_type dist = (stride == 1 ? n : 1); | |
4773 | 73 |
74 const Complex *in (fortran_vec ()); | |
75 ComplexNDArray retval (dv); | |
76 Complex *out (retval.fortran_vec ()); | |
77 | |
78 // Need to be careful here about the distance between fft's | |
5275 | 79 for (octave_idx_type k = 0; k < nloop; k++) |
4773 | 80 octave_fftw::fft (in + k * stride * n, out + k * stride * n, |
81 n, howmany, stride, dist); | |
82 | |
83 return retval; | |
84 } | |
85 | |
86 ComplexNDArray | |
4816 | 87 ComplexNDArray::ifourier (int dim) const |
4773 | 88 { |
89 dim_vector dv = dims (); | |
90 | |
91 if (dim > dv.length () || dim < 0) | |
92 return ComplexNDArray (); | |
93 | |
5275 | 94 octave_idx_type stride = 1; |
95 octave_idx_type n = dv(dim); | |
4773 | 96 |
97 for (int i = 0; i < dim; i++) | |
98 stride *= dv(i); | |
99 | |
5275 | 100 octave_idx_type howmany = numel () / dv (dim); |
4773 | 101 howmany = (stride == 1 ? howmany : (howmany > stride ? stride : howmany)); |
5275 | 102 octave_idx_type nloop = (stride == 1 ? 1 : numel () / dv (dim) / stride); |
103 octave_idx_type dist = (stride == 1 ? n : 1); | |
4773 | 104 |
105 const Complex *in (fortran_vec ()); | |
106 ComplexNDArray retval (dv); | |
107 Complex *out (retval.fortran_vec ()); | |
108 | |
109 // Need to be careful here about the distance between fft's | |
5275 | 110 for (octave_idx_type k = 0; k < nloop; k++) |
4773 | 111 octave_fftw::ifft (in + k * stride * n, out + k * stride * n, |
112 n, howmany, stride, dist); | |
113 | |
114 return retval; | |
115 } | |
116 | |
117 ComplexNDArray | |
118 ComplexNDArray::fourier2d (void) const | |
119 { | |
120 dim_vector dv = dims(); | |
121 if (dv.length () < 2) | |
122 return ComplexNDArray (); | |
123 | |
124 dim_vector dv2(dv(0), dv(1)); | |
125 const Complex *in = fortran_vec (); | |
126 ComplexNDArray retval (dv); | |
127 Complex *out = retval.fortran_vec (); | |
5275 | 128 octave_idx_type howmany = numel() / dv(0) / dv(1); |
129 octave_idx_type dist = dv(0) * dv(1); | |
4773 | 130 |
5275 | 131 for (octave_idx_type i=0; i < howmany; i++) |
4773 | 132 octave_fftw::fftNd (in + i*dist, out + i*dist, 2, dv2); |
133 | |
134 return retval; | |
135 } | |
136 | |
137 ComplexNDArray | |
138 ComplexNDArray::ifourier2d (void) const | |
139 { | |
140 dim_vector dv = dims(); | |
141 if (dv.length () < 2) | |
142 return ComplexNDArray (); | |
143 | |
144 dim_vector dv2(dv(0), dv(1)); | |
145 const Complex *in = fortran_vec (); | |
146 ComplexNDArray retval (dv); | |
147 Complex *out = retval.fortran_vec (); | |
5275 | 148 octave_idx_type howmany = numel() / dv(0) / dv(1); |
149 octave_idx_type dist = dv(0) * dv(1); | |
4773 | 150 |
5275 | 151 for (octave_idx_type i=0; i < howmany; i++) |
4773 | 152 octave_fftw::ifftNd (in + i*dist, out + i*dist, 2, dv2); |
153 | |
154 return retval; | |
155 } | |
156 | |
157 ComplexNDArray | |
158 ComplexNDArray::fourierNd (void) const | |
159 { | |
160 dim_vector dv = dims (); | |
161 int rank = dv.length (); | |
162 | |
163 const Complex *in (fortran_vec ()); | |
164 ComplexNDArray retval (dv); | |
165 Complex *out (retval.fortran_vec ()); | |
166 | |
167 octave_fftw::fftNd (in, out, rank, dv); | |
168 | |
169 return retval; | |
170 } | |
171 | |
172 ComplexNDArray | |
173 ComplexNDArray::ifourierNd (void) const | |
174 { | |
175 dim_vector dv = dims (); | |
176 int rank = dv.length (); | |
177 | |
178 const Complex *in (fortran_vec ()); | |
179 ComplexNDArray retval (dv); | |
180 Complex *out (retval.fortran_vec ()); | |
181 | |
182 octave_fftw::ifftNd (in, out, rank, dv); | |
183 | |
184 return retval; | |
185 } | |
186 | |
187 #else | |
9523
0ce82753dd72
more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents:
9513
diff
changeset
|
188 |
0ce82753dd72
more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents:
9513
diff
changeset
|
189 extern "C" |
0ce82753dd72
more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents:
9513
diff
changeset
|
190 { |
0ce82753dd72
more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents:
9513
diff
changeset
|
191 // Note that the original complex fft routines were not written for |
0ce82753dd72
more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents:
9513
diff
changeset
|
192 // double complex arguments. They have been modified by adding an |
0ce82753dd72
more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents:
9513
diff
changeset
|
193 // implicit double precision (a-h,o-z) statement at the beginning of |
0ce82753dd72
more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents:
9513
diff
changeset
|
194 // each subroutine. |
0ce82753dd72
more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents:
9513
diff
changeset
|
195 |
0ce82753dd72
more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents:
9513
diff
changeset
|
196 F77_RET_T |
0ce82753dd72
more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents:
9513
diff
changeset
|
197 F77_FUNC (zffti, ZFFTI) (const octave_idx_type&, Complex*); |
0ce82753dd72
more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents:
9513
diff
changeset
|
198 |
0ce82753dd72
more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents:
9513
diff
changeset
|
199 F77_RET_T |
0ce82753dd72
more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents:
9513
diff
changeset
|
200 F77_FUNC (zfftf, ZFFTF) (const octave_idx_type&, Complex*, Complex*); |
0ce82753dd72
more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents:
9513
diff
changeset
|
201 |
0ce82753dd72
more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents:
9513
diff
changeset
|
202 F77_RET_T |
0ce82753dd72
more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents:
9513
diff
changeset
|
203 F77_FUNC (zfftb, ZFFTB) (const octave_idx_type&, Complex*, Complex*); |
0ce82753dd72
more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents:
9513
diff
changeset
|
204 } |
0ce82753dd72
more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents:
9513
diff
changeset
|
205 |
4773 | 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 { | |
9553
0c72d9284087
further bool ops tweaks
Jaroslav Hajek <highegg@gmail.com>
parents:
9551
diff
changeset
|
500 return do_mx_unary_op<boolNDArray, ComplexNDArray> (*this, mx_inline_not); |
4543 | 501 } |
502 | |
5775 | 503 // FIXME -- this is not quite the right thing. |
4514 | 504 |
4687 | 505 bool |
7922
935be827eaf8
error for NaN values in & and | expressions
John W. Eaton <jwe@octave.org>
parents:
7789
diff
changeset
|
506 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
|
507 { |
935be827eaf8
error for NaN values in & and | expressions
John W. Eaton <jwe@octave.org>
parents:
7789
diff
changeset
|
508 octave_idx_type nel = nelem (); |
935be827eaf8
error for NaN values in & and | expressions
John W. Eaton <jwe@octave.org>
parents:
7789
diff
changeset
|
509 |
935be827eaf8
error for NaN values in & and | expressions
John W. Eaton <jwe@octave.org>
parents:
7789
diff
changeset
|
510 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
|
511 { |
935be827eaf8
error for NaN values in & and | expressions
John W. Eaton <jwe@octave.org>
parents:
7789
diff
changeset
|
512 Complex val = elem (i); |
935be827eaf8
error for NaN values in & and | expressions
John W. Eaton <jwe@octave.org>
parents:
7789
diff
changeset
|
513 if (xisnan (val)) |
935be827eaf8
error for NaN values in & and | expressions
John W. Eaton <jwe@octave.org>
parents:
7789
diff
changeset
|
514 return true; |
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 return false; |
935be827eaf8
error for NaN values in & and | expressions
John W. Eaton <jwe@octave.org>
parents:
7789
diff
changeset
|
517 } |
935be827eaf8
error for NaN values in & and | expressions
John W. Eaton <jwe@octave.org>
parents:
7789
diff
changeset
|
518 |
935be827eaf8
error for NaN values in & and | expressions
John W. Eaton <jwe@octave.org>
parents:
7789
diff
changeset
|
519 bool |
4687 | 520 ComplexNDArray::any_element_is_inf_or_nan (void) const |
521 { | |
5275 | 522 octave_idx_type nel = nelem (); |
4687 | 523 |
5275 | 524 for (octave_idx_type i = 0; i < nel; i++) |
4687 | 525 { |
526 Complex val = elem (i); | |
527 if (xisinf (val) || xisnan (val)) | |
528 return true; | |
529 } | |
530 return false; | |
531 } | |
532 | |
533 // Return true if no elements have imaginary components. | |
534 | |
535 bool | |
536 ComplexNDArray::all_elements_are_real (void) const | |
537 { | |
5275 | 538 octave_idx_type nel = nelem (); |
4687 | 539 |
5275 | 540 for (octave_idx_type i = 0; i < nel; i++) |
4687 | 541 { |
5260 | 542 double ip = std::imag (elem (i)); |
4687 | 543 |
544 if (ip != 0.0 || lo_ieee_signbit (ip)) | |
545 return false; | |
546 } | |
547 | |
548 return true; | |
549 } | |
550 | |
551 // Return nonzero if any element of CM has a non-integer real or | |
552 // imaginary part. Also extract the largest and smallest (real or | |
553 // imaginary) values and return them in MAX_VAL and MIN_VAL. | |
554 | |
555 bool | |
556 ComplexNDArray::all_integers (double& max_val, double& min_val) const | |
557 { | |
5275 | 558 octave_idx_type nel = nelem (); |
4687 | 559 |
560 if (nel > 0) | |
561 { | |
562 Complex val = elem (0); | |
563 | |
5260 | 564 double r_val = std::real (val); |
565 double i_val = std::imag (val); | |
4687 | 566 |
567 max_val = r_val; | |
568 min_val = r_val; | |
569 | |
570 if (i_val > max_val) | |
571 max_val = i_val; | |
572 | |
573 if (i_val < max_val) | |
574 min_val = i_val; | |
575 } | |
576 else | |
577 return false; | |
578 | |
5275 | 579 for (octave_idx_type i = 0; i < nel; i++) |
4687 | 580 { |
581 Complex val = elem (i); | |
582 | |
5260 | 583 double r_val = std::real (val); |
584 double i_val = std::imag (val); | |
4687 | 585 |
586 if (r_val > max_val) | |
587 max_val = r_val; | |
588 | |
589 if (i_val > max_val) | |
590 max_val = i_val; | |
591 | |
592 if (r_val < min_val) | |
593 min_val = r_val; | |
594 | |
595 if (i_val < min_val) | |
596 min_val = i_val; | |
597 | |
598 if (D_NINT (r_val) != r_val || D_NINT (i_val) != i_val) | |
599 return false; | |
600 } | |
601 | |
602 return true; | |
603 } | |
604 | |
605 bool | |
606 ComplexNDArray::too_large_for_float (void) const | |
607 { | |
5275 | 608 octave_idx_type nel = nelem (); |
4687 | 609 |
5275 | 610 for (octave_idx_type i = 0; i < nel; i++) |
4687 | 611 { |
612 Complex val = elem (i); | |
613 | |
5260 | 614 double r_val = std::real (val); |
615 double i_val = std::imag (val); | |
4687 | 616 |
5389 | 617 if ((! (xisnan (r_val) || xisinf (r_val)) |
5387 | 618 && fabs (r_val) > FLT_MAX) |
5389 | 619 || (! (xisnan (i_val) || xisinf (i_val)) |
5387 | 620 && fabs (i_val) > FLT_MAX)) |
4687 | 621 return true; |
622 } | |
623 | |
624 return false; | |
625 } | |
626 | |
4556 | 627 boolNDArray |
4514 | 628 ComplexNDArray::all (int dim) const |
629 { | |
9227
8145f2255276
use explicit template qualifs to please Intel C++ and MSVC++
Jaroslav Hajek <highegg@gmail.com>
parents:
8999
diff
changeset
|
630 return do_mx_red_op<boolNDArray, Complex> (*this, dim, mx_inline_all); |
4514 | 631 } |
632 | |
4556 | 633 boolNDArray |
4514 | 634 ComplexNDArray::any (int dim) const |
635 { | |
9227
8145f2255276
use explicit template qualifs to please Intel C++ and MSVC++
Jaroslav Hajek <highegg@gmail.com>
parents:
8999
diff
changeset
|
636 return do_mx_red_op<boolNDArray, Complex> (*this, dim, mx_inline_any); |
4569 | 637 } |
638 | |
4584 | 639 ComplexNDArray |
4569 | 640 ComplexNDArray::cumprod (int dim) const |
641 { | |
9227
8145f2255276
use explicit template qualifs to please Intel C++ and MSVC++
Jaroslav Hajek <highegg@gmail.com>
parents:
8999
diff
changeset
|
642 return do_mx_cum_op<ComplexNDArray, Complex> (*this, dim, mx_inline_cumprod); |
4569 | 643 } |
644 | |
4584 | 645 ComplexNDArray |
4569 | 646 ComplexNDArray::cumsum (int dim) const |
647 { | |
9227
8145f2255276
use explicit template qualifs to please Intel C++ and MSVC++
Jaroslav Hajek <highegg@gmail.com>
parents:
8999
diff
changeset
|
648 return do_mx_cum_op<ComplexNDArray, Complex> (*this, dim, mx_inline_cumsum); |
4569 | 649 } |
650 | |
651 ComplexNDArray | |
652 ComplexNDArray::prod (int dim) const | |
653 { | |
9227
8145f2255276
use explicit template qualifs to please Intel C++ and MSVC++
Jaroslav Hajek <highegg@gmail.com>
parents:
8999
diff
changeset
|
654 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
|
655 } |
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 ComplexNDArray |
53b4fdeacc2e
improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8650
diff
changeset
|
658 ComplexNDArray::sum (int dim) const |
53b4fdeacc2e
improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8650
diff
changeset
|
659 { |
9227
8145f2255276
use explicit template qualifs to please Intel C++ and MSVC++
Jaroslav Hajek <highegg@gmail.com>
parents:
8999
diff
changeset
|
660 return do_mx_red_op<ComplexNDArray, Complex> (*this, dim, mx_inline_sum); |
4569 | 661 } |
662 | |
663 ComplexNDArray | |
664 ComplexNDArray::sumsq (int dim) const | |
665 { | |
9227
8145f2255276
use explicit template qualifs to please Intel C++ and MSVC++
Jaroslav Hajek <highegg@gmail.com>
parents:
8999
diff
changeset
|
666 return do_mx_red_op<NDArray, Complex> (*this, dim, mx_inline_sumsq); |
4569 | 667 } |
668 | |
4915 | 669 ComplexNDArray |
9513
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9469
diff
changeset
|
670 ComplexNDArray::diff (octave_idx_type order, int dim) const |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9469
diff
changeset
|
671 { |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9469
diff
changeset
|
672 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
|
673 } |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9469
diff
changeset
|
674 |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9469
diff
changeset
|
675 ComplexNDArray |
5275 | 676 ComplexNDArray::concat (const ComplexNDArray& rb, const Array<octave_idx_type>& ra_idx) |
4915 | 677 { |
4940 | 678 if (rb.numel () > 0) |
5073 | 679 insert (rb, ra_idx); |
680 return *this; | |
4915 | 681 } |
682 | |
683 ComplexNDArray | |
5275 | 684 ComplexNDArray::concat (const NDArray& rb, const Array<octave_idx_type>& ra_idx) |
4758 | 685 { |
4915 | 686 ComplexNDArray tmp (rb); |
4940 | 687 if (rb.numel () > 0) |
5073 | 688 insert (tmp, ra_idx); |
689 return *this; | |
4915 | 690 } |
691 | |
692 ComplexNDArray | |
5275 | 693 concat (NDArray& ra, ComplexNDArray& rb, const Array<octave_idx_type>& ra_idx) |
4915 | 694 { |
695 ComplexNDArray retval (ra); | |
4940 | 696 if (rb.numel () > 0) |
4915 | 697 retval.insert (rb, ra_idx); |
698 return retval; | |
4758 | 699 } |
700 | |
4844 | 701 static const Complex Complex_NaN_result (octave_NaN, octave_NaN); |
702 | |
703 ComplexNDArray | |
704 ComplexNDArray::max (int dim) const | |
705 { | |
8751
9f7ce4bf7650
optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8743
diff
changeset
|
706 return do_mx_minmax_op<ComplexNDArray> (*this, dim, mx_inline_max); |
4844 | 707 } |
708 | |
709 ComplexNDArray | |
5275 | 710 ComplexNDArray::max (ArrayN<octave_idx_type>& idx_arg, int dim) const |
4844 | 711 { |
8751
9f7ce4bf7650
optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8743
diff
changeset
|
712 return do_mx_minmax_op<ComplexNDArray> (*this, idx_arg, dim, mx_inline_max); |
4844 | 713 } |
714 | |
715 ComplexNDArray | |
716 ComplexNDArray::min (int dim) const | |
717 { | |
8751
9f7ce4bf7650
optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8743
diff
changeset
|
718 return do_mx_minmax_op<ComplexNDArray> (*this, dim, mx_inline_min); |
4844 | 719 } |
720 | |
721 ComplexNDArray | |
5275 | 722 ComplexNDArray::min (ArrayN<octave_idx_type>& idx_arg, int dim) const |
4844 | 723 { |
8751
9f7ce4bf7650
optimize min/max functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8743
diff
changeset
|
724 return do_mx_minmax_op<ComplexNDArray> (*this, idx_arg, dim, mx_inline_min); |
4844 | 725 } |
726 | |
8777
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8774
diff
changeset
|
727 ComplexNDArray |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8774
diff
changeset
|
728 ComplexNDArray::cummax (int dim) const |
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 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
|
731 } |
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 ComplexNDArray |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8774
diff
changeset
|
734 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
|
735 { |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8774
diff
changeset
|
736 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
|
737 } |
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 ComplexNDArray |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8774
diff
changeset
|
740 ComplexNDArray::cummin (int dim) const |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8774
diff
changeset
|
741 { |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8774
diff
changeset
|
742 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
|
743 } |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8774
diff
changeset
|
744 |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8774
diff
changeset
|
745 ComplexNDArray |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8774
diff
changeset
|
746 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
|
747 { |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8774
diff
changeset
|
748 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
|
749 } |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8774
diff
changeset
|
750 |
4634 | 751 NDArray |
4569 | 752 ComplexNDArray::abs (void) const |
753 { | |
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
|
754 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
|
755 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
|
756 } |
4634 | 757 |
8998
a48fba01e4ac
optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents:
8981
diff
changeset
|
758 boolNDArray |
a48fba01e4ac
optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents:
8981
diff
changeset
|
759 ComplexNDArray::isnan (void) const |
a48fba01e4ac
optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents:
8981
diff
changeset
|
760 { |
a48fba01e4ac
optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents:
8981
diff
changeset
|
761 return ArrayN<bool> (fastmap<bool> (xisnan)); |
a48fba01e4ac
optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents:
8981
diff
changeset
|
762 } |
a48fba01e4ac
optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents:
8981
diff
changeset
|
763 |
a48fba01e4ac
optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents:
8981
diff
changeset
|
764 boolNDArray |
a48fba01e4ac
optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents:
8981
diff
changeset
|
765 ComplexNDArray::isinf (void) const |
a48fba01e4ac
optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents:
8981
diff
changeset
|
766 { |
a48fba01e4ac
optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents:
8981
diff
changeset
|
767 return ArrayN<bool> (fastmap<bool> (xisinf)); |
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 |
a48fba01e4ac
optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents:
8981
diff
changeset
|
770 boolNDArray |
a48fba01e4ac
optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents:
8981
diff
changeset
|
771 ComplexNDArray::isfinite (void) const |
a48fba01e4ac
optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents:
8981
diff
changeset
|
772 { |
a48fba01e4ac
optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents:
8981
diff
changeset
|
773 return ArrayN<bool> (fastmap<bool> (xfinite)); |
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 |
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
|
776 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
|
777 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
|
778 { |
a1ae2aae903e
abs,real,imag,conj: use code from mx-inlines rather than the generic map
Jaroslav Hajek <highegg@gmail.com>
parents:
8377
diff
changeset
|
779 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
|
780 a.dims ()); |
4514 | 781 } |
782 | |
4765 | 783 ComplexNDArray& |
5275 | 784 ComplexNDArray::insert (const NDArray& a, octave_idx_type r, octave_idx_type c) |
4765 | 785 { |
786 dim_vector a_dv = a.dims (); | |
787 | |
788 int n = a_dv.length (); | |
789 | |
790 if (n == dimensions.length ()) | |
791 { | |
5275 | 792 Array<octave_idx_type> a_ra_idx (a_dv.length (), 0); |
4765 | 793 |
794 a_ra_idx.elem (0) = r; | |
795 a_ra_idx.elem (1) = c; | |
796 | |
797 for (int i = 0; i < n; i++) | |
798 { | |
799 if (a_ra_idx (i) < 0 || (a_ra_idx (i) + a_dv (i)) > dimensions (i)) | |
800 { | |
801 (*current_liboctave_error_handler) | |
802 ("Array<T>::insert: range error for insert"); | |
803 return *this; | |
804 } | |
805 } | |
806 | |
807 a_ra_idx.elem (0) = 0; | |
808 a_ra_idx.elem (1) = 0; | |
809 | |
5275 | 810 octave_idx_type n_elt = a.numel (); |
4765 | 811 |
812 // IS make_unique () NECCESSARY HERE?? | |
813 | |
5275 | 814 for (octave_idx_type i = 0; i < n_elt; i++) |
4765 | 815 { |
5275 | 816 Array<octave_idx_type> ra_idx = a_ra_idx; |
4765 | 817 |
818 ra_idx.elem (0) = a_ra_idx (0) + r; | |
819 ra_idx.elem (1) = a_ra_idx (1) + c; | |
820 | |
821 elem (ra_idx) = a.elem (a_ra_idx); | |
822 | |
823 increment_index (a_ra_idx, a_dv); | |
824 } | |
825 } | |
826 else | |
827 (*current_liboctave_error_handler) | |
828 ("Array<T>::insert: invalid indexing operation"); | |
829 | |
830 return *this; | |
831 } | |
832 | |
833 ComplexNDArray& | |
5275 | 834 ComplexNDArray::insert (const ComplexNDArray& a, octave_idx_type r, octave_idx_type c) |
4765 | 835 { |
836 Array<Complex>::insert (a, r, c); | |
837 return *this; | |
838 } | |
839 | |
4915 | 840 ComplexNDArray& |
5275 | 841 ComplexNDArray::insert (const ComplexNDArray& a, const Array<octave_idx_type>& ra_idx) |
4915 | 842 { |
843 Array<Complex>::insert (a, ra_idx); | |
844 return *this; | |
845 } | |
846 | |
4514 | 847 ComplexMatrix |
848 ComplexNDArray::matrix_value (void) const | |
849 { | |
850 ComplexMatrix retval; | |
851 | |
8981
ed5055b0a476
fix & simplify ndarray->matrix conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
8956
diff
changeset
|
852 if (ndims () == 2) |
ed5055b0a476
fix & simplify ndarray->matrix conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
8956
diff
changeset
|
853 retval = ComplexMatrix (Array2<Complex> (*this)); |
ed5055b0a476
fix & simplify ndarray->matrix conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
8956
diff
changeset
|
854 else |
ed5055b0a476
fix & simplify ndarray->matrix conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
8956
diff
changeset
|
855 (*current_liboctave_error_handler) |
ed5055b0a476
fix & simplify ndarray->matrix conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
8956
diff
changeset
|
856 ("invalid conversion of ComplexNDArray to ComplexMatrix"); |
4514 | 857 |
858 return retval; | |
859 } | |
860 | |
4532 | 861 void |
5275 | 862 ComplexNDArray::increment_index (Array<octave_idx_type>& ra_idx, |
4532 | 863 const dim_vector& dimensions, |
864 int start_dimension) | |
865 { | |
866 ::increment_index (ra_idx, dimensions, start_dimension); | |
867 } | |
868 | |
5275 | 869 octave_idx_type |
870 ComplexNDArray::compute_index (Array<octave_idx_type>& ra_idx, | |
4556 | 871 const dim_vector& dimensions) |
872 { | |
873 return ::compute_index (ra_idx, dimensions); | |
874 } | |
875 | |
7620
36594d5bbe13
Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents:
7600
diff
changeset
|
876 ComplexNDArray |
36594d5bbe13
Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents:
7600
diff
changeset
|
877 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
|
878 { |
36594d5bbe13
Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents:
7600
diff
changeset
|
879 return MArrayN<Complex>::diag (k); |
36594d5bbe13
Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents:
7600
diff
changeset
|
880 } |
36594d5bbe13
Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents:
7600
diff
changeset
|
881 |
7503
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
882 NDArray |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
883 ComplexNDArray::map (dmapper fcn) const |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
884 { |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
885 return MArrayN<Complex>::map<double> (func_ptr (fcn)); |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
886 } |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
887 |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
888 ComplexNDArray |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
889 ComplexNDArray::map (cmapper fcn) const |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
890 { |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
891 return MArrayN<Complex>::map<Complex> (func_ptr (fcn)); |
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 |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
894 boolNDArray |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
895 ComplexNDArray::map (bmapper fcn) const |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
896 { |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
897 return MArrayN<Complex>::map<bool> (func_ptr (fcn)); |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
898 } |
4687 | 899 |
900 // This contains no information on the array structure !!! | |
901 std::ostream& | |
902 operator << (std::ostream& os, const ComplexNDArray& a) | |
903 { | |
5275 | 904 octave_idx_type nel = a.nelem (); |
4687 | 905 |
5275 | 906 for (octave_idx_type i = 0; i < nel; i++) |
4687 | 907 { |
908 os << " "; | |
909 octave_write_complex (os, a.elem (i)); | |
910 os << "\n"; | |
911 } | |
912 return os; | |
913 } | |
914 | |
915 std::istream& | |
916 operator >> (std::istream& is, ComplexNDArray& a) | |
917 { | |
5275 | 918 octave_idx_type nel = a.nelem (); |
4687 | 919 |
8999
dc07bc4157b8
allow empty matrices in stream input operators
Jaroslav Hajek <highegg@gmail.com>
parents:
8998
diff
changeset
|
920 if (nel > 0) |
4687 | 921 { |
922 Complex tmp; | |
5275 | 923 for (octave_idx_type i = 0; i < nel; i++) |
4687 | 924 { |
9469
c6edba80dfae
sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents:
9227
diff
changeset
|
925 tmp = octave_read_value<Complex> (is); |
4687 | 926 if (is) |
927 a.elem (i) = tmp; | |
928 else | |
929 goto done; | |
930 } | |
931 } | |
932 | |
933 done: | |
934 | |
935 return is; | |
936 } | |
937 | |
5775 | 938 // FIXME -- it would be nice to share code among the min/max |
4844 | 939 // functions below. |
940 | |
941 #define EMPTY_RETURN_CHECK(T) \ | |
942 if (nel == 0) \ | |
943 return T (dv); | |
944 | |
945 ComplexNDArray | |
946 min (const Complex& c, const ComplexNDArray& m) | |
947 { | |
948 dim_vector dv = m.dims (); | |
949 int nel = dv.numel (); | |
950 | |
951 EMPTY_RETURN_CHECK (ComplexNDArray); | |
952 | |
953 ComplexNDArray result (dv); | |
954 | |
955 for (int i = 0; i < nel; i++) | |
956 { | |
957 OCTAVE_QUIT; | |
958 result (i) = xmin (c, m (i)); | |
959 } | |
960 | |
961 return result; | |
962 } | |
963 | |
964 ComplexNDArray | |
965 min (const ComplexNDArray& m, const Complex& c) | |
966 { | |
967 dim_vector dv = m.dims (); | |
968 int nel = dv.numel (); | |
969 | |
970 EMPTY_RETURN_CHECK (ComplexNDArray); | |
971 | |
972 ComplexNDArray result (dv); | |
973 | |
974 for (int i = 0; i < nel; i++) | |
975 { | |
976 OCTAVE_QUIT; | |
977 result (i) = xmin (c, m (i)); | |
978 } | |
979 | |
980 return result; | |
981 } | |
982 | |
983 ComplexNDArray | |
984 min (const ComplexNDArray& a, const ComplexNDArray& b) | |
985 { | |
986 dim_vector dv = a.dims (); | |
987 int nel = dv.numel (); | |
988 | |
989 if (dv != b.dims ()) | |
990 { | |
991 (*current_liboctave_error_handler) | |
992 ("two-arg min expecting args of same size"); | |
993 return ComplexNDArray (); | |
994 } | |
995 | |
996 EMPTY_RETURN_CHECK (ComplexNDArray); | |
997 | |
998 ComplexNDArray result (dv); | |
999 | |
1000 for (int i = 0; i < nel; i++) | |
1001 { | |
1002 OCTAVE_QUIT; | |
1003 result (i) = xmin (a (i), b (i)); | |
1004 } | |
1005 | |
1006 return result; | |
1007 } | |
1008 | |
1009 ComplexNDArray | |
1010 max (const Complex& c, const ComplexNDArray& m) | |
1011 { | |
1012 dim_vector dv = m.dims (); | |
1013 int nel = dv.numel (); | |
1014 | |
1015 EMPTY_RETURN_CHECK (ComplexNDArray); | |
1016 | |
1017 ComplexNDArray result (dv); | |
1018 | |
1019 for (int i = 0; i < nel; i++) | |
1020 { | |
1021 OCTAVE_QUIT; | |
1022 result (i) = xmax (c, m (i)); | |
1023 } | |
1024 | |
1025 return result; | |
1026 } | |
1027 | |
1028 ComplexNDArray | |
1029 max (const ComplexNDArray& m, const Complex& c) | |
1030 { | |
1031 dim_vector dv = m.dims (); | |
1032 int nel = dv.numel (); | |
1033 | |
1034 EMPTY_RETURN_CHECK (ComplexNDArray); | |
1035 | |
1036 ComplexNDArray result (dv); | |
1037 | |
1038 for (int i = 0; i < nel; i++) | |
1039 { | |
1040 OCTAVE_QUIT; | |
1041 result (i) = xmax (c, m (i)); | |
1042 } | |
1043 | |
1044 return result; | |
1045 } | |
1046 | |
1047 ComplexNDArray | |
1048 max (const ComplexNDArray& a, const ComplexNDArray& b) | |
1049 { | |
1050 dim_vector dv = a.dims (); | |
1051 int nel = dv.numel (); | |
1052 | |
1053 if (dv != b.dims ()) | |
1054 { | |
1055 (*current_liboctave_error_handler) | |
1056 ("two-arg max expecting args of same size"); | |
1057 return ComplexNDArray (); | |
1058 } | |
1059 | |
1060 EMPTY_RETURN_CHECK (ComplexNDArray); | |
1061 | |
1062 ComplexNDArray result (dv); | |
1063 | |
1064 for (int i = 0; i < nel; i++) | |
1065 { | |
1066 OCTAVE_QUIT; | |
1067 result (i) = xmax (a (i), b (i)); | |
1068 } | |
1069 | |
1070 return result; | |
1071 } | |
1072 | |
5260 | 1073 NDS_CMP_OPS(ComplexNDArray, std::real, Complex, std::real) |
9550
3d6a9aea2aea
refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
9546
diff
changeset
|
1074 NDS_BOOL_OPS (ComplexNDArray, Complex) |
4543 | 1075 |
5260 | 1076 SND_CMP_OPS(Complex, std::real, ComplexNDArray, std::real) |
9550
3d6a9aea2aea
refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
9546
diff
changeset
|
1077 SND_BOOL_OPS (Complex, ComplexNDArray) |
4543 | 1078 |
5260 | 1079 NDND_CMP_OPS(ComplexNDArray, std::real, ComplexNDArray, std::real) |
9550
3d6a9aea2aea
refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
9546
diff
changeset
|
1080 NDND_BOOL_OPS (ComplexNDArray, ComplexNDArray) |
4543 | 1081 |
9546
1beb23d2b892
optimize op= in common cases
Jaroslav Hajek <highegg@gmail.com>
parents:
9523
diff
changeset
|
1082 ComplexNDArray& operator *= (ComplexNDArray& a, double s) |
1beb23d2b892
optimize op= in common cases
Jaroslav Hajek <highegg@gmail.com>
parents:
9523
diff
changeset
|
1083 { |
1beb23d2b892
optimize op= in common cases
Jaroslav Hajek <highegg@gmail.com>
parents:
9523
diff
changeset
|
1084 if (a.is_shared ()) |
1beb23d2b892
optimize op= in common cases
Jaroslav Hajek <highegg@gmail.com>
parents:
9523
diff
changeset
|
1085 return a = a * s; |
1beb23d2b892
optimize op= in common cases
Jaroslav Hajek <highegg@gmail.com>
parents:
9523
diff
changeset
|
1086 DO_VS_OP2 (Complex, a, *=, s) |
1beb23d2b892
optimize op= in common cases
Jaroslav Hajek <highegg@gmail.com>
parents:
9523
diff
changeset
|
1087 return a; |
1beb23d2b892
optimize op= in common cases
Jaroslav Hajek <highegg@gmail.com>
parents:
9523
diff
changeset
|
1088 } |
1beb23d2b892
optimize op= in common cases
Jaroslav Hajek <highegg@gmail.com>
parents:
9523
diff
changeset
|
1089 |
1beb23d2b892
optimize op= in common cases
Jaroslav Hajek <highegg@gmail.com>
parents:
9523
diff
changeset
|
1090 ComplexNDArray& operator /= (ComplexNDArray& a, double s) |
1beb23d2b892
optimize op= in common cases
Jaroslav Hajek <highegg@gmail.com>
parents:
9523
diff
changeset
|
1091 { |
1beb23d2b892
optimize op= in common cases
Jaroslav Hajek <highegg@gmail.com>
parents:
9523
diff
changeset
|
1092 if (a.is_shared ()) |
1beb23d2b892
optimize op= in common cases
Jaroslav Hajek <highegg@gmail.com>
parents:
9523
diff
changeset
|
1093 return a = a / s; |
1beb23d2b892
optimize op= in common cases
Jaroslav Hajek <highegg@gmail.com>
parents:
9523
diff
changeset
|
1094 DO_VS_OP2 (Complex, a, /=, s) |
1beb23d2b892
optimize op= in common cases
Jaroslav Hajek <highegg@gmail.com>
parents:
9523
diff
changeset
|
1095 return a; |
1beb23d2b892
optimize op= in common cases
Jaroslav Hajek <highegg@gmail.com>
parents:
9523
diff
changeset
|
1096 } |
1beb23d2b892
optimize op= in common cases
Jaroslav Hajek <highegg@gmail.com>
parents:
9523
diff
changeset
|
1097 |
4514 | 1098 /* |
1099 ;;; Local Variables: *** | |
1100 ;;; mode: C++ *** | |
1101 ;;; End: *** | |
1102 */ |