Mercurial > hg > octave-nkf
annotate liboctave/array/dNDArray.cc @ 19537:8f6a8422435d
Replace instances of deprecated Array constructor in FFTPACK-related code.
* dNDArray.cc (fourier, ifourier, fourier2d, ifourier2d, fourierNd,
ifourierNd): Use Array constructor with dim_vector input.
* fNDArray.cc (fourier, ifourier, fourier2d, ifourier2d, fourierNd,
ifourierNd): Use Array constructor with dim_vector input.
* fCNDArray.cc (fourier, ifourier, fourier2d, ifourier2d, fourierNd,
ifourierNd): Use Array constructor with dim_vector input.
author | Rik <rik@octave.org> |
---|---|
date | Sat, 22 Nov 2014 12:35:08 -0800 |
parents | d0c73e23a505 |
children | 4197fc428c7d |
rev | line source |
---|---|
4513 | 1 // N-D Array manipulations. |
4511 | 2 /* |
3 | |
17744
d63878346099
maint: Update copyright notices for release.
John W. Eaton <jwe@octave.org>
parents:
15271
diff
changeset
|
4 Copyright (C) 1996-2013 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. |
4511 | 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. | |
4511 | 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/>. | |
4511 | 22 |
23 */ | |
24 | |
25 #ifdef HAVE_CONFIG_H | |
26 #include <config.h> | |
27 #endif | |
28 | |
4634 | 29 #include <cfloat> |
5164 | 30 |
4780 | 31 #include <vector> |
4634 | 32 |
4588 | 33 #include "Array-util.h" |
4513 | 34 #include "dNDArray.h" |
9523
0ce82753dd72
more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents:
9513
diff
changeset
|
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" |
4513 | 37 #include "lo-error.h" |
4511 | 38 #include "lo-ieee.h" |
4634 | 39 #include "lo-mappers.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" |
4773 | 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 |
7919
9d080df0c843
new NDArray constructor for ArrayN<octave_idx_type>
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
47 NDArray::NDArray (const Array<octave_idx_type>& a, bool zero_based, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
48 bool negative_to_nan) |
7919
9d080df0c843
new NDArray constructor for ArrayN<octave_idx_type>
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
49 { |
9d080df0c843
new NDArray constructor for ArrayN<octave_idx_type>
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
50 const octave_idx_type *pa = a.fortran_vec (); |
9d080df0c843
new NDArray constructor for ArrayN<octave_idx_type>
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
51 resize (a.dims ()); |
9d080df0c843
new NDArray constructor for ArrayN<octave_idx_type>
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
52 double *ptmp = fortran_vec (); |
9d080df0c843
new NDArray constructor for ArrayN<octave_idx_type>
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
53 if (negative_to_nan) |
9d080df0c843
new NDArray constructor for ArrayN<octave_idx_type>
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
54 { |
9d080df0c843
new NDArray constructor for ArrayN<octave_idx_type>
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
55 double nan_val = lo_ieee_nan_value (); |
9d080df0c843
new NDArray constructor for ArrayN<octave_idx_type>
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
56 |
9d080df0c843
new NDArray constructor for ArrayN<octave_idx_type>
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
57 if (zero_based) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
58 for (octave_idx_type i = 0; i < a.numel (); i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
59 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
60 double val = static_cast<double> |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
61 (pa[i] + static_cast<octave_idx_type> (1)); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
62 if (val <= 0) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
63 ptmp[i] = nan_val; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
64 else |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
65 ptmp[i] = val; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
66 } |
7919
9d080df0c843
new NDArray constructor for ArrayN<octave_idx_type>
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
67 else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
68 for (octave_idx_type i = 0; i < a.numel (); i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
69 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
70 double val = static_cast<double> (pa[i]); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
71 if (val <= 0) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
72 ptmp[i] = nan_val; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
73 else |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
74 ptmp[i] = val; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
75 } |
7919
9d080df0c843
new NDArray constructor for ArrayN<octave_idx_type>
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
76 } |
9d080df0c843
new NDArray constructor for ArrayN<octave_idx_type>
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
77 else |
9d080df0c843
new NDArray constructor for ArrayN<octave_idx_type>
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
78 { |
9d080df0c843
new NDArray constructor for ArrayN<octave_idx_type>
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
79 if (zero_based) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
80 for (octave_idx_type i = 0; i < a.numel (); i++) |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
81 ptmp[i] = static_cast<double> |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
82 (pa[i] + static_cast<octave_idx_type> (1)); |
7919
9d080df0c843
new NDArray constructor for ArrayN<octave_idx_type>
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
83 else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
84 for (octave_idx_type i = 0; i < a.numel (); i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
85 ptmp[i] = static_cast<double> (pa[i]); |
7919
9d080df0c843
new NDArray constructor for ArrayN<octave_idx_type>
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
86 } |
9d080df0c843
new NDArray constructor for ArrayN<octave_idx_type>
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
87 } |
9d080df0c843
new NDArray constructor for ArrayN<octave_idx_type>
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
88 |
8956
d91fa4b20bbb
ensure nonnegative char -> real conversion
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
89 NDArray::NDArray (const charNDArray& a) |
10350
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10329
diff
changeset
|
90 : MArray<double> (a.dims ()) |
8956
d91fa4b20bbb
ensure nonnegative char -> real conversion
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
91 { |
d91fa4b20bbb
ensure nonnegative char -> real conversion
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
92 octave_idx_type n = a.numel (); |
d91fa4b20bbb
ensure nonnegative char -> real conversion
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
93 for (octave_idx_type i = 0; i < n; i++) |
d91fa4b20bbb
ensure nonnegative char -> real conversion
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
94 xelem (i) = static_cast<unsigned char> (a(i)); |
d91fa4b20bbb
ensure nonnegative char -> real conversion
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
95 } |
d91fa4b20bbb
ensure nonnegative char -> real conversion
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
96 |
9523
0ce82753dd72
more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents:
9513
diff
changeset
|
97 #if defined (HAVE_FFTW) |
7941
f8cab9eeb128
Fix NDArray compilation/export
John W. Eaton <jwe@octave.org>
parents:
7922
diff
changeset
|
98 |
4773 | 99 ComplexNDArray |
100 NDArray::fourier (int dim) const | |
101 { | |
102 dim_vector dv = dims (); | |
103 | |
104 if (dim > dv.length () || dim < 0) | |
105 return ComplexNDArray (); | |
106 | |
5275 | 107 octave_idx_type stride = 1; |
108 octave_idx_type n = dv(dim); | |
4773 | 109 |
110 for (int i = 0; i < dim; i++) | |
111 stride *= dv(i); | |
112 | |
5275 | 113 octave_idx_type howmany = numel () / dv (dim); |
4773 | 114 howmany = (stride == 1 ? howmany : (howmany > stride ? stride : howmany)); |
5275 | 115 octave_idx_type nloop = (stride == 1 ? 1 : numel () / dv (dim) / stride); |
116 octave_idx_type dist = (stride == 1 ? n : 1); | |
4773 | 117 |
118 const double *in (fortran_vec ()); | |
119 ComplexNDArray retval (dv); | |
120 Complex *out (retval.fortran_vec ()); | |
121 | |
122 // Need to be careful here about the distance between fft's | |
5275 | 123 for (octave_idx_type k = 0; k < nloop; k++) |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
124 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
|
125 n, howmany, stride, dist); |
4773 | 126 |
127 return retval; | |
128 } | |
129 | |
130 ComplexNDArray | |
4816 | 131 NDArray::ifourier (int dim) const |
4773 | 132 { |
133 dim_vector dv = dims (); | |
134 | |
135 if (dim > dv.length () || dim < 0) | |
136 return ComplexNDArray (); | |
137 | |
5275 | 138 octave_idx_type stride = 1; |
139 octave_idx_type n = dv(dim); | |
4773 | 140 |
141 for (int i = 0; i < dim; i++) | |
142 stride *= dv(i); | |
143 | |
5275 | 144 octave_idx_type howmany = numel () / dv (dim); |
4773 | 145 howmany = (stride == 1 ? howmany : (howmany > stride ? stride : howmany)); |
5275 | 146 octave_idx_type nloop = (stride == 1 ? 1 : numel () / dv (dim) / stride); |
147 octave_idx_type dist = (stride == 1 ? n : 1); | |
4773 | 148 |
149 ComplexNDArray retval (*this); | |
150 Complex *out (retval.fortran_vec ()); | |
151 | |
152 // Need to be careful here about the distance between fft's | |
5275 | 153 for (octave_idx_type k = 0; k < nloop; k++) |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
154 octave_fftw::ifft (out + k * stride * n, out + k * stride * n, |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
155 n, howmany, stride, dist); |
4773 | 156 |
157 return retval; | |
158 } | |
159 | |
160 ComplexNDArray | |
161 NDArray::fourier2d (void) const | |
162 { | |
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
|
163 dim_vector dv = dims (); |
4773 | 164 if (dv.length () < 2) |
165 return ComplexNDArray (); | |
166 | |
167 dim_vector dv2(dv(0), dv(1)); | |
168 const double *in = fortran_vec (); | |
169 ComplexNDArray retval (dv); | |
170 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
|
171 octave_idx_type howmany = numel () / dv(0) / dv(1); |
5275 | 172 octave_idx_type dist = dv(0) * dv(1); |
4773 | 173 |
5275 | 174 for (octave_idx_type i=0; i < howmany; i++) |
4773 | 175 octave_fftw::fftNd (in + i*dist, out + i*dist, 2, dv2); |
176 | |
177 return retval; | |
178 } | |
179 | |
180 ComplexNDArray | |
181 NDArray::ifourier2d (void) const | |
182 { | |
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
|
183 dim_vector dv = dims (); |
4773 | 184 if (dv.length () < 2) |
185 return ComplexNDArray (); | |
186 | |
187 dim_vector dv2(dv(0), dv(1)); | |
188 ComplexNDArray retval (*this); | |
189 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
|
190 octave_idx_type howmany = numel () / dv(0) / dv(1); |
5275 | 191 octave_idx_type dist = dv(0) * dv(1); |
4773 | 192 |
5275 | 193 for (octave_idx_type i=0; i < howmany; i++) |
4773 | 194 octave_fftw::ifftNd (out + i*dist, out + i*dist, 2, dv2); |
195 | |
196 return retval; | |
197 } | |
198 | |
199 ComplexNDArray | |
200 NDArray::fourierNd (void) const | |
201 { | |
202 dim_vector dv = dims (); | |
203 int rank = dv.length (); | |
204 | |
205 const double *in (fortran_vec ()); | |
206 ComplexNDArray retval (dv); | |
207 Complex *out (retval.fortran_vec ()); | |
208 | |
209 octave_fftw::fftNd (in, out, rank, dv); | |
210 | |
211 return retval; | |
212 } | |
213 | |
214 ComplexNDArray | |
215 NDArray::ifourierNd (void) const | |
216 { | |
217 dim_vector dv = dims (); | |
218 int rank = dv.length (); | |
219 | |
220 ComplexNDArray tmp (*this); | |
221 Complex *in (tmp.fortran_vec ()); | |
222 ComplexNDArray retval (dv); | |
223 Complex *out (retval.fortran_vec ()); | |
224 | |
225 octave_fftw::ifftNd (in, out, rank, dv); | |
226 | |
227 return retval; | |
228 } | |
229 | |
230 #else | |
231 | |
232 extern "C" | |
233 { | |
234 // Note that the original complex fft routines were not written for | |
235 // double complex arguments. They have been modified by adding an | |
236 // implicit double precision (a-h,o-z) statement at the beginning of | |
237 // each subroutine. | |
238 | |
239 F77_RET_T | |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7620
diff
changeset
|
240 F77_FUNC (zffti, ZFFTI) (const octave_idx_type&, Complex*); |
4773 | 241 |
242 F77_RET_T | |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7620
diff
changeset
|
243 F77_FUNC (zfftf, ZFFTF) (const octave_idx_type&, Complex*, Complex*); |
4773 | 244 |
245 F77_RET_T | |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7620
diff
changeset
|
246 F77_FUNC (zfftb, ZFFTB) (const octave_idx_type&, Complex*, Complex*); |
4773 | 247 } |
248 | |
249 ComplexNDArray | |
250 NDArray::fourier (int dim) const | |
251 { | |
252 dim_vector dv = dims (); | |
253 | |
254 if (dim > dv.length () || dim < 0) | |
255 return ComplexNDArray (); | |
256 | |
257 ComplexNDArray retval (dv); | |
5275 | 258 octave_idx_type npts = dv(dim); |
259 octave_idx_type nn = 4*npts+15; | |
19537
8f6a8422435d
Replace instances of deprecated Array constructor in FFTPACK-related code.
Rik <rik@octave.org>
parents:
19510
diff
changeset
|
260 Array<Complex> wsave (dim_vector (nn, 1)); |
4773 | 261 Complex *pwsave = wsave.fortran_vec (); |
262 | |
263 OCTAVE_LOCAL_BUFFER (Complex, tmp, npts); | |
264 | |
5275 | 265 octave_idx_type stride = 1; |
4773 | 266 |
267 for (int i = 0; i < dim; i++) | |
268 stride *= dv(i); | |
269 | |
5275 | 270 octave_idx_type howmany = numel () / npts; |
4773 | 271 howmany = (stride == 1 ? howmany : (howmany > stride ? stride : howmany)); |
5275 | 272 octave_idx_type nloop = (stride == 1 ? 1 : numel () / npts / stride); |
273 octave_idx_type dist = (stride == 1 ? npts : 1); | |
4773 | 274 |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7620
diff
changeset
|
275 F77_FUNC (zffti, ZFFTI) (npts, pwsave); |
4773 | 276 |
5275 | 277 for (octave_idx_type k = 0; k < nloop; k++) |
4773 | 278 { |
5275 | 279 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
|
280 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
281 octave_quit (); |
4773 | 282 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
283 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
|
284 tmp[i] = elem ((i + k*npts)*stride + j*dist); |
4773 | 285 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
286 F77_FUNC (zfftf, ZFFTF) (npts, tmp, pwsave); |
4773 | 287 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
288 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
|
289 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
|
290 } |
4773 | 291 } |
292 | |
293 return retval; | |
294 } | |
295 | |
296 ComplexNDArray | |
297 NDArray::ifourier (int dim) const | |
298 { | |
299 dim_vector dv = dims (); | |
300 | |
301 if (dim > dv.length () || dim < 0) | |
302 return ComplexNDArray (); | |
303 | |
304 ComplexNDArray retval (dv); | |
5275 | 305 octave_idx_type npts = dv(dim); |
306 octave_idx_type nn = 4*npts+15; | |
19537
8f6a8422435d
Replace instances of deprecated Array constructor in FFTPACK-related code.
Rik <rik@octave.org>
parents:
19510
diff
changeset
|
307 Array<Complex> wsave (dim_vector (nn, 1)); |
4773 | 308 Complex *pwsave = wsave.fortran_vec (); |
309 | |
310 OCTAVE_LOCAL_BUFFER (Complex, tmp, npts); | |
311 | |
5275 | 312 octave_idx_type stride = 1; |
4773 | 313 |
314 for (int i = 0; i < dim; i++) | |
315 stride *= dv(i); | |
316 | |
5275 | 317 octave_idx_type howmany = numel () / npts; |
4773 | 318 howmany = (stride == 1 ? howmany : (howmany > stride ? stride : howmany)); |
5275 | 319 octave_idx_type nloop = (stride == 1 ? 1 : numel () / npts / stride); |
320 octave_idx_type dist = (stride == 1 ? npts : 1); | |
4773 | 321 |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7620
diff
changeset
|
322 F77_FUNC (zffti, ZFFTI) (npts, pwsave); |
4773 | 323 |
5275 | 324 for (octave_idx_type k = 0; k < nloop; k++) |
4773 | 325 { |
5275 | 326 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
|
327 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
328 octave_quit (); |
4773 | 329 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
330 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
|
331 tmp[i] = elem ((i + k*npts)*stride + j*dist); |
4773 | 332 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
333 F77_FUNC (zfftb, ZFFTB) (npts, tmp, pwsave); |
4773 | 334 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
335 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
|
336 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
|
337 static_cast<double> (npts); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
338 } |
4773 | 339 } |
340 | |
341 return retval; | |
342 } | |
343 | |
344 ComplexNDArray | |
345 NDArray::fourier2d (void) const | |
346 { | |
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
|
347 dim_vector dv = dims (); |
4773 | 348 dim_vector dv2 (dv(0), dv(1)); |
349 int rank = 2; | |
350 ComplexNDArray retval (*this); | |
5275 | 351 octave_idx_type stride = 1; |
4773 | 352 |
353 for (int i = 0; i < rank; i++) | |
354 { | |
5275 | 355 octave_idx_type npts = dv2(i); |
356 octave_idx_type nn = 4*npts+15; | |
19537
8f6a8422435d
Replace instances of deprecated Array constructor in FFTPACK-related code.
Rik <rik@octave.org>
parents:
19510
diff
changeset
|
357 Array<Complex> wsave (dim_vector (nn, 1)); |
4773 | 358 Complex *pwsave = wsave.fortran_vec (); |
19537
8f6a8422435d
Replace instances of deprecated Array constructor in FFTPACK-related code.
Rik <rik@octave.org>
parents:
19510
diff
changeset
|
359 Array<Complex> row (dim_vector (npts, 1)); |
4773 | 360 Complex *prow = row.fortran_vec (); |
361 | |
5275 | 362 octave_idx_type howmany = numel () / npts; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
363 howmany = (stride == 1 ? howmany : |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
364 (howmany > stride ? stride : howmany)); |
5275 | 365 octave_idx_type nloop = (stride == 1 ? 1 : numel () / npts / stride); |
366 octave_idx_type dist = (stride == 1 ? npts : 1); | |
4773 | 367 |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7620
diff
changeset
|
368 F77_FUNC (zffti, ZFFTI) (npts, pwsave); |
4773 | 369 |
5275 | 370 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
|
371 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
372 for (octave_idx_type j = 0; j < howmany; j++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
373 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
374 octave_quit (); |
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++) |
14844
5bc9b9cb4362
maint: Use Octave coding conventions for cuddled parenthesis in retval assignments.
Rik <octave@nomad.inbox5.com>
parents:
14557
diff
changeset
|
377 prow[l] = retval((l + k*npts)*stride + j*dist); |
4773 | 378 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
379 F77_FUNC (zfftf, ZFFTF) (npts, prow, pwsave); |
4773 | 380 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
381 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
|
382 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
|
383 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
384 } |
4773 | 385 |
386 stride *= dv2(i); | |
387 } | |
388 | |
389 return retval; | |
390 } | |
391 | |
392 ComplexNDArray | |
393 NDArray::ifourier2d (void) const | |
394 { | |
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
|
395 dim_vector dv = dims (); |
4773 | 396 dim_vector dv2 (dv(0), dv(1)); |
397 int rank = 2; | |
398 ComplexNDArray retval (*this); | |
5275 | 399 octave_idx_type stride = 1; |
4773 | 400 |
401 for (int i = 0; i < rank; i++) | |
402 { | |
5275 | 403 octave_idx_type npts = dv2(i); |
404 octave_idx_type nn = 4*npts+15; | |
19537
8f6a8422435d
Replace instances of deprecated Array constructor in FFTPACK-related code.
Rik <rik@octave.org>
parents:
19510
diff
changeset
|
405 Array<Complex> wsave (dim_vector (nn, 1)); |
4773 | 406 Complex *pwsave = wsave.fortran_vec (); |
19537
8f6a8422435d
Replace instances of deprecated Array constructor in FFTPACK-related code.
Rik <rik@octave.org>
parents:
19510
diff
changeset
|
407 Array<Complex> row (dim_vector (npts, 1)); |
4773 | 408 Complex *prow = row.fortran_vec (); |
409 | |
5275 | 410 octave_idx_type howmany = numel () / npts; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
411 howmany = (stride == 1 ? howmany : |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
412 (howmany > stride ? stride : howmany)); |
5275 | 413 octave_idx_type nloop = (stride == 1 ? 1 : numel () / npts / stride); |
414 octave_idx_type dist = (stride == 1 ? npts : 1); | |
4773 | 415 |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7620
diff
changeset
|
416 F77_FUNC (zffti, ZFFTI) (npts, pwsave); |
4773 | 417 |
5275 | 418 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
|
419 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
420 for (octave_idx_type j = 0; j < howmany; j++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
421 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
422 octave_quit (); |
4773 | 423 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
424 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
|
425 prow[l] = retval((l + k*npts)*stride + j*dist); |
4773 | 426 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
427 F77_FUNC (zfftb, ZFFTB) (npts, prow, pwsave); |
4773 | 428 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
429 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
|
430 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
|
431 prow[l] / static_cast<double> (npts); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
432 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
433 } |
4773 | 434 |
435 stride *= dv2(i); | |
436 } | |
437 | |
438 return retval; | |
439 } | |
440 | |
441 ComplexNDArray | |
442 NDArray::fourierNd (void) const | |
443 { | |
444 dim_vector dv = dims (); | |
445 int rank = dv.length (); | |
446 ComplexNDArray retval (*this); | |
5275 | 447 octave_idx_type stride = 1; |
4773 | 448 |
449 for (int i = 0; i < rank; i++) | |
450 { | |
5275 | 451 octave_idx_type npts = dv(i); |
452 octave_idx_type nn = 4*npts+15; | |
19537
8f6a8422435d
Replace instances of deprecated Array constructor in FFTPACK-related code.
Rik <rik@octave.org>
parents:
19510
diff
changeset
|
453 Array<Complex> wsave (dim_vector (nn, 1)); |
4773 | 454 Complex *pwsave = wsave.fortran_vec (); |
19537
8f6a8422435d
Replace instances of deprecated Array constructor in FFTPACK-related code.
Rik <rik@octave.org>
parents:
19510
diff
changeset
|
455 Array<Complex> row (dim_vector (npts, 1)); |
4773 | 456 Complex *prow = row.fortran_vec (); |
457 | |
5275 | 458 octave_idx_type howmany = numel () / npts; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
459 howmany = (stride == 1 ? howmany : |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
460 (howmany > stride ? stride : howmany)); |
5275 | 461 octave_idx_type nloop = (stride == 1 ? 1 : numel () / npts / stride); |
462 octave_idx_type dist = (stride == 1 ? npts : 1); | |
4773 | 463 |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7620
diff
changeset
|
464 F77_FUNC (zffti, ZFFTI) (npts, pwsave); |
4773 | 465 |
5275 | 466 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
|
467 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
468 for (octave_idx_type j = 0; j < howmany; j++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
469 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
470 octave_quit (); |
4773 | 471 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
472 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
|
473 prow[l] = retval((l + k*npts)*stride + j*dist); |
4773 | 474 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
475 F77_FUNC (zfftf, ZFFTF) (npts, prow, pwsave); |
4773 | 476 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
477 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
|
478 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
|
479 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
480 } |
4773 | 481 |
482 stride *= dv(i); | |
483 } | |
484 | |
485 return retval; | |
486 } | |
487 | |
488 ComplexNDArray | |
489 NDArray::ifourierNd (void) const | |
490 { | |
491 dim_vector dv = dims (); | |
492 int rank = dv.length (); | |
493 ComplexNDArray retval (*this); | |
5275 | 494 octave_idx_type stride = 1; |
4773 | 495 |
496 for (int i = 0; i < rank; i++) | |
497 { | |
5275 | 498 octave_idx_type npts = dv(i); |
499 octave_idx_type nn = 4*npts+15; | |
19537
8f6a8422435d
Replace instances of deprecated Array constructor in FFTPACK-related code.
Rik <rik@octave.org>
parents:
19510
diff
changeset
|
500 Array<Complex> wsave (dim_vector (nn, 1)); |
4773 | 501 Complex *pwsave = wsave.fortran_vec (); |
19537
8f6a8422435d
Replace instances of deprecated Array constructor in FFTPACK-related code.
Rik <rik@octave.org>
parents:
19510
diff
changeset
|
502 Array<Complex> row (dim_vector (npts, 1)); |
4773 | 503 Complex *prow = row.fortran_vec (); |
504 | |
5275 | 505 octave_idx_type howmany = numel () / npts; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
506 howmany = (stride == 1 ? howmany : |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
507 (howmany > stride ? stride : howmany)); |
5275 | 508 octave_idx_type nloop = (stride == 1 ? 1 : numel () / npts / stride); |
509 octave_idx_type dist = (stride == 1 ? npts : 1); | |
4773 | 510 |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7620
diff
changeset
|
511 F77_FUNC (zffti, ZFFTI) (npts, pwsave); |
4773 | 512 |
5275 | 513 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
|
514 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
515 for (octave_idx_type j = 0; j < howmany; j++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
516 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
517 octave_quit (); |
4773 | 518 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
519 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
|
520 prow[l] = retval((l + k*npts)*stride + j*dist); |
4773 | 521 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
522 F77_FUNC (zfftb, ZFFTB) (npts, prow, pwsave); |
4773 | 523 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
524 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
|
525 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
|
526 prow[l] / static_cast<double> (npts); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
527 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
528 } |
4773 | 529 |
530 stride *= dv(i); | |
531 } | |
532 | |
533 return retval; | |
534 } | |
535 | |
536 #endif | |
537 | |
4543 | 538 // unary operations |
539 | |
540 boolNDArray | |
541 NDArray::operator ! (void) const | |
542 { | |
11130
7c573eb981eb
consistently give error for operator not applied to NaN values
John W. Eaton <jwe@octave.org>
parents:
11010
diff
changeset
|
543 if (any_element_is_nan ()) |
7c573eb981eb
consistently give error for operator not applied to NaN values
John W. Eaton <jwe@octave.org>
parents:
11010
diff
changeset
|
544 gripe_nan_to_logical_conversion (); |
7c573eb981eb
consistently give error for operator not applied to NaN values
John W. Eaton <jwe@octave.org>
parents:
11010
diff
changeset
|
545 |
10362
b47ab50a6aa8
simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
546 return do_mx_unary_op<bool, double> (*this, mx_inline_not); |
4543 | 547 } |
548 | |
4634 | 549 bool |
550 NDArray::any_element_is_negative (bool neg_zero) const | |
551 { | |
11010
9478b216752e
simplify more array tests
Jaroslav Hajek <highegg@gmail.com>
parents:
11008
diff
changeset
|
552 return (neg_zero ? test_all (xnegative_sign) |
9478b216752e
simplify more array tests
Jaroslav Hajek <highegg@gmail.com>
parents:
11008
diff
changeset
|
553 : do_mx_check<double> (*this, mx_inline_any_negative)); |
4634 | 554 } |
555 | |
7922
935be827eaf8
error for NaN values in & and | expressions
John W. Eaton <jwe@octave.org>
parents:
7919
diff
changeset
|
556 bool |
13756
6dfebfa334cb
allow negative data log plots with OpenGL+FLTK graphics (bug #34232)
John W. Eaton <jwe@octave.org>
parents:
13005
diff
changeset
|
557 NDArray::any_element_is_positive (bool neg_zero) const |
6dfebfa334cb
allow negative data log plots with OpenGL+FLTK graphics (bug #34232)
John W. Eaton <jwe@octave.org>
parents:
13005
diff
changeset
|
558 { |
6dfebfa334cb
allow negative data log plots with OpenGL+FLTK graphics (bug #34232)
John W. Eaton <jwe@octave.org>
parents:
13005
diff
changeset
|
559 return (neg_zero ? test_all (xpositive_sign) |
6dfebfa334cb
allow negative data log plots with OpenGL+FLTK graphics (bug #34232)
John W. Eaton <jwe@octave.org>
parents:
13005
diff
changeset
|
560 : do_mx_check<double> (*this, mx_inline_any_positive)); |
6dfebfa334cb
allow negative data log plots with OpenGL+FLTK graphics (bug #34232)
John W. Eaton <jwe@octave.org>
parents:
13005
diff
changeset
|
561 } |
6dfebfa334cb
allow negative data log plots with OpenGL+FLTK graphics (bug #34232)
John W. Eaton <jwe@octave.org>
parents:
13005
diff
changeset
|
562 |
6dfebfa334cb
allow negative data log plots with OpenGL+FLTK graphics (bug #34232)
John W. Eaton <jwe@octave.org>
parents:
13005
diff
changeset
|
563 bool |
7922
935be827eaf8
error for NaN values in & and | expressions
John W. Eaton <jwe@octave.org>
parents:
7919
diff
changeset
|
564 NDArray::any_element_is_nan (void) const |
935be827eaf8
error for NaN values in & and | expressions
John W. Eaton <jwe@octave.org>
parents:
7919
diff
changeset
|
565 { |
11008
3622db30ff05
simplify some array tests in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10362
diff
changeset
|
566 return do_mx_check<double> (*this, mx_inline_any_nan); |
7922
935be827eaf8
error for NaN values in & and | expressions
John W. Eaton <jwe@octave.org>
parents:
7919
diff
changeset
|
567 } |
4634 | 568 |
569 bool | |
570 NDArray::any_element_is_inf_or_nan (void) const | |
571 { | |
11008
3622db30ff05
simplify some array tests in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10362
diff
changeset
|
572 return ! do_mx_check<double> (*this, mx_inline_all_finite); |
4634 | 573 } |
574 | |
575 bool | |
5943 | 576 NDArray::any_element_not_one_or_zero (void) const |
577 { | |
11010
9478b216752e
simplify more array tests
Jaroslav Hajek <highegg@gmail.com>
parents:
11008
diff
changeset
|
578 return ! test_all (xis_one_or_zero); |
5943 | 579 } |
580 | |
581 bool | |
6989 | 582 NDArray::all_elements_are_zero (void) const |
583 { | |
11010
9478b216752e
simplify more array tests
Jaroslav Hajek <highegg@gmail.com>
parents:
11008
diff
changeset
|
584 return test_all (xis_zero); |
6989 | 585 } |
586 | |
587 bool | |
4634 | 588 NDArray::all_elements_are_int_or_inf_or_nan (void) const |
589 { | |
11010
9478b216752e
simplify more array tests
Jaroslav Hajek <highegg@gmail.com>
parents:
11008
diff
changeset
|
590 return test_all (xis_int_or_inf_or_nan); |
4634 | 591 } |
592 | |
593 // Return nonzero if any element of M is not an integer. Also extract | |
594 // the largest and smallest values and return them in MAX_VAL and MIN_VAL. | |
595 | |
596 bool | |
597 NDArray::all_integers (double& max_val, double& min_val) const | |
598 { | |
5275 | 599 octave_idx_type nel = nelem (); |
4634 | 600 |
601 if (nel > 0) | |
602 { | |
603 max_val = elem (0); | |
604 min_val = elem (0); | |
605 } | |
606 else | |
607 return false; | |
608 | |
5275 | 609 for (octave_idx_type i = 0; i < nel; i++) |
4634 | 610 { |
611 double val = elem (i); | |
612 | |
613 if (val > max_val) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
614 max_val = val; |
4634 | 615 |
616 if (val < min_val) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
617 min_val = val; |
4634 | 618 |
11010
9478b216752e
simplify more array tests
Jaroslav Hajek <highegg@gmail.com>
parents:
11008
diff
changeset
|
619 if (! xisinteger (val)) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
620 return false; |
4634 | 621 } |
622 | |
623 return true; | |
624 } | |
625 | |
626 bool | |
9827
c15a5ed0da58
optimize bsxfun (@power, ...)
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
627 NDArray::all_integers (void) const |
c15a5ed0da58
optimize bsxfun (@power, ...)
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
628 { |
11010
9478b216752e
simplify more array tests
Jaroslav Hajek <highegg@gmail.com>
parents:
11008
diff
changeset
|
629 return test_all (xisinteger); |
9827
c15a5ed0da58
optimize bsxfun (@power, ...)
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
630 } |
c15a5ed0da58
optimize bsxfun (@power, ...)
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
631 |
c15a5ed0da58
optimize bsxfun (@power, ...)
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
632 bool |
4634 | 633 NDArray::too_large_for_float (void) const |
634 { | |
15212
4bbd3bbb8912
reduce code duplication in too_large_for_float array functions
John W. Eaton <jwe@octave.org>
parents:
15018
diff
changeset
|
635 return test_any (xtoo_large_for_float); |
4634 | 636 } |
637 | |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
638 // FIXME: this is not quite the right thing. |
4513 | 639 |
4556 | 640 boolNDArray |
4513 | 641 NDArray::all (int dim) const |
642 { | |
10362
b47ab50a6aa8
simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
643 return do_mx_red_op<bool, double> (*this, dim, mx_inline_all); |
4513 | 644 } |
645 | |
4556 | 646 boolNDArray |
4513 | 647 NDArray::any (int dim) const |
648 { | |
10362
b47ab50a6aa8
simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
649 return do_mx_red_op<bool, double> (*this, dim, mx_inline_any); |
4569 | 650 } |
651 | |
4584 | 652 NDArray |
4569 | 653 NDArray::cumprod (int dim) const |
654 { | |
10362
b47ab50a6aa8
simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
655 return do_mx_cum_op<double, double> (*this, dim, mx_inline_cumprod); |
4569 | 656 } |
657 | |
4584 | 658 NDArray |
4569 | 659 NDArray::cumsum (int dim) const |
660 { | |
10362
b47ab50a6aa8
simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
661 return do_mx_cum_op<double, double> (*this, dim, mx_inline_cumsum); |
4513 | 662 } |
663 | |
4569 | 664 NDArray |
665 NDArray::prod (int dim) const | |
666 { | |
10362
b47ab50a6aa8
simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
667 return do_mx_red_op<double, double> (*this, dim, mx_inline_prod); |
8736
53b4fdeacc2e
improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8650
diff
changeset
|
668 } |
53b4fdeacc2e
improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8650
diff
changeset
|
669 |
53b4fdeacc2e
improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8650
diff
changeset
|
670 NDArray |
53b4fdeacc2e
improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8650
diff
changeset
|
671 NDArray::sum (int dim) const |
53b4fdeacc2e
improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8650
diff
changeset
|
672 { |
10362
b47ab50a6aa8
simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
673 return do_mx_red_op<double, double> (*this, dim, mx_inline_sum); |
4569 | 674 } |
675 | |
676 NDArray | |
9721
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9601
diff
changeset
|
677 NDArray::xsum (int dim) const |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9601
diff
changeset
|
678 { |
10362
b47ab50a6aa8
simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
679 return do_mx_red_op<double, double> (*this, dim, mx_inline_xsum); |
9721
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9601
diff
changeset
|
680 } |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9601
diff
changeset
|
681 |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9601
diff
changeset
|
682 NDArray |
4569 | 683 NDArray::sumsq (int dim) const |
684 { | |
10362
b47ab50a6aa8
simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
685 return do_mx_red_op<double, double> (*this, dim, mx_inline_sumsq); |
4569 | 686 } |
687 | |
4844 | 688 NDArray |
689 NDArray::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<double> (*this, dim, mx_inline_max); |
4844 | 692 } |
693 | |
694 NDArray | |
9732
b4fdfee405b5
remove ArrayN<T> + fix nonhom. diag-scalar ops
Jaroslav Hajek <highegg@gmail.com>
parents:
9721
diff
changeset
|
695 NDArray::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<double> (*this, idx_arg, dim, mx_inline_max); |
4844 | 698 } |
699 | |
700 NDArray | |
701 NDArray::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<double> (*this, dim, mx_inline_min); |
4844 | 704 } |
705 | |
706 NDArray | |
9732
b4fdfee405b5
remove ArrayN<T> + fix nonhom. diag-scalar ops
Jaroslav Hajek <highegg@gmail.com>
parents:
9721
diff
changeset
|
707 NDArray::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<double> (*this, idx_arg, dim, mx_inline_min); |
4844 | 710 } |
711 | |
4915 | 712 NDArray |
8777
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8774
diff
changeset
|
713 NDArray::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<double> (*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 NDArray |
9732
b4fdfee405b5
remove ArrayN<T> + fix nonhom. diag-scalar ops
Jaroslav Hajek <highegg@gmail.com>
parents:
9721
diff
changeset
|
719 NDArray::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<double> (*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 NDArray |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8774
diff
changeset
|
725 NDArray::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<double> (*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 NDArray |
9732
b4fdfee405b5
remove ArrayN<T> + fix nonhom. diag-scalar ops
Jaroslav Hajek <highegg@gmail.com>
parents:
9721
diff
changeset
|
731 NDArray::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<double> (*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 |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8774
diff
changeset
|
736 NDArray |
9513
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9469
diff
changeset
|
737 NDArray::diff (octave_idx_type order, int dim) const |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9469
diff
changeset
|
738 { |
10362
b47ab50a6aa8
simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
739 return do_mx_diff_op<double> (*this, dim, order, mx_inline_diff); |
9513
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9469
diff
changeset
|
740 } |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9469
diff
changeset
|
741 |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9469
diff
changeset
|
742 NDArray |
5275 | 743 NDArray::concat (const NDArray& rb, const Array<octave_idx_type>& ra_idx) |
4758 | 744 { |
5073 | 745 if (rb.numel () > 0) |
746 insert (rb, ra_idx); | |
747 return *this; | |
748 } | |
749 | |
750 ComplexNDArray | |
5275 | 751 NDArray::concat (const ComplexNDArray& rb, const Array<octave_idx_type>& ra_idx) |
5073 | 752 { |
753 ComplexNDArray retval (*this); | |
4940 | 754 if (rb.numel () > 0) |
4915 | 755 retval.insert (rb, ra_idx); |
756 return retval; | |
4758 | 757 } |
758 | |
5073 | 759 charNDArray |
5275 | 760 NDArray::concat (const charNDArray& rb, const Array<octave_idx_type>& ra_idx) |
5073 | 761 { |
762 charNDArray retval (dims ()); | |
5275 | 763 octave_idx_type nel = numel (); |
5073 | 764 |
5275 | 765 for (octave_idx_type i = 0; i < nel; i++) |
5073 | 766 { |
767 double d = elem (i); | |
768 | |
769 if (xisnan (d)) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
770 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
771 (*current_liboctave_error_handler) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
772 ("invalid conversion from NaN to character"); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
773 return retval; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
774 } |
5073 | 775 else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
776 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
777 octave_idx_type ival = NINTbig (d); |
5073 | 778 |
15215
9020dddc925a
use std::numeric_limits for integer max and min values
John W. Eaton <jwe@octave.org>
parents:
15212
diff
changeset
|
779 if (ival < 0 || ival > std::numeric_limits<unsigned char>::max ()) |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
780 // FIXME: is there something better to do? Should we warn the user? |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
781 ival = 0; |
5073 | 782 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
783 retval.elem (i) = static_cast<char>(ival); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
784 } |
5073 | 785 } |
786 | |
787 if (rb.numel () == 0) | |
788 return retval; | |
789 | |
790 retval.insert (rb, ra_idx); | |
791 return retval; | |
792 } | |
793 | |
4634 | 794 NDArray |
795 real (const ComplexNDArray& a) | |
796 { | |
10362
b47ab50a6aa8
simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
797 return do_mx_unary_op<double, Complex> (a, mx_inline_real); |
4634 | 798 } |
799 | |
800 NDArray | |
801 imag (const ComplexNDArray& a) | |
802 { | |
10362
b47ab50a6aa8
simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
803 return do_mx_unary_op<double, Complex> (a, mx_inline_imag); |
4634 | 804 } |
805 | |
4915 | 806 NDArray& |
5275 | 807 NDArray::insert (const NDArray& a, octave_idx_type r, octave_idx_type c) |
4915 | 808 { |
809 Array<double>::insert (a, r, c); | |
810 return *this; | |
811 } | |
812 | |
813 NDArray& | |
5275 | 814 NDArray::insert (const NDArray& a, const Array<octave_idx_type>& ra_idx) |
4915 | 815 { |
816 Array<double>::insert (a, ra_idx); | |
817 return *this; | |
818 } | |
819 | |
4634 | 820 NDArray |
4569 | 821 NDArray::abs (void) const |
822 { | |
10362
b47ab50a6aa8
simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
823 return do_mx_unary_map<double, double, std::abs> (*this); |
4569 | 824 } |
825 | |
8998
a48fba01e4ac
optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents:
8981
diff
changeset
|
826 boolNDArray |
a48fba01e4ac
optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents:
8981
diff
changeset
|
827 NDArray::isnan (void) const |
a48fba01e4ac
optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents:
8981
diff
changeset
|
828 { |
10362
b47ab50a6aa8
simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
829 return do_mx_unary_map<bool, double, xisnan> (*this); |
8998
a48fba01e4ac
optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents:
8981
diff
changeset
|
830 } |
a48fba01e4ac
optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents:
8981
diff
changeset
|
831 |
a48fba01e4ac
optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents:
8981
diff
changeset
|
832 boolNDArray |
a48fba01e4ac
optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents:
8981
diff
changeset
|
833 NDArray::isinf (void) const |
a48fba01e4ac
optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents:
8981
diff
changeset
|
834 { |
10362
b47ab50a6aa8
simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
835 return do_mx_unary_map<bool, double, xisinf> (*this); |
8998
a48fba01e4ac
optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents:
8981
diff
changeset
|
836 } |
a48fba01e4ac
optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents:
8981
diff
changeset
|
837 |
a48fba01e4ac
optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents:
8981
diff
changeset
|
838 boolNDArray |
a48fba01e4ac
optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents:
8981
diff
changeset
|
839 NDArray::isfinite (void) const |
a48fba01e4ac
optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents:
8981
diff
changeset
|
840 { |
10362
b47ab50a6aa8
simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
841 return do_mx_unary_map<bool, double, xfinite> (*this); |
8998
a48fba01e4ac
optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents:
8981
diff
changeset
|
842 } |
a48fba01e4ac
optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents:
8981
diff
changeset
|
843 |
4532 | 844 void |
5275 | 845 NDArray::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 | |
5275 | 852 octave_idx_type |
853 NDArray::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 | |
7503
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
859 NDArray |
7620
36594d5bbe13
Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents:
7600
diff
changeset
|
860 NDArray::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<double>::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 NDArray |
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 NDArray::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<double>::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 NDArray& 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_double (os, a.elem (i)); | |
881 os << "\n"; | |
882 } | |
883 return os; | |
884 } | |
885 | |
886 std::istream& | |
887 operator >> (std::istream& is, NDArray& 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 double tmp; | |
5275 | 894 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
|
895 { |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
896 tmp = octave_read_value<double> (is); |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
897 if (is) |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
898 a.elem (i) = tmp; |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
899 else |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
900 goto done; |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
901 } |
4687 | 902 } |
903 | |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
904 done: |
4687 | 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 (NDArray, double) |
4844 | 910 |
9578
7dafdb8b062f
refactor comparison ops implementations
Jaroslav Hajek <highegg@gmail.com>
parents:
9553
diff
changeset
|
911 NDS_CMP_OPS (NDArray, double) |
9550
3d6a9aea2aea
refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
9523
diff
changeset
|
912 NDS_BOOL_OPS (NDArray, double) |
4543 | 913 |
9578
7dafdb8b062f
refactor comparison ops implementations
Jaroslav Hajek <highegg@gmail.com>
parents:
9553
diff
changeset
|
914 SND_CMP_OPS (double, NDArray) |
9550
3d6a9aea2aea
refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
9523
diff
changeset
|
915 SND_BOOL_OPS (double, NDArray) |
4543 | 916 |
9578
7dafdb8b062f
refactor comparison ops implementations
Jaroslav Hajek <highegg@gmail.com>
parents:
9553
diff
changeset
|
917 NDND_CMP_OPS (NDArray, NDArray) |
9550
3d6a9aea2aea
refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
9523
diff
changeset
|
918 NDND_BOOL_OPS (NDArray, NDArray) |
4543 | 919 |
9743
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
920 BSXFUN_STDOP_DEFS_MXLOOP (NDArray) |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
921 BSXFUN_STDREL_DEFS_MXLOOP (NDArray) |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
922 |
9827
c15a5ed0da58
optimize bsxfun (@power, ...)
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
923 BSXFUN_OP_DEF_MXLOOP (pow, NDArray, mx_inline_pow) |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
924 BSXFUN_OP2_DEF_MXLOOP (pow, ComplexNDArray, ComplexNDArray, |
9827
c15a5ed0da58
optimize bsxfun (@power, ...)
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
925 NDArray, mx_inline_pow) |
13005
4061106b1c4b
Enable automatic bsxfun for power operators
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
11586
diff
changeset
|
926 BSXFUN_OP2_DEF_MXLOOP (pow, ComplexNDArray, NDArray, |
4061106b1c4b
Enable automatic bsxfun for power operators
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
11586
diff
changeset
|
927 ComplexNDArray, mx_inline_pow) |