GNU Octave  4.0.0
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
CNDArray.cc
Go to the documentation of this file.
1 // N-D Array manipulations.
2 /*
3 
4 Copyright (C) 1996-2015 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 #ifdef 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 "CNDArray.h"
35 #include "f77-fcn.h"
36 #include "functor.h"
37 #include "lo-ieee.h"
38 #include "lo-mappers.h"
39 #include "MArray-defs.h"
40 #include "mx-base.h"
41 #include "mx-op-defs.h"
42 #include "mx-cnda-s.h"
43 #include "oct-fftw.h"
44 #include "oct-locbuf.h"
45 
46 #include "bsxfun-defs.cc"
47 
49  : MArray<Complex> (a.dims ())
50 {
51  octave_idx_type n = a.numel ();
52  for (octave_idx_type i = 0; i < n; i++)
53  xelem (i) = static_cast<unsigned char> (a(i));
54 }
55 
56 #if defined (HAVE_FFTW)
57 
59 ComplexNDArray::fourier (int dim) const
60 {
61  dim_vector dv = dims ();
62 
63  if (dim > dv.length () || dim < 0)
64  return ComplexNDArray ();
65 
66  octave_idx_type stride = 1;
67  octave_idx_type n = dv(dim);
68 
69  for (int i = 0; i < dim; i++)
70  stride *= dv(i);
71 
72  octave_idx_type howmany = numel () / dv (dim);
73  howmany = (stride == 1 ? howmany : (howmany > stride ? stride : howmany));
74  octave_idx_type nloop = (stride == 1 ? 1 : numel () / dv (dim) / stride);
75  octave_idx_type dist = (stride == 1 ? n : 1);
76 
77  const Complex *in (fortran_vec ());
78  ComplexNDArray retval (dv);
79  Complex *out (retval.fortran_vec ());
80 
81  // Need to be careful here about the distance between fft's
82  for (octave_idx_type k = 0; k < nloop; k++)
83  octave_fftw::fft (in + k * stride * n, out + k * stride * n,
84  n, howmany, stride, dist);
85 
86  return retval;
87 }
88 
90 ComplexNDArray::ifourier (int dim) const
91 {
92  dim_vector dv = dims ();
93 
94  if (dim > dv.length () || dim < 0)
95  return ComplexNDArray ();
96 
97  octave_idx_type stride = 1;
98  octave_idx_type n = dv(dim);
99 
100  for (int i = 0; i < dim; i++)
101  stride *= dv(i);
102 
103  octave_idx_type howmany = numel () / dv (dim);
104  howmany = (stride == 1 ? howmany : (howmany > stride ? stride : howmany));
105  octave_idx_type nloop = (stride == 1 ? 1 : numel () / dv (dim) / stride);
106  octave_idx_type dist = (stride == 1 ? n : 1);
107 
108  const Complex *in (fortran_vec ());
109  ComplexNDArray retval (dv);
110  Complex *out (retval.fortran_vec ());
111 
112  // Need to be careful here about the distance between fft's
113  for (octave_idx_type k = 0; k < nloop; k++)
114  octave_fftw::ifft (in + k * stride * n, out + k * stride * n,
115  n, howmany, stride, dist);
116 
117  return retval;
118 }
119 
122 {
123  dim_vector dv = dims ();
124  if (dv.length () < 2)
125  return ComplexNDArray ();
126 
127  dim_vector dv2(dv(0), dv(1));
128  const Complex *in = fortran_vec ();
129  ComplexNDArray retval (dv);
130  Complex *out = retval.fortran_vec ();
131  octave_idx_type howmany = numel () / dv(0) / dv(1);
132  octave_idx_type dist = dv(0) * dv(1);
133 
134  for (octave_idx_type i=0; i < howmany; i++)
135  octave_fftw::fftNd (in + i*dist, out + i*dist, 2, dv2);
136 
137  return retval;
138 }
139 
142 {
143  dim_vector dv = dims ();
144  if (dv.length () < 2)
145  return ComplexNDArray ();
146 
147  dim_vector dv2(dv(0), dv(1));
148  const Complex *in = fortran_vec ();
149  ComplexNDArray retval (dv);
150  Complex *out = retval.fortran_vec ();
151  octave_idx_type howmany = numel () / dv(0) / dv(1);
152  octave_idx_type dist = dv(0) * dv(1);
153 
154  for (octave_idx_type i=0; i < howmany; i++)
155  octave_fftw::ifftNd (in + i*dist, out + i*dist, 2, dv2);
156 
157  return retval;
158 }
159 
162 {
163  dim_vector dv = dims ();
164  int rank = dv.length ();
165 
166  const Complex *in (fortran_vec ());
167  ComplexNDArray retval (dv);
168  Complex *out (retval.fortran_vec ());
169 
170  octave_fftw::fftNd (in, out, rank, dv);
171 
172  return retval;
173 }
174 
177 {
178  dim_vector dv = dims ();
179  int rank = dv.length ();
180 
181  const Complex *in (fortran_vec ());
182  ComplexNDArray retval (dv);
183  Complex *out (retval.fortran_vec ());
184 
185  octave_fftw::ifftNd (in, out, rank, dv);
186 
187  return retval;
188 }
189 
190 #else
191 
192 extern "C"
193 {
194  // Note that the original complex fft routines were not written for
195  // double complex arguments. They have been modified by adding an
196  // implicit double precision (a-h,o-z) statement at the beginning of
197  // each subroutine.
198 
199  F77_RET_T
200  F77_FUNC (zffti, ZFFTI) (const octave_idx_type&, Complex*);
201 
202  F77_RET_T
203  F77_FUNC (zfftf, ZFFTF) (const octave_idx_type&, Complex*, Complex*);
204 
205  F77_RET_T
206  F77_FUNC (zfftb, ZFFTB) (const octave_idx_type&, Complex*, Complex*);
207 }
208 
210 ComplexNDArray::fourier (int dim) const
211 {
212  dim_vector dv = dims ();
213 
214  if (dim > dv.length () || dim < 0)
215  return ComplexNDArray ();
216 
217  ComplexNDArray retval (dv);
218  octave_idx_type npts = dv(dim);
219  octave_idx_type nn = 4*npts+15;
220  Array<Complex> wsave (dim_vector (nn, 1));
221  Complex *pwsave = wsave.fortran_vec ();
222 
223  OCTAVE_LOCAL_BUFFER (Complex, tmp, npts);
224 
225  octave_idx_type stride = 1;
226 
227  for (int i = 0; i < dim; i++)
228  stride *= dv(i);
229 
230  octave_idx_type howmany = numel () / npts;
231  howmany = (stride == 1 ? howmany : (howmany > stride ? stride : howmany));
232  octave_idx_type nloop = (stride == 1 ? 1 : numel () / npts / stride);
233  octave_idx_type dist = (stride == 1 ? npts : 1);
234 
235  F77_FUNC (zffti, ZFFTI) (npts, pwsave);
236 
237  for (octave_idx_type k = 0; k < nloop; k++)
238  {
239  for (octave_idx_type j = 0; j < howmany; j++)
240  {
241  octave_quit ();
242 
243  for (octave_idx_type i = 0; i < npts; i++)
244  tmp[i] = elem ((i + k*npts)*stride + j*dist);
245 
246  F77_FUNC (zfftf, ZFFTF) (npts, tmp, pwsave);
247 
248  for (octave_idx_type i = 0; i < npts; i++)
249  retval((i + k*npts)*stride + j*dist) = tmp[i];
250  }
251  }
252 
253  return retval;
254 }
255 
257 ComplexNDArray::ifourier (int dim) const
258 {
259  dim_vector dv = dims ();
260 
261  if (dim > dv.length () || dim < 0)
262  return ComplexNDArray ();
263 
264  ComplexNDArray retval (dv);
265  octave_idx_type npts = dv(dim);
266  octave_idx_type nn = 4*npts+15;
267  Array<Complex> wsave (dim_vector (nn, 1));
268  Complex *pwsave = wsave.fortran_vec ();
269 
270  OCTAVE_LOCAL_BUFFER (Complex, tmp, npts);
271 
272  octave_idx_type stride = 1;
273 
274  for (int i = 0; i < dim; i++)
275  stride *= dv(i);
276 
277  octave_idx_type howmany = numel () / npts;
278  howmany = (stride == 1 ? howmany : (howmany > stride ? stride : howmany));
279  octave_idx_type nloop = (stride == 1 ? 1 : numel () / npts / stride);
280  octave_idx_type dist = (stride == 1 ? npts : 1);
281 
282  F77_FUNC (zffti, ZFFTI) (npts, pwsave);
283 
284  for (octave_idx_type k = 0; k < nloop; k++)
285  {
286  for (octave_idx_type j = 0; j < howmany; j++)
287  {
288  octave_quit ();
289 
290  for (octave_idx_type i = 0; i < npts; i++)
291  tmp[i] = elem ((i + k*npts)*stride + j*dist);
292 
293  F77_FUNC (zfftb, ZFFTB) (npts, tmp, pwsave);
294 
295  for (octave_idx_type i = 0; i < npts; i++)
296  retval((i + k*npts)*stride + j*dist) = tmp[i] /
297  static_cast<double> (npts);
298  }
299  }
300 
301  return retval;
302 }
303 
305 ComplexNDArray::fourier2d (void) const
306 {
307  dim_vector dv = dims ();
308  dim_vector dv2 (dv(0), dv(1));
309  int rank = 2;
310  ComplexNDArray retval (*this);
311  octave_idx_type stride = 1;
312 
313  for (int i = 0; i < rank; i++)
314  {
315  octave_idx_type npts = dv2(i);
316  octave_idx_type nn = 4*npts+15;
317  Array<Complex> wsave (dim_vector (nn, 1));
318  Complex *pwsave = wsave.fortran_vec ();
319  Array<Complex> row (dim_vector (npts, 1));
320  Complex *prow = row.fortran_vec ();
321 
322  octave_idx_type howmany = numel () / npts;
323  howmany = (stride == 1 ? howmany :
324  (howmany > stride ? stride : howmany));
325  octave_idx_type nloop = (stride == 1 ? 1 : numel () / npts / stride);
326  octave_idx_type dist = (stride == 1 ? npts : 1);
327 
328  F77_FUNC (zffti, ZFFTI) (npts, pwsave);
329 
330  for (octave_idx_type k = 0; k < nloop; k++)
331  {
332  for (octave_idx_type j = 0; j < howmany; j++)
333  {
334  octave_quit ();
335 
336  for (octave_idx_type l = 0; l < npts; l++)
337  prow[l] = retval((l + k*npts)*stride + j*dist);
338 
339  F77_FUNC (zfftf, ZFFTF) (npts, prow, pwsave);
340 
341  for (octave_idx_type l = 0; l < npts; l++)
342  retval((l + k*npts)*stride + j*dist) = prow[l];
343  }
344  }
345 
346  stride *= dv2(i);
347  }
348 
349  return retval;
350 }
351 
353 ComplexNDArray::ifourier2d (void) const
354 {
355  dim_vector dv = dims ();
356  dim_vector dv2 (dv(0), dv(1));
357  int rank = 2;
358  ComplexNDArray retval (*this);
359  octave_idx_type stride = 1;
360 
361  for (int i = 0; i < rank; i++)
362  {
363  octave_idx_type npts = dv2(i);
364  octave_idx_type nn = 4*npts+15;
365  Array<Complex> wsave (dim_vector (nn, 1));
366  Complex *pwsave = wsave.fortran_vec ();
367  Array<Complex> row (dim_vector (npts, 1));
368  Complex *prow = row.fortran_vec ();
369 
370  octave_idx_type howmany = numel () / npts;
371  howmany = (stride == 1 ? howmany :
372  (howmany > stride ? stride : howmany));
373  octave_idx_type nloop = (stride == 1 ? 1 : numel () / npts / stride);
374  octave_idx_type dist = (stride == 1 ? npts : 1);
375 
376  F77_FUNC (zffti, ZFFTI) (npts, pwsave);
377 
378  for (octave_idx_type k = 0; k < nloop; k++)
379  {
380  for (octave_idx_type j = 0; j < howmany; j++)
381  {
382  octave_quit ();
383 
384  for (octave_idx_type l = 0; l < npts; l++)
385  prow[l] = retval((l + k*npts)*stride + j*dist);
386 
387  F77_FUNC (zfftb, ZFFTB) (npts, prow, pwsave);
388 
389  for (octave_idx_type l = 0; l < npts; l++)
390  retval((l + k*npts)*stride + j*dist) =
391  prow[l] / static_cast<double> (npts);
392  }
393  }
394 
395  stride *= dv2(i);
396  }
397 
398  return retval;
399 }
400 
402 ComplexNDArray::fourierNd (void) const
403 {
404  dim_vector dv = dims ();
405  int rank = dv.length ();
406  ComplexNDArray retval (*this);
407  octave_idx_type stride = 1;
408 
409  for (int i = 0; i < rank; i++)
410  {
411  octave_idx_type npts = dv(i);
412  octave_idx_type nn = 4*npts+15;
413  Array<Complex> wsave (dim_vector (nn, 1));
414  Complex *pwsave = wsave.fortran_vec ();
415  Array<Complex> row (dim_vector (npts, 1));
416  Complex *prow = row.fortran_vec ();
417 
418  octave_idx_type howmany = numel () / npts;
419  howmany = (stride == 1 ? howmany :
420  (howmany > stride ? stride : howmany));
421  octave_idx_type nloop = (stride == 1 ? 1 : numel () / npts / stride);
422  octave_idx_type dist = (stride == 1 ? npts : 1);
423 
424  F77_FUNC (zffti, ZFFTI) (npts, pwsave);
425 
426  for (octave_idx_type k = 0; k < nloop; k++)
427  {
428  for (octave_idx_type j = 0; j < howmany; j++)
429  {
430  octave_quit ();
431 
432  for (octave_idx_type l = 0; l < npts; l++)
433  prow[l] = retval((l + k*npts)*stride + j*dist);
434 
435  F77_FUNC (zfftf, ZFFTF) (npts, prow, pwsave);
436 
437  for (octave_idx_type l = 0; l < npts; l++)
438  retval((l + k*npts)*stride + j*dist) = prow[l];
439  }
440  }
441 
442  stride *= dv(i);
443  }
444 
445  return retval;
446 }
447 
449 ComplexNDArray::ifourierNd (void) const
450 {
451  dim_vector dv = dims ();
452  int rank = dv.length ();
453  ComplexNDArray retval (*this);
454  octave_idx_type stride = 1;
455 
456  for (int i = 0; i < rank; i++)
457  {
458  octave_idx_type npts = dv(i);
459  octave_idx_type nn = 4*npts+15;
460  Array<Complex> wsave (dim_vector (nn, 1));
461  Complex *pwsave = wsave.fortran_vec ();
462  Array<Complex> row (dim_vector (npts, 1));
463  Complex *prow = row.fortran_vec ();
464 
465  octave_idx_type howmany = numel () / npts;
466  howmany = (stride == 1 ? howmany :
467  (howmany > stride ? stride : howmany));
468  octave_idx_type nloop = (stride == 1 ? 1 : numel () / npts / stride);
469  octave_idx_type dist = (stride == 1 ? npts : 1);
470 
471  F77_FUNC (zffti, ZFFTI) (npts, pwsave);
472 
473  for (octave_idx_type k = 0; k < nloop; k++)
474  {
475  for (octave_idx_type j = 0; j < howmany; j++)
476  {
477  octave_quit ();
478 
479  for (octave_idx_type l = 0; l < npts; l++)
480  prow[l] = retval((l + k*npts)*stride + j*dist);
481 
482  F77_FUNC (zfftb, ZFFTB) (npts, prow, pwsave);
483 
484  for (octave_idx_type l = 0; l < npts; l++)
485  retval((l + k*npts)*stride + j*dist) =
486  prow[l] / static_cast<double> (npts);
487  }
488  }
489 
490  stride *= dv(i);
491  }
492 
493  return retval;
494 }
495 
496 #endif
497 
498 // unary operations
499 
502 {
503  if (any_element_is_nan ())
505 
506  return do_mx_unary_op<bool, Complex> (*this, mx_inline_not);
507 }
508 
509 // FIXME: this is not quite the right thing.
510 
511 bool
513 {
514  return do_mx_check<Complex> (*this, mx_inline_any_nan);
515 }
516 
517 bool
519 {
520  return ! do_mx_check<Complex> (*this, mx_inline_all_finite);
521 }
522 
523 // Return true if no elements have imaginary components.
524 
525 bool
527 {
528  return do_mx_check<Complex> (*this, mx_inline_all_real);
529 }
530 
531 // Return nonzero if any element of CM has a non-integer real or
532 // imaginary part. Also extract the largest and smallest (real or
533 // imaginary) values and return them in MAX_VAL and MIN_VAL.
534 
535 bool
536 ComplexNDArray::all_integers (double& max_val, double& min_val) const
537 {
538  octave_idx_type nel = nelem ();
539 
540  if (nel > 0)
541  {
542  Complex val = elem (0);
543 
544  double r_val = std::real (val);
545  double i_val = std::imag (val);
546 
547  max_val = r_val;
548  min_val = r_val;
549 
550  if (i_val > max_val)
551  max_val = i_val;
552 
553  if (i_val < max_val)
554  min_val = i_val;
555  }
556  else
557  return false;
558 
559  for (octave_idx_type i = 0; i < nel; i++)
560  {
561  Complex val = elem (i);
562 
563  double r_val = std::real (val);
564  double i_val = std::imag (val);
565 
566  if (r_val > max_val)
567  max_val = r_val;
568 
569  if (i_val > max_val)
570  max_val = i_val;
571 
572  if (r_val < min_val)
573  min_val = r_val;
574 
575  if (i_val < min_val)
576  min_val = i_val;
577 
578  if (D_NINT (r_val) != r_val || D_NINT (i_val) != i_val)
579  return false;
580  }
581 
582  return true;
583 }
584 
585 bool
587 {
589 }
590 
592 ComplexNDArray::all (int dim) const
593 {
594  return do_mx_red_op<bool, Complex> (*this, dim, mx_inline_all);
595 }
596 
598 ComplexNDArray::any (int dim) const
599 {
600  return do_mx_red_op<bool, Complex> (*this, dim, mx_inline_any);
601 }
602 
604 ComplexNDArray::cumprod (int dim) const
605 {
606  return do_mx_cum_op<Complex, Complex> (*this, dim, mx_inline_cumprod);
607 }
608 
610 ComplexNDArray::cumsum (int dim) const
611 {
612  return do_mx_cum_op<Complex, Complex> (*this, dim, mx_inline_cumsum);
613 }
614 
616 ComplexNDArray::prod (int dim) const
617 {
618  return do_mx_red_op<Complex, Complex> (*this, dim, mx_inline_prod);
619 }
620 
622 ComplexNDArray::sum (int dim) const
623 {
624  return do_mx_red_op<Complex, Complex> (*this, dim, mx_inline_sum);
625 }
626 
628 ComplexNDArray::xsum (int dim) const
629 {
630  return do_mx_red_op<Complex, Complex> (*this, dim, mx_inline_xsum);
631 }
632 
634 ComplexNDArray::sumsq (int dim) const
635 {
636  return do_mx_red_op<double, Complex> (*this, dim, mx_inline_sumsq);
637 }
638 
640 ComplexNDArray::diff (octave_idx_type order, int dim) const
641 {
642  return do_mx_diff_op<Complex> (*this, dim, order, mx_inline_diff);
643 }
644 
648 {
649  if (rb.numel () > 0)
650  insert (rb, ra_idx);
651  return *this;
652 }
653 
656 {
657  ComplexNDArray tmp (rb);
658  if (rb.numel () > 0)
659  insert (tmp, ra_idx);
660  return *this;
661 }
662 
665 {
666  ComplexNDArray retval (ra);
667  if (rb.numel () > 0)
668  retval.insert (rb, ra_idx);
669  return retval;
670 }
671 
673 
675 ComplexNDArray::max (int dim) const
676 {
677  return do_mx_minmax_op<Complex> (*this, dim, mx_inline_max);
678 }
679 
682 {
683  return do_mx_minmax_op<Complex> (*this, idx_arg, dim, mx_inline_max);
684 }
685 
687 ComplexNDArray::min (int dim) const
688 {
689  return do_mx_minmax_op<Complex> (*this, dim, mx_inline_min);
690 }
691 
694 {
695  return do_mx_minmax_op<Complex> (*this, idx_arg, dim, mx_inline_min);
696 }
697 
699 ComplexNDArray::cummax (int dim) const
700 {
701  return do_mx_cumminmax_op<Complex> (*this, dim, mx_inline_cummax);
702 }
703 
706 {
707  return do_mx_cumminmax_op<Complex> (*this, idx_arg, dim, mx_inline_cummax);
708 }
709 
711 ComplexNDArray::cummin (int dim) const
712 {
713  return do_mx_cumminmax_op<Complex> (*this, dim, mx_inline_cummin);
714 }
715 
718 {
719  return do_mx_cumminmax_op<Complex> (*this, idx_arg, dim, mx_inline_cummin);
720 }
721 
722 NDArray
724 {
725  return do_mx_unary_map<double, Complex, std::abs> (*this);
726 }
727 
730 {
731  return do_mx_unary_map<bool, Complex, xisnan> (*this);
732 }
733 
736 {
737  return do_mx_unary_map<bool, Complex, xisinf> (*this);
738 }
739 
742 {
743  return do_mx_unary_map<bool, Complex, xfinite> (*this);
744 }
745 
748 {
749  return do_mx_unary_map<Complex, Complex, std::conj<double> > (a);
750 }
751 
754 {
755  dim_vector a_dv = a.dims ();
756 
757  int n = a_dv.length ();
758 
759  if (n == dimensions.length ())
760  {
761  Array<octave_idx_type> a_ra_idx (dim_vector (a_dv.length (), 1), 0);
762 
763  a_ra_idx.elem (0) = r;
764  a_ra_idx.elem (1) = c;
765 
766  for (int i = 0; i < n; i++)
767  {
768  if (a_ra_idx (i) < 0 || (a_ra_idx (i) + a_dv (i)) > dimensions (i))
769  {
770  (*current_liboctave_error_handler)
771  ("Array<T>::insert: range error for insert");
772  return *this;
773  }
774  }
775 
776  a_ra_idx.elem (0) = 0;
777  a_ra_idx.elem (1) = 0;
778 
779  octave_idx_type n_elt = a.numel ();
780 
781  // IS make_unique () NECCESSARY HERE??
782 
783  for (octave_idx_type i = 0; i < n_elt; i++)
784  {
785  Array<octave_idx_type> ra_idx = a_ra_idx;
786 
787  ra_idx.elem (0) = a_ra_idx (0) + r;
788  ra_idx.elem (1) = a_ra_idx (1) + c;
789 
790  elem (ra_idx) = a.elem (a_ra_idx);
791 
792  increment_index (a_ra_idx, a_dv);
793  }
794  }
795  else
797  ("Array<T>::insert: invalid indexing operation");
798 
799  return *this;
800 }
801 
805 {
806  Array<Complex>::insert (a, r, c);
807  return *this;
808 }
809 
813 {
814  Array<Complex>::insert (a, ra_idx);
815  return *this;
816 }
817 
818 void
820  const dim_vector& dimensions,
821  int start_dimension)
822 {
823  ::increment_index (ra_idx, dimensions, start_dimension);
824 }
825 
828  const dim_vector& dimensions)
829 {
830  return ::compute_index (ra_idx, dimensions);
831 }
832 
835 {
836  return MArray<Complex>::diag (k);
837 }
838 
841 {
842  return MArray<Complex>::diag (m, n);
843 }
844 
845 // This contains no information on the array structure !!!
846 std::ostream&
847 operator << (std::ostream& os, const ComplexNDArray& a)
848 {
849  octave_idx_type nel = a.nelem ();
850 
851  for (octave_idx_type i = 0; i < nel; i++)
852  {
853  os << " ";
854  octave_write_complex (os, a.elem (i));
855  os << "\n";
856  }
857  return os;
858 }
859 
860 std::istream&
861 operator >> (std::istream& is, ComplexNDArray& a)
862 {
863  octave_idx_type nel = a.nelem ();
864 
865  if (nel > 0)
866  {
867  Complex tmp;
868  for (octave_idx_type i = 0; i < nel; i++)
869  {
870  tmp = octave_read_value<Complex> (is);
871  if (is)
872  a.elem (i) = tmp;
873  else
874  goto done;
875  }
876  }
877 
878 done:
879 
880  return is;
881 }
882 
884 
886 NDS_BOOL_OPS (ComplexNDArray, Complex)
887 
888 SND_CMP_OPS (Complex, ComplexNDArray)
889 SND_BOOL_OPS (Complex, ComplexNDArray)
890 
891 NDND_CMP_OPS (ComplexNDArray, ComplexNDArray)
892 NDND_BOOL_OPS (ComplexNDArray, ComplexNDArray)
893 
894 ComplexNDArray& operator *= (ComplexNDArray& a, double s)
895 {
896  if (a.is_shared ())
897  a = a * s;
898  else
899  do_ms_inplace_op<Complex, double> (a, s, mx_inline_mul2);
900  return a;
901 }
902 
904 {
905  if (a.is_shared ())
906  return a = a / s;
907  else
908  do_ms_inplace_op<Complex, double> (a, s, mx_inline_div2);
909  return a;
910 }
911 
914 
dim_vector dimensions
Definition: Array.h:127
T mx_inline_xsum(const T *v, octave_idx_type n)
Definition: mx-inlines.cc:1344
octave_idx_type compute_index(octave_idx_type n, const dim_vector &dims)
Definition: Array-util.cc:178
void mx_inline_mul2(size_t n, R *r, const X *x)
Definition: mx-inlines.cc:97
ComplexNDArray concat(const ComplexNDArray &rb, const Array< octave_idx_type > &ra_idx)
Definition: CNDArray.cc:646
std::istream & operator>>(std::istream &is, ComplexNDArray &a)
Definition: CNDArray.cc:861
#define NDS_BOOL_OPS(ND, S)
Definition: mx-op-defs.h:253
#define NDS_CMP_OPS(ND, S)
Definition: mx-op-defs.h:236
bool all_integers(double &max_val, double &min_val) const
Definition: CNDArray.cc:536
ComplexNDArray conj(const ComplexNDArray &a)
Definition: CNDArray.cc:747
void mx_inline_cummax(const T *v, T *r, octave_idx_type n)
Definition: mx-inlines.cc:894
ComplexNDArray ifourier2d(void) const
Definition: CNDArray.cc:141
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:827
const octave_base_value const Array< octave_idx_type > & ra_idx
bool any_element_is_nan(void) const
Definition: CNDArray.cc:512
#define SND_CMP_OPS(S, ND)
Definition: mx-op-defs.h:283
#define BSXFUN_OP_DEF_MXLOOP(OP, ARRAY, LOOP)
Definition: bsxfun-defs.cc:221
ComplexNDArray diag(octave_idx_type k=0) const
Definition: CNDArray.cc:834
octave_idx_type numel(void) const
Number of elements in the array.
Definition: Array.h:275
subroutine zffti(n, wsave)
Definition: zffti.f:1
static octave_idx_type nn
Definition: DASPK.cc:71
ComplexNDArray & operator/=(ComplexNDArray &a, double s)
Definition: CNDArray.cc:903
bool mx_inline_all_finite(size_t n, const T *x)
Definition: mx-inlines.cc:195
ComplexNDArray fourier(int dim=1) const
Definition: CNDArray.cc:59
#define MINMAX_FCNS(T, S)
Definition: mx-op-defs.h:590
void octave_write_complex(std::ostream &os, const Complex &c)
Definition: lo-utils.cc:399
ComplexNDArray concat(NDArray &ra, ComplexNDArray &rb, const Array< octave_idx_type > &ra_idx)
Definition: CNDArray.cc:664
Array< T > diag(octave_idx_type k=0) const
Get the kth super or subdiagonal.
Definition: Array.cc:2526
ComplexNDArray ifourierNd(void) const
Definition: CNDArray.cc:176
ComplexRowVector row(octave_idx_type i) const
Definition: CMatrix.cc:990
Complex & elem(octave_idx_type n)
Definition: Array.h:380
Definition: MArray.h:36
T mx_inline_sumsq(const T *v, octave_idx_type n)
Definition: mx-inlines.cc:524
void mx_inline_max(const T *v, T *r, octave_idx_type n)
Definition: mx-inlines.cc:719
bool mx_inline_any(const T *v, octave_idx_type n)
Definition: mx-inlines.cc:524
subroutine zfftb(n, c, wsave)
Definition: zfftb.f:1
ComplexNDArray fourier2d(void) const
Definition: CNDArray.cc:121
static void increment_index(Array< octave_idx_type > &ra_idx, const dim_vector &dimensions, int start_dimension=0)
Definition: CNDArray.cc:819
static int fftNd(const double *, Complex *, const int, const dim_vector &)
Definition: oct-fftw.cc:889
bool too_large_for_float(void) const
Definition: CNDArray.cc:586
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:1591
octave_idx_type nelem(void) const
Number of elements in the array.
Definition: Array.h:271
ComplexNDArray sumsq(int dim=-1) const
Definition: CNDArray.cc:634
ComplexNDArray ifourier(int dim=1) const
Definition: CNDArray.cc:90
ComplexNDArray min(int dim=-1) const
Definition: CNDArray.cc:687
bool mx_inline_all_real(size_t n, const std::complex< T > *x)
Definition: mx-inlines.cc:234
boolNDArray operator!(void) const
Definition: CNDArray.cc:501
const dim_vector & dims(void) const
Return a const-reference so that dims ()(i) works efficiently.
Definition: Array.h:337
ComplexNDArray cumprod(int dim=-1) const
Definition: CNDArray.cc:604
liboctave_error_handler current_liboctave_error_handler
Definition: lo-error.c:38
ComplexNDArray prod(int dim=-1) const
Definition: CNDArray.cc:616
#define NDND_CMP_OPS(ND1, ND2)
Definition: mx-op-defs.h:330
ComplexNDArray sum(int dim=-1) const
Definition: CNDArray.cc:622
bool all_elements_are_real(void) const
Definition: CNDArray.cc:526
bool test_any(F fcn) const
Simpler calls.
Definition: Array.h:710
ComplexNDArray & insert(const NDArray &a, octave_idx_type r, octave_idx_type c)
Definition: CNDArray.cc:753
#define NDND_BOOL_OPS(ND1, ND2)
Definition: mx-op-defs.h:347
NDArray abs(void) const
Definition: CNDArray.cc:723
ComplexNDArray cummin(int dim=-1) const
Definition: CNDArray.cc:711
void gripe_nan_to_logical_conversion(void)
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:865
octave_int< T > pow(const octave_int< T > &a, const octave_int< T > &b)
#define SND_BOOL_OPS(S, ND)
Definition: mx-op-defs.h:300
boolNDArray all(int dim=-1) const
Definition: CNDArray.cc:592
ComplexNDArray xsum(int dim=-1) const
Definition: CNDArray.cc:628
#define F77_RET_T
Definition: f77-fcn.h:264
bool any_element_is_inf_or_nan(void) const
Definition: CNDArray.cc:518
void mx_inline_cummin(const T *v, T *r, octave_idx_type n)
Definition: mx-inlines.cc:893
OCTAVE_API double D_NINT(double x)
Definition: lo-mappers.h:240
void mx_inline_pow(size_t n, R *r, const X *x, const Y *y)
Definition: mx-inlines.cc:311
bool mx_inline_any_nan(size_t n, const T *x)
Definition: mx-inlines.cc:182
static int ifftNd(const Complex *, Complex *, const int, const dim_vector &)
Definition: oct-fftw.cc:933
#define BSXFUN_STDREL_DEFS_MXLOOP(ARRAY)
Definition: bsxfun-defs.cc:244
ComplexNDArray fourierNd(void) const
Definition: CNDArray.cc:161
Complex & xelem(octave_idx_type n)
Definition: Array.h:353
T mx_inline_sum(const T *v, octave_idx_type n)
Definition: mx-inlines.cc:522
ComplexNDArray cumsum(int dim=-1) const
Definition: CNDArray.cc:610
ComplexNDArray max(int dim=-1) const
Definition: CNDArray.cc:675
void mx_inline_cumprod(const T *v, T *r, octave_idx_type n)
Definition: mx-inlines.cc:628
ComplexNDArray(void)
Definition: CNDArray.h:38
static octave_idx_type compute_index(Array< octave_idx_type > &ra_idx, const dim_vector &dimensions)
Definition: CNDArray.cc:827
void mx_inline_cumsum(const T *v, T *r, octave_idx_type n)
Definition: mx-inlines.cc:627
#define octave_NaN
Definition: lo-ieee.h:37
std::ostream & operator<<(std::ostream &os, const ComplexNDArray &a)
Definition: CNDArray.cc:847
bool is_shared(void)
Definition: Array.h:485
boolNDArray isfinite(void) const
Definition: CNDArray.cc:741
F77_RET_T F77_FUNC(zgemv, ZGEMV)(F77_CONST_CHAR_ARG_DECL
#define OCTAVE_LOCAL_BUFFER(T, buf, size)
Definition: oct-locbuf.h:197
static const Complex Complex_NaN_result((lo_ieee_nan_value()),(lo_ieee_nan_value()))
bool xtoo_large_for_float(double x)
Definition: lo-utils.cc:56
ComplexNDArray diff(octave_idx_type order=1, int dim=-1) const
Definition: CNDArray.cc:640
ColumnVector imag(const ComplexColumnVector &a)
Definition: dColVector.cc:162
boolNDArray isinf(void) const
Definition: CNDArray.cc:735
bool mx_inline_all(const T *v, octave_idx_type n)
Definition: mx-inlines.cc:524
#define BSXFUN_STDOP_DEFS_MXLOOP(ARRAY)
Definition: bsxfun-defs.cc:236
std::complex< double > Complex
Definition: oct-cmplx.h:29
const Complex * fortran_vec(void) const
Definition: Array.h:481
void mx_inline_div2(size_t n, R *r, const X *x)
Definition: mx-inlines.cc:98
void mx_inline_not(size_t n, bool *r, const X *x)
Definition: mx-inlines.cc:126
ColumnVector real(const ComplexColumnVector &a)
Definition: dColVector.cc:156
int length(void) const
Definition: dim-vector.h:281
T mx_inline_prod(const T *v, octave_idx_type n)
Definition: mx-inlines.cc:523
ComplexNDArray cummax(int dim=-1) const
Definition: CNDArray.cc:699
boolNDArray any(int dim=-1) const
Definition: CNDArray.cc:598
subroutine zfftf(n, c, wsave)
Definition: zfftf.f:1
boolNDArray isnan(void) const
Definition: CNDArray.cc:729
void mx_inline_diff(const T *v, T *r, octave_idx_type n, octave_idx_type order)
Definition: mx-inlines.cc:1036
void mx_inline_min(const T *v, T *r, octave_idx_type n)
Definition: mx-inlines.cc:718