Mercurial > hg > octave-lyh
annotate liboctave/dNDArray.cc @ 11008:3622db30ff05
simplify some array tests in liboctave
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Tue, 21 Sep 2010 13:09:12 +0200 |
parents | b47ab50a6aa8 |
children | 9478b216752e |
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 { | |
10362
b47ab50a6aa8
simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
544 return do_mx_unary_op<bool, double> (*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 | |
11008
3622db30ff05
simplify some array tests in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10362
diff
changeset
|
559 return do_mx_check<double> (*this, mx_inline_any_negative); |
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 { |
11008
3622db30ff05
simplify some array tests in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10362
diff
changeset
|
567 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
|
568 } |
4634 | 569 |
570 bool | |
571 NDArray::any_element_is_inf_or_nan (void) const | |
572 { | |
11008
3622db30ff05
simplify some array tests in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10362
diff
changeset
|
573 return ! do_mx_check<double> (*this, mx_inline_all_finite); |
4634 | 574 } |
575 | |
576 bool | |
5943 | 577 NDArray::any_element_not_one_or_zero (void) const |
578 { | |
579 octave_idx_type nel = nelem (); | |
580 | |
581 for (octave_idx_type i = 0; i < nel; i++) | |
582 { | |
583 double val = elem (i); | |
584 if (val != 0 && val != 1) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
585 return true; |
5943 | 586 } |
587 | |
588 return false; | |
589 } | |
590 | |
591 bool | |
6989 | 592 NDArray::all_elements_are_zero (void) const |
593 { | |
594 octave_idx_type nel = nelem (); | |
595 | |
596 for (octave_idx_type i = 0; i < nel; i++) | |
597 if (elem (i) != 0) | |
598 return false; | |
599 | |
600 return true; | |
601 } | |
602 | |
603 bool | |
4634 | 604 NDArray::all_elements_are_int_or_inf_or_nan (void) const |
605 { | |
5275 | 606 octave_idx_type nel = nelem (); |
4634 | 607 |
5275 | 608 for (octave_idx_type i = 0; i < nel; i++) |
4634 | 609 { |
610 double val = elem (i); | |
611 if (xisnan (val) || D_NINT (val) == val) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
612 continue; |
4634 | 613 else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
614 return false; |
4634 | 615 } |
616 | |
617 return true; | |
618 } | |
619 | |
620 // Return nonzero if any element of M is not an integer. Also extract | |
621 // the largest and smallest values and return them in MAX_VAL and MIN_VAL. | |
622 | |
623 bool | |
624 NDArray::all_integers (double& max_val, double& min_val) const | |
625 { | |
5275 | 626 octave_idx_type nel = nelem (); |
4634 | 627 |
628 if (nel > 0) | |
629 { | |
630 max_val = elem (0); | |
631 min_val = elem (0); | |
632 } | |
633 else | |
634 return false; | |
635 | |
5275 | 636 for (octave_idx_type i = 0; i < nel; i++) |
4634 | 637 { |
638 double val = elem (i); | |
639 | |
640 if (val > max_val) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
641 max_val = val; |
4634 | 642 |
643 if (val < min_val) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
644 min_val = val; |
4634 | 645 |
646 if (D_NINT (val) != val) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
647 return false; |
4634 | 648 } |
649 | |
650 return true; | |
651 } | |
652 | |
653 bool | |
9827
c15a5ed0da58
optimize bsxfun (@power, ...)
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
654 NDArray::all_integers (void) const |
c15a5ed0da58
optimize bsxfun (@power, ...)
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
655 { |
c15a5ed0da58
optimize bsxfun (@power, ...)
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
656 octave_idx_type nel = nelem (); |
c15a5ed0da58
optimize bsxfun (@power, ...)
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
657 |
c15a5ed0da58
optimize bsxfun (@power, ...)
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
658 for (octave_idx_type i = 0; i < nel; i++) |
c15a5ed0da58
optimize bsxfun (@power, ...)
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
659 { |
c15a5ed0da58
optimize bsxfun (@power, ...)
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
660 double val = elem (i); |
c15a5ed0da58
optimize bsxfun (@power, ...)
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
661 |
c15a5ed0da58
optimize bsxfun (@power, ...)
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
662 if (D_NINT (val) != val) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
663 return false; |
9827
c15a5ed0da58
optimize bsxfun (@power, ...)
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
664 } |
c15a5ed0da58
optimize bsxfun (@power, ...)
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
665 |
c15a5ed0da58
optimize bsxfun (@power, ...)
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
666 return true; |
c15a5ed0da58
optimize bsxfun (@power, ...)
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
667 } |
c15a5ed0da58
optimize bsxfun (@power, ...)
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
668 |
c15a5ed0da58
optimize bsxfun (@power, ...)
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
669 bool |
4634 | 670 NDArray::too_large_for_float (void) const |
671 { | |
5275 | 672 octave_idx_type nel = nelem (); |
4634 | 673 |
5275 | 674 for (octave_idx_type i = 0; i < nel; i++) |
4634 | 675 { |
676 double val = elem (i); | |
677 | |
5389 | 678 if (! (xisnan (val) || xisinf (val)) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
679 && fabs (val) > FLT_MAX) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
680 return true; |
4634 | 681 } |
682 | |
683 return false; | |
684 } | |
685 | |
5775 | 686 // FIXME -- this is not quite the right thing. |
4513 | 687 |
4556 | 688 boolNDArray |
4513 | 689 NDArray::all (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_red_op<bool, double> (*this, dim, mx_inline_all); |
4513 | 692 } |
693 | |
4556 | 694 boolNDArray |
4513 | 695 NDArray::any (int dim) const |
696 { | |
10362
b47ab50a6aa8
simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
697 return do_mx_red_op<bool, double> (*this, dim, mx_inline_any); |
4569 | 698 } |
699 | |
4584 | 700 NDArray |
4569 | 701 NDArray::cumprod (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_cum_op<double, double> (*this, dim, mx_inline_cumprod); |
4569 | 704 } |
705 | |
4584 | 706 NDArray |
4569 | 707 NDArray::cumsum (int dim) const |
708 { | |
10362
b47ab50a6aa8
simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
709 return do_mx_cum_op<double, double> (*this, dim, mx_inline_cumsum); |
4513 | 710 } |
711 | |
4569 | 712 NDArray |
713 NDArray::prod (int dim) const | |
714 { | |
10362
b47ab50a6aa8
simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
715 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
|
716 } |
53b4fdeacc2e
improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8650
diff
changeset
|
717 |
53b4fdeacc2e
improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8650
diff
changeset
|
718 NDArray |
53b4fdeacc2e
improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8650
diff
changeset
|
719 NDArray::sum (int dim) const |
53b4fdeacc2e
improve reduction functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8650
diff
changeset
|
720 { |
10362
b47ab50a6aa8
simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
721 return do_mx_red_op<double, double> (*this, dim, mx_inline_sum); |
4569 | 722 } |
723 | |
724 NDArray | |
9721
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9601
diff
changeset
|
725 NDArray::xsum (int dim) const |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9601
diff
changeset
|
726 { |
10362
b47ab50a6aa8
simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
727 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
|
728 } |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9601
diff
changeset
|
729 |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9601
diff
changeset
|
730 NDArray |
4569 | 731 NDArray::sumsq (int dim) const |
732 { | |
10362
b47ab50a6aa8
simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
733 return do_mx_red_op<double, double> (*this, dim, mx_inline_sumsq); |
4569 | 734 } |
735 | |
4844 | 736 NDArray |
737 NDArray::max (int dim) const | |
738 { | |
10362
b47ab50a6aa8
simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
739 return do_mx_minmax_op<double> (*this, dim, mx_inline_max); |
4844 | 740 } |
741 | |
742 NDArray | |
9732
b4fdfee405b5
remove ArrayN<T> + fix nonhom. diag-scalar ops
Jaroslav Hajek <highegg@gmail.com>
parents:
9721
diff
changeset
|
743 NDArray::max (Array<octave_idx_type>& idx_arg, int dim) const |
4844 | 744 { |
10362
b47ab50a6aa8
simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
745 return do_mx_minmax_op<double> (*this, idx_arg, dim, mx_inline_max); |
4844 | 746 } |
747 | |
748 NDArray | |
749 NDArray::min (int dim) const | |
750 { | |
10362
b47ab50a6aa8
simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
751 return do_mx_minmax_op<double> (*this, dim, mx_inline_min); |
4844 | 752 } |
753 | |
754 NDArray | |
9732
b4fdfee405b5
remove ArrayN<T> + fix nonhom. diag-scalar ops
Jaroslav Hajek <highegg@gmail.com>
parents:
9721
diff
changeset
|
755 NDArray::min (Array<octave_idx_type>& idx_arg, int dim) const |
4844 | 756 { |
10362
b47ab50a6aa8
simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
757 return do_mx_minmax_op<double> (*this, idx_arg, dim, mx_inline_min); |
4844 | 758 } |
759 | |
4915 | 760 NDArray |
8777
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8774
diff
changeset
|
761 NDArray::cummax (int dim) const |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8774
diff
changeset
|
762 { |
10362
b47ab50a6aa8
simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
763 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
|
764 } |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8774
diff
changeset
|
765 |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8774
diff
changeset
|
766 NDArray |
9732
b4fdfee405b5
remove ArrayN<T> + fix nonhom. diag-scalar ops
Jaroslav Hajek <highegg@gmail.com>
parents:
9721
diff
changeset
|
767 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
|
768 { |
10362
b47ab50a6aa8
simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
769 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
|
770 } |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8774
diff
changeset
|
771 |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8774
diff
changeset
|
772 NDArray |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8774
diff
changeset
|
773 NDArray::cummin (int dim) const |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8774
diff
changeset
|
774 { |
10362
b47ab50a6aa8
simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
775 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
|
776 } |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8774
diff
changeset
|
777 |
724c0f46d9d4
implement cummin/cummax functions
Jaroslav Hajek <highegg@gmail.com>
parents:
8774
diff
changeset
|
778 NDArray |
9732
b4fdfee405b5
remove ArrayN<T> + fix nonhom. diag-scalar ops
Jaroslav Hajek <highegg@gmail.com>
parents:
9721
diff
changeset
|
779 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
|
780 { |
10362
b47ab50a6aa8
simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
781 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
|
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 |
9513
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9469
diff
changeset
|
785 NDArray::diff (octave_idx_type order, int dim) const |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9469
diff
changeset
|
786 { |
10362
b47ab50a6aa8
simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
787 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
|
788 } |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9469
diff
changeset
|
789 |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9469
diff
changeset
|
790 NDArray |
5275 | 791 NDArray::concat (const NDArray& rb, const Array<octave_idx_type>& ra_idx) |
4758 | 792 { |
5073 | 793 if (rb.numel () > 0) |
794 insert (rb, ra_idx); | |
795 return *this; | |
796 } | |
797 | |
798 ComplexNDArray | |
5275 | 799 NDArray::concat (const ComplexNDArray& rb, const Array<octave_idx_type>& ra_idx) |
5073 | 800 { |
801 ComplexNDArray retval (*this); | |
4940 | 802 if (rb.numel () > 0) |
4915 | 803 retval.insert (rb, ra_idx); |
804 return retval; | |
4758 | 805 } |
806 | |
5073 | 807 charNDArray |
5275 | 808 NDArray::concat (const charNDArray& rb, const Array<octave_idx_type>& ra_idx) |
5073 | 809 { |
810 charNDArray retval (dims ()); | |
5275 | 811 octave_idx_type nel = numel (); |
5073 | 812 |
5275 | 813 for (octave_idx_type i = 0; i < nel; i++) |
5073 | 814 { |
815 double d = elem (i); | |
816 | |
817 if (xisnan (d)) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
818 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
819 (*current_liboctave_error_handler) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
820 ("invalid conversion from NaN to character"); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
821 return retval; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
822 } |
5073 | 823 else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
824 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
825 octave_idx_type ival = NINTbig (d); |
5073 | 826 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
827 if (ival < 0 || ival > UCHAR_MAX) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
828 // FIXME -- is there something |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
829 // better we could do? Should we warn the user? |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
830 ival = 0; |
5073 | 831 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
832 retval.elem (i) = static_cast<char>(ival); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
833 } |
5073 | 834 } |
835 | |
836 if (rb.numel () == 0) | |
837 return retval; | |
838 | |
839 retval.insert (rb, ra_idx); | |
840 return retval; | |
841 } | |
842 | |
4634 | 843 NDArray |
844 real (const ComplexNDArray& a) | |
845 { | |
10362
b47ab50a6aa8
simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
846 return do_mx_unary_op<double, Complex> (a, mx_inline_real); |
4634 | 847 } |
848 | |
849 NDArray | |
850 imag (const ComplexNDArray& a) | |
851 { | |
10362
b47ab50a6aa8
simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
852 return do_mx_unary_op<double, Complex> (a, mx_inline_imag); |
4634 | 853 } |
854 | |
4915 | 855 NDArray& |
5275 | 856 NDArray::insert (const NDArray& a, octave_idx_type r, octave_idx_type c) |
4915 | 857 { |
858 Array<double>::insert (a, r, c); | |
859 return *this; | |
860 } | |
861 | |
862 NDArray& | |
5275 | 863 NDArray::insert (const NDArray& a, const Array<octave_idx_type>& ra_idx) |
4915 | 864 { |
865 Array<double>::insert (a, ra_idx); | |
866 return *this; | |
867 } | |
868 | |
4634 | 869 NDArray |
4569 | 870 NDArray::abs (void) const |
871 { | |
10362
b47ab50a6aa8
simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
872 return do_mx_unary_map<double, double, std::abs> (*this); |
4569 | 873 } |
874 | |
8998
a48fba01e4ac
optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents:
8981
diff
changeset
|
875 boolNDArray |
a48fba01e4ac
optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents:
8981
diff
changeset
|
876 NDArray::isnan (void) const |
a48fba01e4ac
optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents:
8981
diff
changeset
|
877 { |
10362
b47ab50a6aa8
simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
878 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
|
879 } |
a48fba01e4ac
optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents:
8981
diff
changeset
|
880 |
a48fba01e4ac
optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents:
8981
diff
changeset
|
881 boolNDArray |
a48fba01e4ac
optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents:
8981
diff
changeset
|
882 NDArray::isinf (void) const |
a48fba01e4ac
optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents:
8981
diff
changeset
|
883 { |
10362
b47ab50a6aa8
simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
884 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
|
885 } |
a48fba01e4ac
optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents:
8981
diff
changeset
|
886 |
a48fba01e4ac
optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents:
8981
diff
changeset
|
887 boolNDArray |
a48fba01e4ac
optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents:
8981
diff
changeset
|
888 NDArray::isfinite (void) const |
a48fba01e4ac
optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents:
8981
diff
changeset
|
889 { |
10362
b47ab50a6aa8
simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
890 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
|
891 } |
a48fba01e4ac
optimize isnan/isinf/isfinite mappers
Jaroslav Hajek <highegg@gmail.com>
parents:
8981
diff
changeset
|
892 |
4532 | 893 Matrix |
894 NDArray::matrix_value (void) const | |
895 { | |
896 Matrix retval; | |
897 | |
8981
ed5055b0a476
fix & simplify ndarray->matrix conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
8956
diff
changeset
|
898 if (ndims () == 2) |
10352 | 899 retval = Matrix (Array<double> (*this)); |
8981
ed5055b0a476
fix & simplify ndarray->matrix conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
8956
diff
changeset
|
900 else |
ed5055b0a476
fix & simplify ndarray->matrix conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
8956
diff
changeset
|
901 (*current_liboctave_error_handler) |
ed5055b0a476
fix & simplify ndarray->matrix conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
8956
diff
changeset
|
902 ("invalid conversion of NDArray to Matrix"); |
4532 | 903 |
904 return retval; | |
905 } | |
906 | |
907 void | |
5275 | 908 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
|
909 const dim_vector& dimensions, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
910 int start_dimension) |
4532 | 911 { |
912 ::increment_index (ra_idx, dimensions, start_dimension); | |
913 } | |
914 | |
5275 | 915 octave_idx_type |
916 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
|
917 const dim_vector& dimensions) |
4556 | 918 { |
919 return ::compute_index (ra_idx, dimensions); | |
920 } | |
921 | |
7503
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
922 NDArray |
7620
36594d5bbe13
Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents:
7600
diff
changeset
|
923 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
|
924 { |
10350
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10329
diff
changeset
|
925 return MArray<double>::diag (k); |
7620
36594d5bbe13
Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents:
7600
diff
changeset
|
926 } |
36594d5bbe13
Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents:
7600
diff
changeset
|
927 |
4687 | 928 // This contains no information on the array structure !!! |
929 std::ostream& | |
930 operator << (std::ostream& os, const NDArray& a) | |
931 { | |
5275 | 932 octave_idx_type nel = a.nelem (); |
4687 | 933 |
5275 | 934 for (octave_idx_type i = 0; i < nel; i++) |
4687 | 935 { |
936 os << " "; | |
937 octave_write_double (os, a.elem (i)); | |
938 os << "\n"; | |
939 } | |
940 return os; | |
941 } | |
942 | |
943 std::istream& | |
944 operator >> (std::istream& is, NDArray& a) | |
945 { | |
5275 | 946 octave_idx_type nel = a.nelem (); |
4687 | 947 |
8999
dc07bc4157b8
allow empty matrices in stream input operators
Jaroslav Hajek <highegg@gmail.com>
parents:
8998
diff
changeset
|
948 if (nel > 0) |
4687 | 949 { |
950 double tmp; | |
5275 | 951 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
|
952 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
953 tmp = octave_read_value<double> (is); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
954 if (is) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
955 a.elem (i) = tmp; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
956 else |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
957 goto done; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
958 } |
4687 | 959 } |
960 | |
961 done: | |
962 | |
963 return is; | |
964 } | |
965 | |
10329
83fa590b8a09
simplify min/max definitions in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10314
diff
changeset
|
966 MINMAX_FCNS (NDArray, double) |
4844 | 967 |
9578
7dafdb8b062f
refactor comparison ops implementations
Jaroslav Hajek <highegg@gmail.com>
parents:
9553
diff
changeset
|
968 NDS_CMP_OPS (NDArray, double) |
9550
3d6a9aea2aea
refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
9523
diff
changeset
|
969 NDS_BOOL_OPS (NDArray, double) |
4543 | 970 |
9578
7dafdb8b062f
refactor comparison ops implementations
Jaroslav Hajek <highegg@gmail.com>
parents:
9553
diff
changeset
|
971 SND_CMP_OPS (double, NDArray) |
9550
3d6a9aea2aea
refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
9523
diff
changeset
|
972 SND_BOOL_OPS (double, NDArray) |
4543 | 973 |
9578
7dafdb8b062f
refactor comparison ops implementations
Jaroslav Hajek <highegg@gmail.com>
parents:
9553
diff
changeset
|
974 NDND_CMP_OPS (NDArray, NDArray) |
9550
3d6a9aea2aea
refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
9523
diff
changeset
|
975 NDND_BOOL_OPS (NDArray, NDArray) |
4543 | 976 |
9743
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
977 BSXFUN_STDOP_DEFS_MXLOOP (NDArray) |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
978 BSXFUN_STDREL_DEFS_MXLOOP (NDArray) |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
979 |
9827
c15a5ed0da58
optimize bsxfun (@power, ...)
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
980 BSXFUN_OP_DEF_MXLOOP (pow, NDArray, mx_inline_pow) |
c15a5ed0da58
optimize bsxfun (@power, ...)
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
981 BSXFUN_OP2_DEF_MXLOOP (pow, ComplexNDArray, ComplexNDArray, |
c15a5ed0da58
optimize bsxfun (@power, ...)
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
982 NDArray, mx_inline_pow) |