GNU Octave  4.4.1
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
CNDArray.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 <complex>
29 #include <iostream>
30 
31 #include "Array-util.h"
32 #include "CNDArray.h"
33 #include "f77-fcn.h"
34 #include "functor.h"
35 #include "lo-ieee.h"
36 #include "lo-mappers.h"
37 #include "mx-base.h"
38 #include "mx-cnda-s.h"
39 #include "mx-op-defs.h"
40 #include "oct-fftw.h"
41 #include "oct-locbuf.h"
42 
43 #include "bsxfun-defs.cc"
44 
46  : MArray<Complex> (a.dims ())
47 {
48  octave_idx_type n = a.numel ();
49  for (octave_idx_type i = 0; i < n; i++)
50  xelem (i) = static_cast<unsigned char> (a(i));
51 }
52 
53 #if defined (HAVE_FFTW)
54 
56 ComplexNDArray::fourier (int dim) const
57 {
58  dim_vector dv = dims ();
59 
60  if (dim > dv.ndims () || dim < 0)
61  return ComplexNDArray ();
62 
63  octave_idx_type stride = 1;
64  octave_idx_type n = dv(dim);
65 
66  for (int i = 0; i < dim; i++)
67  stride *= dv(i);
68 
69  octave_idx_type howmany = numel () / dv(dim);
70  howmany = (stride == 1 ? howmany : (howmany > stride ? stride : howmany));
71  octave_idx_type nloop = (stride == 1 ? 1 : numel () / dv(dim) / stride);
72  octave_idx_type dist = (stride == 1 ? n : 1);
73 
74  const Complex *in (fortran_vec ());
76  Complex *out (retval.fortran_vec ());
77 
78  // Need to be careful here about the distance between fft's
79  for (octave_idx_type k = 0; k < nloop; k++)
80  octave::fftw::fft (in + k * stride * n, out + k * stride * n,
81  n, howmany, stride, dist);
82 
83  return retval;
84 }
85 
87 ComplexNDArray::ifourier (int dim) const
88 {
89  dim_vector dv = dims ();
90 
91  if (dim > dv.ndims () || dim < 0)
92  return ComplexNDArray ();
93 
94  octave_idx_type stride = 1;
95  octave_idx_type n = dv(dim);
96 
97  for (int i = 0; i < dim; i++)
98  stride *= dv(i);
99 
100  octave_idx_type howmany = numel () / dv(dim);
101  howmany = (stride == 1 ? howmany : (howmany > stride ? stride : howmany));
102  octave_idx_type nloop = (stride == 1 ? 1 : numel () / dv(dim) / stride);
103  octave_idx_type dist = (stride == 1 ? n : 1);
104 
105  const Complex *in (fortran_vec ());
107  Complex *out (retval.fortran_vec ());
108 
109  // Need to be careful here about the distance between fft's
110  for (octave_idx_type k = 0; k < nloop; k++)
111  octave::fftw::ifft (in + k * stride * n, out + k * stride * n,
112  n, howmany, stride, dist);
113 
114  return retval;
115 }
116 
119 {
120  dim_vector dv = dims ();
121  if (dv.ndims () < 2)
122  return ComplexNDArray ();
123 
124  dim_vector dv2 (dv(0), dv(1));
125  const Complex *in = fortran_vec ();
127  Complex *out = retval.fortran_vec ();
128  octave_idx_type howmany = numel () / dv(0) / dv(1);
129  octave_idx_type dist = dv(0) * dv(1);
130 
131  for (octave_idx_type i=0; i < howmany; i++)
132  octave::fftw::fftNd (in + i*dist, out + i*dist, 2, dv2);
133 
134  return retval;
135 }
136 
139 {
140  dim_vector dv = dims ();
141  if (dv.ndims () < 2)
142  return ComplexNDArray ();
143 
144  dim_vector dv2 (dv(0), dv(1));
145  const Complex *in = fortran_vec ();
147  Complex *out = retval.fortran_vec ();
148  octave_idx_type howmany = numel () / dv(0) / dv(1);
149  octave_idx_type dist = dv(0) * dv(1);
150 
151  for (octave_idx_type i=0; i < howmany; i++)
152  octave::fftw::ifftNd (in + i*dist, out + i*dist, 2, dv2);
153 
154  return retval;
155 }
156 
159 {
160  dim_vector dv = dims ();
161  int rank = dv.ndims ();
162 
163  const Complex *in (fortran_vec ());
165  Complex *out (retval.fortran_vec ());
166 
167  octave::fftw::fftNd (in, out, rank, dv);
168 
169  return retval;
170 }
171 
174 {
175  dim_vector dv = dims ();
176  int rank = dv.ndims ();
177 
178  const Complex *in (fortran_vec ());
180  Complex *out (retval.fortran_vec ());
181 
182  octave::fftw::ifftNd (in, out, rank, dv);
183 
184  return retval;
185 }
186 
187 #else
188 
189 #include "lo-fftpack-proto.h"
190 
192 ComplexNDArray::fourier (int dim) const
193 {
194  dim_vector dv = dims ();
195 
196  if (dim > dv.ndims () || dim < 0)
197  return ComplexNDArray ();
198 
200  octave_idx_type npts = dv(dim);
201  octave_idx_type nn = 4*npts+15;
202  Array<Complex> wsave (dim_vector (nn, 1));
203  Complex *pwsave = wsave.fortran_vec ();
204 
206 
207  octave_idx_type stride = 1;
208 
209  for (int i = 0; i < dim; i++)
210  stride *= dv(i);
211 
212  octave_idx_type howmany = numel () / npts;
213  howmany = (stride == 1 ? howmany : (howmany > stride ? stride : howmany));
214  octave_idx_type nloop = (stride == 1 ? 1 : numel () / npts / stride);
215  octave_idx_type dist = (stride == 1 ? npts : 1);
216 
217  F77_FUNC (zffti, ZFFTI) (npts, F77_DBLE_CMPLX_ARG (pwsave));
218 
219  for (octave_idx_type k = 0; k < nloop; k++)
220  {
221  for (octave_idx_type j = 0; j < howmany; j++)
222  {
223  octave_quit ();
224 
225  for (octave_idx_type i = 0; i < npts; i++)
226  tmp[i] = elem ((i + k*npts)*stride + j*dist);
227 
228  F77_FUNC (zfftf, ZFFTF) (npts, F77_DBLE_CMPLX_ARG (tmp),
229  F77_DBLE_CMPLX_ARG (pwsave));
230 
231  for (octave_idx_type i = 0; i < npts; i++)
232  retval((i + k*npts)*stride + j*dist) = tmp[i];
233  }
234  }
235 
236  return retval;
237 }
238 
240 ComplexNDArray::ifourier (int dim) const
241 {
242  dim_vector dv = dims ();
243 
244  if (dim > dv.ndims () || dim < 0)
245  return ComplexNDArray ();
246 
248  octave_idx_type npts = dv(dim);
249  octave_idx_type nn = 4*npts+15;
250  Array<Complex> wsave (dim_vector (nn, 1));
251  Complex *pwsave = wsave.fortran_vec ();
252 
254 
255  octave_idx_type stride = 1;
256 
257  for (int i = 0; i < dim; i++)
258  stride *= dv(i);
259 
260  octave_idx_type howmany = numel () / npts;
261  howmany = (stride == 1 ? howmany : (howmany > stride ? stride : howmany));
262  octave_idx_type nloop = (stride == 1 ? 1 : numel () / npts / stride);
263  octave_idx_type dist = (stride == 1 ? npts : 1);
264 
265  F77_FUNC (zffti, ZFFTI) (npts, F77_DBLE_CMPLX_ARG (pwsave));
266 
267  for (octave_idx_type k = 0; k < nloop; k++)
268  {
269  for (octave_idx_type j = 0; j < howmany; j++)
270  {
271  octave_quit ();
272 
273  for (octave_idx_type i = 0; i < npts; i++)
274  tmp[i] = elem ((i + k*npts)*stride + j*dist);
275 
276  F77_FUNC (zfftb, ZFFTB) (npts, F77_DBLE_CMPLX_ARG (tmp),
277  F77_DBLE_CMPLX_ARG (pwsave));
278 
279  for (octave_idx_type i = 0; i < npts; i++)
280  retval((i + k*npts)*stride + j*dist) = tmp[i] /
281  static_cast<double> (npts);
282  }
283  }
284 
285  return retval;
286 }
287 
289 ComplexNDArray::fourier2d (void) const
290 {
291  dim_vector dv = dims ();
292  dim_vector dv2 (dv(0), dv(1));
293  int rank = 2;
294  ComplexNDArray retval (*this);
295  octave_idx_type stride = 1;
296 
297  for (int i = 0; i < rank; i++)
298  {
299  octave_idx_type npts = dv2(i);
300  octave_idx_type nn = 4*npts+15;
301  Array<Complex> wsave (dim_vector (nn, 1));
302  Complex *pwsave = wsave.fortran_vec ();
303  Array<Complex> row (dim_vector (npts, 1));
304  Complex *prow = row.fortran_vec ();
305 
306  octave_idx_type howmany = numel () / npts;
307  howmany = (stride == 1 ? howmany
308  : (howmany > stride ? stride : howmany));
309  octave_idx_type nloop = (stride == 1 ? 1 : numel () / npts / stride);
310  octave_idx_type dist = (stride == 1 ? npts : 1);
311 
312  F77_FUNC (zffti, ZFFTI) (npts, F77_DBLE_CMPLX_ARG (pwsave));
313 
314  for (octave_idx_type k = 0; k < nloop; k++)
315  {
316  for (octave_idx_type j = 0; j < howmany; j++)
317  {
318  octave_quit ();
319 
320  for (octave_idx_type l = 0; l < npts; l++)
321  prow[l] = retval((l + k*npts)*stride + j*dist);
322 
323  F77_FUNC (zfftf, ZFFTF) (npts, F77_DBLE_CMPLX_ARG (prow),
324  F77_DBLE_CMPLX_ARG (pwsave));
325 
326  for (octave_idx_type l = 0; l < npts; l++)
327  retval((l + k*npts)*stride + j*dist) = prow[l];
328  }
329  }
330 
331  stride *= dv2(i);
332  }
333 
334  return retval;
335 }
336 
338 ComplexNDArray::ifourier2d (void) const
339 {
340  dim_vector dv = dims ();
341  dim_vector dv2 (dv(0), dv(1));
342  int rank = 2;
343  ComplexNDArray retval (*this);
344  octave_idx_type stride = 1;
345 
346  for (int i = 0; i < rank; i++)
347  {
348  octave_idx_type npts = dv2(i);
349  octave_idx_type nn = 4*npts+15;
350  Array<Complex> wsave (dim_vector (nn, 1));
351  Complex *pwsave = wsave.fortran_vec ();
352  Array<Complex> row (dim_vector (npts, 1));
353  Complex *prow = row.fortran_vec ();
354 
355  octave_idx_type howmany = numel () / npts;
356  howmany = (stride == 1 ? howmany
357  : (howmany > stride ? stride : howmany));
358  octave_idx_type nloop = (stride == 1 ? 1 : numel () / npts / stride);
359  octave_idx_type dist = (stride == 1 ? npts : 1);
360 
361  F77_FUNC (zffti, ZFFTI) (npts, F77_DBLE_CMPLX_ARG (pwsave));
362 
363  for (octave_idx_type k = 0; k < nloop; k++)
364  {
365  for (octave_idx_type j = 0; j < howmany; j++)
366  {
367  octave_quit ();
368 
369  for (octave_idx_type l = 0; l < npts; l++)
370  prow[l] = retval((l + k*npts)*stride + j*dist);
371 
372  F77_FUNC (zfftb, ZFFTB) (npts, F77_DBLE_CMPLX_ARG (prow),
373  F77_DBLE_CMPLX_ARG (pwsave));
374 
375  for (octave_idx_type l = 0; l < npts; l++)
376  retval((l + k*npts)*stride + j*dist) =
377  prow[l] / static_cast<double> (npts);
378  }
379  }
380 
381  stride *= dv2(i);
382  }
383 
384  return retval;
385 }
386 
388 ComplexNDArray::fourierNd (void) const
389 {
390  dim_vector dv = dims ();
391  int rank = dv.ndims ();
392  ComplexNDArray retval (*this);
393  octave_idx_type stride = 1;
394 
395  for (int i = 0; i < rank; i++)
396  {
397  octave_idx_type npts = dv(i);
398  octave_idx_type nn = 4*npts+15;
399  Array<Complex> wsave (dim_vector (nn, 1));
400  Complex *pwsave = wsave.fortran_vec ();
401  Array<Complex> row (dim_vector (npts, 1));
402  Complex *prow = row.fortran_vec ();
403 
404  octave_idx_type howmany = numel () / npts;
405  howmany = (stride == 1 ? howmany
406  : (howmany > stride ? stride : howmany));
407  octave_idx_type nloop = (stride == 1 ? 1 : numel () / npts / stride);
408  octave_idx_type dist = (stride == 1 ? npts : 1);
409 
410  F77_FUNC (zffti, ZFFTI) (npts, F77_DBLE_CMPLX_ARG (pwsave));
411 
412  for (octave_idx_type k = 0; k < nloop; k++)
413  {
414  for (octave_idx_type j = 0; j < howmany; j++)
415  {
416  octave_quit ();
417 
418  for (octave_idx_type l = 0; l < npts; l++)
419  prow[l] = retval((l + k*npts)*stride + j*dist);
420 
421  F77_FUNC (zfftf, ZFFTF) (npts, F77_DBLE_CMPLX_ARG (prow),
422  F77_DBLE_CMPLX_ARG (pwsave));
423 
424  for (octave_idx_type l = 0; l < npts; l++)
425  retval((l + k*npts)*stride + j*dist) = prow[l];
426  }
427  }
428 
429  stride *= dv(i);
430  }
431 
432  return retval;
433 }
434 
436 ComplexNDArray::ifourierNd (void) const
437 {
438  dim_vector dv = dims ();
439  int rank = dv.ndims ();
440  ComplexNDArray retval (*this);
441  octave_idx_type stride = 1;
442 
443  for (int i = 0; i < rank; i++)
444  {
445  octave_idx_type npts = dv(i);
446  octave_idx_type nn = 4*npts+15;
447  Array<Complex> wsave (dim_vector (nn, 1));
448  Complex *pwsave = wsave.fortran_vec ();
449  Array<Complex> row (dim_vector (npts, 1));
450  Complex *prow = row.fortran_vec ();
451 
452  octave_idx_type howmany = numel () / npts;
453  howmany = (stride == 1 ? howmany
454  : (howmany > stride ? stride : howmany));
455  octave_idx_type nloop = (stride == 1 ? 1 : numel () / npts / stride);
456  octave_idx_type dist = (stride == 1 ? npts : 1);
457 
458  F77_FUNC (zffti, ZFFTI) (npts, F77_DBLE_CMPLX_ARG (pwsave));
459 
460  for (octave_idx_type k = 0; k < nloop; k++)
461  {
462  for (octave_idx_type j = 0; j < howmany; j++)
463  {
464  octave_quit ();
465 
466  for (octave_idx_type l = 0; l < npts; l++)
467  prow[l] = retval((l + k*npts)*stride + j*dist);
468 
469  F77_FUNC (zfftb, ZFFTB) (npts, F77_DBLE_CMPLX_ARG (prow),
470  F77_DBLE_CMPLX_ARG (pwsave));
471 
472  for (octave_idx_type l = 0; l < npts; l++)
473  retval((l + k*npts)*stride + j*dist) =
474  prow[l] / static_cast<double> (npts);
475  }
476  }
477 
478  stride *= dv(i);
479  }
480 
481  return retval;
482 }
483 
484 #endif
485 
486 // unary operations
487 
490 {
491  if (any_element_is_nan ())
493 
494  return do_mx_unary_op<bool, Complex> (*this, mx_inline_not);
495 }
496 
497 // FIXME: this is not quite the right thing.
498 
499 bool
501 {
502  return do_mx_check<Complex> (*this, mx_inline_any_nan);
503 }
504 
505 bool
507 {
508  return ! do_mx_check<Complex> (*this, mx_inline_all_finite);
509 }
510 
511 // Return true if no elements have imaginary components.
512 
513 bool
515 {
516  return do_mx_check<Complex> (*this, mx_inline_all_real);
517 }
518 
519 // Return nonzero if any element of CM has a non-integer real or
520 // imaginary part. Also extract the largest and smallest (real or
521 // imaginary) values and return them in MAX_VAL and MIN_VAL.
522 
523 bool
524 ComplexNDArray::all_integers (double& max_val, double& min_val) const
525 {
526  octave_idx_type nel = numel ();
527 
528  if (nel > 0)
529  {
530  Complex val = elem (0);
531 
532  double r_val = val.real ();
533  double i_val = val.imag ();
534 
535  max_val = r_val;
536  min_val = r_val;
537 
538  if (i_val > max_val)
539  max_val = i_val;
540 
541  if (i_val < max_val)
542  min_val = i_val;
543  }
544  else
545  return false;
546 
547  for (octave_idx_type i = 0; i < nel; i++)
548  {
549  Complex val = elem (i);
550 
551  double r_val = val.real ();
552  double i_val = val.imag ();
553 
554  if (r_val > max_val)
555  max_val = r_val;
556 
557  if (i_val > max_val)
558  max_val = i_val;
559 
560  if (r_val < min_val)
561  min_val = r_val;
562 
563  if (i_val < min_val)
564  min_val = i_val;
565 
566  if (octave::math::x_nint (r_val) != r_val
567  || octave::math::x_nint (i_val) != i_val)
568  return false;
569  }
570 
571  return true;
572 }
573 
574 bool
576 {
578 }
579 
581 ComplexNDArray::all (int dim) const
582 {
583  return do_mx_red_op<bool, Complex> (*this, dim, mx_inline_all);
584 }
585 
587 ComplexNDArray::any (int dim) const
588 {
589  return do_mx_red_op<bool, Complex> (*this, dim, mx_inline_any);
590 }
591 
593 ComplexNDArray::cumprod (int dim) const
594 {
595  return do_mx_cum_op<Complex, Complex> (*this, dim, mx_inline_cumprod);
596 }
597 
599 ComplexNDArray::cumsum (int dim) const
600 {
601  return do_mx_cum_op<Complex, Complex> (*this, dim, mx_inline_cumsum);
602 }
603 
605 ComplexNDArray::prod (int dim) const
606 {
607  return do_mx_red_op<Complex, Complex> (*this, dim, mx_inline_prod);
608 }
609 
611 ComplexNDArray::sum (int dim) const
612 {
613  return do_mx_red_op<Complex, Complex> (*this, dim, mx_inline_sum);
614 }
615 
617 ComplexNDArray::xsum (int dim) const
618 {
619  return do_mx_red_op<Complex, Complex> (*this, dim, mx_inline_xsum);
620 }
621 
623 ComplexNDArray::sumsq (int dim) const
624 {
625  return do_mx_red_op<double, Complex> (*this, dim, mx_inline_sumsq);
626 }
627 
629 ComplexNDArray::diff (octave_idx_type order, int dim) const
630 {
631  return do_mx_diff_op<Complex> (*this, dim, order, mx_inline_diff);
632 }
633 
637 {
638  if (rb.numel () > 0)
639  insert (rb, ra_idx);
640  return *this;
641 }
642 
645 {
646  ComplexNDArray tmp (rb);
647  if (rb.numel () > 0)
648  insert (tmp, ra_idx);
649  return *this;
650 }
651 
654 {
655  ComplexNDArray retval (ra);
656  if (rb.numel () > 0)
657  retval.insert (rb, ra_idx);
658  return retval;
659 }
660 
663 
665 ComplexNDArray::max (int dim) const
666 {
667  return do_mx_minmax_op<Complex> (*this, dim, mx_inline_max);
668 }
669 
672 {
673  return do_mx_minmax_op<Complex> (*this, idx_arg, dim, mx_inline_max);
674 }
675 
677 ComplexNDArray::min (int dim) const
678 {
679  return do_mx_minmax_op<Complex> (*this, dim, mx_inline_min);
680 }
681 
684 {
685  return do_mx_minmax_op<Complex> (*this, idx_arg, dim, mx_inline_min);
686 }
687 
689 ComplexNDArray::cummax (int dim) const
690 {
691  return do_mx_cumminmax_op<Complex> (*this, dim, mx_inline_cummax);
692 }
693 
696 {
697  return do_mx_cumminmax_op<Complex> (*this, idx_arg, dim, mx_inline_cummax);
698 }
699 
701 ComplexNDArray::cummin (int dim) const
702 {
703  return do_mx_cumminmax_op<Complex> (*this, dim, mx_inline_cummin);
704 }
705 
708 {
709  return do_mx_cumminmax_op<Complex> (*this, idx_arg, dim, mx_inline_cummin);
710 }
711 
712 NDArray
714 {
715  return do_mx_unary_map<double, Complex, std::abs> (*this);
716 }
717 
720 {
721  return do_mx_unary_map<bool, Complex, octave::math::isnan> (*this);
722 }
723 
726 {
727  return do_mx_unary_map<bool, Complex, octave::math::isinf> (*this);
728 }
729 
732 {
733  return do_mx_unary_map<bool, Complex, octave::math::isfinite> (*this);
734 }
735 
738 {
739  return do_mx_unary_map<Complex, Complex, std::conj<double>> (a);
740 }
741 
744 {
745  dim_vector a_dv = a.dims ();
746 
747  int n = a_dv.ndims ();
748 
749  if (n != dimensions.ndims ())
751  ("Array<T>::insert: invalid indexing operation");
752 
753  Array<octave_idx_type> a_ra_idx (dim_vector (a_dv.ndims (), 1), 0);
754 
755  a_ra_idx.elem (0) = r;
756  a_ra_idx.elem (1) = c;
757 
758  for (int i = 0; i < n; i++)
759  {
760  if (a_ra_idx(i) < 0 || (a_ra_idx(i) + a_dv(i)) > dimensions(i))
761  (*current_liboctave_error_handler)
762  ("Array<T>::insert: range error for insert");
763  }
764 
765  a_ra_idx.elem (0) = 0;
766  a_ra_idx.elem (1) = 0;
767 
768  octave_idx_type n_elt = a.numel ();
769 
770  // IS make_unique () NECESSARY HERE?
771 
772  for (octave_idx_type i = 0; i < n_elt; i++)
773  {
774  Array<octave_idx_type> ra_idx = a_ra_idx;
775 
776  ra_idx.elem (0) = a_ra_idx(0) + r;
777  ra_idx.elem (1) = a_ra_idx(1) + c;
778 
779  elem (ra_idx) = a.elem (a_ra_idx);
780 
781  increment_index (a_ra_idx, a_dv);
782  }
783 
784  return *this;
785 }
786 
790 {
791  Array<Complex>::insert (a, r, c);
792  return *this;
793 }
794 
798 {
800  return *this;
801 }
802 
803 void
805  const dim_vector& dimensions,
806  int start_dimension)
807 {
808  ::increment_index (ra_idx, dimensions, start_dimension);
809 }
810 
813  const dim_vector& dimensions)
814 {
816 }
817 
820 {
821  return MArray<Complex>::diag (k);
822 }
823 
826 {
827  return MArray<Complex>::diag (m, n);
828 }
829 
830 // This contains no information on the array structure !!!
831 std::ostream&
832 operator << (std::ostream& os, const ComplexNDArray& a)
833 {
834  octave_idx_type nel = a.numel ();
835 
836  for (octave_idx_type i = 0; i < nel; i++)
837  {
838  os << ' ';
839  octave_write_complex (os, a.elem (i));
840  os << "\n";
841  }
842  return os;
843 }
844 
845 std::istream&
846 operator >> (std::istream& is, ComplexNDArray& a)
847 {
848  octave_idx_type nel = a.numel ();
849 
850  if (nel > 0)
851  {
852  Complex tmp;
853  for (octave_idx_type i = 0; i < nel; i++)
854  {
855  tmp = octave_read_value<Complex> (is);
856  if (is)
857  a.elem (i) = tmp;
858  else
859  return is;
860  }
861  }
862 
863  return is;
864 }
865 
867 
870 
873 
876 
877 ComplexNDArray& operator *= (ComplexNDArray& a, double s)
878 {
879  if (a.is_shared ())
880  a = a * s;
881  else
882  do_ms_inplace_op<Complex, double> (a, s, mx_inline_mul2);
883  return a;
884 }
885 
887 {
888  if (a.is_shared ())
889  return a = a / s;
890  else
891  do_ms_inplace_op<Complex, double> (a, s, mx_inline_div2);
892  return a;
893 }
894 
897 
ComplexNDArray cumprod(int dim=-1) const
Definition: CNDArray.cc:593
dim_vector dimensions
Definition: Array.h:216
T mx_inline_xsum(const T *v, octave_idx_type n)
Definition: mx-inlines.cc:1688
octave_idx_type compute_index(octave_idx_type n, const dim_vector &dims)
Definition: Array-util.cc:175
void mx_inline_mul2(size_t n, R *r, const X *x)
Definition: mx-inlines.cc:127
ComplexNDArray fourierNd(void) const
Definition: CNDArray.cc:158
ComplexNDArray concat(const ComplexNDArray &rb, const Array< octave_idx_type > &ra_idx)
Definition: CNDArray.cc:635
std::istream & operator>>(std::istream &is, ComplexNDArray &a)
Definition: CNDArray.cc:846
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 ifourierNd(void) const
Definition: CNDArray.cc:173
Template for N-dimensional array classes with like-type math operators.
Definition: MArray.h:32
ComplexNDArray conj(const ComplexNDArray &a)
Definition: CNDArray.cc:737
boolNDArray operator!(void) const
Definition: CNDArray.cc:489
void mx_inline_cummax(const T *v, T *r, octave_idx_type n)
Definition: mx-inlines.cc:1184
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:219
ComplexNDArray xsum(int dim=-1) const
Definition: CNDArray.cc:617
subroutine zffti(n, wsave)
Definition: zffti.f:2
identity matrix If supplied two scalar respectively For allows like xample val
Definition: data.cc:4986
OCTAVE_NORETURN liboctave_error_handler current_liboctave_error_handler
Definition: lo-error.c:38
#define F77_DBLE_CMPLX_ARG(x)
Definition: f77-fcn.h:315
ComplexNDArray sumsq(int dim=-1) const
Definition: CNDArray.cc:623
ComplexNDArray & operator/=(ComplexNDArray &a, double s)
Definition: CNDArray.cc:886
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 Complex * fortran_vec(void) const
Definition: Array.h:584
#define MINMAX_FCNS(T, S)
Definition: mx-op-defs.h:584
boolNDArray isfinite(void) const
Definition: CNDArray.cc:731
void octave_write_complex(std::ostream &os, const Complex &c)
Definition: lo-utils.cc:408
ComplexNDArray diag(octave_idx_type k=0) const
Definition: CNDArray.cc:819
ComplexNDArray concat(NDArray &ra, ComplexNDArray &rb, const Array< octave_idx_type > &ra_idx)
Definition: CNDArray.cc:653
static F77_INT nn
Definition: DASPK.cc:62
ComplexNDArray diff(octave_idx_type order=1, int dim=-1) const
Definition: CNDArray.cc:629
boolNDArray isnan(void) const
Definition: CNDArray.cc:719
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
ComplexNDArray sum(int dim=-1) const
Definition: CNDArray.cc:611
Complex & elem(octave_idx_type n)
Definition: Array.h:488
T mx_inline_sumsq(const T *v, octave_idx_type n)
Definition: mx-inlines.cc:753
ComplexNDArray cummin(int dim=-1) const
Definition: CNDArray.cc:701
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
s
Definition: file-io.cc:2729
void err_nan_to_logical_conversion(void)
bool too_large_for_float(void) const
Definition: CNDArray.cc:575
bool mx_inline_any(const T *v, octave_idx_type n)
Definition: mx-inlines.cc:753
ComplexNDArray prod(int dim=-1) const
Definition: CNDArray.cc:605
subroutine zfftb(n, c, wsave)
Definition: zfftb.f:2
static void increment_index(Array< octave_idx_type > &ra_idx, const dim_vector &dimensions, int start_dimension=0)
Definition: CNDArray.cc:804
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
ComplexNDArray fourier(int dim=1) const
Definition: CNDArray.cc:56
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
bool mx_inline_all_real(size_t n, const std::complex< T > *x)
Definition: mx-inlines.cc:308
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
ComplexNDArray cummax(int dim=-1) const
Definition: CNDArray.cc:689
#define NDND_CMP_OPS(ND1, ND2)
Definition: mx-op-defs.h:332
ComplexNDArray & insert(const NDArray &a, octave_idx_type r, octave_idx_type c)
Definition: CNDArray.cc:743
#define NDND_BOOL_OPS(ND1, ND2)
Definition: mx-op-defs.h:349
boolNDArray any(int dim=-1) const
Definition: CNDArray.cc:587
ComplexNDArray min(int dim=-1) const
Definition: CNDArray.cc:677
octave_int< T > pow(const octave_int< T > &a, const octave_int< T > &b)
double tmp
Definition: data.cc:6252
octave_value retval
Definition: data.cc:6246
#define SND_BOOL_OPS(S, ND)
Definition: mx-op-defs.h:302
ComplexNDArray ifourier2d(void) const
Definition: CNDArray.cc:138
bool any_element_is_inf_or_nan(void) const
Definition: CNDArray.cc:506
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
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
bool any_element_is_nan(void) const
Definition: CNDArray.cc:500
Complex & xelem(octave_idx_type n)
Definition: Array.h:458
T mx_inline_sum(const T *v, octave_idx_type n)
Definition: mx-inlines.cc:751
ComplexNDArray cumsum(int dim=-1) const
Definition: CNDArray.cc:599
bool all_integers(double &max_val, double &min_val) const
Definition: CNDArray.cc:524
void mx_inline_cumprod(const T *v, T *r, octave_idx_type n)
Definition: mx-inlines.cc:858
ComplexNDArray(void)
Definition: CNDArray.h:39
static octave_idx_type compute_index(Array< octave_idx_type > &ra_idx, const dim_vector &dimensions)
Definition: CNDArray.cc:812
boolNDArray isinf(void) const
Definition: CNDArray.cc:725
void mx_inline_cumsum(const T *v, T *r, octave_idx_type n)
Definition: mx-inlines.cc:857
std::ostream & operator<<(std::ostream &os, const ComplexNDArray &a)
Definition: CNDArray.cc:832
OCTAVE_EXPORT octave_value_list or N dimensional array whose elements are all equal to the IEEE symbol NaN(Not a Number). NaN is the result of operations which do not produce a well defined 0 result. Common operations which produce a NaN are arithmetic with infinity ex($\infty - \infty$)
Array< T > diag(octave_idx_type k=0) const
Get the kth super or subdiagonal.
Definition: Array.cc:2530
static int ifftNd(const Complex *, Complex *, const int, const dim_vector &)
Definition: oct-fftw.cc:967
ComplexNDArray max(int dim=-1) const
Definition: CNDArray.cc:665
#define OCTAVE_LOCAL_BUFFER(T, buf, size)
Definition: oct-locbuf.h:41
bool xtoo_large_for_float(double x)
Definition: lo-utils.cc:51
for i
Definition: data.cc:5264
bool all_elements_are_real(void) const
Definition: CNDArray.cc:514
static const Complex Complex_NaN_result(octave::numeric_limits< double >::NaN(), octave::numeric_limits< double >::NaN())
octave_idx_type ndims(void) const
Number of dimensions.
Definition: dim-vector.h:295
NDArray abs(void) const
Definition: CNDArray.cc:713
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_div2(size_t n, R *r, const X *x)
Definition: mx-inlines.cc:128
void mx_inline_not(size_t n, bool *r, const X *x)
Definition: mx-inlines.cc:180
ComplexNDArray ifourier(int dim=1) const
Definition: CNDArray.cc:87
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
boolNDArray all(int dim=-1) const
Definition: CNDArray.cc:581
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:752
dim_vector dv
Definition: sub2ind.cc:263
octave::stream os
Definition: file-io.cc:627
T x_nint(T x)
Definition: lo-mappers.h:284
ComplexNDArray fourier2d(void) const
Definition: CNDArray.cc:118
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
void mx_inline_min(const T *v, T *r, octave_idx_type n)
Definition: mx-inlines.cc:961