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