GNU Octave  4.2.1
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
dNDArray.cc
Go to the documentation of this file.
1 // N-D Array manipulations.
2 /*
3 
4 Copyright (C) 1996-2017 John W. Eaton
5 Copyright (C) 2009 VZLU Prague, a.s.
6 
7 This file is part of Octave.
8 
9 Octave is free software; you can redistribute it and/or modify it
10 under the terms of the GNU General Public License as published by the
11 Free Software Foundation; either version 3 of the License, or (at your
12 option) any later version.
13 
14 Octave is distributed in the hope that it will be useful, but WITHOUT
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 for more details.
18 
19 You should have received a copy of the GNU General Public License
20 along with Octave; see the file COPYING. If not, see
21 <http://www.gnu.org/licenses/>.
22 
23 */
24 
25 #if defined (HAVE_CONFIG_H)
26 # include "config.h"
27 #endif
28 
29 #include <cfloat>
30 
31 #include <vector>
32 
33 #include "Array-util.h"
34 #include "dNDArray.h"
35 #include "f77-fcn.h"
36 #include "functor.h"
37 #include "lo-error.h"
38 #include "lo-ieee.h"
39 #include "lo-mappers.h"
40 #include "mx-base.h"
41 #include "mx-op-defs.h"
42 #include "oct-fftw.h"
43 #include "oct-locbuf.h"
44 
45 #include "bsxfun-defs.cc"
46 
47 NDArray::NDArray (const Array<octave_idx_type>& a, bool zero_based,
48  bool negative_to_nan)
49 {
50  const octave_idx_type *pa = a.fortran_vec ();
51  resize (a.dims ());
52  double *ptmp = fortran_vec ();
53  if (negative_to_nan)
54  {
55  double nan_val = lo_ieee_nan_value ();
56 
57  if (zero_based)
58  for (octave_idx_type i = 0; i < a.numel (); i++)
59  {
60  double val = static_cast<double>
61  (pa[i] + static_cast<octave_idx_type> (1));
62  if (val <= 0)
63  ptmp[i] = nan_val;
64  else
65  ptmp[i] = val;
66  }
67  else
68  for (octave_idx_type i = 0; i < a.numel (); i++)
69  {
70  double val = static_cast<double> (pa[i]);
71  if (val <= 0)
72  ptmp[i] = nan_val;
73  else
74  ptmp[i] = val;
75  }
76  }
77  else
78  {
79  if (zero_based)
80  for (octave_idx_type i = 0; i < a.numel (); i++)
81  ptmp[i] = static_cast<double>
82  (pa[i] + static_cast<octave_idx_type> (1));
83  else
84  for (octave_idx_type i = 0; i < a.numel (); i++)
85  ptmp[i] = static_cast<double> (pa[i]);
86  }
87 }
88 
90  : MArray<double> (a.dims ())
91 {
92  octave_idx_type n = a.numel ();
93  for (octave_idx_type i = 0; i < n; i++)
94  xelem (i) = static_cast<unsigned char> (a(i));
95 }
96 
97 #if defined (HAVE_FFTW)
98 
100 NDArray::fourier (int dim) const
101 {
102  dim_vector dv = dims ();
103 
104  if (dim > dv.ndims () || dim < 0)
105  return ComplexNDArray ();
106 
107  octave_idx_type stride = 1;
108  octave_idx_type n = dv(dim);
109 
110  for (int i = 0; i < dim; i++)
111  stride *= dv(i);
112 
113  octave_idx_type howmany = numel () / dv(dim);
114  howmany = (stride == 1 ? howmany : (howmany > stride ? stride : howmany));
115  octave_idx_type nloop = (stride == 1 ? 1 : numel () / dv(dim) / stride);
116  octave_idx_type dist = (stride == 1 ? n : 1);
117 
118  const double *in (fortran_vec ());
119  ComplexNDArray retval (dv);
120  Complex *out (retval.fortran_vec ());
121 
122  // Need to be careful here about the distance between fft's
123  for (octave_idx_type k = 0; k < nloop; k++)
124  octave_fftw::fft (in + k * stride * n, out + k * stride * n,
125  n, howmany, stride, dist);
126 
127  return retval;
128 }
129 
131 NDArray::ifourier (int dim) const
132 {
133  dim_vector dv = dims ();
134 
135  if (dim > dv.ndims () || dim < 0)
136  return ComplexNDArray ();
137 
138  octave_idx_type stride = 1;
139  octave_idx_type n = dv(dim);
140 
141  for (int i = 0; i < dim; i++)
142  stride *= dv(i);
143 
144  octave_idx_type howmany = numel () / dv(dim);
145  howmany = (stride == 1 ? howmany : (howmany > stride ? stride : howmany));
146  octave_idx_type nloop = (stride == 1 ? 1 : numel () / dv(dim) / stride);
147  octave_idx_type dist = (stride == 1 ? n : 1);
148 
149  ComplexNDArray retval (*this);
150  Complex *out (retval.fortran_vec ());
151 
152  // Need to be careful here about the distance between fft's
153  for (octave_idx_type k = 0; k < nloop; k++)
154  octave_fftw::ifft (out + k * stride * n, out + k * stride * n,
155  n, howmany, stride, dist);
156 
157  return retval;
158 }
159 
161 NDArray::fourier2d (void) const
162 {
163  dim_vector dv = dims ();
164  if (dv.ndims () < 2)
165  return ComplexNDArray ();
166 
167  dim_vector dv2 (dv(0), dv(1));
168  const double *in = fortran_vec ();
169  ComplexNDArray retval (dv);
170  Complex *out = retval.fortran_vec ();
171  octave_idx_type howmany = numel () / dv(0) / dv(1);
172  octave_idx_type dist = dv(0) * dv(1);
173 
174  for (octave_idx_type i=0; i < howmany; i++)
175  octave_fftw::fftNd (in + i*dist, out + i*dist, 2, dv2);
176 
177  return retval;
178 }
179 
182 {
183  dim_vector dv = dims ();
184  if (dv.ndims () < 2)
185  return ComplexNDArray ();
186 
187  dim_vector dv2 (dv(0), dv(1));
188  ComplexNDArray retval (*this);
189  Complex *out = retval.fortran_vec ();
190  octave_idx_type howmany = numel () / dv(0) / dv(1);
191  octave_idx_type dist = dv(0) * dv(1);
192 
193  for (octave_idx_type i=0; i < howmany; i++)
194  octave_fftw::ifftNd (out + i*dist, out + i*dist, 2, dv2);
195 
196  return retval;
197 }
198 
200 NDArray::fourierNd (void) const
201 {
202  dim_vector dv = dims ();
203  int rank = dv.ndims ();
204 
205  const double *in (fortran_vec ());
206  ComplexNDArray retval (dv);
207  Complex *out (retval.fortran_vec ());
208 
209  octave_fftw::fftNd (in, out, rank, dv);
210 
211  return retval;
212 }
213 
216 {
217  dim_vector dv = dims ();
218  int rank = dv.ndims ();
219 
220  ComplexNDArray tmp (*this);
221  Complex *in (tmp.fortran_vec ());
222  ComplexNDArray retval (dv);
223  Complex *out (retval.fortran_vec ());
224 
225  octave_fftw::ifftNd (in, out, rank, dv);
226 
227  return retval;
228 }
229 
230 #else
231 
232 #include "lo-fftpack-proto.h"
233 
235 NDArray::fourier (int dim) const
236 {
237  dim_vector dv = dims ();
238 
239  if (dim > dv.ndims () || dim < 0)
240  return ComplexNDArray ();
241 
242  ComplexNDArray retval (dv);
243  octave_idx_type npts = dv(dim);
244  octave_idx_type nn = 4*npts+15;
245  Array<Complex> wsave (dim_vector (nn, 1));
246  Complex *pwsave = wsave.fortran_vec ();
247 
249 
250  octave_idx_type stride = 1;
251 
252  for (int i = 0; i < dim; i++)
253  stride *= dv(i);
254 
255  octave_idx_type howmany = numel () / npts;
256  howmany = (stride == 1 ? howmany : (howmany > stride ? stride : howmany));
257  octave_idx_type nloop = (stride == 1 ? 1 : numel () / npts / stride);
258  octave_idx_type dist = (stride == 1 ? npts : 1);
259 
260  F77_FUNC (zffti, ZFFTI) (npts, F77_DBLE_CMPLX_ARG (pwsave));
261 
262  for (octave_idx_type k = 0; k < nloop; k++)
263  {
264  for (octave_idx_type j = 0; j < howmany; j++)
265  {
266  octave_quit ();
267 
268  for (octave_idx_type i = 0; i < npts; i++)
269  tmp[i] = elem ((i + k*npts)*stride + j*dist);
270 
271  F77_FUNC (zfftf, ZFFTF) (npts, F77_DBLE_CMPLX_ARG (tmp),
272  F77_DBLE_CMPLX_ARG (pwsave));
273 
274  for (octave_idx_type i = 0; i < npts; i++)
275  retval((i + k*npts)*stride + j*dist) = tmp[i];
276  }
277  }
278 
279  return retval;
280 }
281 
283 NDArray::ifourier (int dim) const
284 {
285  dim_vector dv = dims ();
286 
287  if (dim > dv.ndims () || dim < 0)
288  return ComplexNDArray ();
289 
290  ComplexNDArray retval (dv);
291  octave_idx_type npts = dv(dim);
292  octave_idx_type nn = 4*npts+15;
293  Array<Complex> wsave (dim_vector (nn, 1));
294  Complex *pwsave = wsave.fortran_vec ();
295 
297 
298  octave_idx_type stride = 1;
299 
300  for (int i = 0; i < dim; i++)
301  stride *= dv(i);
302 
303  octave_idx_type howmany = numel () / npts;
304  howmany = (stride == 1 ? howmany : (howmany > stride ? stride : howmany));
305  octave_idx_type nloop = (stride == 1 ? 1 : numel () / npts / stride);
306  octave_idx_type dist = (stride == 1 ? npts : 1);
307 
308  F77_FUNC (zffti, ZFFTI) (npts, F77_DBLE_CMPLX_ARG (pwsave));
309 
310  for (octave_idx_type k = 0; k < nloop; k++)
311  {
312  for (octave_idx_type j = 0; j < howmany; j++)
313  {
314  octave_quit ();
315 
316  for (octave_idx_type i = 0; i < npts; i++)
317  tmp[i] = elem ((i + k*npts)*stride + j*dist);
318 
319  F77_FUNC (zfftb, ZFFTB) (npts, F77_DBLE_CMPLX_ARG (tmp),
320  F77_DBLE_CMPLX_ARG (pwsave));
321 
322  for (octave_idx_type i = 0; i < npts; i++)
323  retval((i + k*npts)*stride + j*dist) = tmp[i] /
324  static_cast<double> (npts);
325  }
326  }
327 
328  return retval;
329 }
330 
332 NDArray::fourier2d (void) const
333 {
334  dim_vector dv = dims ();
335  dim_vector dv2 (dv(0), dv(1));
336  int rank = 2;
337  ComplexNDArray retval (*this);
338  octave_idx_type stride = 1;
339 
340  for (int i = 0; i < rank; i++)
341  {
342  octave_idx_type npts = dv2(i);
343  octave_idx_type nn = 4*npts+15;
344  Array<Complex> wsave (dim_vector (nn, 1));
345  Complex *pwsave = wsave.fortran_vec ();
346  Array<Complex> row (dim_vector (npts, 1));
347  Complex *prow = row.fortran_vec ();
348 
349  octave_idx_type howmany = numel () / npts;
350  howmany = (stride == 1 ? howmany :
351  (howmany > stride ? stride : howmany));
352  octave_idx_type nloop = (stride == 1 ? 1 : numel () / npts / stride);
353  octave_idx_type dist = (stride == 1 ? npts : 1);
354 
355  F77_FUNC (zffti, ZFFTI) (npts, F77_DBLE_CMPLX_ARG (pwsave));
356 
357  for (octave_idx_type k = 0; k < nloop; k++)
358  {
359  for (octave_idx_type j = 0; j < howmany; j++)
360  {
361  octave_quit ();
362 
363  for (octave_idx_type l = 0; l < npts; l++)
364  prow[l] = retval((l + k*npts)*stride + j*dist);
365 
366  F77_FUNC (zfftf, ZFFTF) (npts, F77_DBLE_CMPLX_ARG (prow),
367  F77_DBLE_CMPLX_ARG (pwsave));
368 
369  for (octave_idx_type l = 0; l < npts; l++)
370  retval((l + k*npts)*stride + j*dist) = prow[l];
371  }
372  }
373 
374  stride *= dv2(i);
375  }
376 
377  return retval;
378 }
379 
381 NDArray::ifourier2d (void) const
382 {
383  dim_vector dv = dims ();
384  dim_vector dv2 (dv(0), dv(1));
385  int rank = 2;
386  ComplexNDArray retval (*this);
387  octave_idx_type stride = 1;
388 
389  for (int i = 0; i < rank; i++)
390  {
391  octave_idx_type npts = dv2(i);
392  octave_idx_type nn = 4*npts+15;
393  Array<Complex> wsave (dim_vector (nn, 1));
394  Complex *pwsave = wsave.fortran_vec ();
395  Array<Complex> row (dim_vector (npts, 1));
396  Complex *prow = row.fortran_vec ();
397 
398  octave_idx_type howmany = numel () / npts;
399  howmany = (stride == 1 ? howmany :
400  (howmany > stride ? stride : howmany));
401  octave_idx_type nloop = (stride == 1 ? 1 : numel () / npts / stride);
402  octave_idx_type dist = (stride == 1 ? npts : 1);
403 
404  F77_FUNC (zffti, ZFFTI) (npts, F77_DBLE_CMPLX_ARG (pwsave));
405 
406  for (octave_idx_type k = 0; k < nloop; k++)
407  {
408  for (octave_idx_type j = 0; j < howmany; j++)
409  {
410  octave_quit ();
411 
412  for (octave_idx_type l = 0; l < npts; l++)
413  prow[l] = retval((l + k*npts)*stride + j*dist);
414 
415  F77_FUNC (zfftb, ZFFTB) (npts, F77_DBLE_CMPLX_ARG (prow),
416  F77_DBLE_CMPLX_ARG (pwsave));
417 
418  for (octave_idx_type l = 0; l < npts; l++)
419  retval((l + k*npts)*stride + j*dist) =
420  prow[l] / static_cast<double> (npts);
421  }
422  }
423 
424  stride *= dv2(i);
425  }
426 
427  return retval;
428 }
429 
431 NDArray::fourierNd (void) const
432 {
433  dim_vector dv = dims ();
434  int rank = dv.ndims ();
435  ComplexNDArray retval (*this);
436  octave_idx_type stride = 1;
437 
438  for (int i = 0; i < rank; i++)
439  {
440  octave_idx_type npts = dv(i);
441  octave_idx_type nn = 4*npts+15;
442  Array<Complex> wsave (dim_vector (nn, 1));
443  Complex *pwsave = wsave.fortran_vec ();
444  Array<Complex> row (dim_vector (npts, 1));
445  Complex *prow = row.fortran_vec ();
446 
447  octave_idx_type howmany = numel () / npts;
448  howmany = (stride == 1 ? howmany :
449  (howmany > stride ? stride : howmany));
450  octave_idx_type nloop = (stride == 1 ? 1 : numel () / npts / stride);
451  octave_idx_type dist = (stride == 1 ? npts : 1);
452 
453  F77_FUNC (zffti, ZFFTI) (npts, F77_DBLE_CMPLX_ARG (pwsave));
454 
455  for (octave_idx_type k = 0; k < nloop; k++)
456  {
457  for (octave_idx_type j = 0; j < howmany; j++)
458  {
459  octave_quit ();
460 
461  for (octave_idx_type l = 0; l < npts; l++)
462  prow[l] = retval((l + k*npts)*stride + j*dist);
463 
464  F77_FUNC (zfftf, ZFFTF) (npts, F77_DBLE_CMPLX_ARG (prow),
465  F77_DBLE_CMPLX_ARG (pwsave));
466 
467  for (octave_idx_type l = 0; l < npts; l++)
468  retval((l + k*npts)*stride + j*dist) = prow[l];
469  }
470  }
471 
472  stride *= dv(i);
473  }
474 
475  return retval;
476 }
477 
479 NDArray::ifourierNd (void) const
480 {
481  dim_vector dv = dims ();
482  int rank = dv.ndims ();
483  ComplexNDArray retval (*this);
484  octave_idx_type stride = 1;
485 
486  for (int i = 0; i < rank; i++)
487  {
488  octave_idx_type npts = dv(i);
489  octave_idx_type nn = 4*npts+15;
490  Array<Complex> wsave (dim_vector (nn, 1));
491  Complex *pwsave = wsave.fortran_vec ();
492  Array<Complex> row (dim_vector (npts, 1));
493  Complex *prow = row.fortran_vec ();
494 
495  octave_idx_type howmany = numel () / npts;
496  howmany = (stride == 1 ? howmany :
497  (howmany > stride ? stride : howmany));
498  octave_idx_type nloop = (stride == 1 ? 1 : numel () / npts / stride);
499  octave_idx_type dist = (stride == 1 ? npts : 1);
500 
501  F77_FUNC (zffti, ZFFTI) (npts, F77_DBLE_CMPLX_ARG (pwsave));
502 
503  for (octave_idx_type k = 0; k < nloop; k++)
504  {
505  for (octave_idx_type j = 0; j < howmany; j++)
506  {
507  octave_quit ();
508 
509  for (octave_idx_type l = 0; l < npts; l++)
510  prow[l] = retval((l + k*npts)*stride + j*dist);
511 
512  F77_FUNC (zfftb, ZFFTB) (npts, F77_DBLE_CMPLX_ARG (prow),
513  F77_DBLE_CMPLX_ARG (pwsave));
514 
515  for (octave_idx_type l = 0; l < npts; l++)
516  retval((l + k*npts)*stride + j*dist) =
517  prow[l] / static_cast<double> (npts);
518  }
519  }
520 
521  stride *= dv(i);
522  }
523 
524  return retval;
525 }
526 
527 #endif
528 
529 // unary operations
530 
533 {
534  if (any_element_is_nan ())
536 
537  return do_mx_unary_op<bool, double> (*this, mx_inline_not);
538 }
539 
540 bool
541 NDArray::any_element_is_negative (bool neg_zero) const
542 {
543  return (neg_zero ? test_all (octave::math::negative_sign)
544  : do_mx_check<double> (*this, mx_inline_any_negative));
545 }
546 
547 bool
548 NDArray::any_element_is_positive (bool neg_zero) const
549 {
550  return (neg_zero ? test_all (octave::math::positive_sign)
551  : do_mx_check<double> (*this, mx_inline_any_positive));
552 }
553 
554 bool
556 {
557  return do_mx_check<double> (*this, mx_inline_any_nan);
558 }
559 
560 bool
562 {
563  return ! do_mx_check<double> (*this, mx_inline_all_finite);
564 }
565 
566 bool
568 {
569  return ! test_all (xis_one_or_zero);
570 }
571 
572 bool
574 {
575  return test_all (xis_zero);
576 }
577 
578 bool
580 {
582 }
583 
584 // Return nonzero if any element of M is not an integer. Also extract
585 // the largest and smallest values and return them in MAX_VAL and MIN_VAL.
586 
587 bool
588 NDArray::all_integers (double& max_val, double& min_val) const
589 {
590  octave_idx_type nel = numel ();
591 
592  if (nel > 0)
593  {
594  max_val = elem (0);
595  min_val = elem (0);
596  }
597  else
598  return false;
599 
600  for (octave_idx_type i = 0; i < nel; i++)
601  {
602  double val = elem (i);
603 
604  if (val > max_val)
605  max_val = val;
606 
607  if (val < min_val)
608  min_val = val;
609 
610  if (! octave::math::isinteger (val))
611  return false;
612  }
613 
614  return true;
615 }
616 
617 bool
619 {
621 }
622 
623 bool
625 {
627 }
628 
629 // FIXME: this is not quite the right thing.
630 
632 NDArray::all (int dim) const
633 {
634  return do_mx_red_op<bool, double> (*this, dim, mx_inline_all);
635 }
636 
638 NDArray::any (int dim) const
639 {
640  return do_mx_red_op<bool, double> (*this, dim, mx_inline_any);
641 }
642 
643 NDArray
644 NDArray::cumprod (int dim) const
645 {
646  return do_mx_cum_op<double, double> (*this, dim, mx_inline_cumprod);
647 }
648 
649 NDArray
650 NDArray::cumsum (int dim) const
651 {
652  return do_mx_cum_op<double, double> (*this, dim, mx_inline_cumsum);
653 }
654 
655 NDArray
656 NDArray::prod (int dim) const
657 {
658  return do_mx_red_op<double, double> (*this, dim, mx_inline_prod);
659 }
660 
661 NDArray
662 NDArray::sum (int dim) const
663 {
664  return do_mx_red_op<double, double> (*this, dim, mx_inline_sum);
665 }
666 
667 NDArray
668 NDArray::xsum (int dim) const
669 {
670  return do_mx_red_op<double, double> (*this, dim, mx_inline_xsum);
671 }
672 
673 NDArray
674 NDArray::sumsq (int dim) const
675 {
676  return do_mx_red_op<double, double> (*this, dim, mx_inline_sumsq);
677 }
678 
679 NDArray
680 NDArray::max (int dim) const
681 {
682  return do_mx_minmax_op<double> (*this, dim, mx_inline_max);
683 }
684 
685 NDArray
686 NDArray::max (Array<octave_idx_type>& idx_arg, int dim) const
687 {
688  return do_mx_minmax_op<double> (*this, idx_arg, dim, mx_inline_max);
689 }
690 
691 NDArray
692 NDArray::min (int dim) const
693 {
694  return do_mx_minmax_op<double> (*this, dim, mx_inline_min);
695 }
696 
697 NDArray
698 NDArray::min (Array<octave_idx_type>& idx_arg, int dim) const
699 {
700  return do_mx_minmax_op<double> (*this, idx_arg, dim, mx_inline_min);
701 }
702 
703 NDArray
704 NDArray::cummax (int dim) const
705 {
706  return do_mx_cumminmax_op<double> (*this, dim, mx_inline_cummax);
707 }
708 
709 NDArray
710 NDArray::cummax (Array<octave_idx_type>& idx_arg, int dim) const
711 {
712  return do_mx_cumminmax_op<double> (*this, idx_arg, dim, mx_inline_cummax);
713 }
714 
715 NDArray
716 NDArray::cummin (int dim) const
717 {
718  return do_mx_cumminmax_op<double> (*this, dim, mx_inline_cummin);
719 }
720 
721 NDArray
722 NDArray::cummin (Array<octave_idx_type>& idx_arg, int dim) const
723 {
724  return do_mx_cumminmax_op<double> (*this, idx_arg, dim, mx_inline_cummin);
725 }
726 
727 NDArray
728 NDArray::diff (octave_idx_type order, int dim) const
729 {
730  return do_mx_diff_op<double> (*this, dim, order, mx_inline_diff);
731 }
732 
733 NDArray
735 {
736  if (rb.numel () > 0)
737  insert (rb, ra_idx);
738  return *this;
739 }
740 
743 {
744  ComplexNDArray retval (*this);
745  if (rb.numel () > 0)
746  retval.insert (rb, ra_idx);
747  return retval;
748 }
749 
752 {
753  charNDArray retval (dims ());
754  octave_idx_type nel = numel ();
755 
756  for (octave_idx_type i = 0; i < nel; i++)
757  {
758  double d = elem (i);
759 
760  if (octave::math::isnan (d))
761  (*current_liboctave_error_handler)
762  ("invalid conversion from NaN to character");
763 
765 
766  if (ival < 0 || ival > std::numeric_limits<unsigned char>::max ())
767  // FIXME: is there something better to do? Should we warn the user?
768  ival = 0;
769 
770  retval.elem (i) = static_cast<char>(ival);
771  }
772 
773  if (rb.is_empty ())
774  return retval;
775 
776  retval.insert (rb, ra_idx);
777  return retval;
778 }
779 
780 NDArray
782 {
783  return do_mx_unary_op<double, Complex> (a, mx_inline_real);
784 }
785 
786 NDArray
788 {
789  return do_mx_unary_op<double, Complex> (a, mx_inline_imag);
790 }
791 
792 NDArray&
794 {
795  Array<double>::insert (a, r, c);
796  return *this;
797 }
798 
799 NDArray&
801 {
802  Array<double>::insert (a, ra_idx);
803  return *this;
804 }
805 
806 NDArray
807 NDArray::abs (void) const
808 {
809  return do_mx_unary_map<double, double, std::abs> (*this);
810 }
811 
813 NDArray::isnan (void) const
814 {
815  return do_mx_unary_map<bool, double, octave::math::isnan> (*this);
816 }
817 
819 NDArray::isinf (void) const
820 {
821  return do_mx_unary_map<bool, double, octave::math::isinf> (*this);
822 }
823 
825 NDArray::isfinite (void) const
826 {
827  return do_mx_unary_map<bool, double, octave::math::finite> (*this);
828 }
829 
830 void
832  const dim_vector& dimensions,
833  int start_dimension)
834 {
835  ::increment_index (ra_idx, dimensions, start_dimension);
836 }
837 
840  const dim_vector& dimensions)
841 {
842  return ::compute_index (ra_idx, dimensions);
843 }
844 
845 NDArray
847 {
848  return MArray<double>::diag (k);
849 }
850 
851 NDArray
853 {
854  return MArray<double>::diag (m, n);
855 }
856 
857 // This contains no information on the array structure !!!
858 std::ostream&
859 operator << (std::ostream& os, const NDArray& a)
860 {
861  octave_idx_type nel = a.numel ();
862 
863  for (octave_idx_type i = 0; i < nel; i++)
864  {
865  os << " ";
866  octave_write_double (os, a.elem (i));
867  os << "\n";
868  }
869  return os;
870 }
871 
872 std::istream&
873 operator >> (std::istream& is, NDArray& a)
874 {
875  octave_idx_type nel = a.numel ();
876 
877  if (nel > 0)
878  {
879  double tmp;
880  for (octave_idx_type i = 0; i < nel; i++)
881  {
882  tmp = octave_read_value<double> (is);
883  if (is)
884  a.elem (i) = tmp;
885  else
886  return is;
887  }
888  }
889 
890  return is;
891 }
892 
894 
896 NDS_BOOL_OPS (NDArray, double)
897 
898 SND_CMP_OPS (double, NDArray)
899 SND_BOOL_OPS (double, NDArray)
900 
901 NDND_CMP_OPS (NDArray, NDArray)
902 NDND_BOOL_OPS (NDArray, NDArray)
903 
906 
908 BSXFUN_OP2_DEF_MXLOOP (pow, ComplexNDArray, ComplexNDArray,
909  NDArray, mx_inline_pow)
910 BSXFUN_OP2_DEF_MXLOOP (pow, ComplexNDArray, NDArray,
911  ComplexNDArray, mx_inline_pow)
dim_vector dimensions
Definition: Array.h:214
T mx_inline_xsum(const T *v, octave_idx_type n)
Definition: mx-inlines.cc:1651
void octave_write_double(std::ostream &os, double d)
Definition: lo-utils.cc:388
octave_idx_type compute_index(octave_idx_type n, const dim_vector &dims)
Definition: Array-util.cc:176
bool isinteger(double x)
Definition: lo-mappers.h:255
bool any_element_is_negative(bool=false) const
Definition: dNDArray.cc:541
NDArray cumsum(int dim=-1) const
Definition: dNDArray.cc:650
#define NDS_BOOL_OPS(ND, S)
Definition: mx-op-defs.h:255
#define NDS_CMP_OPS(ND, S)
Definition: mx-op-defs.h:238
bool is_empty(void) const
Definition: Array.h:575
void mx_inline_cummax(const T *v, T *r, octave_idx_type n)
Definition: mx-inlines.cc:1147
std::istream & operator>>(std::istream &is, NDArray &a)
Definition: dNDArray.cc:873
static int fft(const double *in, Complex *out, size_t npts, size_t nsamples=1, octave_idx_type stride=1, octave_idx_type dist=-1)
Definition: oct-fftw.cc:860
const octave_base_value const Array< octave_idx_type > & ra_idx
#define SND_CMP_OPS(S, ND)
Definition: mx-op-defs.h:285
#define BSXFUN_OP_DEF_MXLOOP(OP, ARRAY, LOOP)
Definition: bsxfun-defs.cc:222
octave_idx_type numel(void) const
Number of elements in the array.
Definition: Array.h:363
subroutine zffti(n, wsave)
Definition: zffti.f:1
static octave_idx_type nn
Definition: DASPK.cc:71
identity matrix If supplied two scalar respectively For allows like xample val
Definition: data.cc:5068
NDArray max(double d, const NDArray &m)
Definition: dNDArray.cc:893
#define F77_DBLE_CMPLX_ARG(x)
Definition: f77-fcn.h:345
NDArray sumsq(int dim=-1) const
Definition: dNDArray.cc:674
void mx_inline_real(size_t n, T *r, const std::complex< T > *x)
Definition: mx-inlines.cc:315
bool isnan(double x)
Definition: lo-mappers.cc:347
bool mx_inline_all_finite(size_t n, const T *x)
Definition: mx-inlines.cc:256
for large enough k
Definition: lu.cc:606
NDArray prod(int dim=-1) const
Definition: dNDArray.cc:656
#define MINMAX_FCNS(T, S)
Definition: mx-op-defs.h:584
bool all_elements_are_zero(void) const
Definition: dNDArray.cc:573
bool xis_zero(double x)
Definition: lo-utils.cc:51
Array< T > diag(octave_idx_type k=0) const
Get the kth super or subdiagonal.
Definition: Array.cc:2529
NDArray(void)
Definition: dNDArray.h:42
double & elem(octave_idx_type n)
Definition: Array.h:482
double lo_ieee_nan_value(void)
Definition: lo-ieee.cc:126
Template for N-dimensional array classes with like-type math operators.
Definition: MArray.h:32
T mx_inline_sumsq(const T *v, octave_idx_type n)
Definition: mx-inlines.cc:716
std::ostream & operator<<(std::ostream &os, const NDArray &a)
Definition: dNDArray.cc:859
bool mx_inline_any_negative(size_t n, const T *x)
Definition: mx-inlines.cc:269
bool positive_sign(double x)
Definition: lo-mappers.h:60
boolNDArray isnan(void) const
Definition: dNDArray.cc:813
NDArray cumprod(int dim=-1) const
Definition: dNDArray.cc:644
bool any_element_is_nan(void) const
Definition: dNDArray.cc:555
void mx_inline_max(const T *v, T *r, octave_idx_type n)
Definition: mx-inlines.cc:925
void err_nan_to_logical_conversion(void)
bool mx_inline_any(const T *v, octave_idx_type n)
Definition: mx-inlines.cc:716
NDArray imag(const ComplexNDArray &a)
Definition: dNDArray.cc:787
F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T const F77_REAL const F77_REAL F77_REAL &F77_RET_T const F77_DBLE const F77_DBLE F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T const F77_DBLE F77_DBLE &F77_RET_T const F77_REAL F77_REAL &F77_RET_T F77_REAL F77_REAL &F77_RET_T F77_DBLE F77_DBLE &F77_RET_T const F77_DBLE const F77_DBLE F77_DBLE * d
subroutine zfftb(n, c, wsave)
Definition: zfftb.f:1
static int fftNd(const double *, Complex *, const int, const dim_vector &)
Definition: oct-fftw.cc:925
NDArray concat(const NDArray &rb, const Array< octave_idx_type > &ra_idx)
Definition: dNDArray.cc:734
void mx_inline_imag(size_t n, T *r, const std::complex< T > *x)
Definition: mx-inlines.cc:322
Array< T > & insert(const Array< T > &a, const Array< octave_idx_type > &idx)
Insert an array into another at a specified position.
Definition: Array.cc:1601
calling an anonymous function involves an overhead quite comparable to the overhead of an m file function Passing a handle to a built in function is because the interpreter is not involved in the internal loop For a
Definition: cellfun.cc:398
bool any_element_not_one_or_zero(void) const
Definition: dNDArray.cc:567
const dim_vector & dims(void) const
Return a const-reference so that dims ()(i) works efficiently.
Definition: Array.h:439
NDArray min(int dim=-1) const
Definition: dNDArray.cc:692
ComplexNDArray fourierNd(void) const
Definition: dNDArray.cc:200
#define NDND_CMP_OPS(ND1, ND2)
Definition: mx-op-defs.h:332
NDArray real(const ComplexNDArray &a)
Definition: dNDArray.cc:781
bool test_any(F fcn) const
Simpler calls.
Definition: Array.h:811
ComplexNDArray & insert(const NDArray &a, octave_idx_type r, octave_idx_type c)
Definition: CNDArray.cc:745
#define NDND_BOOL_OPS(ND1, ND2)
Definition: mx-op-defs.h:349
ComplexNDArray ifourier(int dim=1) const
Definition: dNDArray.cc:131
nd deftypefn *octave_map m
Definition: ov-struct.cc:2058
NDArray & insert(const NDArray &a, octave_idx_type r, octave_idx_type c)
Definition: dNDArray.cc:793
bool any_element_is_positive(bool=false) const
Definition: dNDArray.cc:548
ComplexNDArray ifourier2d(void) const
Definition: dNDArray.cc:181
static int ifft(const Complex *in, Complex *out, size_t npts, size_t nsamples=1, octave_idx_type stride=1, octave_idx_type dist=-1)
Definition: oct-fftw.cc:900
NDArray cummax(int dim=-1) const
Definition: dNDArray.cc:704
void resize(const dim_vector &dv, const double &rfv)
static octave_idx_type compute_index(Array< octave_idx_type > &ra_idx, const dim_vector &dimensions)
Definition: dNDArray.cc:839
octave_int< T > pow(const octave_int< T > &a, const octave_int< T > &b)
double tmp
Definition: data.cc:6300
octave_value retval
Definition: data.cc:6294
#define SND_BOOL_OPS(S, ND)
Definition: mx-op-defs.h:302
F77_RET_T F77_FUNC(xstopx, XSTOPX) const
Definition: f77-fcn.c:53
bool mx_inline_any_positive(size_t n, const T *x)
Definition: mx-inlines.cc:282
NDArray max(int dim=-1) const
Definition: dNDArray.cc:680
void mx_inline_cummin(const T *v, T *r, octave_idx_type n)
Definition: mx-inlines.cc:1146
void mx_inline_pow(size_t n, R *r, const X *x, const Y *y)
Definition: mx-inlines.cc:402
the sparsity preserving column transformation such that that defines the pivoting threshold can be given in which case it defines the c
Definition: lu.cc:138
the exceeded dimensions are set to if fewer subscripts than dimensions are the exceeding dimensions are merged into the final requested dimension For consider the following dims
Definition: sub2ind.cc:255
NDArray abs(void) const
Definition: dNDArray.cc:807
bool mx_inline_any_nan(size_t n, const T *x)
Definition: mx-inlines.cc:243
static int ifftNd(const Complex *, Complex *, const int, const dim_vector &)
Definition: oct-fftw.cc:971
#define BSXFUN_STDREL_DEFS_MXLOOP(ARRAY)
Definition: bsxfun-defs.cc:245
double & xelem(octave_idx_type n)
Definition: Array.h:455
T mx_inline_sum(const T *v, octave_idx_type n)
Definition: mx-inlines.cc:714
bool all_elements_are_int_or_inf_or_nan(void) const
Definition: dNDArray.cc:579
charNDArray & insert(const charNDArray &a, octave_idx_type r, octave_idx_type c)
Definition: chNDArray.cc:164
bool test_all(F fcn) const
Definition: Array.h:815
boolNDArray all(int dim=-1) const
Definition: dNDArray.cc:632
NDArray cummin(int dim=-1) const
Definition: dNDArray.cc:716
static void increment_index(Array< octave_idx_type > &ra_idx, const dim_vector &dimensions, int start_dimension=0)
Definition: dNDArray.cc:831
void mx_inline_cumprod(const T *v, T *r, octave_idx_type n)
Definition: mx-inlines.cc:821
NDArray sum(int dim=-1) const
Definition: dNDArray.cc:662
boolNDArray any(int dim=-1) const
Definition: dNDArray.cc:638
NDArray diag(octave_idx_type k=0) const
Definition: dNDArray.cc:846
void mx_inline_cumsum(const T *v, T *r, octave_idx_type n)
Definition: mx-inlines.cc:820
boolNDArray isfinite(void) const
Definition: dNDArray.cc:825
=val(i)}if ode{val(i)}occurs in table i
Definition: lookup.cc:239
octave_idx_type nint_big(double x)
Definition: lo-mappers.cc:409
bool negative_sign(double x)
Definition: lo-mappers.cc:324
ComplexNDArray fourier(int dim=1) const
Definition: dNDArray.cc:100
bool all_integers(void) const
Definition: dNDArray.cc:618
issues an error eealso double
Definition: ov-bool-mat.cc:594
octave_idx_type ndims(void) const
Number of dimensions.
Definition: dim-vector.h:301
ComplexNDArray fourier2d(void) const
Definition: dNDArray.cc:161
bool any_element_is_inf_or_nan(void) const
Definition: dNDArray.cc:561
#define OCTAVE_LOCAL_BUFFER(T, buf, size)
Definition: oct-locbuf.h:200
#define BSXFUN_OP2_DEF_MXLOOP(OP, ARRAY, ARRAY1, ARRAY2, LOOP)
Definition: bsxfun-defs.cc:227
bool xtoo_large_for_float(double x)
Definition: lo-utils.cc:54
ComplexNDArray ifourierNd(void) const
Definition: dNDArray.cc:215
bool mx_inline_all(const T *v, octave_idx_type n)
Definition: mx-inlines.cc:716
#define BSXFUN_STDOP_DEFS_MXLOOP(ARRAY)
Definition: bsxfun-defs.cc:237
std::complex< double > Complex
Definition: oct-cmplx.h:31
const T * fortran_vec(void) const
Definition: Array.h:584
void mx_inline_not(size_t n, bool *r, const X *x)
Definition: mx-inlines.cc:182
write the output to stdout if nargout is
Definition: load-save.cc:1576
Vector representing the dimensions (size) of an Array.
Definition: dim-vector.h:87
T mx_inline_prod(const T *v, octave_idx_type n)
Definition: mx-inlines.cc:715
dim_vector dv
Definition: sub2ind.cc:263
bool xis_one_or_zero(double x)
Definition: lo-utils.cc:48
NDArray diff(octave_idx_type order=1, int dim=-1) const
Definition: dNDArray.cc:728
where the brackets indicate optional arguments and and character or cell array For character arrays the conversion is repeated for every row
Definition: str2double.cc:342
subroutine zfftf(n, c, wsave)
Definition: zfftf.f:1
NDArray xsum(int dim=-1) const
Definition: dNDArray.cc:668
bool too_large_for_float(void) const
Definition: dNDArray.cc:624
boolNDArray isinf(void) const
Definition: dNDArray.cc:819
void mx_inline_diff(const T *v, T *r, octave_idx_type n, octave_idx_type order)
Definition: mx-inlines.cc:1343
bool xis_int_or_inf_or_nan(double x)
Definition: lo-utils.cc:45
boolNDArray operator!(void) const
Definition: dNDArray.cc:532
void mx_inline_min(const T *v, T *r, octave_idx_type n)
Definition: mx-inlines.cc:924