Mercurial > hg > octave-lyh
annotate liboctave/CNDArray.cc @ 14819:67b6b47a22f6
doc: Clarify docstrings for canonicalize_file_name, make_absolute_filename
* syscalls.cc (canonicalize_file_name): Clarify docstring.
* utils.cc (make_absolute_filename): Clarify docstring.
author | Rik <octave@nomad.inbox5.com> |
---|---|
date | Fri, 29 Jun 2012 13:38:28 -0700 |
parents | e8e86ae3abbc |
children | 5bc9b9cb4362 |
rev | line source |
---|---|
4514 | 1 // N-D Array manipulations. |
2 /* | |
3 | |
14138
72c96de7a403
maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents:
13107
diff
changeset
|
4 Copyright (C) 1996-2012 John W. Eaton |
9601
a9b37bae1802
add a couple of missing copyright statements
Jaroslav Hajek <highegg@gmail.com>
parents:
9578
diff
changeset
|
5 Copyright (C) 2009 VZLU Prague, a.s. |
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 |
9743
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
45 #include "bsxfun-defs.cc" |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
46 |
8956
d91fa4b20bbb
ensure nonnegative char -> real conversion
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
47 ComplexNDArray::ComplexNDArray (const charNDArray& a) |
10350
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10329
diff
changeset
|
48 : MArray<Complex> (a.dims ()) |
8956
d91fa4b20bbb
ensure nonnegative char -> real conversion
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
49 { |
d91fa4b20bbb
ensure nonnegative char -> real conversion
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
50 octave_idx_type n = a.numel (); |
d91fa4b20bbb
ensure nonnegative char -> real conversion
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
51 for (octave_idx_type i = 0; i < n; i++) |
d91fa4b20bbb
ensure nonnegative char -> real conversion
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
52 xelem (i) = static_cast<unsigned char> (a(i)); |
d91fa4b20bbb
ensure nonnegative char -> real conversion
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
53 } |
d91fa4b20bbb
ensure nonnegative char -> real conversion
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
54 |
9523
0ce82753dd72
more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents:
9513
diff
changeset
|
55 #if defined (HAVE_FFTW) |
0ce82753dd72
more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents:
9513
diff
changeset
|
56 |
4773 | 57 ComplexNDArray |
58 ComplexNDArray::fourier (int dim) const | |
59 { | |
60 dim_vector dv = dims (); | |
61 | |
62 if (dim > dv.length () || dim < 0) | |
63 return ComplexNDArray (); | |
64 | |
5275 | 65 octave_idx_type stride = 1; |
66 octave_idx_type n = dv(dim); | |
4773 | 67 |
68 for (int i = 0; i < dim; i++) | |
69 stride *= dv(i); | |
70 | |
5275 | 71 octave_idx_type howmany = numel () / dv (dim); |
4773 | 72 howmany = (stride == 1 ? howmany : (howmany > stride ? stride : howmany)); |
5275 | 73 octave_idx_type nloop = (stride == 1 ? 1 : numel () / dv (dim) / stride); |
74 octave_idx_type dist = (stride == 1 ? n : 1); | |
4773 | 75 |
76 const Complex *in (fortran_vec ()); | |
77 ComplexNDArray retval (dv); | |
78 Complex *out (retval.fortran_vec ()); | |
79 | |
80 // Need to be careful here about the distance between fft's | |
5275 | 81 for (octave_idx_type k = 0; k < nloop; k++) |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
82 octave_fftw::fft (in + k * stride * n, out + k * stride * n, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
83 n, howmany, stride, dist); |
4773 | 84 |
85 return retval; | |
86 } | |
87 | |
88 ComplexNDArray | |
4816 | 89 ComplexNDArray::ifourier (int dim) const |
4773 | 90 { |
91 dim_vector dv = dims (); | |
92 | |
93 if (dim > dv.length () || dim < 0) | |
94 return ComplexNDArray (); | |
95 | |
5275 | 96 octave_idx_type stride = 1; |
97 octave_idx_type n = dv(dim); | |
4773 | 98 |
99 for (int i = 0; i < dim; i++) | |
100 stride *= dv(i); | |
101 | |
5275 | 102 octave_idx_type howmany = numel () / dv (dim); |
4773 | 103 howmany = (stride == 1 ? howmany : (howmany > stride ? stride : howmany)); |
5275 | 104 octave_idx_type nloop = (stride == 1 ? 1 : numel () / dv (dim) / stride); |
105 octave_idx_type dist = (stride == 1 ? n : 1); | |
4773 | 106 |
107 const Complex *in (fortran_vec ()); | |
108 ComplexNDArray retval (dv); | |
109 Complex *out (retval.fortran_vec ()); | |
110 | |
111 // Need to be careful here about the distance between fft's | |
5275 | 112 for (octave_idx_type k = 0; k < nloop; k++) |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
113 octave_fftw::ifft (in + k * stride * n, out + k * stride * n, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
114 n, howmany, stride, dist); |
4773 | 115 |
116 return retval; | |
117 } | |
118 | |
119 ComplexNDArray | |
120 ComplexNDArray::fourier2d (void) const | |
121 { | |
122 dim_vector dv = dims(); | |
123 if (dv.length () < 2) | |
124 return ComplexNDArray (); | |
125 | |
126 dim_vector dv2(dv(0), dv(1)); | |
127 const Complex *in = fortran_vec (); | |
128 ComplexNDArray retval (dv); | |
129 Complex *out = retval.fortran_vec (); | |
5275 | 130 octave_idx_type howmany = numel() / dv(0) / dv(1); |
131 octave_idx_type dist = dv(0) * dv(1); | |
4773 | 132 |
5275 | 133 for (octave_idx_type i=0; i < howmany; i++) |
4773 | 134 octave_fftw::fftNd (in + i*dist, out + i*dist, 2, dv2); |
135 | |
136 return retval; | |
137 } | |
138 | |
139 ComplexNDArray | |
140 ComplexNDArray::ifourier2d (void) const | |
141 { | |
142 dim_vector dv = dims(); | |
143 if (dv.length () < 2) | |
144 return ComplexNDArray (); | |
145 | |
146 dim_vector dv2(dv(0), dv(1)); | |
147 const Complex *in = fortran_vec (); | |
148 ComplexNDArray retval (dv); | |
149 Complex *out = retval.fortran_vec (); | |
5275 | 150 octave_idx_type howmany = numel() / dv(0) / dv(1); |
151 octave_idx_type dist = dv(0) * dv(1); | |
4773 | 152 |
5275 | 153 for (octave_idx_type i=0; i < howmany; i++) |
4773 | 154 octave_fftw::ifftNd (in + i*dist, out + i*dist, 2, dv2); |
155 | |
156 return retval; | |
157 } | |
158 | |
159 ComplexNDArray | |
160 ComplexNDArray::fourierNd (void) const | |
161 { | |
162 dim_vector dv = dims (); | |
163 int rank = dv.length (); | |
164 | |
165 const Complex *in (fortran_vec ()); | |
166 ComplexNDArray retval (dv); | |
167 Complex *out (retval.fortran_vec ()); | |
168 | |
169 octave_fftw::fftNd (in, out, rank, dv); | |
170 | |
171 return retval; | |
172 } | |
173 | |
174 ComplexNDArray | |
175 ComplexNDArray::ifourierNd (void) const | |
176 { | |
177 dim_vector dv = dims (); | |
178 int rank = dv.length (); | |
179 | |
180 const Complex *in (fortran_vec ()); | |
181 ComplexNDArray retval (dv); | |
182 Complex *out (retval.fortran_vec ()); | |
183 | |
184 octave_fftw::ifftNd (in, out, rank, dv); | |
185 | |
186 return retval; | |
187 } | |
188 | |
189 #else | |
9523
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 extern "C" |
0ce82753dd72
more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents:
9513
diff
changeset
|
192 { |
0ce82753dd72
more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents:
9513
diff
changeset
|
193 // 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
|
194 // 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
|
195 // 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
|
196 // each subroutine. |
0ce82753dd72
more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents:
9513
diff
changeset
|
197 |
0ce82753dd72
more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents:
9513
diff
changeset
|
198 F77_RET_T |
0ce82753dd72
more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents:
9513
diff
changeset
|
199 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
|
200 |
0ce82753dd72
more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents:
9513
diff
changeset
|
201 F77_RET_T |
0ce82753dd72
more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents:
9513
diff
changeset
|
202 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
|
203 |
0ce82753dd72
more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents:
9513
diff
changeset
|
204 F77_RET_T |
0ce82753dd72
more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents:
9513
diff
changeset
|
205 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
|
206 } |
0ce82753dd72
more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents:
9513
diff
changeset
|
207 |
4773 | 208 ComplexNDArray |
209 ComplexNDArray::fourier (int dim) const | |
210 { | |
211 dim_vector dv = dims (); | |
212 | |
213 if (dim > dv.length () || dim < 0) | |
214 return ComplexNDArray (); | |
215 | |
216 ComplexNDArray retval (dv); | |
5275 | 217 octave_idx_type npts = dv(dim); |
218 octave_idx_type nn = 4*npts+15; | |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
219 Array<Complex> wsave (dim_vector (nn, 1)); |
4773 | 220 Complex *pwsave = wsave.fortran_vec (); |
221 | |
222 OCTAVE_LOCAL_BUFFER (Complex, tmp, npts); | |
223 | |
5275 | 224 octave_idx_type stride = 1; |
4773 | 225 |
226 for (int i = 0; i < dim; i++) | |
227 stride *= dv(i); | |
228 | |
5275 | 229 octave_idx_type howmany = numel () / npts; |
4773 | 230 howmany = (stride == 1 ? howmany : (howmany > stride ? stride : howmany)); |
5275 | 231 octave_idx_type nloop = (stride == 1 ? 1 : numel () / npts / stride); |
232 octave_idx_type dist = (stride == 1 ? npts : 1); | |
4773 | 233 |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7620
diff
changeset
|
234 F77_FUNC (zffti, ZFFTI) (npts, pwsave); |
4773 | 235 |
5275 | 236 for (octave_idx_type k = 0; k < nloop; k++) |
4773 | 237 { |
5275 | 238 for (octave_idx_type j = 0; j < howmany; j++) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
239 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
240 octave_quit (); |
4773 | 241 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
242 for (octave_idx_type i = 0; i < npts; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
243 tmp[i] = elem((i + k*npts)*stride + j*dist); |
4773 | 244 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
245 F77_FUNC (zfftf, ZFFTF) (npts, tmp, pwsave); |
4773 | 246 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
247 for (octave_idx_type i = 0; i < npts; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
248 retval ((i + k*npts)*stride + j*dist) = tmp[i]; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
249 } |
4773 | 250 } |
251 | |
252 return retval; | |
253 } | |
254 | |
255 ComplexNDArray | |
256 ComplexNDArray::ifourier (int dim) const | |
257 { | |
258 dim_vector dv = dims (); | |
259 | |
260 if (dim > dv.length () || dim < 0) | |
261 return ComplexNDArray (); | |
262 | |
263 ComplexNDArray retval (dv); | |
5275 | 264 octave_idx_type npts = dv(dim); |
265 octave_idx_type nn = 4*npts+15; | |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
266 Array<Complex> wsave (dim_vector (nn, 1)); |
4773 | 267 Complex *pwsave = wsave.fortran_vec (); |
268 | |
269 OCTAVE_LOCAL_BUFFER (Complex, tmp, npts); | |
270 | |
5275 | 271 octave_idx_type stride = 1; |
4773 | 272 |
273 for (int i = 0; i < dim; i++) | |
274 stride *= dv(i); | |
275 | |
5275 | 276 octave_idx_type howmany = numel () / npts; |
4773 | 277 howmany = (stride == 1 ? howmany : (howmany > stride ? stride : howmany)); |
5275 | 278 octave_idx_type nloop = (stride == 1 ? 1 : numel () / npts / stride); |
279 octave_idx_type dist = (stride == 1 ? npts : 1); | |
4773 | 280 |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7620
diff
changeset
|
281 F77_FUNC (zffti, ZFFTI) (npts, pwsave); |
4773 | 282 |
5275 | 283 for (octave_idx_type k = 0; k < nloop; k++) |
4773 | 284 { |
5275 | 285 for (octave_idx_type j = 0; j < howmany; j++) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
286 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
287 octave_quit (); |
4773 | 288 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
289 for (octave_idx_type i = 0; i < npts; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
290 tmp[i] = elem((i + k*npts)*stride + j*dist); |
4773 | 291 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
292 F77_FUNC (zfftb, ZFFTB) (npts, tmp, pwsave); |
4773 | 293 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
294 for (octave_idx_type i = 0; i < npts; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
295 retval ((i + k*npts)*stride + j*dist) = tmp[i] / |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
296 static_cast<double> (npts); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
297 } |
4773 | 298 } |
299 | |
300 return retval; | |
301 } | |
302 | |
303 ComplexNDArray | |
304 ComplexNDArray::fourier2d (void) const | |
305 { | |
306 dim_vector dv = dims (); | |
307 dim_vector dv2 (dv(0), dv(1)); | |
308 int rank = 2; | |
309 ComplexNDArray retval (*this); | |
5275 | 310 octave_idx_type stride = 1; |
4773 | 311 |
312 for (int i = 0; i < rank; i++) | |
313 { | |
5275 | 314 octave_idx_type npts = dv2(i); |
315 octave_idx_type nn = 4*npts+15; | |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
316 Array<Complex> wsave (dim_vector (nn, 1)); |
4773 | 317 Complex *pwsave = wsave.fortran_vec (); |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
318 Array<Complex> row (dim_vector (npts, 1)); |
4773 | 319 Complex *prow = row.fortran_vec (); |
320 | |
5275 | 321 octave_idx_type howmany = numel () / npts; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
322 howmany = (stride == 1 ? howmany : |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
323 (howmany > stride ? stride : howmany)); |
5275 | 324 octave_idx_type nloop = (stride == 1 ? 1 : numel () / npts / stride); |
325 octave_idx_type dist = (stride == 1 ? npts : 1); | |
4773 | 326 |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7620
diff
changeset
|
327 F77_FUNC (zffti, ZFFTI) (npts, pwsave); |
4773 | 328 |
5275 | 329 for (octave_idx_type k = 0; k < nloop; k++) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
330 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
331 for (octave_idx_type j = 0; j < howmany; j++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
332 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
333 octave_quit (); |
4773 | 334 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
335 for (octave_idx_type l = 0; l < npts; l++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
336 prow[l] = retval ((l + k*npts)*stride + j*dist); |
4773 | 337 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
338 F77_FUNC (zfftf, ZFFTF) (npts, prow, pwsave); |
4773 | 339 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
340 for (octave_idx_type l = 0; l < npts; l++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
341 retval ((l + k*npts)*stride + j*dist) = prow[l]; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
342 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
343 } |
4773 | 344 |
345 stride *= dv2(i); | |
346 } | |
347 | |
348 return retval; | |
349 } | |
350 | |
351 ComplexNDArray | |
352 ComplexNDArray::ifourier2d (void) const | |
353 { | |
354 dim_vector dv = dims(); | |
355 dim_vector dv2 (dv(0), dv(1)); | |
356 int rank = 2; | |
357 ComplexNDArray retval (*this); | |
5275 | 358 octave_idx_type stride = 1; |
4773 | 359 |
360 for (int i = 0; i < rank; i++) | |
361 { | |
5275 | 362 octave_idx_type npts = dv2(i); |
363 octave_idx_type nn = 4*npts+15; | |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
364 Array<Complex> wsave (dim_vector (nn, 1)); |
4773 | 365 Complex *pwsave = wsave.fortran_vec (); |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
366 Array<Complex> row (dim_vector (npts, 1)); |
4773 | 367 Complex *prow = row.fortran_vec (); |
368 | |
5275 | 369 octave_idx_type howmany = numel () / npts; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
370 howmany = (stride == 1 ? howmany : |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
371 (howmany > stride ? stride : howmany)); |
5275 | 372 octave_idx_type nloop = (stride == 1 ? 1 : numel () / npts / stride); |
373 octave_idx_type dist = (stride == 1 ? npts : 1); | |
4773 | 374 |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7620
diff
changeset
|
375 F77_FUNC (zffti, ZFFTI) (npts, pwsave); |
4773 | 376 |
5275 | 377 for (octave_idx_type k = 0; k < nloop; k++) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
378 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
379 for (octave_idx_type j = 0; j < howmany; j++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
380 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
381 octave_quit (); |
4773 | 382 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
383 for (octave_idx_type l = 0; l < npts; l++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
384 prow[l] = retval ((l + k*npts)*stride + j*dist); |
4773 | 385 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
386 F77_FUNC (zfftb, ZFFTB) (npts, prow, pwsave); |
4773 | 387 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
388 for (octave_idx_type l = 0; l < npts; l++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
389 retval ((l + k*npts)*stride + j*dist) = prow[l] / |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
390 static_cast<double> (npts); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
391 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
392 } |
4773 | 393 |
394 stride *= dv2(i); | |
395 } | |
396 | |
397 return retval; | |
398 } | |
399 | |
400 ComplexNDArray | |
401 ComplexNDArray::fourierNd (void) const | |
402 { | |
403 dim_vector dv = dims (); | |
404 int rank = dv.length (); | |
405 ComplexNDArray retval (*this); | |
5275 | 406 octave_idx_type stride = 1; |
4773 | 407 |
408 for (int i = 0; i < rank; i++) | |
409 { | |
5275 | 410 octave_idx_type npts = dv(i); |
411 octave_idx_type nn = 4*npts+15; | |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
412 Array<Complex> wsave (dim_vector (nn, 1)); |
4773 | 413 Complex *pwsave = wsave.fortran_vec (); |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
414 Array<Complex> row (dim_vector (npts, 1)); |
4773 | 415 Complex *prow = row.fortran_vec (); |
416 | |
5275 | 417 octave_idx_type howmany = numel () / npts; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
418 howmany = (stride == 1 ? howmany : |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
419 (howmany > stride ? stride : howmany)); |
5275 | 420 octave_idx_type nloop = (stride == 1 ? 1 : numel () / npts / stride); |
421 octave_idx_type dist = (stride == 1 ? npts : 1); | |
4773 | 422 |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7620
diff
changeset
|
423 F77_FUNC (zffti, ZFFTI) (npts, pwsave); |
4773 | 424 |
5275 | 425 for (octave_idx_type k = 0; k < nloop; k++) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
426 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
427 for (octave_idx_type j = 0; j < howmany; j++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
428 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
429 octave_quit (); |
4773 | 430 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
431 for (octave_idx_type l = 0; l < npts; l++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
432 prow[l] = retval ((l + k*npts)*stride + j*dist); |
4773 | 433 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
434 F77_FUNC (zfftf, ZFFTF) (npts, prow, pwsave); |
4773 | 435 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
436 for (octave_idx_type l = 0; l < npts; l++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
437 retval ((l + k*npts)*stride + j*dist) = prow[l]; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
438 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
439 } |
4773 | 440 |
441 stride *= dv(i); | |
442 } | |
443 | |
444 return retval; | |
445 } | |
446 | |
447 ComplexNDArray | |
448 ComplexNDArray::ifourierNd (void) const | |
449 { | |
450 dim_vector dv = dims (); | |
451 int rank = dv.length (); | |
452 ComplexNDArray retval (*this); | |
5275 | 453 octave_idx_type stride = 1; |
4773 | 454 |
455 for (int i = 0; i < rank; i++) | |
456 { | |
5275 | 457 octave_idx_type npts = dv(i); |
458 octave_idx_type nn = 4*npts+15; | |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
459 Array<Complex> wsave (dim_vector (nn, 1)); |
4773 | 460 Complex *pwsave = wsave.fortran_vec (); |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
461 Array<Complex> row (dim_vector (npts, 1)); |
4773 | 462 Complex *prow = row.fortran_vec (); |
463 | |
5275 | 464 octave_idx_type howmany = numel () / npts; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
465 howmany = (stride == 1 ? howmany : |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
466 (howmany > stride ? stride : howmany)); |
5275 | 467 octave_idx_type nloop = (stride == 1 ? 1 : numel () / npts / stride); |
468 octave_idx_type dist = (stride == 1 ? npts : 1); | |
4773 | 469 |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7620
diff
changeset
|
470 F77_FUNC (zffti, ZFFTI) (npts, pwsave); |
4773 | 471 |
5275 | 472 for (octave_idx_type k = 0; k < nloop; k++) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
473 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
474 for (octave_idx_type j = 0; j < howmany; j++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
475 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
476 octave_quit (); |
4773 | 477 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
478 for (octave_idx_type l = 0; l < npts; l++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
479 prow[l] = retval ((l + k*npts)*stride + j*dist); |
4773 | 480 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
481 F77_FUNC (zfftb, ZFFTB) (npts, prow, pwsave); |
4773 | 482 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
483 for (octave_idx_type l = 0; l < npts; l++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
484 retval ((l + k*npts)*stride + j*dist) = prow[l] / |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
485 static_cast<double> (npts); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
486 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
487 } |
4773 | 488 |
489 stride *= dv(i); | |
490 } | |
491 | |
492 return retval; | |
493 } | |
494 | |
495 #endif | |
496 | |
4543 | 497 // unary operations |
498 | |
499 boolNDArray | |
500 ComplexNDArray::operator ! (void) const | |
501 { | |
11130
7c573eb981eb
consistently give error for operator not applied to NaN values
John W. Eaton <jwe@octave.org>
parents:
11008
diff
changeset
|
502 if (any_element_is_nan ()) |
7c573eb981eb
consistently give error for operator not applied to NaN values
John W. Eaton <jwe@octave.org>
parents:
11008
diff
changeset
|
503 gripe_nan_to_logical_conversion (); |
7c573eb981eb
consistently give error for operator not applied to NaN values
John W. Eaton <jwe@octave.org>
parents:
11008
diff
changeset
|
504 |
10362
b47ab50a6aa8
simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
505 return do_mx_unary_op<bool, Complex> (*this, mx_inline_not); |
4543 | 506 } |
507 | |
5775 | 508 // FIXME -- this is not quite the right thing. |
4514 | 509 |
4687 | 510 bool |
7922
935be827eaf8
error for NaN values in & and | expressions
John W. Eaton <jwe@octave.org>
parents:
7789
diff
changeset
|
511 ComplexNDArray::any_element_is_nan (void) const |
935be827eaf8
error for NaN values in & and | expressions
John W. Eaton <jwe@octave.org>
parents:
7789
diff
changeset
|
512 { |
11008
3622db30ff05
simplify some array tests in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10362
diff
changeset
|
513 return do_mx_check<Complex> (*this, mx_inline_any_nan); |
7922
935be827eaf8
error for NaN values in & and | expressions
John W. Eaton <jwe@octave.org>
parents:
7789
diff
changeset
|
514 } |
935be827eaf8
error for NaN values in & and | expressions
John W. Eaton <jwe@octave.org>
parents:
7789
diff
changeset
|
515 |
935be827eaf8
error for NaN values in & and | expressions
John W. Eaton <jwe@octave.org>
parents:
7789
diff
changeset
|
516 bool |
4687 | 517 ComplexNDArray::any_element_is_inf_or_nan (void) const |
518 { | |
11008
3622db30ff05
simplify some array tests in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10362
diff
changeset
|
519 return ! do_mx_check<Complex> (*this, mx_inline_all_finite); |
4687 | 520 } |
521 | |
522 // Return true if no elements have imaginary components. | |
523 | |
524 bool | |
525 ComplexNDArray::all_elements_are_real (void) const | |
526 { | |
11008
3622db30ff05
simplify some array tests in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10362
diff
changeset
|
527 return do_mx_check<Complex> (*this, mx_inline_all_real); |
4687 | 528 } |
529 | |
530 // Return nonzero if any element of CM has a non-integer real or | |
531 // imaginary part. Also extract the largest and smallest (real or | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
532 // imaginary) values and return them in MAX_VAL and MIN_VAL. |
4687 | 533 |
534 bool | |
535 ComplexNDArray::all_integers (double& max_val, double& min_val) const | |
536 { | |
5275 | 537 octave_idx_type nel = nelem (); |
4687 | 538 |
539 if (nel > 0) | |
540 { | |
541 Complex val = elem (0); | |
542 | |
5260 | 543 double r_val = std::real (val); |
544 double i_val = std::imag (val); | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
545 |
4687 | 546 max_val = r_val; |
547 min_val = r_val; | |
548 | |
549 if (i_val > max_val) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
550 max_val = i_val; |
4687 | 551 |
552 if (i_val < max_val) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
553 min_val = i_val; |
4687 | 554 } |
555 else | |
556 return false; | |
557 | |
5275 | 558 for (octave_idx_type i = 0; i < nel; i++) |
4687 | 559 { |
560 Complex val = elem (i); | |
561 | |
5260 | 562 double r_val = std::real (val); |
563 double i_val = std::imag (val); | |
4687 | 564 |
565 if (r_val > max_val) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
566 max_val = r_val; |
4687 | 567 |
568 if (i_val > max_val) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
569 max_val = i_val; |
4687 | 570 |
571 if (r_val < min_val) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
572 min_val = r_val; |
4687 | 573 |
574 if (i_val < min_val) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
575 min_val = i_val; |
4687 | 576 |
577 if (D_NINT (r_val) != r_val || D_NINT (i_val) != i_val) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
578 return false; |
4687 | 579 } |
580 | |
581 return true; | |
582 } | |
583 | |
584 bool | |
585 ComplexNDArray::too_large_for_float (void) const | |
586 { | |
5275 | 587 octave_idx_type nel = nelem (); |
4687 | 588 |
5275 | 589 for (octave_idx_type i = 0; i < nel; i++) |
4687 | 590 { |
591 Complex val = elem (i); | |
592 | |
5260 | 593 double r_val = std::real (val); |
594 double i_val = std::imag (val); | |
4687 | 595 |
5389 | 596 if ((! (xisnan (r_val) || xisinf (r_val)) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
597 && fabs (r_val) > FLT_MAX) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
598 || (! (xisnan (i_val) || xisinf (i_val)) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
599 && fabs (i_val) > FLT_MAX)) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
600 return true; |
4687 | 601 } |
602 | |
603 return false; | |
604 } | |
605 | |
4556 | 606 boolNDArray |
4514 | 607 ComplexNDArray::all (int dim) const |
608 { | |
10362
b47ab50a6aa8
simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
609 return do_mx_red_op<bool, Complex> (*this, dim, mx_inline_all); |
4514 | 610 } |
611 | |
4556 | 612 boolNDArray |
4514 | 613 ComplexNDArray::any (int dim) const |
614 { | |
10362
b47ab50a6aa8
simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
615 return do_mx_red_op<bool, Complex> (*this, dim, mx_inline_any); |
4569 | 616 } |
617 | |
4584 | 618 ComplexNDArray |
4569 | 619 ComplexNDArray::cumprod (int dim) const |
620 { | |
10362
b47ab50a6aa8
simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
621 return do_mx_cum_op<Complex, Complex> (*this, dim, mx_inline_cumprod); |
4569 | 622 } |
623 | |
4584 | 624 ComplexNDArray |
4569 | 625 ComplexNDArray::cumsum (int dim) const |
626 { | |
10362
b47ab50a6aa8
simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
627 return do_mx_cum_op<Complex, Complex> (*this, dim, mx_inline_cumsum); |
4569 | 628 } |
629 | |
630 ComplexNDArray | |
631 ComplexNDArray::prod (int dim) const | |
632 { | |
10362
b47ab50a6aa8
simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
633 return do_mx_red_op<Complex, Complex> (*this, dim, mx_inline_prod); |
8736
53b4fdeacc2e
improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8650
diff
changeset
|
634 } |
53b4fdeacc2e
improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8650
diff
changeset
|
635 |
53b4fdeacc2e
improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8650
diff
changeset
|
636 ComplexNDArray |
53b4fdeacc2e
improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8650
diff
changeset
|
637 ComplexNDArray::sum (int dim) const |
53b4fdeacc2e
improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8650
diff
changeset
|
638 { |
10362
b47ab50a6aa8
simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
639 return do_mx_red_op<Complex, Complex> (*this, dim, mx_inline_sum); |
4569 | 640 } |
641 | |
642 ComplexNDArray | |
9721
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9612
diff
changeset
|
643 ComplexNDArray::xsum (int dim) const |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9612
diff
changeset
|
644 { |
10362
b47ab50a6aa8
simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
645 return do_mx_red_op<Complex, Complex> (*this, dim, mx_inline_xsum); |
9721
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9612
diff
changeset
|
646 } |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9612
diff
changeset
|
647 |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9612
diff
changeset
|
648 ComplexNDArray |
4569 | 649 ComplexNDArray::sumsq (int dim) const |
650 { | |
10362
b47ab50a6aa8
simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
651 return do_mx_red_op<double, Complex> (*this, dim, mx_inline_sumsq); |
4569 | 652 } |
653 | |
4915 | 654 ComplexNDArray |
9513
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9469
diff
changeset
|
655 ComplexNDArray::diff (octave_idx_type order, int dim) const |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9469
diff
changeset
|
656 { |
10362
b47ab50a6aa8
simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
657 return do_mx_diff_op<Complex> (*this, dim, order, mx_inline_diff); |
9513
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9469
diff
changeset
|
658 } |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9469
diff
changeset
|
659 |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9469
diff
changeset
|
660 ComplexNDArray |
5275 | 661 ComplexNDArray::concat (const ComplexNDArray& rb, const Array<octave_idx_type>& ra_idx) |
4915 | 662 { |
4940 | 663 if (rb.numel () > 0) |
5073 | 664 insert (rb, ra_idx); |
665 return *this; | |
4915 | 666 } |
667 | |
668 ComplexNDArray | |
5275 | 669 ComplexNDArray::concat (const NDArray& rb, const Array<octave_idx_type>& ra_idx) |
4758 | 670 { |
4915 | 671 ComplexNDArray tmp (rb); |
4940 | 672 if (rb.numel () > 0) |
5073 | 673 insert (tmp, ra_idx); |
674 return *this; | |
4915 | 675 } |
676 | |
677 ComplexNDArray | |
5275 | 678 concat (NDArray& ra, ComplexNDArray& rb, const Array<octave_idx_type>& ra_idx) |
4915 | 679 { |
680 ComplexNDArray retval (ra); | |
4940 | 681 if (rb.numel () > 0) |
4915 | 682 retval.insert (rb, ra_idx); |
683 return retval; | |
4758 | 684 } |
685 | |
4844 | 686 static const Complex Complex_NaN_result (octave_NaN, octave_NaN); |
687 | |
688 ComplexNDArray | |
689 ComplexNDArray::max (int dim) const | |
690 { | |
10362
b47ab50a6aa8
simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
691 return do_mx_minmax_op<Complex> (*this, dim, mx_inline_max); |
4844 | 692 } |
693 | |
694 ComplexNDArray | |
9732
b4fdfee405b5
remove ArrayN<T> + fix nonhom. diag-scalar ops
Jaroslav Hajek <highegg@gmail.com>
parents:
9721
diff
changeset
|
695 ComplexNDArray::max (Array<octave_idx_type>& idx_arg, int dim) const |
4844 | 696 { |
10362
b47ab50a6aa8
simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
697 return do_mx_minmax_op<Complex> (*this, idx_arg, dim, mx_inline_max); |
4844 | 698 } |
699 | |
700 ComplexNDArray | |
701 ComplexNDArray::min (int dim) const | |
702 { | |
10362
b47ab50a6aa8
simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
703 return do_mx_minmax_op<Complex> (*this, dim, mx_inline_min); |
4844 | 704 } |
705 | |
706 ComplexNDArray | |
9732
b4fdfee405b5
remove ArrayN<T> + fix nonhom. diag-scalar ops
Jaroslav Hajek <highegg@gmail.com>
parents:
9721
diff
changeset
|
707 ComplexNDArray::min (Array<octave_idx_type>& idx_arg, int dim) const |
4844 | 708 { |
10362
b47ab50a6aa8
simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
709 return do_mx_minmax_op<Complex> (*this, idx_arg, dim, mx_inline_min); |
4844 | 710 } |
711 | |
8777
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8774
diff
changeset
|
712 ComplexNDArray |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8774
diff
changeset
|
713 ComplexNDArray::cummax (int dim) const |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8774
diff
changeset
|
714 { |
10362
b47ab50a6aa8
simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
715 return do_mx_cumminmax_op<Complex> (*this, dim, mx_inline_cummax); |
8777
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8774
diff
changeset
|
716 } |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8774
diff
changeset
|
717 |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8774
diff
changeset
|
718 ComplexNDArray |
9732
b4fdfee405b5
remove ArrayN<T> + fix nonhom. diag-scalar ops
Jaroslav Hajek <highegg@gmail.com>
parents:
9721
diff
changeset
|
719 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
|
720 { |
10362
b47ab50a6aa8
simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
721 return do_mx_cumminmax_op<Complex> (*this, idx_arg, dim, mx_inline_cummax); |
8777
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8774
diff
changeset
|
722 } |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8774
diff
changeset
|
723 |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8774
diff
changeset
|
724 ComplexNDArray |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8774
diff
changeset
|
725 ComplexNDArray::cummin (int dim) const |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8774
diff
changeset
|
726 { |
10362
b47ab50a6aa8
simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
727 return do_mx_cumminmax_op<Complex> (*this, dim, mx_inline_cummin); |
8777
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8774
diff
changeset
|
728 } |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8774
diff
changeset
|
729 |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8774
diff
changeset
|
730 ComplexNDArray |
9732
b4fdfee405b5
remove ArrayN<T> + fix nonhom. diag-scalar ops
Jaroslav Hajek <highegg@gmail.com>
parents:
9721
diff
changeset
|
731 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
|
732 { |
10362
b47ab50a6aa8
simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
733 return do_mx_cumminmax_op<Complex> (*this, idx_arg, dim, mx_inline_cummin); |
8777
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8774
diff
changeset
|
734 } |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8774
diff
changeset
|
735 |
4634 | 736 NDArray |
4569 | 737 ComplexNDArray::abs (void) const |
738 { | |
10362
b47ab50a6aa8
simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
739 return do_mx_unary_map<double, Complex, std::abs> (*this); |
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
|
740 } |
4634 | 741 |
8998
a48fba01e4ac
optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents:
8981
diff
changeset
|
742 boolNDArray |
a48fba01e4ac
optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents:
8981
diff
changeset
|
743 ComplexNDArray::isnan (void) const |
a48fba01e4ac
optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents:
8981
diff
changeset
|
744 { |
10362
b47ab50a6aa8
simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
745 return do_mx_unary_map<bool, Complex, xisnan> (*this); |
8998
a48fba01e4ac
optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents:
8981
diff
changeset
|
746 } |
a48fba01e4ac
optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents:
8981
diff
changeset
|
747 |
a48fba01e4ac
optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents:
8981
diff
changeset
|
748 boolNDArray |
a48fba01e4ac
optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents:
8981
diff
changeset
|
749 ComplexNDArray::isinf (void) const |
a48fba01e4ac
optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents:
8981
diff
changeset
|
750 { |
10362
b47ab50a6aa8
simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
751 return do_mx_unary_map<bool, Complex, xisinf> (*this); |
8998
a48fba01e4ac
optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents:
8981
diff
changeset
|
752 } |
a48fba01e4ac
optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents:
8981
diff
changeset
|
753 |
a48fba01e4ac
optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents:
8981
diff
changeset
|
754 boolNDArray |
a48fba01e4ac
optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents:
8981
diff
changeset
|
755 ComplexNDArray::isfinite (void) const |
a48fba01e4ac
optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents:
8981
diff
changeset
|
756 { |
10362
b47ab50a6aa8
simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
757 return do_mx_unary_map<bool, Complex, xfinite> (*this); |
8998
a48fba01e4ac
optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents:
8981
diff
changeset
|
758 } |
a48fba01e4ac
optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents:
8981
diff
changeset
|
759 |
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
|
760 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
|
761 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
|
762 { |
13107
353c71c76f22
maint: fix compilation problem with g++ -std=c++0x option
Júlio Hoffimann <julio.hoffimann@gmail.com>
parents:
11586
diff
changeset
|
763 return do_mx_unary_map<Complex, Complex, std::conj<double> > (a); |
4514 | 764 } |
765 | |
4765 | 766 ComplexNDArray& |
5275 | 767 ComplexNDArray::insert (const NDArray& a, octave_idx_type r, octave_idx_type c) |
4765 | 768 { |
769 dim_vector a_dv = a.dims (); | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
770 |
4765 | 771 int n = a_dv.length (); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
772 |
4765 | 773 if (n == dimensions.length ()) |
774 { | |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
775 Array<octave_idx_type> a_ra_idx (dim_vector (a_dv.length (), 1), 0); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
776 |
4765 | 777 a_ra_idx.elem (0) = r; |
778 a_ra_idx.elem (1) = c; | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
779 |
4765 | 780 for (int i = 0; i < n; i++) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
781 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
782 if (a_ra_idx (i) < 0 || (a_ra_idx (i) + a_dv (i)) > dimensions (i)) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
783 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
784 (*current_liboctave_error_handler) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
785 ("Array<T>::insert: range error for insert"); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
786 return *this; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
787 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
788 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
789 |
4765 | 790 a_ra_idx.elem (0) = 0; |
791 a_ra_idx.elem (1) = 0; | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
792 |
5275 | 793 octave_idx_type n_elt = a.numel (); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
794 |
4765 | 795 // IS make_unique () NECCESSARY HERE?? |
796 | |
5275 | 797 for (octave_idx_type i = 0; i < n_elt; i++) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
798 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
799 Array<octave_idx_type> ra_idx = a_ra_idx; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
800 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
801 ra_idx.elem (0) = a_ra_idx (0) + r; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
802 ra_idx.elem (1) = a_ra_idx (1) + c; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
803 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
804 elem (ra_idx) = a.elem (a_ra_idx); |
4765 | 805 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
806 increment_index (a_ra_idx, a_dv); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
807 } |
4765 | 808 } |
809 else | |
810 (*current_liboctave_error_handler) | |
811 ("Array<T>::insert: invalid indexing operation"); | |
812 | |
813 return *this; | |
814 } | |
815 | |
816 ComplexNDArray& | |
5275 | 817 ComplexNDArray::insert (const ComplexNDArray& a, octave_idx_type r, octave_idx_type c) |
4765 | 818 { |
819 Array<Complex>::insert (a, r, c); | |
820 return *this; | |
821 } | |
822 | |
4915 | 823 ComplexNDArray& |
5275 | 824 ComplexNDArray::insert (const ComplexNDArray& a, const Array<octave_idx_type>& ra_idx) |
4915 | 825 { |
826 Array<Complex>::insert (a, ra_idx); | |
827 return *this; | |
828 } | |
829 | |
4514 | 830 ComplexMatrix |
831 ComplexNDArray::matrix_value (void) const | |
832 { | |
833 ComplexMatrix retval; | |
834 | |
8981
ed5055b0a476
fix & simplify ndarray->matrix conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
8956
diff
changeset
|
835 if (ndims () == 2) |
10352 | 836 retval = ComplexMatrix (Array<Complex> (*this)); |
8981
ed5055b0a476
fix & simplify ndarray->matrix conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
8956
diff
changeset
|
837 else |
ed5055b0a476
fix & simplify ndarray->matrix conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
8956
diff
changeset
|
838 (*current_liboctave_error_handler) |
ed5055b0a476
fix & simplify ndarray->matrix conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
8956
diff
changeset
|
839 ("invalid conversion of ComplexNDArray to ComplexMatrix"); |
4514 | 840 |
841 return retval; | |
842 } | |
843 | |
4532 | 844 void |
5275 | 845 ComplexNDArray::increment_index (Array<octave_idx_type>& ra_idx, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
846 const dim_vector& dimensions, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
847 int start_dimension) |
4532 | 848 { |
849 ::increment_index (ra_idx, dimensions, start_dimension); | |
850 } | |
851 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
852 octave_idx_type |
5275 | 853 ComplexNDArray::compute_index (Array<octave_idx_type>& ra_idx, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
854 const dim_vector& dimensions) |
4556 | 855 { |
856 return ::compute_index (ra_idx, dimensions); | |
857 } | |
858 | |
7620
36594d5bbe13
Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents:
7600
diff
changeset
|
859 ComplexNDArray |
36594d5bbe13
Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents:
7600
diff
changeset
|
860 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
|
861 { |
10350
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10329
diff
changeset
|
862 return MArray<Complex>::diag (k); |
7620
36594d5bbe13
Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents:
7600
diff
changeset
|
863 } |
36594d5bbe13
Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents:
7600
diff
changeset
|
864 |
14557
e8e86ae3abbc
make diag (x, m, n) return a proper diagonal matrix object (bug #36099)
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
865 ComplexNDArray |
e8e86ae3abbc
make diag (x, m, n) return a proper diagonal matrix object (bug #36099)
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
866 ComplexNDArray::diag (octave_idx_type m, octave_idx_type n) const |
e8e86ae3abbc
make diag (x, m, n) return a proper diagonal matrix object (bug #36099)
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
867 { |
e8e86ae3abbc
make diag (x, m, n) return a proper diagonal matrix object (bug #36099)
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
868 return MArray<Complex>::diag (m, n); |
e8e86ae3abbc
make diag (x, m, n) return a proper diagonal matrix object (bug #36099)
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
869 } |
e8e86ae3abbc
make diag (x, m, n) return a proper diagonal matrix object (bug #36099)
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
870 |
4687 | 871 // This contains no information on the array structure !!! |
872 std::ostream& | |
873 operator << (std::ostream& os, const ComplexNDArray& a) | |
874 { | |
5275 | 875 octave_idx_type nel = a.nelem (); |
4687 | 876 |
5275 | 877 for (octave_idx_type i = 0; i < nel; i++) |
4687 | 878 { |
879 os << " "; | |
880 octave_write_complex (os, a.elem (i)); | |
881 os << "\n"; | |
882 } | |
883 return os; | |
884 } | |
885 | |
886 std::istream& | |
887 operator >> (std::istream& is, ComplexNDArray& a) | |
888 { | |
5275 | 889 octave_idx_type nel = a.nelem (); |
4687 | 890 |
8999
dc07bc4157b8
allow empty matrices in stream input operators
Jaroslav Hajek <highegg@gmail.com>
parents:
8998
diff
changeset
|
891 if (nel > 0) |
4687 | 892 { |
893 Complex tmp; | |
5275 | 894 for (octave_idx_type i = 0; i < nel; i++) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
895 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
896 tmp = octave_read_value<Complex> (is); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
897 if (is) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
898 a.elem (i) = tmp; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
899 else |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
900 goto done; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
901 } |
4687 | 902 } |
903 | |
904 done: | |
905 | |
906 return is; | |
907 } | |
908 | |
10329
83fa590b8a09
simplify min/max definitions in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10314
diff
changeset
|
909 MINMAX_FCNS (ComplexNDArray, Complex) |
4844 | 910 |
9578
7dafdb8b062f
refactor comparison ops implementations
Jaroslav Hajek <highegg@gmail.com>
parents:
9553
diff
changeset
|
911 NDS_CMP_OPS (ComplexNDArray, Complex) |
9550
3d6a9aea2aea
refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
9546
diff
changeset
|
912 NDS_BOOL_OPS (ComplexNDArray, Complex) |
4543 | 913 |
9578
7dafdb8b062f
refactor comparison ops implementations
Jaroslav Hajek <highegg@gmail.com>
parents:
9553
diff
changeset
|
914 SND_CMP_OPS (Complex, ComplexNDArray) |
9550
3d6a9aea2aea
refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
9546
diff
changeset
|
915 SND_BOOL_OPS (Complex, ComplexNDArray) |
4543 | 916 |
9578
7dafdb8b062f
refactor comparison ops implementations
Jaroslav Hajek <highegg@gmail.com>
parents:
9553
diff
changeset
|
917 NDND_CMP_OPS (ComplexNDArray, ComplexNDArray) |
9550
3d6a9aea2aea
refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
9546
diff
changeset
|
918 NDND_BOOL_OPS (ComplexNDArray, ComplexNDArray) |
4543 | 919 |
9546
1beb23d2b892
optimize op= in common cases
Jaroslav Hajek <highegg@gmail.com>
parents:
9523
diff
changeset
|
920 ComplexNDArray& operator *= (ComplexNDArray& a, double s) |
1beb23d2b892
optimize op= in common cases
Jaroslav Hajek <highegg@gmail.com>
parents:
9523
diff
changeset
|
921 { |
1beb23d2b892
optimize op= in common cases
Jaroslav Hajek <highegg@gmail.com>
parents:
9523
diff
changeset
|
922 if (a.is_shared ()) |
9612
66970dd627f6
further liboctave design improvements
Jaroslav Hajek <highegg@gmail.com>
parents:
9601
diff
changeset
|
923 a = a * s; |
66970dd627f6
further liboctave design improvements
Jaroslav Hajek <highegg@gmail.com>
parents:
9601
diff
changeset
|
924 else |
10362
b47ab50a6aa8
simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
925 do_ms_inplace_op<Complex, double> (a, s, mx_inline_mul2); |
9546
1beb23d2b892
optimize op= in common cases
Jaroslav Hajek <highegg@gmail.com>
parents:
9523
diff
changeset
|
926 return a; |
1beb23d2b892
optimize op= in common cases
Jaroslav Hajek <highegg@gmail.com>
parents:
9523
diff
changeset
|
927 } |
1beb23d2b892
optimize op= in common cases
Jaroslav Hajek <highegg@gmail.com>
parents:
9523
diff
changeset
|
928 |
1beb23d2b892
optimize op= in common cases
Jaroslav Hajek <highegg@gmail.com>
parents:
9523
diff
changeset
|
929 ComplexNDArray& operator /= (ComplexNDArray& a, double s) |
1beb23d2b892
optimize op= in common cases
Jaroslav Hajek <highegg@gmail.com>
parents:
9523
diff
changeset
|
930 { |
1beb23d2b892
optimize op= in common cases
Jaroslav Hajek <highegg@gmail.com>
parents:
9523
diff
changeset
|
931 if (a.is_shared ()) |
1beb23d2b892
optimize op= in common cases
Jaroslav Hajek <highegg@gmail.com>
parents:
9523
diff
changeset
|
932 return a = a / s; |
9612
66970dd627f6
further liboctave design improvements
Jaroslav Hajek <highegg@gmail.com>
parents:
9601
diff
changeset
|
933 else |
10362
b47ab50a6aa8
simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
934 do_ms_inplace_op<Complex, double> (a, s, mx_inline_div2); |
9546
1beb23d2b892
optimize op= in common cases
Jaroslav Hajek <highegg@gmail.com>
parents:
9523
diff
changeset
|
935 return a; |
1beb23d2b892
optimize op= in common cases
Jaroslav Hajek <highegg@gmail.com>
parents:
9523
diff
changeset
|
936 } |
1beb23d2b892
optimize op= in common cases
Jaroslav Hajek <highegg@gmail.com>
parents:
9523
diff
changeset
|
937 |
9743
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
938 BSXFUN_STDOP_DEFS_MXLOOP (ComplexNDArray) |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
939 BSXFUN_STDREL_DEFS_MXLOOP (ComplexNDArray) |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
940 |
9827
c15a5ed0da58
optimize bsxfun (@power, ...)
Jaroslav Hajek <highegg@gmail.com>
parents:
9825
diff
changeset
|
941 BSXFUN_OP_DEF_MXLOOP (pow, ComplexNDArray, mx_inline_pow) |