casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MArrayMath.h
Go to the documentation of this file.
1 //# MArrayMath.h: Mathematical operations on MArray objects
2 //# Copyright (C) 2012
3 //# Associated Universities, Inc. Washington DC, USA.
4 //#
5 //# This library is free software; you can redistribute it and/or modify it
6 //# under the terms of the GNU Library General Public License as published by
7 //# the Free Software Foundation; either version 2 of the License, or (at your
8 //# option) any later version.
9 //#
10 //# This library is distributed in the hope that it will be useful, but WITHOUT
11 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13 //# License for more details.
14 //#
15 //# You should have received a copy of the GNU Library General Public License
16 //# along with this library; if not, write to the Free Software Foundation,
17 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
18 //#
19 //# Correspondence concerning AIPS++ should be addressed as follows:
20 //# Internet email: aips2-request@nrao.edu.
21 //# Postal address: AIPS++ Project Office
22 //# National Radio Astronomy Observatory
23 //# 520 Edgemont Road
24 //# Charlottesville, VA 22903-2475 USA
25 //#
26 //# $Id: MArrayMath.h 21262 2012-09-07 12:38:36Z gervandiepen $
27 
28 #ifndef CASA_MARRAYMATH_H
29 #define CASA_MARRAYMATH_H
30 
31 //# Includes
32 #include <casacore/casa/aips.h>
37 
38 namespace casacore {
39 
40  // <summary>
41  // Mathematical operations for MArray objects.
42  // </summary>
43  //
44  // <reviewed reviewer="UNKNOWN" date="" tests="tMArrayMath">
45  //
46  // <prerequisite>
47  // <li> <linkto class=MArray>MArray</linkto>
48  // </prerequisite>
49  //
50  // <synopsis>
51  // These functions perform element by element mathematical operations on
52  // optionally masked arrays and/or scalars.
53  // If two arrays are used, the arrays must conform, except for allEQ which
54  // returns False if the arrays do not conform.
55  //
56  // The functions in this file can be divided in 3 groups:
57  // <ul>
58  // <li> Full array operations like ==, near, etc.
59  // They are defined for array-array and array-scalar operations. Arrays
60  // shapes have to be conformant. They operate on all elements
61  // (also the masked ones). The result is an MArray with the same
62  // shape as the input array(s). It will have a mask if one of the
63  // operands has a mask. If both operands have a mask, the resulting
64  // mask is the OR of both masks.
65  // <li> Full reduction functions like ntrue, all, allEQ, etc.
66  // They operate on the unmasked elements only. If there are no unmasked
67  // elements, the results is 0 or True.
68  // <li> Reduction functions working on unmasked elements in parts of the
69  // input array. The result is an MArray that has a mask if the input
70  // array has a mask. An output element is masked off if its input
71  // part has no unmasked elements.
72  // The functors defined at the beginning of this file are used to
73  // operate on each part.
74  // There are 3 flavours:
75  // <ul>
76  // <li> partialXXX reduces one or more axes. E.g. one can count the
77  // number of True elements for particular array axes.
78  // The result is an array with a lower dimensionality.
79  // They can be seen as a special versions of the boxedXXX functions.
80  // <li> slidingXXX operates in a sliding window over the array. So the
81  // result is an array with the same shape as the input, although
82  // the output array is smaller if the edge is not filled.
83  // <li> boxedXXX divides the input array in boxes with the given size
84  // and operates on each box. The result is an array with the same
85  // dimensionality, but with a smaller size.
86  // If the box size does not fit integrally, the edge box is smaller.
87  // </ul>
88  // </ul>
89  // </synopsis>
90  //
91  // <group name="MArray mathematical operations">
92 
93  // Define functors to perform a reduction function on an MArray object.
94  // <group>
95  template<typename T> class MSumFunc : public MArrayFunctorBase<T> {
96  public:
97  virtual ~MSumFunc() {}
98  T operator() (const MArray<T>& arr) const { return sum(arr); }
99  };
100  template<typename T> class MSumSqrFunc : public MArrayFunctorBase<T> {
101  public:
102  virtual ~MSumSqrFunc() {}
103  T operator() (const MArray<T>& arr) const { return sumsqr(arr); }
104  };
105  template<typename T> class MProductFunc : public MArrayFunctorBase<T> {
106  public:
107  virtual ~MProductFunc() {}
108  T operator() (const MArray<T>& arr) const { return product(arr); }
109  };
110  template<typename T> class MMinFunc : public MArrayFunctorBase<T> {
111  public:
112  virtual ~MMinFunc() {}
113  T operator() (const MArray<T>& arr) const { return min(arr); }
114  };
115  template<typename T> class MMaxFunc : public MArrayFunctorBase<T> {
116  public:
117  virtual ~MMaxFunc() {}
118  T operator() (const MArray<T>& arr) const { return max(arr); }
119  };
120  template<typename T> class MMeanFunc : public MArrayFunctorBase<T> {
121  public:
122  virtual ~MMeanFunc() {}
123  T operator() (const MArray<T>& arr) const { return mean(arr); }
124  };
125  template<typename T> class MVarianceFunc : public MArrayFunctorBase<T> {
126  public:
127  explicit MVarianceFunc(uInt ddof=0)
128  : itsDdof(ddof) {}
129  virtual ~MVarianceFunc() {}
130  T operator() (const MArray<T>& arr) const { return variance(arr, itsDdof); }
131  private:
133  };
134  template<typename T> class MStddevFunc : public MArrayFunctorBase<T> {
135  public:
136  explicit MStddevFunc(uInt ddof=0)
137  : itsDdof(ddof) {}
139  T operator() (const MArray<T>& arr) const { return stddev(arr, itsDdof); }
140  private:
142  };
143  template<typename T> class MAvdevFunc : public MArrayFunctorBase<T> {
144  public:
145  virtual ~MAvdevFunc() {}
146  T operator() (const MArray<T>& arr) const { return avdev(arr); }
147  };
148  template<typename T> class MRmsFunc : public MArrayFunctorBase<T> {
149  public:
150  virtual ~MRmsFunc() {}
151  T operator() (const MArray<T>& arr) const { return rms(arr); }
152  };
153  template<typename T> class MMedianFunc : public MArrayFunctorBase<T> {
154  public:
155  explicit MMedianFunc (Bool sorted=False, Bool takeEvenMean=True,
156  Bool inPlace = False)
157  : itsSorted(sorted), itsTakeEvenMean(takeEvenMean), itsInPlace(inPlace) {}
158  virtual ~MMedianFunc() {}
159  T operator() (const MArray<T>& arr) const
160  { return median(arr, itsSorted, itsTakeEvenMean, itsInPlace); }
161  private:
165  };
166  template<typename T> class MFractileFunc : public MArrayFunctorBase<T> {
167  public:
168  explicit MFractileFunc (Float fraction,
169  Bool sorted = False, Bool inPlace = False)
170  : itsFraction(fraction), itsSorted(sorted), itsInPlace(inPlace) {}
171  virtual ~MFractileFunc() {}
172  T operator() (const MArray<T>& arr) const
173  { return fractile(arr, itsFraction, itsSorted, itsInPlace); }
174  private:
175  float itsFraction;
178  };
179 
180 
181  // Do partial reduction of an MArray object. I.e., perform the operation
182  // on a subset of the array axes (the collapse axes).
183  template<typename T>
185  const IPosition& collapseAxes,
186  const MArrayFunctorBase<T>& funcObj)
187  {
188  MArray<T> res;
189  partialArrayMath (res, a, collapseAxes, funcObj);
190  return res;
191  }
192  template<typename T, typename RES>
194  const MArray<T>& a,
195  const IPosition& collapseAxes,
196  const MArrayFunctorBase<T,RES>& funcObj)
197  {
199  // This can also be done as boxedArrayMath with a removeDegenerate thereafter.
200  //
201  // It should be possible to parallelize this loop.
202  // Determine nr of iteration steps and iterate over that as an int.
203  // Do not use Array slicing, because that is not thread-safe.
204  // Instead create ArraySTLIterator directly from Array and blc,trc,
205  // so funcObj should accept iterators instead of Array.
206  // However, ArraySTLIterator needs the sliced array, not original.
207  // Maybe keep ref of itsSteps in iterator instead of array.
208  // Hmm, tricky for median and fractile.
209  // Better to make Array copy ctor thread-safe (thus use boost shared_ptr).
210  ReadOnlyArrayIterator<T> aiter(a.array(), collapseAxes);
211  ReadOnlyArrayIterator<Bool> miter(a.mask(), collapseAxes);
212  IPosition shape(a.array().shape().removeAxes (collapseAxes));
213  /*
214  Int64 nr = 1;
215  for (uInt i=0; i<collapseAxes.size(); ++i) {
216  nr *= a.array().shape()[collapseAxes[i]];
217  }
219  for (Int64 i=0; i<nr; ++i) {
220  IPosition pos = findPos(i);
221  IPosition endPos = pos + cursorShape - 1;
222  *data[pos] = funcObj(MArray<T>(a.array()(pos,endPos), a.mask()(pos,endpos)));
223  }
224  */
226  res.resize (shape, False);
227  Array<Bool> resMask(shape);
228  RES* data = res.array().data();
229  Bool* mask = resMask.data();
230  while (!aiter.pastEnd()) {
231  if (allTrue(miter.array())) {
232  *mask++ = True;
233  *data++ = RES();
234  } else {
235  *mask++ = False;
236  *data++ = funcObj(MArray<T> (aiter.array(), miter.array()));
237  }
238  aiter.next();
239  miter.next();
240  }
241  res.setMask (resMask);
242  }
243  // </group>
244 
245 
246  template<typename T>
248  const IPosition& boxShape,
249  const MArrayFunctorBase<T>& funcObj)
250  {
251  MArray<T> res;
252  boxedArrayMath (res, a, boxShape, funcObj);
253  return res;
254  }
255  template<typename T, typename RES>
257  const MArray<T>& array,
258  const IPosition& boxShape,
259  const MArrayFunctorBase<T,RES>& funcObj)
260  {
261  AlwaysAssert (array.hasMask(), AipsError);
262  const IPosition& shape = array.shape();
263  uInt ndim = shape.size();
264  IPosition fullBoxShape, resShape;
265  fillBoxedShape (shape, boxShape, fullBoxShape, resShape);
266  res.resize (resShape, False);
267  Array<Bool> resMask(resShape);
268  RES* data = res.array().data();
269  Bool* mask = resMask.data();
270  // Loop through all data and assemble as needed.
271  IPosition blc(ndim, 0);
272  IPosition trc(fullBoxShape-1);
273  while (True) {
274  Array<Bool> subMask (array.mask()(blc,trc));
275  if (allTrue(subMask)) {
276  *data++ = RES();
277  *mask++ = True;
278  } else {
279  *data++ = funcObj (MArray<T>(array.array()(blc,trc), subMask));
280  *mask++ = False;
281  }
282  uInt ax;
283  for (ax=0; ax<ndim; ++ax) {
284  blc[ax] += fullBoxShape[ax];
285  if (blc[ax] < shape[ax]) {
286  trc[ax] += fullBoxShape[ax];
287  if (trc[ax] >= shape[ax]) {
288  trc[ax] = shape[ax]-1;
289  }
290  break;
291  }
292  blc[ax] = 0;
293  trc[ax] = fullBoxShape[ax]-1;
294  }
295  if (ax == ndim) {
296  break;
297  }
298  }
299  res.setMask (resMask);
300  }
301 
302  template <typename T>
304  const IPosition& halfBoxShape,
305  const MArrayFunctorBase<T>& funcObj,
306  Bool fillEdge=True)
307  {
308  MArray<T> res;
309  slidingArrayMath (res, array, halfBoxShape, funcObj, fillEdge);
310  return res;
311  }
312  template <typename T, typename RES>
314  const MArray<T>& array,
315  const IPosition& halfBoxShape,
316  const MArrayFunctorBase<T,RES>& funcObj,
317  Bool fillEdge=True)
318  {
319  AlwaysAssert (array.hasMask(), AipsError);
320  const IPosition& shape = array.shape();
321  uInt ndim = shape.size();
322  IPosition boxEnd, resShape;
323  Bool empty = fillSlidingShape (shape, halfBoxShape, boxEnd, resShape);
324  if (fillEdge) {
325  res.resize (shape, False);
326  res.array() = RES();
327  Array<Bool> mask(shape, True);
328  res.setMask (mask);
329  } else {
330  res.resize (resShape, True);
331  }
332  if (!empty) {
333  Array<RES> resa (res.array());
334  Array<Bool> resm (res.mask());
335  if (fillEdge) {
336  IPosition boxEnd2 (boxEnd/2);
337  resa.reference (resa(boxEnd2, resShape+boxEnd2-1));
338  resm.reference (resm(boxEnd2, resShape+boxEnd2-1));
339  }
340  typename Array<RES>::iterator iterarr(resa.begin());
341  typename Array<Bool>::iterator itermask(resm.begin());
342  // Loop through all data and assemble as needed.
343  IPosition blc(ndim, 0);
344  IPosition trc(boxEnd);
345  IPosition pos(ndim, 0);
346  while (True) {
347  Array<Bool> subMask (array.mask()(blc,trc));
348  if (allTrue(subMask)) {
349  *iterarr = RES();
350  *itermask = True;
351  } else {
352  *iterarr = funcObj (MArray<T>(array.array()(blc,trc), subMask));
353  *itermask = False;
354  }
355  ++iterarr;
356  ++itermask;
357  uInt ax;
358  for (ax=0; ax<ndim; ++ax) {
359  if (++pos[ax] < resShape[ax]) {
360  blc[ax]++;
361  trc[ax]++;
362  break;
363  }
364  pos(ax) = 0;
365  blc[ax] = 0;
366  trc[ax] = boxEnd[ax];
367  }
368  if (ax == ndim) {
369  break;
370  }
371  }
372  }
373  }
374 
375 
376  // Add, subtract, etc. 2 arrays or array and scalar.
377  // <group>
378  template<typename T>
379  MArray<T> operator+ (const MArray<T>& left, const MArray<T>& right)
380  { return (left.isNull() || right.isNull() ? MArray<T>() :
381  MArray<T> (left.array() + right.array(),
382  left.combineMask(right))); }
383 
384  template<typename T>
385  MArray<T> operator- (const MArray<T>& left, const MArray<T>& right)
386  { return (left.isNull() || right.isNull() ? MArray<T>() :
387  MArray<T> (left.array() - right.array(),
388  left.combineMask(right))); }
389 
390  template<typename T>
391  MArray<T> operator* (const MArray<T>& left, const MArray<T>& right)
392  { return (left.isNull() || right.isNull() ? MArray<T>() :
393  MArray<T> (left.array() * right.array(),
394  left.combineMask(right))); }
395 
396  template<typename T>
397  MArray<T> operator/ (const MArray<T>& left, const MArray<T>& right)
398  { return (left.isNull() || right.isNull() ? MArray<T>() :
399  MArray<T> (left.array() / right.array(),
400  left.combineMask(right))); }
401 
402  template<typename T>
403  MArray<T> operator% (const MArray<T>& left, const MArray<T>& right)
404  { return (left.isNull() || right.isNull() ? MArray<T>() :
405  MArray<T> (left.array() % right.array(),
406  left.combineMask(right))); }
407 
408  template<typename T>
409  MArray<T> operator& (const MArray<T>& left, const MArray<T>& right)
410  { return (left.isNull() || right.isNull() ? MArray<T>() :
411  MArray<T> (left.array() & right.array(),
412  left.combineMask(right))); }
413 
414  template<typename T>
415  MArray<T> operator| (const MArray<T>& left, const MArray<T>& right)
416  { return (left.isNull() || right.isNull() ? MArray<T>() :
417  MArray<T> (left.array() | right.array(),
418  left.combineMask(right))); }
419 
420  template<typename T>
421  MArray<T> operator^ (const MArray<T>& left, const MArray<T>& right)
422  { return (left.isNull() || right.isNull() ? MArray<T>() :
423  MArray<T> (left.array() ^ right.array(),
424  left.combineMask(right))); }
425 
426  template<typename T>
427  MArray<T> operator+ (const MArray<T>& left, const T& right)
428  { return MArray<T> (left.array() + right, left); }
429 
430  template<typename T>
431  MArray<T> operator- (const MArray<T>& left, const T& right)
432  { return MArray<T> (left.array() - right, left); }
433 
434  template<typename T>
435  MArray<T> operator* (const MArray<T>& left, const T& right)
436  { return MArray<T> (left.array() * right, left); }
437 
438  template<typename T>
439  MArray<T> operator/ (const MArray<T>& left, const T& right)
440  { return MArray<T> (left.array() / right, left); }
441 
442  template<typename T>
443  MArray<T> operator% (const MArray<T>& left, const T& right)
444  { return MArray<T> (left.array() % right, left); }
445 
446  template<typename T>
447  MArray<T> operator& (const MArray<T>& left, const T& right)
448  { return MArray<T> (left.array() & right, left); }
449 
450  template<typename T>
451  MArray<T> operator| (const MArray<T>& left, const T& right)
452  { return MArray<T> (left.array() | right, left); }
453 
454  template<typename T>
455  MArray<T> operator^ (const MArray<T>& left, const T& right)
456  { return MArray<T> (left.array() ^ right, left); }
457 
458  template<typename T>
459  MArray<T> operator+ (const T& left, const MArray<T>& right)
460  { return MArray<T> (left + right.array(), right); }
461 
462  template<typename T>
463  MArray<T> operator- (const T& left, const MArray<T>& right)
464  { return MArray<T> (left - right.array(), right); }
465 
466  template<typename T>
467  MArray<T> operator* (const T& left, const MArray<T>& right)
468  { return MArray<T> (left * right.array(), right); }
469 
470  template<typename T>
471  MArray<T> operator/ (const T& left, const MArray<T>& right)
472  { return MArray<T> (left / right.array(), right); }
473 
474  template<typename T>
475  MArray<T> operator% (const T& left, const MArray<T>& right)
476  { return MArray<T> (left % right.array(), right); }
477 
478  template<typename T>
479  MArray<T> operator& (const T& left, const MArray<T>& right)
480  { return MArray<T> (left & right.array(), right); }
481 
482  template<typename T>
483  MArray<T> operator| (const T& left, const MArray<T>& right)
484  { return MArray<T> (left | right.array(), right); }
485 
486  template<typename T>
487  MArray<T> operator^ (const T& left, const MArray<T>& right)
488  { return MArray<T> (left ^ right.array(), right); }
489  // </group>
490 
491  // Negate the elements in an array.
492  template<typename T>
494  { return MArray<T> (-a.array(), a); }
495 
496  // Take the complement of the elements in an array.
497  template<typename T>
498  MArray<T> operator~ (const MArray<T>& a)
499  { return MArray<T> (~a.array(), a); }
500 
501  // Perform mathematical function on each element in an array.
502  // <group>
503  template<typename T>
505  { return MArray<T> (sin(a.array()), a); }
506 
507  template<typename T>
509  { return MArray<T> (cos(a.array()), a); }
510 
511  template<typename T>
513  { return MArray<T> (tan(a.array()), a); }
514 
515  template<typename T>
517  { return MArray<T> (sinh(a.array()), a); }
518 
519  template<typename T>
521  { return MArray<T> (cosh(a.array()), a); }
522 
523  template<typename T>
525  { return MArray<T> (tanh(a.array()), a); }
526 
527  template<typename T>
529  { return MArray<T> (asin(a.array()), a); }
530 
531  template<typename T>
533  { return MArray<T> (acos(a.array()), a); }
534 
535  template<typename T>
537  { return MArray<T> (atan(a.array()), a); }
538 
539  template<typename T>
540  MArray<T> atan2(const MArray<T>& left, const MArray<T>& right)
541  { return (left.isNull() || right.isNull() ? MArray<T>() :
542  MArray<T> (atan2(left.array(), right.array()),
543  left.combineMask(right))); }
544 
545  template<typename T>
546  MArray<T> atan2(const MArray<T>& left, const T& right)
547  { return MArray<T> (atan2(left.array(), right), left); }
548 
549  template<typename T>
550  MArray<T> atan2(const T& left, const MArray<T>& right)
551  { return MArray<T> (atan2(left, right.array()), right); }
552 
553  template<typename T>
555  { return MArray<T> (exp(a.array()), a); }
556 
557  template<typename T>
559  { return MArray<T> (log(a.array()), a); }
560 
561  template<typename T>
563  { return MArray<T> (log10(a.array()), a); }
564 
565  template<typename T>
567  { return MArray<T> (sqrt(a.array()), a); }
568 
569  template<typename T>
571  { return MArray<T> (square(a.array()), a); }
572 
573  template<typename T>
575  { return MArray<T> (cube(a.array()), a); }
576 
577  template<typename T>
578  MArray<T> pow(const MArray<T>& a, const MArray<T>& exp)
579  { return (a.isNull() || exp.isNull() ? MArray<T>() :
580  MArray<T> (pow(a.array(), exp.array()),
581  a.combineMask(exp))); }
582 
583  template<typename T>
584  MArray<T> pow(const T& a, const MArray<T>& exp)
585  { return MArray<T> (pow(a, exp.array()), exp); }
586 
587  template<typename T>
588  MArray<T> pow(const MArray<T>& a, const Double& exp)
589  { return MArray<T> (pow(a.array(), exp), a); }
590 
591  template<typename T>
592  MArray<T> min(const MArray<T>& left, const MArray<T>& right)
593  { return (left.isNull() || right.isNull() ? MArray<T>() :
594  MArray<T> (min(left.array(), right.array()),
595  left.combineMask(right))); }
596 
597  template<typename T>
598  MArray<T> min(const MArray<T>& left, const T& right)
599  { return MArray<T> (min(left.array(), right), left); }
600 
601  template<typename T>
602  MArray<T> min(const T& left, const MArray<T>& right)
603  { return MArray<T> (min(left, right.array()), right); }
604 
605  template<typename T>
606  MArray<T> max(const MArray<T>& left, const MArray<T>& right)
607  { return (left.isNull() || right.isNull() ? MArray<T>() :
608  MArray<T> (max(left.array(), right.array()),
609  left.combineMask(right))); }
610 
611  template<typename T>
612  MArray<T> max(const MArray<T>& left, const T& right)
613  { return MArray<T> (max(left.array(), right), left); }
614 
615  template<typename T>
616  MArray<T> max(const T& left, const MArray<T>& right)
617  { return MArray<T> (max(left, right.array()), right); }
618 
619  template<typename T>
621  { return MArray<T> (ceil(a.array()), a); }
622 
623  template<typename T>
625  { return MArray<T> (floor(a.array()), a); }
626 
627  template<typename T>
629  { return MArray<T> (round(a.array()), a); }
630 
631  template<typename T>
633  { return MArray<T> (sign(a.array()), a); }
634 
635  template<typename T>
637  { return MArray<T> (abs(a.array()), a); }
638 
639  template<typename T>
641  { return MArray<T> (fabs(a.array()), a); }
642 
643  template<typename T>
644  MArray<T> fmod(const MArray<T>& left, const MArray<T>& right)
645  { return (left.isNull() || right.isNull() ? MArray<T>() :
646  MArray<T> (fmod(left.array(), right.array()),
647  left.combineMask(right))); }
648 
649  template<typename T>
650  MArray<T> fmod(const MArray<T>& left, const T& right)
651  { return MArray<T> (fmod(left.array(), right), left); }
652 
653  template<typename T>
654  MArray<T> fmod(const T& left, const MArray<T>& right)
655  { return MArray<T> (fmod(left, right.array()), right); }
656 
657  template<typename T>
658  MArray<T> floormod(const MArray<T>& left, const MArray<T>& right)
659  { return (left.isNull() || right.isNull() ? MArray<T>() :
660  MArray<T> (floormod(left.array(), right.array()),
661  left.combineMask(right))); }
662 
663  template<typename T>
664  MArray<T> floormod(const MArray<T>& left, const T& right)
665  { return MArray<T> (floormod(left.array(), right), left); }
666 
667  template<typename T>
668  MArray<T> floormod(const T& left, const MArray<T>& right)
669  { return MArray<T> (floormod(left, right.array()), right); }
670 
671  template<typename T>
673  { return MArray<T> (conj(arr.array()), arr); }
674 
675  inline MArray<Float> real(const MArray<Complex> &arr)
676  { return MArray<Float> (real(arr.array()), arr); }
677 
678  inline MArray<Float> imag(const MArray<Complex> &arr)
679  { return MArray<Float> (imag(arr.array()), arr); }
680 
682  { return MArray<Float> (amplitude(arr.array()), arr); }
683 
685  { return MArray<Float> (phase(arr.array()), arr); }
686 
688  { return MArray<Double> (real(arr.array()), arr); }
689 
691  { return MArray<Double> (imag(arr.array()), arr); }
692 
694  { return MArray<Double> (amplitude(arr.array()), arr); }
695 
697  { return MArray<Double> (phase(arr.array()), arr); }
698  // </group>
699 
700 
701  // Reduce an array to a scalar using the unmasked elements only.
702  // The result is 0 if there are no unmasked elements.
703  // <group>
704  template<typename T>
705  T sum(const MArray<T>& a)
706  {
707  if (a.hasMask()) {
708  return a.array().contiguousStorage() && a.mask().contiguousStorage() ?
709  accumulateMasked<T>(a.array().cbegin(), a.array().cend(),
710  a.mask().cbegin(), T(), std::plus<T>()) :
711  accumulateMasked<T>(a.array().begin(), a.array().end(),
712  a.mask().begin(), T(), std::plus<T>());
713  }
714  return sum(a.array());
715  }
716 
717  template<typename T>
718  T sumsqr(const MArray<T>& a)
719  {
720  if (a.hasMask()) {
721  return a.array().contiguousStorage() && a.mask().contiguousStorage() ?
722  accumulateMasked<T>(a.array().cbegin(), a.array().cend(),
723  a.mask().cbegin(), T(), SumSqr<T>()) :
724  accumulateMasked<T>(a.array().begin(), a.array().end(),
725  a.mask().begin(), T(), SumSqr<T>());
726  }
727  return sumsqr(a.array());
728  }
729 
730  template<typename T>
731  T product(const MArray<T>& a)
732  {
733  if (a.hasMask()) {
734  return a.array().contiguousStorage() && a.mask().contiguousStorage() ?
735  accumulateMasked<T>(a.array().cbegin(), a.array().cend(),
736  a.mask().cbegin(), std::multiplies<T>()) :
737  accumulateMasked<T>(a.array().begin(), a.array().end(),
738  a.mask().begin(), std::multiplies<T>());
739  }
740  return product(a.array());
741  }
742 
743  template<typename T>
744  T min(const MArray<T>& a)
745  {
746  if (a.hasMask()) {
747  return a.array().contiguousStorage() && a.mask().contiguousStorage() ?
748  accumulateMasked<T>(a.array().cbegin(), a.array().cend(),
749  a.mask().cbegin(), Min<T>()) :
750  accumulateMasked<T>(a.array().begin(), a.array().end(),
751  a.mask().begin(), Min<T>());
752  }
753  return min(a.array());
754  }
755 
756  template<typename T>
757  T max(const MArray<T>& a)
758  {
759  if (a.hasMask()) {
760  return a.array().contiguousStorage() && a.mask().contiguousStorage() ?
761  accumulateMasked<T>(a.array().cbegin(), a.array().cend(),
762  a.mask().cbegin(), Max<T>()) :
763  accumulateMasked<T>(a.array().begin(), a.array().end(),
764  a.mask().begin(), Max<T>());
765  }
766  return max(a.array());
767  }
768 
769  template<typename T>
770  T mean(const MArray<T>& a)
771  {
772  Int64 nv = a.nvalid();
773  if (nv == 0) return T();
774  if (! a.hasMask()) return mean(a.array());
775  return T(sum(a) / (1.0*nv));
776  }
777 
778  template<typename T>
779  T variance(const MArray<T>& a, T mean, uInt ddof)
780  {
781  Int64 nv = a.nvalid();
782  if (nv < ddof+1) return T();
783  if (! a.hasMask()) return pvariance(a.array(), mean, ddof);
784  T sum = a.array().contiguousStorage() && a.mask().contiguousStorage() ?
785  accumulateMasked<T>(a.array().cbegin(), a.array().cend(),
786  a.mask().cbegin(), T(), SumSqrDiff<T>(mean)) :
787  accumulateMasked<T>(a.array().begin(), a.array().end(),
788  a.mask().begin(), T(), SumSqrDiff<T>(mean));
789  return T(sum / (1.0*nv - ddof));
790  }
791 
792  template<typename T>
793  T variance(const MArray<T>& a, uInt ddof)
794  {
795  return variance(a, mean(a), ddof);
796  }
797 
798  template<typename T>
799  T stddev(const MArray<T>& a, uInt ddof)
800  {
801  return sqrt(variance(a, ddof));
802  }
803 
804  template<typename T>
805  T stddev(const MArray<T>& a, T mean, uInt ddof)
806  {
807  return sqrt(variance(a, mean, ddof));
808  }
809 
810  template<typename T>
811  T avdev(const MArray<T>& a, T mean)
812  {
813  Int64 nv = a.nvalid();
814  if (nv == 0) return T();
815  if (! a.hasMask()) return avdev(a.array(), mean);
816  T sum = a.array().contiguousStorage() && a.mask().contiguousStorage() ?
817  accumulateMasked<T>(a.array().cbegin(), a.array().cend(),
818  a.mask().cbegin(), T(), SumAbsDiff<T>(mean)) :
819  accumulateMasked<T>(a.array().begin(), a.array().end(),
820  a.mask().begin(), T(), SumAbsDiff<T>(mean));
821  return T(sum / (1.0*nv));
822  }
823 
824  template<typename T>
825  T avdev(const MArray<T>& a)
826  {
827  return avdev(a, mean(a));
828  }
829 
830  template<typename T>
831  T rms(const MArray<T>& a)
832  {
833  Int64 nv = a.nvalid();
834  if (nv == 0) return T();
835  if (! a.hasMask()) return rms(a.array());
836  T sum = a.array().contiguousStorage() && a.mask().contiguousStorage() ?
837  accumulateMasked<T>(a.array().cbegin(), a.array().cend(),
838  a.mask().cbegin(), T(), SumSqr<T>()) :
839  accumulateMasked<T>(a.array().begin(), a.array().end(),
840  a.mask().begin(), T(), SumSqr<T>());
841  return T(sqrt(sum / (1.0*nv)));
842  }
843 
844  template<typename T>
845  T median(const MArray<T> &a, Bool sorted, Bool takeEvenMean,
846  Bool inPlace=False)
847  {
848  // The normal median function needs at least one element, so shortcut.
849  if (a.empty()) return T();
850  if (! a.hasMask()) return median(a.array(), sorted, takeEvenMean, inPlace);
851  Block<T> buf(a.size());
852  Int64 nv = a.flatten (buf.storage(), buf.size());
853  if (nv == 0) return T();
854  Array<T> arr(IPosition(1, nv), buf.storage(), SHARE);
855  // Median can be taken in place.
856  return median (arr, sorted, takeEvenMean, True);
857  }
858  template<typename T>
859  inline T median(const MArray<T> &a)
860  { return median (a, False, (a.size() <= 100), False); }
861  template<typename T>
862  inline T median(const MArray<T> &a, Bool sorted)
863  { return median (a, sorted, (a.nelements() <= 100), False); }
864  template<typename T>
865  inline T medianInPlace(const MArray<T> &a, Bool sorted = False)
866  { return median (a, sorted, (a.nelements() <= 100), True); }
867 
868  // Return the fractile of an array.
869  // It returns the value at the given fraction of the array.
870  // A fraction of 0.5 is the same as the median, be it that no mean of
871  // the two middle elements is taken if the array has an even nr of elements.
872  // It uses kthLargest if the array is not sorted yet.
873  template<typename T>
874  T fractile(const MArray<T> &a, Float fraction, Bool sorted=False,
875  Bool inPlace=False)
876  {
877  // The normal fractile function needs at least one element, so shortcut.
878  if (a.empty()) return T();
879  if (! a.hasMask()) return fractile(a.array(), fraction, sorted, inPlace);
880  Block<T> buf(a.size());
881  Int64 nv = a.flatten (buf.storage(), a.size());
882  if (nv == 0) return T();
883  Array<T> arr(IPosition(1, nv), buf.storage(), SHARE);
884  return fractile (arr, fraction, sorted, True);
885  }
886  // </group>
887 
888  // Get partial sums, etc.
889  // <group>
890  template<typename T>
892  const IPosition& collapseAxes)
893  {
894  if (a.isNull()) {
895  return MArray<T>();
896  } else if (! a.hasMask()) {
897  return MArray<T>(partialSums (a.array(), collapseAxes));
898  }
899  return partialArrayMath (a, collapseAxes, MSumFunc<T>());
900  }
901  template<typename T>
903  const IPosition& collapseAxes)
904  {
905  if (a.isNull()) {
906  return MArray<T>();
907  } else if (! a.hasMask()) {
908  return MArray<T>(partialArrayMath (a.array(), collapseAxes,
909  SumSqrFunc<T>()));
910  }
911  return partialArrayMath (a, collapseAxes, MSumSqrFunc<T>());
912  }
913  template<typename T>
915  const IPosition& collapseAxes)
916  {
917  if (a.isNull()) {
918  return MArray<T>();
919  } else if (! a.hasMask()) {
920  return MArray<T>(partialProducts (a.array(), collapseAxes));
921  }
922  return partialArrayMath (a, collapseAxes, MProductFunc<T>());
923  }
924  template<typename T>
926  const IPosition& collapseAxes)
927  {
928  if (a.isNull()) {
929  return MArray<T>();
930  } else if (! a.hasMask()) {
931  return MArray<T>(partialMins (a.array(), collapseAxes));
932  }
933  return partialArrayMath (a, collapseAxes, MMinFunc<T>());
934  }
935  template<typename T>
937  const IPosition& collapseAxes)
938  {
939  if (a.isNull()) {
940  return MArray<T>();
941  } else if (! a.hasMask()) {
942  return MArray<T>(partialMaxs (a.array(), collapseAxes));
943  }
944  return partialArrayMath (a, collapseAxes, MMaxFunc<T>());
945  }
946  template<typename T>
948  const IPosition& collapseAxes)
949  {
950  if (a.isNull()) {
951  return MArray<T>();
952  } else if (! a.hasMask()) {
953  return MArray<T>(partialMeans (a.array(), collapseAxes));
954  }
955  return partialArrayMath (a, collapseAxes, MMeanFunc<T>());
956  }
957  template<typename T>
959  const IPosition& collapseAxes,
960  uInt ddof)
961  {
962  if (a.isNull()) {
963  return MArray<T>();
964  } else if (! a.hasMask()) {
965  return MArray<T>(partialVariances (a.array(), collapseAxes, ddof));
966  }
967  return partialArrayMath (a, collapseAxes, MVarianceFunc<T>(ddof));
968  }
969  template<typename T>
971  const IPosition& collapseAxes,
972  uInt ddof)
973  {
974  if (a.isNull()) {
975  return MArray<T>();
976  } else if (! a.hasMask()) {
977  return MArray<T>(partialStddevs (a.array(), collapseAxes, ddof));
978  }
979  return partialArrayMath (a, collapseAxes, MStddevFunc<T>(ddof));
980  }
981  template<typename T>
983  const IPosition& collapseAxes)
984  {
985  if (a.isNull()) {
986  return MArray<T>();
987  } else if (! a.hasMask()) {
988  return MArray<T>(partialAvdevs (a.array(), collapseAxes));
989  }
990  return partialArrayMath (a, collapseAxes, MAvdevFunc<T>());
991  }
992  template<typename T>
994  const IPosition& collapseAxes)
995  {
996  if (a.isNull()) {
997  return MArray<T>();
998  } else if (! a.hasMask()) {
999  return MArray<T>(partialRmss (a.array(), collapseAxes));
1000  }
1001  return partialArrayMath (a, collapseAxes, MRmsFunc<T>());
1002  }
1003  template<typename T>
1005  const IPosition& collapseAxes,
1006  Bool takeEvenMean=False,
1007  Bool inPlace=False)
1008  {
1009  if (a.isNull()) {
1010  return MArray<T>();
1011  } else if (! a.hasMask()) {
1012  return MArray<T>(partialMedians (a.array(), collapseAxes,
1013  takeEvenMean, inPlace));
1014  }
1015  return partialArrayMath (a, collapseAxes,
1016  MMedianFunc<T>(False, takeEvenMean, inPlace));
1017  }
1018  template<typename T>
1020  const IPosition& collapseAxes,
1021  Float fraction,
1022  Bool inPlace=False)
1023  {
1024  if (a.isNull()) {
1025  return MArray<T>();
1026  } else if (! a.hasMask()) {
1027  return MArray<T>(partialFractiles (a.array(), collapseAxes,
1028  fraction, inPlace));
1029  }
1030  return partialArrayMath (a, collapseAxes,
1031  MFractileFunc<T>(fraction, False, inPlace));
1032  }
1033  // </group>
1034 
1035  // Get sliding sums.
1036  // <group>
1037  template<typename T>
1039  const IPosition& halfBoxSize, Bool fillEdge=True)
1040  {
1041  if (a.isNull()) {
1042  return MArray<T>();
1043  } else if (! a.hasMask()) {
1044  return MArray<T>(slidingArrayMath (a.array(), halfBoxSize,
1045  SumFunc<T>(), fillEdge));
1046  }
1047  return slidingArrayMath (a, halfBoxSize, MSumFunc<T>(), fillEdge);
1048  }
1049  template<typename T>
1051  const IPosition& halfBoxSize, Bool fillEdge=True)
1052  {
1053  if (a.isNull()) {
1054  return MArray<T>();
1055  } else if (! a.hasMask()) {
1056  return MArray<T>(slidingArrayMath (a.array(), halfBoxSize,
1057  SumSqrFunc<T>(), fillEdge));
1058  }
1059  return slidingArrayMath (a, halfBoxSize, MSumSqrFunc<T>(), fillEdge);
1060  }
1061  template<typename T>
1063  const IPosition& halfBoxSize, Bool fillEdge=True)
1064  {
1065  if (a.isNull()) {
1066  return MArray<T>();
1067  } else if (! a.hasMask()) {
1068  return MArray<T>(slidingArrayMath (a.array(), halfBoxSize,
1069  ProductFunc<T>(), fillEdge));
1070  }
1071  return slidingArrayMath (a, halfBoxSize, MProductFunc<T>(), fillEdge);
1072  }
1073  template<typename T>
1075  const IPosition& halfBoxSize, Bool fillEdge=True)
1076  {
1077  if (a.isNull()) {
1078  return MArray<T>();
1079  } else if (! a.hasMask()) {
1080  return MArray<T>(slidingArrayMath (a.array(), halfBoxSize,
1081  MinFunc<T>(), fillEdge));
1082  }
1083  return slidingArrayMath (a, halfBoxSize, MMinFunc<T>(), fillEdge);
1084  }
1085  template<typename T>
1087  const IPosition& halfBoxSize, Bool fillEdge=True)
1088  {
1089  if (a.isNull()) {
1090  return MArray<T>();
1091  } else if (! a.hasMask()) {
1092  return MArray<T>(slidingArrayMath (a.array(), halfBoxSize,
1093  MaxFunc<T>(), fillEdge));
1094  }
1095  return slidingArrayMath (a, halfBoxSize, MMaxFunc<T>(), fillEdge);
1096  }
1097  template<typename T>
1099  const IPosition& halfBoxSize, Bool fillEdge=True)
1100  {
1101  if (a.isNull()) {
1102  return MArray<T>();
1103  } else if (! a.hasMask()) {
1104  return MArray<T>(slidingArrayMath (a.array(), halfBoxSize,
1105  MeanFunc<T>(), fillEdge));
1106  }
1107  return slidingArrayMath (a, halfBoxSize, MMeanFunc<T>(), fillEdge);
1108  }
1109  template<typename T>
1111  const IPosition& halfBoxSize,
1112  uInt ddof,
1113  Bool fillEdge=True)
1114  {
1115  if (a.isNull()) {
1116  return MArray<T>();
1117  } else if (! a.hasMask()) {
1118  return MArray<T>(slidingArrayMath (a.array(), halfBoxSize,
1119  VarianceFunc<T>(ddof), fillEdge));
1120  }
1121  return slidingArrayMath (a, halfBoxSize, MVarianceFunc<T>(ddof), fillEdge);
1122  }
1123  template<typename T>
1125  const IPosition& halfBoxSize,
1126  uInt ddof,
1127  Bool fillEdge=True)
1128  {
1129  if (a.isNull()) {
1130  return MArray<T>();
1131  } else if (! a.hasMask()) {
1132  return MArray<T>(slidingArrayMath (a.array(), halfBoxSize,
1133  StddevFunc<T>(ddof), fillEdge));
1134  }
1135  return slidingArrayMath (a, halfBoxSize, MStddevFunc<T>(ddof), fillEdge);
1136  }
1137  template<typename T>
1139  const IPosition& halfBoxSize, Bool fillEdge=True)
1140  {
1141  if (a.isNull()) {
1142  return MArray<T>();
1143  } else if (! a.hasMask()) {
1144  return MArray<T>(slidingArrayMath (a.array(), halfBoxSize,
1145  AvdevFunc<T>(), fillEdge));
1146  }
1147  return slidingArrayMath (a, halfBoxSize, MAvdevFunc<T>(), fillEdge);
1148  }
1149  template<typename T>
1151  const IPosition& halfBoxSize, Bool fillEdge=True)
1152  {
1153  if (a.isNull()) {
1154  return MArray<T>();
1155  } else if (! a.hasMask()) {
1156  return MArray<T>(slidingArrayMath (a.array(), halfBoxSize,
1157  RmsFunc<T>(), fillEdge));
1158  }
1159  return slidingArrayMath (a, halfBoxSize, MRmsFunc<T>(), fillEdge);
1160  }
1161  template<typename T>
1163  const IPosition& halfBoxSize,
1164  Bool takeEvenMean=False,
1165  Bool inPlace=False,
1166  Bool fillEdge=True)
1167  {
1168  if (a.isNull()) {
1169  return MArray<T>();
1170  } else if (! a.hasMask()) {
1171  return MArray<T>(slidingArrayMath (a.array(), halfBoxSize,
1172  MedianFunc<T>(False, takeEvenMean,
1173  inPlace),
1174  fillEdge));
1175  }
1176  return slidingArrayMath (a, halfBoxSize,
1177  MMedianFunc<T>(False, takeEvenMean, inPlace),
1178  fillEdge);
1179  }
1180  template<typename T>
1182  const IPosition& halfBoxSize,
1183  Float fraction,
1184  Bool inPlace=False,
1185  Bool fillEdge=True)
1186  {
1187  if (a.isNull()) {
1188  return MArray<T>();
1189  } else if (! a.hasMask()) {
1190  return MArray<T>(slidingArrayMath (a.array(), halfBoxSize,
1191  FractileFunc<T>(fraction, False,
1192  inPlace),
1193  fillEdge));
1194  }
1195  return slidingArrayMath (a, halfBoxSize,
1196  MFractileFunc<T>(fraction, False, inPlace),
1197  fillEdge);
1198  }
1199  // </group>
1200 
1201  // Get boxed sums.
1202  // <group>
1203  template<typename T>
1205  const IPosition& boxSize)
1206  {
1207  if (a.isNull()) {
1208  return MArray<T>();
1209  } else if (! a.hasMask()) {
1210  return MArray<T>(boxedArrayMath (a.array(), boxSize, SumFunc<T>()));
1211  }
1212  return boxedArrayMath (a, boxSize, MSumFunc<T>());
1213  }
1214  template<typename T>
1216  const IPosition& boxSize)
1217  {
1218  if (a.isNull()) {
1219  return MArray<T>();
1220  } else if (! a.hasMask()) {
1221  return MArray<T>(boxedArrayMath (a.array(), boxSize, SumSqrFunc<T>()));
1222  }
1223  return boxedArrayMath (a, boxSize, MSumSqrFunc<T>());
1224  }
1225  template<typename T>
1227  const IPosition& boxSize)
1228  {
1229  if (a.isNull()) {
1230  return MArray<T>();
1231  } else if (! a.hasMask()) {
1232  return MArray<T>(boxedArrayMath (a.array(), boxSize, ProductFunc<T>()));
1233  }
1234  return boxedArrayMath (a, boxSize, MProductFunc<T>());
1235  }
1236  template<typename T>
1238  const IPosition& boxSize)
1239  {
1240  if (a.isNull()) {
1241  return MArray<T>();
1242  } else if (! a.hasMask()) {
1243  return MArray<T>(boxedArrayMath (a.array(), boxSize, MinFunc<T>()));
1244  }
1245  return boxedArrayMath (a, boxSize, MMinFunc<T>());
1246  }
1247  template<typename T>
1249  const IPosition& boxSize)
1250  {
1251  if (a.isNull()) {
1252  return MArray<T>();
1253  } else if (! a.hasMask()) {
1254  return MArray<T>(boxedArrayMath (a.array(), boxSize, MaxFunc<T>()));
1255  }
1256  return boxedArrayMath (a, boxSize, MMaxFunc<T>());
1257  }
1258  template<typename T>
1260  const IPosition& boxSize)
1261  {
1262  if (a.isNull()) {
1263  return MArray<T>();
1264  } else if (! a.hasMask()) {
1265  return MArray<T>(boxedArrayMath (a.array(), boxSize, MeanFunc<T>()));
1266  }
1267  return boxedArrayMath (a, boxSize, MMeanFunc<T>());
1268  }
1269  template<typename T>
1271  const IPosition& boxSize,
1272  uInt ddof)
1273  {
1274  if (a.isNull()) {
1275  return MArray<T>();
1276  } else if (! a.hasMask()) {
1277  return MArray<T>(boxedArrayMath (a.array(), boxSize, VarianceFunc<T>(ddof)));
1278  }
1279  return boxedArrayMath (a, boxSize, MVarianceFunc<T>(ddof));
1280  }
1281  template<typename T>
1283  const IPosition& boxSize,
1284  uInt ddof)
1285  {
1286  if (a.isNull()) {
1287  return MArray<T>();
1288  } else if (! a.hasMask()) {
1289  return MArray<T>(boxedArrayMath (a.array(), boxSize, StddevFunc<T>(ddof)));
1290  }
1291  return boxedArrayMath (a, boxSize, MStddevFunc<T>(ddof));
1292  }
1293  template<typename T>
1295  const IPosition& boxSize)
1296  {
1297  if (a.isNull()) {
1298  return MArray<T>();
1299  } else if (! a.hasMask()) {
1300  return MArray<T>(boxedArrayMath (a.array(), boxSize, AvdevFunc<T>()));
1301  }
1302  return boxedArrayMath (a, boxSize, MAvdevFunc<T>());
1303  }
1304  template<typename T>
1306  const IPosition& boxSize)
1307  {
1308  if (a.isNull()) {
1309  return MArray<T>();
1310  } else if (! a.hasMask()) {
1311  return MArray<T>(boxedArrayMath (a.array(), boxSize, RmsFunc<T>()));
1312  }
1313  return boxedArrayMath (a, boxSize, MRmsFunc<T>());
1314  }
1315  template<typename T>
1317  const IPosition& boxSize,
1318  Bool takeEvenMean=False,
1319  Bool inPlace=False)
1320  {
1321  if (a.isNull()) {
1322  return MArray<T>();
1323  } else if (! a.hasMask()) {
1324  return MArray<T>(boxedArrayMath (a.array(), boxSize,
1325  MedianFunc<T>(False, takeEvenMean,
1326  inPlace)));
1327  }
1328  return boxedArrayMath (a, boxSize,
1329  MMedianFunc<T>(False, takeEvenMean, inPlace));
1330  }
1331  template<typename T>
1333  const IPosition& boxSize,
1334  Float fraction,
1335  Bool inPlace=False)
1336  {
1337  if (a.isNull()) {
1338  return MArray<T>();
1339  } else if (! a.hasMask()) {
1340  return MArray<T>(boxedArrayMath (a.array(), boxSize,
1341  FractileFunc<T>(fraction, False,
1342  inPlace)));
1343  }
1344  return boxedArrayMath (a, boxSize,
1345  MFractileFunc<T>(fraction, False, inPlace));
1346  }
1347  // </group>
1348 
1349  // </group>
1350 
1351 } //# end namespace
1352 
1353 #endif
MArray< T > slidingRmss(const MArray< T > &a, const IPosition &halfBoxSize, Bool fillEdge=True)
Definition: MArrayMath.h:1150
A Vector of integers, for indexing into Array&lt;T&gt; objects.
Definition: IPosition.h:119
LatticeExprNode log10(const LatticeExprNode &expr)
void setMask(const Array< Bool > &mask)
Set the mask.
long long Int64
Define the extra non-standard types used by Casacore (like proposed uSize, Size)
Definition: aipsxtype.h:38
Class to handle an Array with an optional mask.
MArray< T > partialAvdevs(const MArray< T > &a, const IPosition &collapseAxes)
Definition: MArrayMath.h:982
LatticeExprNode log(const LatticeExprNode &expr)
Share means that the Array will just use the pointer (no copy), however the Array will NOT delete it ...
Definition: ArrayBase.h:64
size_t size() const
Get the size.
Definition: MArrayBase.h:152
void boxedArrayMath(MArray< RES > &res, const MArray< T > &array, const IPosition &boxShape, const MArrayFunctorBase< T, RES > &funcObj)
Definition: MArrayMath.h:256
MArray< T > slidingStddevs(const MArray< T > &a, const IPosition &halfBoxSize, uInt ddof, Bool fillEdge=True)
Definition: MArrayMath.h:1124
MArray< Double > phase(const MArray< DComplex > &arr)
Definition: MArrayMath.h:696
MArray< T > boxedMaxs(const MArray< T > &a, const IPosition &boxSize)
Definition: MArrayMath.h:1248
LatticeExprNode median(const LatticeExprNode &expr)
MArray< T > partialMins(const MArray< T > &a, const IPosition &collapseAxes)
Definition: MArrayMath.h:925
MArray< T > sin(const MArray< T > &a)
Perform mathematical function on each element in an array.
Definition: MArrayMath.h:504
MArray< T > fmod(const T &left, const MArray< T > &right)
Definition: MArrayMath.h:654
Functor to add square of right to left.
Definition: Functors.h:597
Functor to add absolute diff of right and base value to left.
Definition: Functors.h:635
MArray< T > partialMaxs(const MArray< T > &a, const IPosition &collapseAxes)
Definition: MArrayMath.h:936
LatticeExprNode operator/(const LatticeExprNode &left, const LatticeExprNode &right)
MArray< Float > imag(const MArray< Complex > &arr)
Definition: MArrayMath.h:678
LatticeExprNode mask(const LatticeExprNode &expr)
This function returns the mask of the given expression.
Bool isNull() const
Is the array null?
Definition: MArrayBase.h:111
MArray< T > slidingArrayMath(const MArray< T > &array, const IPosition &halfBoxShape, const MArrayFunctorBase< T > &funcObj, Bool fillEdge=True)
Definition: MArrayMath.h:303
LatticeExprNode imag(const LatticeExprNode &expr)
MArray< T > boxedFractiles(const MArray< T > &a, const IPosition &boxSize, Float fraction, Bool inPlace=False)
Definition: MArrayMath.h:1332
MFractileFunc(Float fraction, Bool sorted=False, Bool inPlace=False)
Definition: MArrayMath.h:168
void partialArrayMath(MArray< RES > &res, const MArray< T > &a, const IPosition &collapseAxes, const MArrayFunctorBase< T, RES > &funcObj)
Definition: MArrayMath.h:193
MArray< T > atan2(const MArray< T > &left, const MArray< T > &right)
Definition: MArrayMath.h:540
TableExprNode array(const TableExprNode &values, const TableExprNodeSet &shape)
Create an array of the given shape and fill it with the values.
Definition: ExprNode.h:1886
LatticeExprNode sum(const LatticeExprNode &expr)
LatticeExprNode max(const LatticeExprNode &left, const LatticeExprNode &right)
LatticeExprNode operator%(const LatticeExprNode &left, const LatticeExprNode &right)
Functor to get maximum of two values.
Definition: Functors.h:589
MArray< T > slidingMedians(const MArray< T > &a, const IPosition &halfBoxSize, Bool takeEvenMean=False, Bool inPlace=False, Bool fillEdge=True)
Definition: MArrayMath.h:1162
TableExprNode phase(const TableExprNode &node)
The phase (i.e.
Definition: ExprNode.h:1405
MArray< T > atan2(const MArray< T > &left, const T &right)
Definition: MArrayMath.h:546
MArray< T > boxedStddevs(const MArray< T > &a, const IPosition &boxSize, uInt ddof)
Definition: MArrayMath.h:1282
Vector< T > flatten() const
Flatten the unmasked elements of the array to a vector.
Definition: MArray.h:184
MArray< T > partialSumSqrs(const MArray< T > &a, const IPosition &collapseAxes)
Definition: MArrayMath.h:902
MArray< T > pow(const MArray< T > &a, const MArray< T > &exp)
Definition: MArrayMath.h:578
MArray< T > boxedMeans(const MArray< T > &a, const IPosition &boxSize)
Definition: MArrayMath.h:1259
LatticeExprNode fractile(const LatticeExprNode &expr, const LatticeExprNode &fraction)
Determine the value of the element at the part fraction from the beginning of the given lattice...
MArray< T > partialFractiles(const MArray< T > &a, const IPosition &collapseAxes, Float fraction, Bool inPlace=False)
Definition: MArrayMath.h:1019
T medianInPlace(const MArray< T > &a, Bool sorted=False)
Definition: MArrayMath.h:865
TableExprNode operator&(const TableExprNode &left, const TableExprNode &right)
Definition: ExprNode.h:1138
LatticeExprNode exp(const LatticeExprNode &expr)
iterator begin()
Get the begin iterator object for any array.
Definition: Array.h:856
T sum(const MArray< T > &a)
Reduce an array to a scalar using the unmasked elements only.
Definition: MArrayMath.h:705
MArray< T > boxedMedians(const MArray< T > &a, const IPosition &boxSize, Bool takeEvenMean=False, Bool inPlace=False)
Definition: MArrayMath.h:1316
MArray< T > slidingProducts(const MArray< T > &a, const IPosition &halfBoxSize, Bool fillEdge=True)
Definition: MArrayMath.h:1062
MArray< Float > phase(const MArray< Complex > &arr)
Definition: MArrayMath.h:684
T variance(const MArray< T > &a, T mean, uInt ddof)
Definition: MArrayMath.h:779
Bool contiguousStorage() const
Are the array data contiguous? If they are not contiguous, getStorage (see below) needs to make a cop...
Definition: ArrayBase.h:112
LatticeExprNode floor(const LatticeExprNode &expr)
void fillBoxedShape(const IPosition &shape, const IPosition &boxShape, IPosition &fullBoxShape, IPosition &resultShape)
Helper functions for boxed and sliding functions.
MArray< T > boxedProducts(const MArray< T > &a, const IPosition &boxSize)
Definition: MArrayMath.h:1226
MArray< T > min(const MArray< T > &left, const T &right)
Definition: MArrayMath.h:598
Define functors to perform a reduction function on an MArray object.
Definition: MArrayMath.h:95
MArray< T > partialProducts(const MArray< T > &a, const IPosition &collapseAxes)
Definition: MArrayMath.h:914
MArray< T > slidingFractiles(const MArray< T > &a, const IPosition &halfBoxSize, Float fraction, Bool inPlace=False, Bool fillEdge=True)
Definition: MArrayMath.h:1181
MVEarthMagnetic operator*(const RotMatrix &left, const MVEarthMagnetic &right)
Rotate a EarthMagnetic vector with rotation matrix and other multiplications.
LatticeExprNode cos(const LatticeExprNode &expr)
contiter cbegin()
Get the begin iterator object for a contiguous array.
Definition: Array.h:868
T median(const MArray< T > &a, Bool sorted, Bool takeEvenMean, Bool inPlace=False)
Definition: MArrayMath.h:845
MArray< T > max(const MArray< T > &left, const MArray< T > &right)
Definition: MArrayMath.h:606
MArray< T > fmod(const MArray< T > &left, const MArray< T > &right)
Definition: MArrayMath.h:644
MArray< Float > amplitude(const MArray< Complex > &arr)
Definition: MArrayMath.h:681
ABSTRACT CLASSES Deliberately vague to be general enough to allow for many different types of data
Definition: PlotData.h:48
void slidingArrayMath(MArray< RES > &res, const MArray< T > &array, const IPosition &halfBoxShape, const MArrayFunctorBase< T, RES > &funcObj, Bool fillEdge=True)
Definition: MArrayMath.h:313
MArray< T > partialArrayMath(const MArray< T > &a, const IPosition &collapseAxes, const MArrayFunctorBase< T > &funcObj)
Do partial reduction of an MArray object.
Definition: MArrayMath.h:184
MArray< T > partialVariances(const MArray< T > &a, const IPosition &collapseAxes, uInt ddof)
Definition: MArrayMath.h:958
T * data()
Get a pointer to the beginning of the array.
Definition: Array.h:597
Functor to get minimum of two values.
Definition: Functors.h:581
LatticeExprNode conj(const LatticeExprNode &expr)
Array< Bool > combineMask(const MArrayBase &other) const
Combine this and the other mask.
const ssize_t * storage() const
Get the storage.
Definition: IPosition.h:607
T fractile(const MArray< T > &a, Float fraction, Bool sorted=False, Bool inPlace=False)
Return the fractile of an array.
Definition: MArrayMath.h:874
LatticeExprNode tanh(const LatticeExprNode &expr)
LatticeExprNode min(const LatticeExprNode &left, const LatticeExprNode &right)
LatticeExprNode avdev(const LatticeExprNode &expr)
MArray< T > slidingMaxs(const MArray< T > &a, const IPosition &halfBoxSize, Bool fillEdge=True)
Definition: MArrayMath.h:1086
MArray< T > partialRmss(const MArray< T > &a, const IPosition &collapseAxes)
Definition: MArrayMath.h:993
MArray< T > floormod(const T &left, const MArray< T > &right)
Definition: MArrayMath.h:668
double Double
Definition: aipstype.h:55
LatticeExprNode abs(const LatticeExprNode &expr)
Numerical 1-argument functions which result in a real number regardless of input expression type...
MArray< T > min(const T &left, const MArray< T > &right)
Definition: MArrayMath.h:602
LatticeExprNode ndim(const LatticeExprNode &expr)
1-argument function to get the dimensionality of a lattice.
Bool fillSlidingShape(const IPosition &shape, const IPosition &halfBoxSize, IPosition &boxEnd, IPosition &resultShape)
Determine the box end and shape of result for a sliding operation.
LatticeExprNode sign(const LatticeExprNode &expr)
LatticeExprNode sqrt(const LatticeExprNode &expr)
MArray< T > min(const MArray< T > &left, const MArray< T > &right)
Definition: MArrayMath.h:592
LatticeExprNode tan(const LatticeExprNode &expr)
MArray< T > slidingAvdevs(const MArray< T > &a, const IPosition &halfBoxSize, Bool fillEdge=True)
Definition: MArrayMath.h:1138
LatticeExprNode atan(const LatticeExprNode &expr)
#define AlwaysAssert(expr, exception)
These marcos are provided for use instead of simply using the constructors of assert_ to allow additi...
Definition: Assert.h:157
TableExprNode product(const TableExprNode &array)
Definition: ExprNode.h:1607
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42
MArray< T > boxedAvdevs(const MArray< T > &a, const IPosition &boxSize)
Definition: MArrayMath.h:1294
MaskedArray< T > boxedArrayMath(const MaskedArray< T > &array, const IPosition &boxSize, const FuncType &funcObj)
Apply the given ArrayMath reduction function objects to each box in the array.
TableExprNode cube(const TableExprNode &node)
Definition: ExprNode.h:1308
LatticeExprNode stddev(const LatticeExprNode &expr)
LatticeExprNode round(const LatticeExprNode &expr)
MArray< T > boxedSumSqrs(const MArray< T > &a, const IPosition &boxSize)
Definition: MArrayMath.h:1215
Iterate a const Array cursor through a const Array.
Definition: ArrayIter.h:174
float Float
Definition: aipstype.h:54
casacore::Bool empty() const
const Bool False
Definition: aipstype.h:44
MArray< T > boxedArrayMath(const MArray< T > &a, const IPosition &boxShape, const MArrayFunctorBase< T > &funcObj)
Definition: MArrayMath.h:247
TableExprNode shape(const TableExprNode &array)
Function operating on any scalar or array resulting in a Double array containing the shape...
Definition: ExprNode.h:1944
void resize(const IPosition &shape, Bool useMask)
Resize the array and optionally the mask.
Definition: MArray.h:122
MArray< T > slidingMins(const MArray< T > &a, const IPosition &halfBoxSize, Bool fillEdge=True)
Definition: MArrayMath.h:1074
TableExprNode operator|(const TableExprNode &left, const TableExprNode &right)
Definition: ExprNode.h:1143
LatticeExprNode atan2(const LatticeExprNode &left, const LatticeExprNode &right)
Numerical 2-argument functions.
MArray< T > boxedVariances(const MArray< T > &a, const IPosition &boxSize, uInt ddof)
Definition: MArrayMath.h:1270
size_t nelements() const
Definition: MArrayBase.h:154
simple 1-D array
MArray< T > boxedRmss(const MArray< T > &a, const IPosition &boxSize)
Definition: MArrayMath.h:1305
MArray< T > partialMedians(const MArray< T > &a, const IPosition &collapseAxes, Bool takeEvenMean=False, Bool inPlace=False)
Definition: MArrayMath.h:1004
MArray< T > slidingSumSqrs(const MArray< T > &a, const IPosition &halfBoxSize, Bool fillEdge=True)
Definition: MArrayMath.h:1050
const Array< T > & array() const
Get access to the array.
Definition: MArray.h:153
LatticeExprNode operator+(const LatticeExprNode &expr)
Global functions operating on a LatticeExprNode.
Int64 nvalid() const
Return the number of valid array values, thus unflagged elements.
Definition: MArrayBase.h:132
virtual casacore::Bool operator()(Flux< casacore::Double > &value, Flux< casacore::Double > &error, const casacore::MFrequency &mfreq, const casacore::Bool updatecoeffs)=0
MArray< T > floormod(const MArray< T > &left, const MArray< T > &right)
Definition: MArrayMath.h:658
LatticeExprNode fmod(const LatticeExprNode &left, const LatticeExprNode &right)
Base class for all Casacore library errors.
Definition: Error.h:134
LatticeExprNode asin(const LatticeExprNode &expr)
LatticeExprNode mean(const LatticeExprNode &expr)
MArray< T > partialSums(const MArray< T > &a, const IPosition &collapseAxes)
Get partial sums, etc.
Definition: MArrayMath.h:891
TableExprNode rms(const TableExprNode &array)
Definition: ExprNode.h:1637
LatticeExprNode sinh(const LatticeExprNode &expr)
MArray< Double > amplitude(const MArray< DComplex > &arr)
Definition: MArrayMath.h:693
Bool hasMask() const
Is there a mask?
Definition: MArrayBase.h:119
LatticeExprNode acos(const LatticeExprNode &expr)
TableExprNode square(const TableExprNode &node)
Definition: ExprNode.h:1303
MArray< T > atan2(const T &left, const MArray< T > &right)
Definition: MArrayMath.h:550
Array< T > slidingArrayMath(const MaskedArray< T > &array, const IPosition &halfBoxSize, const FuncType &funcObj, Bool fillEdge=True)
Apply for each element in the array the given ArrayMath reduction function object to the box around t...
LatticeExprNode operator-(const LatticeExprNode &expr)
MArray< T > boxedSums(const MArray< T > &a, const IPosition &boxSize)
Get boxed sums.
Definition: MArrayMath.h:1204
MArray< T > max(const MArray< T > &left, const T &right)
Definition: MArrayMath.h:612
MArray< T > fmod(const MArray< T > &left, const T &right)
Definition: MArrayMath.h:650
MArray< T > max(const T &left, const MArray< T > &right)
Definition: MArrayMath.h:616
MArray< T > slidingMeans(const MArray< T > &a, const IPosition &halfBoxSize, Bool fillEdge=True)
Definition: MArrayMath.h:1098
LatticeExprNode operator^(const LatticeExprNode &left, const LatticeExprNode &right)
MArray< T > slidingVariances(const MArray< T > &a, const IPosition &halfBoxSize, uInt ddof, Bool fillEdge=True)
Definition: MArrayMath.h:1110
MArray< T > partialMeans(const MArray< T > &a, const IPosition &collapseAxes)
Definition: MArrayMath.h:947
LatticeExprNode variance(const LatticeExprNode &expr)
LatticeExprNode ceil(const LatticeExprNode &expr)
LatticeExprNode pow(const LatticeExprNode &left, const LatticeExprNode &right)
MArray< T > pow(const T &a, const MArray< T > &exp)
Definition: MArrayMath.h:584
MArray< Double > real(const MArray< DComplex > &arr)
Definition: MArrayMath.h:687
MArray< Float > real(const MArray< Complex > &arr)
Definition: MArrayMath.h:675
Bool empty() const
Is the array empty?
Definition: MArrayBase.h:139
MArray< T > floormod(const MArray< T > &left, const T &right)
Definition: MArrayMath.h:664
const Bool True
Definition: aipstype.h:43
LatticeExprNode cosh(const LatticeExprNode &expr)
MArray< Double > imag(const MArray< DComplex > &arr)
Definition: MArrayMath.h:690
const IPosition & shape() const
Get the shape.
Definition: MArrayBase.h:147
LatticeExprNode real(const LatticeExprNode &expr)
Functor to add squared diff of right and base value to left.
Definition: Functors.h:607
MArray< T > partialStddevs(const MArray< T > &a, const IPosition &collapseAxes, uInt ddof)
Definition: MArrayMath.h:970
LatticeExprNode sin(const LatticeExprNode &expr)
Numerical 1-argument functions.
MArray< T > pow(const MArray< T > &a, const Double &exp)
Definition: MArrayMath.h:588
unsigned int uInt
Definition: aipstype.h:51
MMedianFunc(Bool sorted=False, Bool takeEvenMean=True, Bool inPlace=False)
Definition: MArrayMath.h:155
MArray< T > boxedMins(const MArray< T > &a, const IPosition &boxSize)
Definition: MArrayMath.h:1237
const Array< Bool > & mask() const
Get the mask.
Definition: MArrayBase.h:126
MArray< T > slidingSums(const MArray< T > &a, const IPosition &halfBoxSize, Bool fillEdge=True)
Get sliding sums.
Definition: MArrayMath.h:1038
#define casacore
&lt;X11/Intrinsic.h&gt; #defines true, false, casacore::Bool, and String.
Definition: X11Intrinsic.h:42
TableExprNode amplitude(const TableExprNode &node)
The amplitude (i.e.
Definition: ExprNode.h:1397