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