Mercurial > octave
annotate liboctave/array/CNDArray.cc @ 23443:3f1bf237908b
maint: Eliminate <cfloat.h> header from liboctave files.
* build-aux/mk-opts.pl: Remove "#include <cfloat>" from script which creates *-opts.h
* Array-util.cc, Array-util.h, Array.cc, Array.h, CColVector.h,
CDiagMatrix.h, CMatrix.cc, CMatrix.h, CNDArray.cc, CNDArray.h, CRowVector.h,
CSparse.cc, CSparse.h, MSparse.h, Matrix.h, Range.cc, Sparse.h, boolMatrix.h,
boolNDArray.h, boolSparse.h, chMatrix.h, chNDArray.h, dColVector.h,
dDiagMatrix.h, dMatrix.cc, dMatrix.h, dNDArray.cc, dNDArray.h, dRowVector.h,
dSparse.cc, dSparse.h, dim-vector.cc, dim-vector.h, fCColVector.h,
fCDiagMatrix.h, fCMatrix.cc, fCMatrix.h, fCNDArray.cc, fCNDArray.h,
fCRowVector.h, fColVector.h, fDiagMatrix.h, fMatrix.cc, fMatrix.h, fNDArray.cc,
fNDArray.h, fRowVector.h, int16NDArray.h, int32NDArray.h, int64NDArray.h,
int8NDArray.h, intNDArray.h, uint16NDArray.h, uint32NDArray.h, uint64NDArray.h,
uint8NDArray.h, CollocWt.cc, DASPK.cc, DASPK.h, DASRT.cc, DASRT.h, DASSL.cc,
DASSL.h, LSODE.cc, LSODE.h, Quad.h, eigs-base.cc, eigs-base.h, lo-mappers.cc,
lo-mappers.h, oct-norm.cc, lo-ieee.cc, lo-utils.cc, lo-utils.h, oct-refcount.h:
Remove "#include <cfloat>". Add "#include <limits>" if necessary. Remove
redundant #includes. Alphabetize #includes.
author | Rik <rik@octave.org> |
---|---|
date | Wed, 26 Apr 2017 09:57:28 -0700 |
parents | 092078913d54 |
children | 855122b993da |
rev | line source |
---|---|
21562
6c2fd62db1f7
maint: Eliminate accidental double spaces in code.
Rik <rik@octave.org>
parents:
21301
diff
changeset
|
1 // N-D Array manipulations. |
4514 | 2 /* |
3 | |
23219
3ac9f9ecfae5
maint: Update copyright dates.
John W. Eaton <jwe@octave.org>
parents:
23083
diff
changeset
|
4 Copyright (C) 1996-2017 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 | |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22402
diff
changeset
|
10 under the terms of the GNU General Public License as published by |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22402
diff
changeset
|
11 the Free Software Foundation; either version 3 of the License, or |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22402
diff
changeset
|
12 (at your option) any later version. |
4514 | 13 |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22402
diff
changeset
|
14 Octave is distributed in the hope that it will be useful, but |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22402
diff
changeset
|
15 WITHOUT ANY WARRANTY; without even the implied warranty of |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22402
diff
changeset
|
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22402
diff
changeset
|
17 GNU General Public License for more details. |
4514 | 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 | |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21723
diff
changeset
|
25 #if defined (HAVE_CONFIG_H) |
21301
40de9f8f23a6
Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents:
21202
diff
changeset
|
26 # include "config.h" |
4514 | 27 #endif |
28 | |
23443
3f1bf237908b
maint: Eliminate <cfloat.h> header from liboctave files.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
29 #include <complex> |
3f1bf237908b
maint: Eliminate <cfloat.h> header from liboctave files.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
30 #include <iostream> |
4687 | 31 |
4588 | 32 #include "Array-util.h" |
4514 | 33 #include "CNDArray.h" |
4773 | 34 #include "f77-fcn.h" |
7503
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
35 #include "functor.h" |
4514 | 36 #include "lo-ieee.h" |
4687 | 37 #include "lo-mappers.h" |
9523
0ce82753dd72
more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents:
9513
diff
changeset
|
38 #include "mx-base.h" |
23443
3f1bf237908b
maint: Eliminate <cfloat.h> header from liboctave files.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
39 #include "mx-cnda-s.h" |
8774
b756ce0002db
split implementation and interface in mx-op-defs and MArray-defs
Jaroslav Hajek <highegg@gmail.com>
parents:
8751
diff
changeset
|
40 #include "mx-op-defs.h" |
4780 | 41 #include "oct-fftw.h" |
9523
0ce82753dd72
more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents:
9513
diff
changeset
|
42 #include "oct-locbuf.h" |
4773 | 43 |
9743
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
44 #include "bsxfun-defs.cc" |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
45 |
8956
d91fa4b20bbb
ensure nonnegative char -> real conversion
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
46 ComplexNDArray::ComplexNDArray (const charNDArray& a) |
10350
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10329
diff
changeset
|
47 : MArray<Complex> (a.dims ()) |
8956
d91fa4b20bbb
ensure nonnegative char -> real conversion
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
48 { |
d91fa4b20bbb
ensure nonnegative char -> real conversion
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
49 octave_idx_type n = a.numel (); |
d91fa4b20bbb
ensure nonnegative char -> real conversion
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
50 for (octave_idx_type i = 0; i < n; i++) |
d91fa4b20bbb
ensure nonnegative char -> real conversion
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
51 xelem (i) = static_cast<unsigned char> (a(i)); |
d91fa4b20bbb
ensure nonnegative char -> real conversion
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
52 } |
d91fa4b20bbb
ensure nonnegative char -> real conversion
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
53 |
9523
0ce82753dd72
more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents:
9513
diff
changeset
|
54 #if defined (HAVE_FFTW) |
0ce82753dd72
more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents:
9513
diff
changeset
|
55 |
4773 | 56 ComplexNDArray |
57 ComplexNDArray::fourier (int dim) const | |
58 { | |
59 dim_vector dv = dims (); | |
60 | |
21660
53728df3e4c9
maint: for clarity, call ndims() rather than length() on dimension vectors.
Rik <rik@octave.org>
parents:
21562
diff
changeset
|
61 if (dim > dv.ndims () || dim < 0) |
4773 | 62 return ComplexNDArray (); |
63 | |
5275 | 64 octave_idx_type stride = 1; |
65 octave_idx_type n = dv(dim); | |
4773 | 66 |
67 for (int i = 0; i < dim; i++) | |
68 stride *= dv(i); | |
69 | |
20218
b2100e1659ac
maint: Use cuddled parentheses when indexing dimension_vectors.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
70 octave_idx_type howmany = numel () / dv(dim); |
4773 | 71 howmany = (stride == 1 ? howmany : (howmany > stride ? stride : howmany)); |
20218
b2100e1659ac
maint: Use cuddled parentheses when indexing dimension_vectors.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
72 octave_idx_type nloop = (stride == 1 ? 1 : numel () / dv(dim) / stride); |
5275 | 73 octave_idx_type dist = (stride == 1 ? n : 1); |
4773 | 74 |
75 const Complex *in (fortran_vec ()); | |
76 ComplexNDArray retval (dv); | |
77 Complex *out (retval.fortran_vec ()); | |
78 | |
79 // Need to be careful here about the distance between fft's | |
5275 | 80 for (octave_idx_type k = 0; k < nloop; k++) |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
81 octave::fftw::fft (in + k * stride * n, out + k * stride * n, |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
82 n, howmany, stride, dist); |
4773 | 83 |
84 return retval; | |
85 } | |
86 | |
87 ComplexNDArray | |
4816 | 88 ComplexNDArray::ifourier (int dim) const |
4773 | 89 { |
90 dim_vector dv = dims (); | |
91 | |
21660
53728df3e4c9
maint: for clarity, call ndims() rather than length() on dimension vectors.
Rik <rik@octave.org>
parents:
21562
diff
changeset
|
92 if (dim > dv.ndims () || dim < 0) |
4773 | 93 return ComplexNDArray (); |
94 | |
5275 | 95 octave_idx_type stride = 1; |
96 octave_idx_type n = dv(dim); | |
4773 | 97 |
98 for (int i = 0; i < dim; i++) | |
99 stride *= dv(i); | |
100 | |
20218
b2100e1659ac
maint: Use cuddled parentheses when indexing dimension_vectors.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
101 octave_idx_type howmany = numel () / dv(dim); |
4773 | 102 howmany = (stride == 1 ? howmany : (howmany > stride ? stride : howmany)); |
20218
b2100e1659ac
maint: Use cuddled parentheses when indexing dimension_vectors.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
103 octave_idx_type nloop = (stride == 1 ? 1 : numel () / dv(dim) / stride); |
5275 | 104 octave_idx_type dist = (stride == 1 ? n : 1); |
4773 | 105 |
106 const Complex *in (fortran_vec ()); | |
107 ComplexNDArray retval (dv); | |
108 Complex *out (retval.fortran_vec ()); | |
109 | |
110 // Need to be careful here about the distance between fft's | |
5275 | 111 for (octave_idx_type k = 0; k < nloop; k++) |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
112 octave::fftw::ifft (in + k * stride * n, out + k * stride * n, |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
113 n, howmany, stride, dist); |
4773 | 114 |
115 return retval; | |
116 } | |
117 | |
118 ComplexNDArray | |
119 ComplexNDArray::fourier2d (void) const | |
120 { | |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14844
diff
changeset
|
121 dim_vector dv = dims (); |
21660
53728df3e4c9
maint: for clarity, call ndims() rather than length() on dimension vectors.
Rik <rik@octave.org>
parents:
21562
diff
changeset
|
122 if (dv.ndims () < 2) |
4773 | 123 return ComplexNDArray (); |
124 | |
20218
b2100e1659ac
maint: Use cuddled parentheses when indexing dimension_vectors.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
125 dim_vector dv2 (dv(0), dv(1)); |
4773 | 126 const Complex *in = fortran_vec (); |
127 ComplexNDArray retval (dv); | |
128 Complex *out = retval.fortran_vec (); | |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14844
diff
changeset
|
129 octave_idx_type howmany = numel () / dv(0) / dv(1); |
5275 | 130 octave_idx_type dist = dv(0) * dv(1); |
4773 | 131 |
5275 | 132 for (octave_idx_type i=0; i < howmany; i++) |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
133 octave::fftw::fftNd (in + i*dist, out + i*dist, 2, dv2); |
4773 | 134 |
135 return retval; | |
136 } | |
137 | |
138 ComplexNDArray | |
139 ComplexNDArray::ifourier2d (void) const | |
140 { | |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14844
diff
changeset
|
141 dim_vector dv = dims (); |
21660
53728df3e4c9
maint: for clarity, call ndims() rather than length() on dimension vectors.
Rik <rik@octave.org>
parents:
21562
diff
changeset
|
142 if (dv.ndims () < 2) |
4773 | 143 return ComplexNDArray (); |
144 | |
20218
b2100e1659ac
maint: Use cuddled parentheses when indexing dimension_vectors.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
145 dim_vector dv2 (dv(0), dv(1)); |
4773 | 146 const Complex *in = fortran_vec (); |
147 ComplexNDArray retval (dv); | |
148 Complex *out = retval.fortran_vec (); | |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14844
diff
changeset
|
149 octave_idx_type howmany = numel () / dv(0) / dv(1); |
5275 | 150 octave_idx_type dist = dv(0) * dv(1); |
4773 | 151 |
5275 | 152 for (octave_idx_type i=0; i < howmany; i++) |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
153 octave::fftw::ifftNd (in + i*dist, out + i*dist, 2, dv2); |
4773 | 154 |
155 return retval; | |
156 } | |
157 | |
158 ComplexNDArray | |
159 ComplexNDArray::fourierNd (void) const | |
160 { | |
161 dim_vector dv = dims (); | |
21660
53728df3e4c9
maint: for clarity, call ndims() rather than length() on dimension vectors.
Rik <rik@octave.org>
parents:
21562
diff
changeset
|
162 int rank = dv.ndims (); |
4773 | 163 |
164 const Complex *in (fortran_vec ()); | |
165 ComplexNDArray retval (dv); | |
166 Complex *out (retval.fortran_vec ()); | |
167 | |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
168 octave::fftw::fftNd (in, out, rank, dv); |
4773 | 169 |
170 return retval; | |
171 } | |
172 | |
173 ComplexNDArray | |
174 ComplexNDArray::ifourierNd (void) const | |
175 { | |
176 dim_vector dv = dims (); | |
21660
53728df3e4c9
maint: for clarity, call ndims() rather than length() on dimension vectors.
Rik <rik@octave.org>
parents:
21562
diff
changeset
|
177 int rank = dv.ndims (); |
4773 | 178 |
179 const Complex *in (fortran_vec ()); | |
180 ComplexNDArray retval (dv); | |
181 Complex *out (retval.fortran_vec ()); | |
182 | |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
183 octave::fftw::ifftNd (in, out, rank, dv); |
4773 | 184 |
185 return retval; | |
186 } | |
187 | |
188 #else | |
9523
0ce82753dd72
more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents:
9513
diff
changeset
|
189 |
22322
93b3cdd36854
move most f77 function decls to separate header files
John W. Eaton <jwe@octave.org>
parents:
22274
diff
changeset
|
190 #include "lo-fftpack-proto.h" |
9523
0ce82753dd72
more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents:
9513
diff
changeset
|
191 |
4773 | 192 ComplexNDArray |
193 ComplexNDArray::fourier (int dim) const | |
194 { | |
195 dim_vector dv = dims (); | |
196 | |
21660
53728df3e4c9
maint: for clarity, call ndims() rather than length() on dimension vectors.
Rik <rik@octave.org>
parents:
21562
diff
changeset
|
197 if (dim > dv.ndims () || dim < 0) |
4773 | 198 return ComplexNDArray (); |
199 | |
200 ComplexNDArray retval (dv); | |
5275 | 201 octave_idx_type npts = dv(dim); |
202 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
|
203 Array<Complex> wsave (dim_vector (nn, 1)); |
4773 | 204 Complex *pwsave = wsave.fortran_vec (); |
205 | |
206 OCTAVE_LOCAL_BUFFER (Complex, tmp, npts); | |
207 | |
5275 | 208 octave_idx_type stride = 1; |
4773 | 209 |
210 for (int i = 0; i < dim; i++) | |
211 stride *= dv(i); | |
212 | |
5275 | 213 octave_idx_type howmany = numel () / npts; |
4773 | 214 howmany = (stride == 1 ? howmany : (howmany > stride ? stride : howmany)); |
5275 | 215 octave_idx_type nloop = (stride == 1 ? 1 : numel () / npts / stride); |
216 octave_idx_type dist = (stride == 1 ? npts : 1); | |
4773 | 217 |
22261
77c4d43e06d1
Use new macros for passing complex arguments to Fortran FFTPACK subroutines
Mike Miller <mtmiller@octave.org>
parents:
22133
diff
changeset
|
218 F77_FUNC (zffti, ZFFTI) (npts, F77_DBLE_CMPLX_ARG (pwsave)); |
4773 | 219 |
5275 | 220 for (octave_idx_type k = 0; k < nloop; k++) |
4773 | 221 { |
5275 | 222 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
|
223 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
224 octave_quit (); |
4773 | 225 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
226 for (octave_idx_type i = 0; i < npts; i++) |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
227 tmp[i] = elem ((i + k*npts)*stride + j*dist); |
4773 | 228 |
22402
4caa7b28d183
maint: Style check C++ code in liboctave/
Rik <rik@octave.org>
parents:
22327
diff
changeset
|
229 F77_FUNC (zfftf, ZFFTF) (npts, F77_DBLE_CMPLX_ARG (tmp), |
4caa7b28d183
maint: Style check C++ code in liboctave/
Rik <rik@octave.org>
parents:
22327
diff
changeset
|
230 F77_DBLE_CMPLX_ARG (pwsave)); |
4773 | 231 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
232 for (octave_idx_type i = 0; i < npts; i++) |
14844
5bc9b9cb4362
maint: Use Octave coding conventions for cuddled parenthesis in retval assignments.
Rik <octave@nomad.inbox5.com>
parents:
14557
diff
changeset
|
233 retval((i + k*npts)*stride + j*dist) = tmp[i]; |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
234 } |
4773 | 235 } |
236 | |
237 return retval; | |
238 } | |
239 | |
240 ComplexNDArray | |
241 ComplexNDArray::ifourier (int dim) const | |
242 { | |
243 dim_vector dv = dims (); | |
244 | |
21660
53728df3e4c9
maint: for clarity, call ndims() rather than length() on dimension vectors.
Rik <rik@octave.org>
parents:
21562
diff
changeset
|
245 if (dim > dv.ndims () || dim < 0) |
4773 | 246 return ComplexNDArray (); |
247 | |
248 ComplexNDArray retval (dv); | |
5275 | 249 octave_idx_type npts = dv(dim); |
250 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
|
251 Array<Complex> wsave (dim_vector (nn, 1)); |
4773 | 252 Complex *pwsave = wsave.fortran_vec (); |
253 | |
254 OCTAVE_LOCAL_BUFFER (Complex, tmp, npts); | |
255 | |
5275 | 256 octave_idx_type stride = 1; |
4773 | 257 |
258 for (int i = 0; i < dim; i++) | |
259 stride *= dv(i); | |
260 | |
5275 | 261 octave_idx_type howmany = numel () / npts; |
4773 | 262 howmany = (stride == 1 ? howmany : (howmany > stride ? stride : howmany)); |
5275 | 263 octave_idx_type nloop = (stride == 1 ? 1 : numel () / npts / stride); |
264 octave_idx_type dist = (stride == 1 ? npts : 1); | |
4773 | 265 |
22261
77c4d43e06d1
Use new macros for passing complex arguments to Fortran FFTPACK subroutines
Mike Miller <mtmiller@octave.org>
parents:
22133
diff
changeset
|
266 F77_FUNC (zffti, ZFFTI) (npts, F77_DBLE_CMPLX_ARG (pwsave)); |
4773 | 267 |
5275 | 268 for (octave_idx_type k = 0; k < nloop; k++) |
4773 | 269 { |
5275 | 270 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
|
271 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
272 octave_quit (); |
4773 | 273 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
274 for (octave_idx_type i = 0; i < npts; i++) |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
275 tmp[i] = elem ((i + k*npts)*stride + j*dist); |
4773 | 276 |
22402
4caa7b28d183
maint: Style check C++ code in liboctave/
Rik <rik@octave.org>
parents:
22327
diff
changeset
|
277 F77_FUNC (zfftb, ZFFTB) (npts, F77_DBLE_CMPLX_ARG (tmp), |
4caa7b28d183
maint: Style check C++ code in liboctave/
Rik <rik@octave.org>
parents:
22327
diff
changeset
|
278 F77_DBLE_CMPLX_ARG (pwsave)); |
4773 | 279 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
280 for (octave_idx_type i = 0; i < npts; i++) |
14844
5bc9b9cb4362
maint: Use Octave coding conventions for cuddled parenthesis in retval assignments.
Rik <octave@nomad.inbox5.com>
parents:
14557
diff
changeset
|
281 retval((i + k*npts)*stride + j*dist) = tmp[i] / |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
282 static_cast<double> (npts); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
283 } |
4773 | 284 } |
285 | |
286 return retval; | |
287 } | |
288 | |
289 ComplexNDArray | |
290 ComplexNDArray::fourier2d (void) const | |
291 { | |
292 dim_vector dv = dims (); | |
293 dim_vector dv2 (dv(0), dv(1)); | |
294 int rank = 2; | |
295 ComplexNDArray retval (*this); | |
5275 | 296 octave_idx_type stride = 1; |
4773 | 297 |
298 for (int i = 0; i < rank; i++) | |
299 { | |
5275 | 300 octave_idx_type npts = dv2(i); |
301 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
|
302 Array<Complex> wsave (dim_vector (nn, 1)); |
4773 | 303 Complex *pwsave = wsave.fortran_vec (); |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
304 Array<Complex> row (dim_vector (npts, 1)); |
4773 | 305 Complex *prow = row.fortran_vec (); |
306 | |
5275 | 307 octave_idx_type howmany = numel () / npts; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
308 howmany = (stride == 1 ? howmany : |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
309 (howmany > stride ? stride : howmany)); |
5275 | 310 octave_idx_type nloop = (stride == 1 ? 1 : numel () / npts / stride); |
311 octave_idx_type dist = (stride == 1 ? npts : 1); | |
4773 | 312 |
22261
77c4d43e06d1
Use new macros for passing complex arguments to Fortran FFTPACK subroutines
Mike Miller <mtmiller@octave.org>
parents:
22133
diff
changeset
|
313 F77_FUNC (zffti, ZFFTI) (npts, F77_DBLE_CMPLX_ARG (pwsave)); |
4773 | 314 |
5275 | 315 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
|
316 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
317 for (octave_idx_type j = 0; j < howmany; j++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
318 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
319 octave_quit (); |
4773 | 320 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
321 for (octave_idx_type l = 0; l < npts; l++) |
14844
5bc9b9cb4362
maint: Use Octave coding conventions for cuddled parenthesis in retval assignments.
Rik <octave@nomad.inbox5.com>
parents:
14557
diff
changeset
|
322 prow[l] = retval((l + k*npts)*stride + j*dist); |
4773 | 323 |
22402
4caa7b28d183
maint: Style check C++ code in liboctave/
Rik <rik@octave.org>
parents:
22327
diff
changeset
|
324 F77_FUNC (zfftf, ZFFTF) (npts, F77_DBLE_CMPLX_ARG (prow), |
4caa7b28d183
maint: Style check C++ code in liboctave/
Rik <rik@octave.org>
parents:
22327
diff
changeset
|
325 F77_DBLE_CMPLX_ARG (pwsave)); |
4773 | 326 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
327 for (octave_idx_type l = 0; l < npts; l++) |
14844
5bc9b9cb4362
maint: Use Octave coding conventions for cuddled parenthesis in retval assignments.
Rik <octave@nomad.inbox5.com>
parents:
14557
diff
changeset
|
328 retval((l + k*npts)*stride + j*dist) = prow[l]; |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
329 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
330 } |
4773 | 331 |
332 stride *= dv2(i); | |
333 } | |
334 | |
335 return retval; | |
336 } | |
337 | |
338 ComplexNDArray | |
339 ComplexNDArray::ifourier2d (void) const | |
340 { | |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14844
diff
changeset
|
341 dim_vector dv = dims (); |
4773 | 342 dim_vector dv2 (dv(0), dv(1)); |
343 int rank = 2; | |
344 ComplexNDArray retval (*this); | |
5275 | 345 octave_idx_type stride = 1; |
4773 | 346 |
347 for (int i = 0; i < rank; i++) | |
348 { | |
5275 | 349 octave_idx_type npts = dv2(i); |
350 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
|
351 Array<Complex> wsave (dim_vector (nn, 1)); |
4773 | 352 Complex *pwsave = wsave.fortran_vec (); |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
353 Array<Complex> row (dim_vector (npts, 1)); |
4773 | 354 Complex *prow = row.fortran_vec (); |
355 | |
5275 | 356 octave_idx_type howmany = numel () / npts; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
357 howmany = (stride == 1 ? howmany : |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
358 (howmany > stride ? stride : howmany)); |
5275 | 359 octave_idx_type nloop = (stride == 1 ? 1 : numel () / npts / stride); |
360 octave_idx_type dist = (stride == 1 ? npts : 1); | |
4773 | 361 |
22261
77c4d43e06d1
Use new macros for passing complex arguments to Fortran FFTPACK subroutines
Mike Miller <mtmiller@octave.org>
parents:
22133
diff
changeset
|
362 F77_FUNC (zffti, ZFFTI) (npts, F77_DBLE_CMPLX_ARG (pwsave)); |
4773 | 363 |
5275 | 364 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
|
365 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
366 for (octave_idx_type j = 0; j < howmany; j++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
367 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
368 octave_quit (); |
4773 | 369 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
370 for (octave_idx_type l = 0; l < npts; l++) |
14844
5bc9b9cb4362
maint: Use Octave coding conventions for cuddled parenthesis in retval assignments.
Rik <octave@nomad.inbox5.com>
parents:
14557
diff
changeset
|
371 prow[l] = retval((l + k*npts)*stride + j*dist); |
4773 | 372 |
22402
4caa7b28d183
maint: Style check C++ code in liboctave/
Rik <rik@octave.org>
parents:
22327
diff
changeset
|
373 F77_FUNC (zfftb, ZFFTB) (npts, F77_DBLE_CMPLX_ARG (prow), |
4caa7b28d183
maint: Style check C++ code in liboctave/
Rik <rik@octave.org>
parents:
22327
diff
changeset
|
374 F77_DBLE_CMPLX_ARG (pwsave)); |
4773 | 375 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
376 for (octave_idx_type l = 0; l < npts; l++) |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
377 retval((l + k*npts)*stride + j*dist) = |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
378 prow[l] / static_cast<double> (npts); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
379 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
380 } |
4773 | 381 |
382 stride *= dv2(i); | |
383 } | |
384 | |
385 return retval; | |
386 } | |
387 | |
388 ComplexNDArray | |
389 ComplexNDArray::fourierNd (void) const | |
390 { | |
391 dim_vector dv = dims (); | |
21660
53728df3e4c9
maint: for clarity, call ndims() rather than length() on dimension vectors.
Rik <rik@octave.org>
parents:
21562
diff
changeset
|
392 int rank = dv.ndims (); |
4773 | 393 ComplexNDArray retval (*this); |
5275 | 394 octave_idx_type stride = 1; |
4773 | 395 |
396 for (int i = 0; i < rank; i++) | |
397 { | |
5275 | 398 octave_idx_type npts = dv(i); |
399 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
|
400 Array<Complex> wsave (dim_vector (nn, 1)); |
4773 | 401 Complex *pwsave = wsave.fortran_vec (); |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
402 Array<Complex> row (dim_vector (npts, 1)); |
4773 | 403 Complex *prow = row.fortran_vec (); |
404 | |
5275 | 405 octave_idx_type howmany = numel () / npts; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
406 howmany = (stride == 1 ? howmany : |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
407 (howmany > stride ? stride : howmany)); |
5275 | 408 octave_idx_type nloop = (stride == 1 ? 1 : numel () / npts / stride); |
409 octave_idx_type dist = (stride == 1 ? npts : 1); | |
4773 | 410 |
22261
77c4d43e06d1
Use new macros for passing complex arguments to Fortran FFTPACK subroutines
Mike Miller <mtmiller@octave.org>
parents:
22133
diff
changeset
|
411 F77_FUNC (zffti, ZFFTI) (npts, F77_DBLE_CMPLX_ARG (pwsave)); |
4773 | 412 |
5275 | 413 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
|
414 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
415 for (octave_idx_type j = 0; j < howmany; j++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
416 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
417 octave_quit (); |
4773 | 418 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
419 for (octave_idx_type l = 0; l < npts; l++) |
14844
5bc9b9cb4362
maint: Use Octave coding conventions for cuddled parenthesis in retval assignments.
Rik <octave@nomad.inbox5.com>
parents:
14557
diff
changeset
|
420 prow[l] = retval((l + k*npts)*stride + j*dist); |
4773 | 421 |
22402
4caa7b28d183
maint: Style check C++ code in liboctave/
Rik <rik@octave.org>
parents:
22327
diff
changeset
|
422 F77_FUNC (zfftf, ZFFTF) (npts, F77_DBLE_CMPLX_ARG (prow), |
4caa7b28d183
maint: Style check C++ code in liboctave/
Rik <rik@octave.org>
parents:
22327
diff
changeset
|
423 F77_DBLE_CMPLX_ARG (pwsave)); |
4773 | 424 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
425 for (octave_idx_type l = 0; l < npts; l++) |
14844
5bc9b9cb4362
maint: Use Octave coding conventions for cuddled parenthesis in retval assignments.
Rik <octave@nomad.inbox5.com>
parents:
14557
diff
changeset
|
426 retval((l + k*npts)*stride + j*dist) = prow[l]; |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
427 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
428 } |
4773 | 429 |
430 stride *= dv(i); | |
431 } | |
432 | |
433 return retval; | |
434 } | |
435 | |
436 ComplexNDArray | |
437 ComplexNDArray::ifourierNd (void) const | |
438 { | |
439 dim_vector dv = dims (); | |
21660
53728df3e4c9
maint: for clarity, call ndims() rather than length() on dimension vectors.
Rik <rik@octave.org>
parents:
21562
diff
changeset
|
440 int rank = dv.ndims (); |
4773 | 441 ComplexNDArray retval (*this); |
5275 | 442 octave_idx_type stride = 1; |
4773 | 443 |
444 for (int i = 0; i < rank; i++) | |
445 { | |
5275 | 446 octave_idx_type npts = dv(i); |
447 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
|
448 Array<Complex> wsave (dim_vector (nn, 1)); |
4773 | 449 Complex *pwsave = wsave.fortran_vec (); |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
450 Array<Complex> row (dim_vector (npts, 1)); |
4773 | 451 Complex *prow = row.fortran_vec (); |
452 | |
5275 | 453 octave_idx_type howmany = numel () / npts; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
454 howmany = (stride == 1 ? howmany : |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
455 (howmany > stride ? stride : howmany)); |
5275 | 456 octave_idx_type nloop = (stride == 1 ? 1 : numel () / npts / stride); |
457 octave_idx_type dist = (stride == 1 ? npts : 1); | |
4773 | 458 |
22261
77c4d43e06d1
Use new macros for passing complex arguments to Fortran FFTPACK subroutines
Mike Miller <mtmiller@octave.org>
parents:
22133
diff
changeset
|
459 F77_FUNC (zffti, ZFFTI) (npts, F77_DBLE_CMPLX_ARG (pwsave)); |
4773 | 460 |
5275 | 461 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
|
462 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
463 for (octave_idx_type j = 0; j < howmany; j++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
464 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
465 octave_quit (); |
4773 | 466 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
467 for (octave_idx_type l = 0; l < npts; l++) |
14844
5bc9b9cb4362
maint: Use Octave coding conventions for cuddled parenthesis in retval assignments.
Rik <octave@nomad.inbox5.com>
parents:
14557
diff
changeset
|
468 prow[l] = retval((l + k*npts)*stride + j*dist); |
4773 | 469 |
22402
4caa7b28d183
maint: Style check C++ code in liboctave/
Rik <rik@octave.org>
parents:
22327
diff
changeset
|
470 F77_FUNC (zfftb, ZFFTB) (npts, F77_DBLE_CMPLX_ARG (prow), |
4caa7b28d183
maint: Style check C++ code in liboctave/
Rik <rik@octave.org>
parents:
22327
diff
changeset
|
471 F77_DBLE_CMPLX_ARG (pwsave)); |
4773 | 472 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
473 for (octave_idx_type l = 0; l < npts; l++) |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
474 retval((l + k*npts)*stride + j*dist) = |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
475 prow[l] / static_cast<double> (npts); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
476 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
477 } |
4773 | 478 |
479 stride *= dv(i); | |
480 } | |
481 | |
482 return retval; | |
483 } | |
484 | |
485 #endif | |
486 | |
4543 | 487 // unary operations |
488 | |
489 boolNDArray | |
490 ComplexNDArray::operator ! (void) const | |
491 { | |
11130
7c573eb981eb
consistently give error for operator not applied to NaN values
John W. Eaton <jwe@octave.org>
parents:
11008
diff
changeset
|
492 if (any_element_is_nan ()) |
22327
d0562b3159c7
move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
493 octave::err_nan_to_logical_conversion (); |
11130
7c573eb981eb
consistently give error for operator not applied to NaN values
John W. Eaton <jwe@octave.org>
parents:
11008
diff
changeset
|
494 |
10362
b47ab50a6aa8
simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
495 return do_mx_unary_op<bool, Complex> (*this, mx_inline_not); |
4543 | 496 } |
497 | |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
498 // FIXME: this is not quite the right thing. |
4514 | 499 |
4687 | 500 bool |
7922
935be827eaf8
error for NaN values in & and | expressions
John W. Eaton <jwe@octave.org>
parents:
7789
diff
changeset
|
501 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
|
502 { |
11008
3622db30ff05
simplify some array tests in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10362
diff
changeset
|
503 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
|
504 } |
935be827eaf8
error for NaN values in & and | expressions
John W. Eaton <jwe@octave.org>
parents:
7789
diff
changeset
|
505 |
935be827eaf8
error for NaN values in & and | expressions
John W. Eaton <jwe@octave.org>
parents:
7789
diff
changeset
|
506 bool |
4687 | 507 ComplexNDArray::any_element_is_inf_or_nan (void) const |
508 { | |
11008
3622db30ff05
simplify some array tests in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10362
diff
changeset
|
509 return ! do_mx_check<Complex> (*this, mx_inline_all_finite); |
4687 | 510 } |
511 | |
512 // Return true if no elements have imaginary components. | |
513 | |
514 bool | |
515 ComplexNDArray::all_elements_are_real (void) const | |
516 { | |
11008
3622db30ff05
simplify some array tests in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10362
diff
changeset
|
517 return do_mx_check<Complex> (*this, mx_inline_all_real); |
4687 | 518 } |
519 | |
520 // Return nonzero if any element of CM has a non-integer real or | |
521 // 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
|
522 // imaginary) values and return them in MAX_VAL and MIN_VAL. |
4687 | 523 |
524 bool | |
525 ComplexNDArray::all_integers (double& max_val, double& min_val) const | |
526 { | |
20228
00cf2847355d
Deprecate Array::nelem() and Range::nelem() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20218
diff
changeset
|
527 octave_idx_type nel = numel (); |
4687 | 528 |
529 if (nel > 0) | |
530 { | |
531 Complex val = elem (0); | |
532 | |
22274
edcad35c364f
don't rely on std:: overloads of arg, conj, imag, and real for real args
John W. Eaton <jwe@octave.org>
parents:
22261
diff
changeset
|
533 double r_val = val.real (); |
edcad35c364f
don't rely on std:: overloads of arg, conj, imag, and real for real args
John W. Eaton <jwe@octave.org>
parents:
22261
diff
changeset
|
534 double i_val = val.imag (); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
535 |
4687 | 536 max_val = r_val; |
537 min_val = r_val; | |
538 | |
539 if (i_val > max_val) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
540 max_val = i_val; |
4687 | 541 |
542 if (i_val < max_val) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
543 min_val = i_val; |
4687 | 544 } |
545 else | |
546 return false; | |
547 | |
5275 | 548 for (octave_idx_type i = 0; i < nel; i++) |
4687 | 549 { |
550 Complex val = elem (i); | |
551 | |
22274
edcad35c364f
don't rely on std:: overloads of arg, conj, imag, and real for real args
John W. Eaton <jwe@octave.org>
parents:
22261
diff
changeset
|
552 double r_val = val.real (); |
edcad35c364f
don't rely on std:: overloads of arg, conj, imag, and real for real args
John W. Eaton <jwe@octave.org>
parents:
22261
diff
changeset
|
553 double i_val = val.imag (); |
4687 | 554 |
555 if (r_val > max_val) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
556 max_val = r_val; |
4687 | 557 |
558 if (i_val > max_val) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
559 max_val = i_val; |
4687 | 560 |
561 if (r_val < min_val) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
562 min_val = r_val; |
4687 | 563 |
564 if (i_val < min_val) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
565 min_val = i_val; |
4687 | 566 |
22402
4caa7b28d183
maint: Style check C++ code in liboctave/
Rik <rik@octave.org>
parents:
22327
diff
changeset
|
567 if (octave::math::x_nint (r_val) != r_val |
4caa7b28d183
maint: Style check C++ code in liboctave/
Rik <rik@octave.org>
parents:
22327
diff
changeset
|
568 || octave::math::x_nint (i_val) != i_val) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
569 return false; |
4687 | 570 } |
571 | |
572 return true; | |
573 } | |
574 | |
575 bool | |
576 ComplexNDArray::too_large_for_float (void) const | |
577 { | |
15212
4bbd3bbb8912
reduce code duplication in too_large_for_float array functions
John W. Eaton <jwe@octave.org>
parents:
15018
diff
changeset
|
578 return test_any (xtoo_large_for_float); |
4687 | 579 } |
580 | |
4556 | 581 boolNDArray |
4514 | 582 ComplexNDArray::all (int dim) const |
583 { | |
10362
b47ab50a6aa8
simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
584 return do_mx_red_op<bool, Complex> (*this, dim, mx_inline_all); |
4514 | 585 } |
586 | |
4556 | 587 boolNDArray |
4514 | 588 ComplexNDArray::any (int dim) const |
589 { | |
10362
b47ab50a6aa8
simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
590 return do_mx_red_op<bool, Complex> (*this, dim, mx_inline_any); |
4569 | 591 } |
592 | |
4584 | 593 ComplexNDArray |
4569 | 594 ComplexNDArray::cumprod (int dim) const |
595 { | |
10362
b47ab50a6aa8
simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
596 return do_mx_cum_op<Complex, Complex> (*this, dim, mx_inline_cumprod); |
4569 | 597 } |
598 | |
4584 | 599 ComplexNDArray |
4569 | 600 ComplexNDArray::cumsum (int dim) const |
601 { | |
10362
b47ab50a6aa8
simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
602 return do_mx_cum_op<Complex, Complex> (*this, dim, mx_inline_cumsum); |
4569 | 603 } |
604 | |
605 ComplexNDArray | |
606 ComplexNDArray::prod (int dim) const | |
607 { | |
10362
b47ab50a6aa8
simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
608 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
|
609 } |
53b4fdeacc2e
improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8650
diff
changeset
|
610 |
53b4fdeacc2e
improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8650
diff
changeset
|
611 ComplexNDArray |
53b4fdeacc2e
improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8650
diff
changeset
|
612 ComplexNDArray::sum (int dim) const |
53b4fdeacc2e
improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8650
diff
changeset
|
613 { |
10362
b47ab50a6aa8
simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
614 return do_mx_red_op<Complex, Complex> (*this, dim, mx_inline_sum); |
4569 | 615 } |
616 | |
617 ComplexNDArray | |
9721
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9612
diff
changeset
|
618 ComplexNDArray::xsum (int dim) const |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9612
diff
changeset
|
619 { |
10362
b47ab50a6aa8
simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
620 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
|
621 } |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9612
diff
changeset
|
622 |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9612
diff
changeset
|
623 ComplexNDArray |
4569 | 624 ComplexNDArray::sumsq (int dim) const |
625 { | |
10362
b47ab50a6aa8
simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
626 return do_mx_red_op<double, Complex> (*this, dim, mx_inline_sumsq); |
4569 | 627 } |
628 | |
4915 | 629 ComplexNDArray |
9513
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9469
diff
changeset
|
630 ComplexNDArray::diff (octave_idx_type order, int dim) const |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9469
diff
changeset
|
631 { |
10362
b47ab50a6aa8
simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
632 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
|
633 } |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9469
diff
changeset
|
634 |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9469
diff
changeset
|
635 ComplexNDArray |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
636 ComplexNDArray::concat (const ComplexNDArray& rb, |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
637 const Array<octave_idx_type>& ra_idx) |
4915 | 638 { |
4940 | 639 if (rb.numel () > 0) |
5073 | 640 insert (rb, ra_idx); |
641 return *this; | |
4915 | 642 } |
643 | |
644 ComplexNDArray | |
5275 | 645 ComplexNDArray::concat (const NDArray& rb, const Array<octave_idx_type>& ra_idx) |
4758 | 646 { |
4915 | 647 ComplexNDArray tmp (rb); |
4940 | 648 if (rb.numel () > 0) |
5073 | 649 insert (tmp, ra_idx); |
650 return *this; | |
4915 | 651 } |
652 | |
653 ComplexNDArray | |
5275 | 654 concat (NDArray& ra, ComplexNDArray& rb, const Array<octave_idx_type>& ra_idx) |
4915 | 655 { |
656 ComplexNDArray retval (ra); | |
4940 | 657 if (rb.numel () > 0) |
4915 | 658 retval.insert (rb, ra_idx); |
659 return retval; | |
4758 | 660 } |
661 | |
21723
bae585228161
use namespace for numeric_limits
John W. Eaton <jwe@octave.org>
parents:
21721
diff
changeset
|
662 static const Complex Complex_NaN_result (octave::numeric_limits<double>::NaN (), |
bae585228161
use namespace for numeric_limits
John W. Eaton <jwe@octave.org>
parents:
21721
diff
changeset
|
663 octave::numeric_limits<double>::NaN ()); |
4844 | 664 |
665 ComplexNDArray | |
666 ComplexNDArray::max (int dim) const | |
667 { | |
10362
b47ab50a6aa8
simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
668 return do_mx_minmax_op<Complex> (*this, dim, mx_inline_max); |
4844 | 669 } |
670 | |
671 ComplexNDArray | |
9732
b4fdfee405b5
remove ArrayN<T> + fix nonhom. diag-scalar ops
Jaroslav Hajek <highegg@gmail.com>
parents:
9721
diff
changeset
|
672 ComplexNDArray::max (Array<octave_idx_type>& idx_arg, int dim) const |
4844 | 673 { |
10362
b47ab50a6aa8
simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
674 return do_mx_minmax_op<Complex> (*this, idx_arg, dim, mx_inline_max); |
4844 | 675 } |
676 | |
677 ComplexNDArray | |
678 ComplexNDArray::min (int dim) const | |
679 { | |
10362
b47ab50a6aa8
simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
680 return do_mx_minmax_op<Complex> (*this, dim, mx_inline_min); |
4844 | 681 } |
682 | |
683 ComplexNDArray | |
9732
b4fdfee405b5
remove ArrayN<T> + fix nonhom. diag-scalar ops
Jaroslav Hajek <highegg@gmail.com>
parents:
9721
diff
changeset
|
684 ComplexNDArray::min (Array<octave_idx_type>& idx_arg, int dim) const |
4844 | 685 { |
10362
b47ab50a6aa8
simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
686 return do_mx_minmax_op<Complex> (*this, idx_arg, dim, mx_inline_min); |
4844 | 687 } |
688 | |
8777
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8774
diff
changeset
|
689 ComplexNDArray |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8774
diff
changeset
|
690 ComplexNDArray::cummax (int dim) const |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8774
diff
changeset
|
691 { |
10362
b47ab50a6aa8
simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
692 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
|
693 } |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8774
diff
changeset
|
694 |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8774
diff
changeset
|
695 ComplexNDArray |
9732
b4fdfee405b5
remove ArrayN<T> + fix nonhom. diag-scalar ops
Jaroslav Hajek <highegg@gmail.com>
parents:
9721
diff
changeset
|
696 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
|
697 { |
10362
b47ab50a6aa8
simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
698 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
|
699 } |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8774
diff
changeset
|
700 |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8774
diff
changeset
|
701 ComplexNDArray |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8774
diff
changeset
|
702 ComplexNDArray::cummin (int dim) const |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8774
diff
changeset
|
703 { |
10362
b47ab50a6aa8
simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
704 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
|
705 } |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8774
diff
changeset
|
706 |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8774
diff
changeset
|
707 ComplexNDArray |
9732
b4fdfee405b5
remove ArrayN<T> + fix nonhom. diag-scalar ops
Jaroslav Hajek <highegg@gmail.com>
parents:
9721
diff
changeset
|
708 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
|
709 { |
10362
b47ab50a6aa8
simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
710 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
|
711 } |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8774
diff
changeset
|
712 |
4634 | 713 NDArray |
4569 | 714 ComplexNDArray::abs (void) const |
715 { | |
10362
b47ab50a6aa8
simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
716 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
|
717 } |
4634 | 718 |
8998
a48fba01e4ac
optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents:
8981
diff
changeset
|
719 boolNDArray |
a48fba01e4ac
optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents:
8981
diff
changeset
|
720 ComplexNDArray::isnan (void) const |
a48fba01e4ac
optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents:
8981
diff
changeset
|
721 { |
21782
2aef506f3fec
use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
722 return do_mx_unary_map<bool, Complex, octave::math::isnan> (*this); |
8998
a48fba01e4ac
optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents:
8981
diff
changeset
|
723 } |
a48fba01e4ac
optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents:
8981
diff
changeset
|
724 |
a48fba01e4ac
optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents:
8981
diff
changeset
|
725 boolNDArray |
a48fba01e4ac
optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents:
8981
diff
changeset
|
726 ComplexNDArray::isinf (void) const |
a48fba01e4ac
optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents:
8981
diff
changeset
|
727 { |
21782
2aef506f3fec
use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
728 return do_mx_unary_map<bool, Complex, octave::math::isinf> (*this); |
8998
a48fba01e4ac
optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents:
8981
diff
changeset
|
729 } |
a48fba01e4ac
optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents:
8981
diff
changeset
|
730 |
a48fba01e4ac
optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents:
8981
diff
changeset
|
731 boolNDArray |
a48fba01e4ac
optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents:
8981
diff
changeset
|
732 ComplexNDArray::isfinite (void) const |
a48fba01e4ac
optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents:
8981
diff
changeset
|
733 { |
21782
2aef506f3fec
use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
734 return do_mx_unary_map<bool, Complex, octave::math::finite> (*this); |
8998
a48fba01e4ac
optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents:
8981
diff
changeset
|
735 } |
a48fba01e4ac
optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents:
8981
diff
changeset
|
736 |
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
|
737 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
|
738 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
|
739 { |
13107
353c71c76f22
maint: fix compilation problem with g++ -std=c++0x option
Júlio Hoffimann <julio.hoffimann@gmail.com>
parents:
11586
diff
changeset
|
740 return do_mx_unary_map<Complex, Complex, std::conj<double> > (a); |
4514 | 741 } |
742 | |
4765 | 743 ComplexNDArray& |
5275 | 744 ComplexNDArray::insert (const NDArray& a, octave_idx_type r, octave_idx_type c) |
4765 | 745 { |
746 dim_vector a_dv = a.dims (); | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
747 |
21660
53728df3e4c9
maint: for clarity, call ndims() rather than length() on dimension vectors.
Rik <rik@octave.org>
parents:
21562
diff
changeset
|
748 int n = a_dv.ndims (); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
749 |
21660
53728df3e4c9
maint: for clarity, call ndims() rather than length() on dimension vectors.
Rik <rik@octave.org>
parents:
21562
diff
changeset
|
750 if (n != dimensions.ndims ()) |
4765 | 751 (*current_liboctave_error_handler) |
752 ("Array<T>::insert: invalid indexing operation"); | |
753 | |
21660
53728df3e4c9
maint: for clarity, call ndims() rather than length() on dimension vectors.
Rik <rik@octave.org>
parents:
21562
diff
changeset
|
754 Array<octave_idx_type> a_ra_idx (dim_vector (a_dv.ndims (), 1), 0); |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
755 |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
756 a_ra_idx.elem (0) = r; |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
757 a_ra_idx.elem (1) = c; |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
758 |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
759 for (int i = 0; i < n; i++) |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
760 { |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
761 if (a_ra_idx(i) < 0 || (a_ra_idx(i) + a_dv(i)) > dimensions(i)) |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
762 (*current_liboctave_error_handler) |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
763 ("Array<T>::insert: range error for insert"); |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
764 } |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
765 |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
766 a_ra_idx.elem (0) = 0; |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
767 a_ra_idx.elem (1) = 0; |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
768 |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
769 octave_idx_type n_elt = a.numel (); |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
770 |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
771 // IS make_unique () NECESSARY HERE? |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
772 |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
773 for (octave_idx_type i = 0; i < n_elt; i++) |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
774 { |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
775 Array<octave_idx_type> ra_idx = a_ra_idx; |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
776 |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
777 ra_idx.elem (0) = a_ra_idx(0) + r; |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
778 ra_idx.elem (1) = a_ra_idx(1) + c; |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
779 |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
780 elem (ra_idx) = a.elem (a_ra_idx); |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
781 |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
782 increment_index (a_ra_idx, a_dv); |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
783 } |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
784 |
4765 | 785 return *this; |
786 } | |
787 | |
788 ComplexNDArray& | |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
789 ComplexNDArray::insert (const ComplexNDArray& a, |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
790 octave_idx_type r, octave_idx_type c) |
4765 | 791 { |
792 Array<Complex>::insert (a, r, c); | |
793 return *this; | |
794 } | |
795 | |
4915 | 796 ComplexNDArray& |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
797 ComplexNDArray::insert (const ComplexNDArray& a, |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
798 const Array<octave_idx_type>& ra_idx) |
4915 | 799 { |
800 Array<Complex>::insert (a, ra_idx); | |
801 return *this; | |
802 } | |
803 | |
4532 | 804 void |
5275 | 805 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
|
806 const dim_vector& dimensions, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
807 int start_dimension) |
4532 | 808 { |
809 ::increment_index (ra_idx, dimensions, start_dimension); | |
810 } | |
811 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
812 octave_idx_type |
5275 | 813 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
|
814 const dim_vector& dimensions) |
4556 | 815 { |
816 return ::compute_index (ra_idx, dimensions); | |
817 } | |
818 | |
7620
36594d5bbe13
Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents:
7600
diff
changeset
|
819 ComplexNDArray |
36594d5bbe13
Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents:
7600
diff
changeset
|
820 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
|
821 { |
10350
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10329
diff
changeset
|
822 return MArray<Complex>::diag (k); |
7620
36594d5bbe13
Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents:
7600
diff
changeset
|
823 } |
36594d5bbe13
Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents:
7600
diff
changeset
|
824 |
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
|
825 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
|
826 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
|
827 { |
e8e86ae3abbc
make diag (x, m, n) return a proper diagonal matrix object (bug #36099)
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
828 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
|
829 } |
e8e86ae3abbc
make diag (x, m, n) return a proper diagonal matrix object (bug #36099)
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
830 |
4687 | 831 // This contains no information on the array structure !!! |
832 std::ostream& | |
833 operator << (std::ostream& os, const ComplexNDArray& a) | |
834 { | |
20228
00cf2847355d
Deprecate Array::nelem() and Range::nelem() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20218
diff
changeset
|
835 octave_idx_type nel = a.numel (); |
4687 | 836 |
5275 | 837 for (octave_idx_type i = 0; i < nel; i++) |
4687 | 838 { |
839 os << " "; | |
840 octave_write_complex (os, a.elem (i)); | |
841 os << "\n"; | |
842 } | |
843 return os; | |
844 } | |
845 | |
846 std::istream& | |
847 operator >> (std::istream& is, ComplexNDArray& a) | |
848 { | |
20228
00cf2847355d
Deprecate Array::nelem() and Range::nelem() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20218
diff
changeset
|
849 octave_idx_type nel = a.numel (); |
4687 | 850 |
8999
dc07bc4157b8
allow empty matrices in stream input operators
Jaroslav Hajek <highegg@gmail.com>
parents:
8998
diff
changeset
|
851 if (nel > 0) |
4687 | 852 { |
853 Complex tmp; | |
5275 | 854 for (octave_idx_type i = 0; i < nel; i++) |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
855 { |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
856 tmp = octave_read_value<Complex> (is); |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
857 if (is) |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
858 a.elem (i) = tmp; |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
859 else |
21168
26f85aa072de
maint: Replace instances of goto in liboctave where convenient.
Rik <rik@octave.org>
parents:
21136
diff
changeset
|
860 return is; |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
861 } |
4687 | 862 } |
863 | |
864 return is; | |
865 } | |
866 | |
10329
83fa590b8a09
simplify min/max definitions in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10314
diff
changeset
|
867 MINMAX_FCNS (ComplexNDArray, Complex) |
4844 | 868 |
9578
7dafdb8b062f
refactor comparison ops implementations
Jaroslav Hajek <highegg@gmail.com>
parents:
9553
diff
changeset
|
869 NDS_CMP_OPS (ComplexNDArray, Complex) |
9550
3d6a9aea2aea
refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
9546
diff
changeset
|
870 NDS_BOOL_OPS (ComplexNDArray, Complex) |
4543 | 871 |
9578
7dafdb8b062f
refactor comparison ops implementations
Jaroslav Hajek <highegg@gmail.com>
parents:
9553
diff
changeset
|
872 SND_CMP_OPS (Complex, ComplexNDArray) |
9550
3d6a9aea2aea
refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
9546
diff
changeset
|
873 SND_BOOL_OPS (Complex, ComplexNDArray) |
4543 | 874 |
9578
7dafdb8b062f
refactor comparison ops implementations
Jaroslav Hajek <highegg@gmail.com>
parents:
9553
diff
changeset
|
875 NDND_CMP_OPS (ComplexNDArray, ComplexNDArray) |
9550
3d6a9aea2aea
refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
9546
diff
changeset
|
876 NDND_BOOL_OPS (ComplexNDArray, ComplexNDArray) |
4543 | 877 |
9546
1beb23d2b892
optimize op= in common cases
Jaroslav Hajek <highegg@gmail.com>
parents:
9523
diff
changeset
|
878 ComplexNDArray& operator *= (ComplexNDArray& a, double s) |
1beb23d2b892
optimize op= in common cases
Jaroslav Hajek <highegg@gmail.com>
parents:
9523
diff
changeset
|
879 { |
1beb23d2b892
optimize op= in common cases
Jaroslav Hajek <highegg@gmail.com>
parents:
9523
diff
changeset
|
880 if (a.is_shared ()) |
9612
66970dd627f6
further liboctave design improvements
Jaroslav Hajek <highegg@gmail.com>
parents:
9601
diff
changeset
|
881 a = a * s; |
66970dd627f6
further liboctave design improvements
Jaroslav Hajek <highegg@gmail.com>
parents:
9601
diff
changeset
|
882 else |
10362
b47ab50a6aa8
simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
883 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
|
884 return a; |
1beb23d2b892
optimize op= in common cases
Jaroslav Hajek <highegg@gmail.com>
parents:
9523
diff
changeset
|
885 } |
1beb23d2b892
optimize op= in common cases
Jaroslav Hajek <highegg@gmail.com>
parents:
9523
diff
changeset
|
886 |
1beb23d2b892
optimize op= in common cases
Jaroslav Hajek <highegg@gmail.com>
parents:
9523
diff
changeset
|
887 ComplexNDArray& operator /= (ComplexNDArray& a, double s) |
1beb23d2b892
optimize op= in common cases
Jaroslav Hajek <highegg@gmail.com>
parents:
9523
diff
changeset
|
888 { |
1beb23d2b892
optimize op= in common cases
Jaroslav Hajek <highegg@gmail.com>
parents:
9523
diff
changeset
|
889 if (a.is_shared ()) |
1beb23d2b892
optimize op= in common cases
Jaroslav Hajek <highegg@gmail.com>
parents:
9523
diff
changeset
|
890 return a = a / s; |
9612
66970dd627f6
further liboctave design improvements
Jaroslav Hajek <highegg@gmail.com>
parents:
9601
diff
changeset
|
891 else |
10362
b47ab50a6aa8
simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
892 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
|
893 return a; |
1beb23d2b892
optimize op= in common cases
Jaroslav Hajek <highegg@gmail.com>
parents:
9523
diff
changeset
|
894 } |
1beb23d2b892
optimize op= in common cases
Jaroslav Hajek <highegg@gmail.com>
parents:
9523
diff
changeset
|
895 |
9743
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
896 BSXFUN_STDOP_DEFS_MXLOOP (ComplexNDArray) |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
897 BSXFUN_STDREL_DEFS_MXLOOP (ComplexNDArray) |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
898 |
9827
c15a5ed0da58
optimize bsxfun (@power, ...)
Jaroslav Hajek <highegg@gmail.com>
parents:
9825
diff
changeset
|
899 BSXFUN_OP_DEF_MXLOOP (pow, ComplexNDArray, mx_inline_pow) |