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