casacore
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>
33 #include <casacore/tables/TaQL/MArray.h>
34 #include <casacore/tables/TaQL/MArrayMathBase.h>
35 #include <casacore/casa/Arrays/ArrayPartMath.h>
36 #include <casacore/casa/Arrays/ArrayIter.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  virtual ~MVarianceFunc() {}
128  T operator() (const MArray<T>& arr) const { return variance(arr); }
129  };
130  template<typename T> class MStddevFunc : public MArrayFunctorBase<T> {
131  public:
132  virtual ~MStddevFunc() {}
133  T operator() (const MArray<T>& arr) const { return stddev(arr); }
134  };
135  template<typename T> class MAvdevFunc : public MArrayFunctorBase<T> {
136  public:
137  virtual ~MAvdevFunc() {}
138  T operator() (const MArray<T>& arr) const { return avdev(arr); }
139  };
140  template<typename T> class MRmsFunc : public MArrayFunctorBase<T> {
141  public:
142  virtual ~MRmsFunc() {}
143  T operator() (const MArray<T>& arr) const { return rms(arr); }
144  };
145  template<typename T> class MMedianFunc : public MArrayFunctorBase<T> {
146  public:
147  explicit MMedianFunc (Bool sorted=False, Bool takeEvenMean=True,
148  Bool inPlace = False)
149  : itsSorted(sorted), itsTakeEvenMean(takeEvenMean), itsInPlace(inPlace) {}
150  virtual ~MMedianFunc() {}
151  T operator() (const MArray<T>& arr) const
152  { return median(arr, itsSorted, itsTakeEvenMean, itsInPlace); }
153  private:
157  };
158  template<typename T> class MFractileFunc : public MArrayFunctorBase<T> {
159  public:
160  explicit MFractileFunc (Float fraction,
161  Bool sorted = False, Bool inPlace = False)
162  : itsFraction(fraction), itsSorted(sorted), itsInPlace(inPlace) {}
163  virtual ~MFractileFunc() {}
164  T operator() (const MArray<T>& arr) const
165  { return fractile(arr, itsFraction, itsSorted, itsInPlace); }
166  private:
167  float itsFraction;
170  };
171 
172 
173  // Do partial reduction of an MArray object. I.e., perform the operation
174  // on a subset of the array axes (the collapse axes).
175  template<typename T>
177  const IPosition& collapseAxes,
178  const MArrayFunctorBase<T>& funcObj)
179  {
180  MArray<T> res;
181  partialArrayMath (res, a, collapseAxes, funcObj);
182  return res;
183  }
184  template<typename T, typename RES>
186  const MArray<T>& a,
187  const IPosition& collapseAxes,
188  const MArrayFunctorBase<T,RES>& funcObj)
189  {
191  // This can also be done as boxedArrayMath with a removeDegenerate thereafter.
192  //
193  // It should be possible to parallelize this loop.
194  // Determine nr of iteration steps and iterate over that as an int.
195  // Do not use Array slicing, because that is not thread-safe.
196  // Instead create ArraySTLIterator directly from Array and blc,trc,
197  // so funcObj should accept iterators instead of Array.
198  // However, ArraySTLIterator needs the sliced array, not original.
199  // Maybe keep ref of itsSteps in iterator instead of array.
200  // Hmm, tricky for median and fractile.
201  // Better to make Array copy ctor thread-safe (thus use boost shared_ptr).
202  ReadOnlyArrayIterator<T> aiter(a.array(), collapseAxes);
203  ReadOnlyArrayIterator<Bool> miter(a.mask(), collapseAxes);
204  IPosition shape(a.array().shape().removeAxes (collapseAxes));
205  /*
206  Int64 nr = 1;
207  for (uInt i=0; i<collapseAxes.size(); ++i) {
208  nr *= a.array().shape()[collapseAxes[i]];
209  }
211  for (Int64 i=0; i<nr; ++i) {
212  IPosition pos = findPos(i);
213  IPosition endPos = pos + cursorShape - 1;
214  *data[pos] = funcObj(MArray<T>(a.array()(pos,endPos), a.mask()(pos,endpos)));
215  }
216  */
218  res.resize (shape, False);
219  Array<Bool> resMask(shape);
220  RES* data = res.array().data();
221  Bool* mask = resMask.data();
222  while (!aiter.pastEnd()) {
223  if (allTrue(miter.array())) {
224  *mask++ = True;
225  *data++ = RES();
226  } else {
227  *mask++ = False;
228  *data++ = funcObj(MArray<T> (aiter.array(), miter.array()));
229  }
230  aiter.next();
231  miter.next();
232  }
233  res.setMask (resMask);
234  }
235  // </group>
236 
237 
238  template<typename T>
240  const IPosition& boxShape,
241  const MArrayFunctorBase<T>& funcObj)
242  {
243  MArray<T> res;
244  boxedArrayMath (res, a, boxShape, funcObj);
245  return res;
246  }
247  template<typename T, typename RES>
249  const MArray<T>& array,
250  const IPosition& boxShape,
251  const MArrayFunctorBase<T,RES>& funcObj)
252  {
253  AlwaysAssert (array.hasMask(), AipsError);
254  const IPosition& shape = array.shape();
255  uInt ndim = shape.size();
256  IPosition fullBoxShape, resShape;
257  fillBoxedShape (shape, boxShape, fullBoxShape, resShape);
258  res.resize (resShape, False);
259  Array<Bool> resMask(resShape);
260  RES* data = res.array().data();
261  Bool* mask = resMask.data();
262  // Loop through all data and assemble as needed.
263  IPosition blc(ndim, 0);
264  IPosition trc(fullBoxShape-1);
265  while (True) {
266  Array<Bool> subMask (array.mask()(blc,trc));
267  if (allTrue(subMask)) {
268  *data++ = RES();
269  *mask++ = True;
270  } else {
271  *data++ = funcObj (MArray<T>(array.array()(blc,trc), subMask));
272  *mask++ = False;
273  }
274  uInt ax;
275  for (ax=0; ax<ndim; ++ax) {
276  blc[ax] += fullBoxShape[ax];
277  if (blc[ax] < shape[ax]) {
278  trc[ax] += fullBoxShape[ax];
279  if (trc[ax] >= shape[ax]) {
280  trc[ax] = shape[ax]-1;
281  }
282  break;
283  }
284  blc[ax] = 0;
285  trc[ax] = fullBoxShape[ax]-1;
286  }
287  if (ax == ndim) {
288  break;
289  }
290  }
291  res.setMask (resMask);
292  }
293 
294  template <typename T>
296  const IPosition& halfBoxShape,
297  const MArrayFunctorBase<T>& funcObj,
298  Bool fillEdge=True)
299  {
300  MArray<T> res;
301  slidingArrayMath (res, array, halfBoxShape, funcObj, fillEdge);
302  return res;
303  }
304  template <typename T, typename RES>
306  const MArray<T>& array,
307  const IPosition& halfBoxShape,
308  const MArrayFunctorBase<T,RES>& funcObj,
309  Bool fillEdge=True)
310  {
311  AlwaysAssert (array.hasMask(), AipsError);
312  const IPosition& shape = array.shape();
313  uInt ndim = shape.size();
314  IPosition boxEnd, resShape;
315  Bool empty = fillSlidingShape (shape, halfBoxShape, boxEnd, resShape);
316  if (fillEdge) {
317  res.resize (shape, False);
318  res.array() = RES();
319  Array<Bool> mask(shape, True);
320  res.setMask (mask);
321  } else {
322  res.resize (resShape, True);
323  }
324  if (!empty) {
325  Array<RES> resa (res.array());
326  Array<Bool> resm (res.mask());
327  if (fillEdge) {
328  IPosition boxEnd2 (boxEnd/2);
329  resa.reference (resa(boxEnd2, resShape+boxEnd2-1));
330  resm.reference (resm(boxEnd2, resShape+boxEnd2-1));
331  }
332  typename Array<RES>::iterator iterarr(resa.begin());
333  typename Array<Bool>::iterator itermask(resm.begin());
334  // Loop through all data and assemble as needed.
335  IPosition blc(ndim, 0);
336  IPosition trc(boxEnd);
337  IPosition pos(ndim, 0);
338  while (True) {
339  Array<Bool> subMask (array.mask()(blc,trc));
340  if (allTrue(subMask)) {
341  *iterarr = RES();
342  *itermask = True;
343  } else {
344  *iterarr = funcObj (MArray<T>(array.array()(blc,trc), subMask));
345  *itermask = False;
346  }
347  ++iterarr;
348  ++itermask;
349  uInt ax;
350  for (ax=0; ax<ndim; ++ax) {
351  if (++pos[ax] < resShape[ax]) {
352  blc[ax]++;
353  trc[ax]++;
354  break;
355  }
356  pos(ax) = 0;
357  blc[ax] = 0;
358  trc[ax] = boxEnd[ax];
359  }
360  if (ax == ndim) {
361  break;
362  }
363  }
364  }
365  }
366 
367 
368  // Add, subtract, etc. 2 arrays or array and scalar.
369  // <group>
370  template<typename T>
371  MArray<T> operator+ (const MArray<T>& left, const MArray<T>& right)
372  { return (left.isNull() || right.isNull() ? MArray<T>() :
373  MArray<T> (left.array() + right.array(),
374  left.combineMask(right))); }
375 
376  template<typename T>
377  MArray<T> operator- (const MArray<T>& left, const MArray<T>& right)
378  { return (left.isNull() || right.isNull() ? MArray<T>() :
379  MArray<T> (left.array() - right.array(),
380  left.combineMask(right))); }
381 
382  template<typename T>
383  MArray<T> operator* (const MArray<T>& left, const MArray<T>& right)
384  { return (left.isNull() || right.isNull() ? MArray<T>() :
385  MArray<T> (left.array() * right.array(),
386  left.combineMask(right))); }
387 
388  template<typename T>
389  MArray<T> operator/ (const MArray<T>& left, const MArray<T>& right)
390  { return (left.isNull() || right.isNull() ? MArray<T>() :
391  MArray<T> (left.array() / right.array(),
392  left.combineMask(right))); }
393 
394  template<typename T>
395  MArray<T> operator% (const MArray<T>& left, const MArray<T>& right)
396  { return (left.isNull() || right.isNull() ? MArray<T>() :
397  MArray<T> (left.array() % right.array(),
398  left.combineMask(right))); }
399 
400  template<typename T>
401  MArray<T> operator& (const MArray<T>& left, const MArray<T>& right)
402  { return (left.isNull() || right.isNull() ? MArray<T>() :
403  MArray<T> (left.array() & right.array(),
404  left.combineMask(right))); }
405 
406  template<typename T>
407  MArray<T> operator| (const MArray<T>& left, const MArray<T>& right)
408  { return (left.isNull() || right.isNull() ? MArray<T>() :
409  MArray<T> (left.array() | right.array(),
410  left.combineMask(right))); }
411 
412  template<typename T>
413  MArray<T> operator^ (const MArray<T>& left, const MArray<T>& right)
414  { return (left.isNull() || right.isNull() ? MArray<T>() :
415  MArray<T> (left.array() ^ right.array(),
416  left.combineMask(right))); }
417 
418  template<typename T>
419  MArray<T> operator+ (const MArray<T>& left, const T& right)
420  { return MArray<T> (left.array() + right, left); }
421 
422  template<typename T>
423  MArray<T> operator- (const MArray<T>& left, const T& right)
424  { return MArray<T> (left.array() - right, left); }
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 T& left, const MArray<T>& right)
452  { return MArray<T> (left + right.array(), right); }
453 
454  template<typename T>
455  MArray<T> operator- (const T& left, const MArray<T>& right)
456  { return MArray<T> (left - right.array(), right); }
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  // </group>
482 
483  // Negate the elements in an array.
484  template<typename T>
486  { return MArray<T> (-a.array(), a); }
487 
488  // Take the complement of the elements in an array.
489  template<typename T>
490  MArray<T> operator~ (const MArray<T>& a)
491  { return MArray<T> (~a.array(), a); }
492 
493  // Perform mathematical function on each element in an array.
494  // <group>
495  template<typename T>
497  { return MArray<T> (sin(a.array()), a); }
498 
499  template<typename T>
501  { return MArray<T> (cos(a.array()), a); }
502 
503  template<typename T>
505  { return MArray<T> (tan(a.array()), a); }
506 
507  template<typename T>
509  { return MArray<T> (sinh(a.array()), a); }
510 
511  template<typename T>
513  { return MArray<T> (cosh(a.array()), a); }
514 
515  template<typename T>
517  { return MArray<T> (tanh(a.array()), a); }
518 
519  template<typename T>
521  { return MArray<T> (asin(a.array()), a); }
522 
523  template<typename T>
525  { return MArray<T> (acos(a.array()), a); }
526 
527  template<typename T>
529  { return MArray<T> (atan(a.array()), a); }
530 
531  template<typename T>
532  MArray<T> atan2(const MArray<T>& left, const MArray<T>& right)
533  { return (left.isNull() || right.isNull() ? MArray<T>() :
534  MArray<T> (atan2(left.array(), right.array()),
535  left.combineMask(right))); }
536 
537  template<typename T>
538  MArray<T> atan2(const MArray<T>& left, const T& right)
539  { return MArray<T> (atan2(left.array(), right), left); }
540 
541  template<typename T>
542  MArray<T> atan2(const T& left, const MArray<T>& right)
543  { return MArray<T> (atan2(left, right.array()), right); }
544 
545  template<typename T>
547  { return MArray<T> (exp(a.array()), a); }
548 
549  template<typename T>
551  { return MArray<T> (log(a.array()), a); }
552 
553  template<typename T>
555  { return MArray<T> (log10(a.array()), a); }
556 
557  template<typename T>
559  { return MArray<T> (sqrt(a.array()), a); }
560 
561  template<typename T>
563  { return MArray<T> (square(a.array()), a); }
564 
565  template<typename T>
567  { return MArray<T> (cube(a.array()), a); }
568 
569  template<typename T>
570  MArray<T> pow(const MArray<T>& a, const MArray<T>& exp)
571  { return (a.isNull() || exp.isNull() ? MArray<T>() :
572  MArray<T> (pow(a.array(), exp.array()),
573  a.combineMask(exp))); }
574 
575  template<typename T>
576  MArray<T> pow(const T& a, const MArray<T>& exp)
577  { return MArray<T> (pow(a, exp.array()), exp); }
578 
579  template<typename T>
580  MArray<T> pow(const MArray<T>& a, const Double& exp)
581  { return MArray<T> (pow(a.array(), exp), a); }
582 
583  template<typename T>
584  MArray<T> min(const MArray<T>& left, const MArray<T>& right)
585  { return (left.isNull() || right.isNull() ? MArray<T>() :
586  MArray<T> (min(left.array(), right.array()),
587  left.combineMask(right))); }
588 
589  template<typename T>
590  MArray<T> min(const MArray<T>& left, const T& right)
591  { return MArray<T> (min(left.array(), right), left); }
592 
593  template<typename T>
594  MArray<T> min(const T& left, const MArray<T>& right)
595  { return MArray<T> (min(left, right.array()), right); }
596 
597  template<typename T>
598  MArray<T> max(const MArray<T>& left, const MArray<T>& right)
599  { return (left.isNull() || right.isNull() ? MArray<T>() :
600  MArray<T> (max(left.array(), right.array()),
601  left.combineMask(right))); }
602 
603  template<typename T>
604  MArray<T> max(const MArray<T>& left, const T& right)
605  { return MArray<T> (max(left.array(), right), left); }
606 
607  template<typename T>
608  MArray<T> max(const T& left, const MArray<T>& right)
609  { return MArray<T> (max(left, right.array()), right); }
610 
611  template<typename T>
613  { return MArray<T> (ceil(a.array()), a); }
614 
615  template<typename T>
617  { return MArray<T> (floor(a.array()), a); }
618 
619  template<typename T>
621  { return MArray<T> (round(a.array()), a); }
622 
623  template<typename T>
625  { return MArray<T> (sign(a.array()), a); }
626 
627  template<typename T>
629  { return MArray<T> (abs(a.array()), a); }
630 
631  template<typename T>
633  { return MArray<T> (fabs(a.array()), a); }
634 
635  template<typename T>
636  MArray<T> fmod(const MArray<T>& left, const MArray<T>& right)
637  { return (left.isNull() || right.isNull() ? MArray<T>() :
638  MArray<T> (fmod(left.array(), right.array()),
639  left.combineMask(right))); }
640 
641  template<typename T>
642  MArray<T> fmod(const MArray<T>& left, const T& right)
643  { return MArray<T> (fmod(left.array(), right), left); }
644 
645  template<typename T>
646  MArray<T> fmod(const T& left, const MArray<T>& right)
647  { return MArray<T> (fmod(left, right.array()), right); }
648 
649  template<typename T>
650  MArray<T> floormod(const MArray<T>& left, const MArray<T>& right)
651  { return (left.isNull() || right.isNull() ? MArray<T>() :
652  MArray<T> (floormod(left.array(), right.array()),
653  left.combineMask(right))); }
654 
655  template<typename T>
656  MArray<T> floormod(const MArray<T>& left, const T& right)
657  { return MArray<T> (floormod(left.array(), right), left); }
658 
659  template<typename T>
660  MArray<T> floormod(const T& left, const MArray<T>& right)
661  { return MArray<T> (floormod(left, right.array()), right); }
662 
663  template<typename T>
665  { return MArray<T> (conj(arr.array()), arr); }
666 
667  inline MArray<Float> real(const MArray<Complex> &arr)
668  { return MArray<Float> (real(arr.array()), arr); }
669 
670  inline MArray<Float> imag(const MArray<Complex> &arr)
671  { return MArray<Float> (imag(arr.array()), arr); }
672 
674  { return MArray<Float> (amplitude(arr.array()), arr); }
675 
677  { return MArray<Float> (phase(arr.array()), arr); }
678 
680  { return MArray<Double> (real(arr.array()), arr); }
681 
683  { return MArray<Double> (imag(arr.array()), arr); }
684 
686  { return MArray<Double> (amplitude(arr.array()), arr); }
687 
689  { return MArray<Double> (phase(arr.array()), arr); }
690  // </group>
691 
692 
693  // Reduce an array to a scalar using the unmasked elements only.
694  // The result is 0 if there are no unmasked elements.
695  // <group>
696  template<typename T>
697  T sum(const MArray<T>& a)
698  {
699  if (a.hasMask()) {
700  return a.array().contiguousStorage() && a.mask().contiguousStorage() ?
701  accumulateMasked<T>(a.array().cbegin(), a.array().cend(),
702  a.mask().cbegin(), T(), std::plus<T>()) :
703  accumulateMasked<T>(a.array().begin(), a.array().end(),
704  a.mask().begin(), T(), std::plus<T>());
705  }
706  return sum(a.array());
707  }
708 
709  template<typename T>
710  T sumsqr(const MArray<T>& a)
711  {
712  if (a.hasMask()) {
713  return a.array().contiguousStorage() && a.mask().contiguousStorage() ?
714  accumulateMasked<T>(a.array().cbegin(), a.array().cend(),
715  a.mask().cbegin(), T(), SumSqr<T>()) :
716  accumulateMasked<T>(a.array().begin(), a.array().end(),
717  a.mask().begin(), T(), SumSqr<T>());
718  }
719  return sumsqr(a.array());
720  }
721 
722  template<typename T>
723  T product(const MArray<T>& a)
724  {
725  if (a.hasMask()) {
726  return a.array().contiguousStorage() && a.mask().contiguousStorage() ?
727  accumulateMasked<T>(a.array().cbegin(), a.array().cend(),
728  a.mask().cbegin(), std::multiplies<T>()) :
729  accumulateMasked<T>(a.array().begin(), a.array().end(),
730  a.mask().begin(), std::multiplies<T>());
731  }
732  return product(a.array());
733  }
734 
735  template<typename T>
736  T min(const MArray<T>& a)
737  {
738  if (a.hasMask()) {
739  return a.array().contiguousStorage() && a.mask().contiguousStorage() ?
740  accumulateMasked<T>(a.array().cbegin(), a.array().cend(),
741  a.mask().cbegin(), Min<T>()) :
742  accumulateMasked<T>(a.array().begin(), a.array().end(),
743  a.mask().begin(), Min<T>());
744  }
745  return min(a.array());
746  }
747 
748  template<typename T>
749  T max(const MArray<T>& a)
750  {
751  if (a.hasMask()) {
752  return a.array().contiguousStorage() && a.mask().contiguousStorage() ?
753  accumulateMasked<T>(a.array().cbegin(), a.array().cend(),
754  a.mask().cbegin(), Max<T>()) :
755  accumulateMasked<T>(a.array().begin(), a.array().end(),
756  a.mask().begin(), Max<T>());
757  }
758  return max(a.array());
759  }
760 
761  template<typename T>
762  T mean(const MArray<T>& a)
763  {
764  Int64 nv = a.nvalid();
765  if (nv == 0) return T();
766  if (! a.hasMask()) return mean(a.array());
767  return T(sum(a) / (1.0*nv));
768  }
769 
770  template<typename T>
771  T variance(const MArray<T>& a, T mean)
772  {
773  Int64 nv = a.nvalid();
774  if (nv < 2) return T();
775  if (! a.hasMask()) return variance(a.array(), mean);
776  T sum = a.array().contiguousStorage() && a.mask().contiguousStorage() ?
777  accumulateMasked<T>(a.array().cbegin(), a.array().cend(),
778  a.mask().cbegin(), T(), SumSqrDiff<T>(mean)) :
779  accumulateMasked<T>(a.array().begin(), a.array().end(),
780  a.mask().begin(), T(), SumSqrDiff<T>(mean));
781  return T(sum / (1.0*nv - 1));
782  }
783 
784  template<typename T>
785  T variance(const MArray<T>& a)
786  {
787  return variance(a, mean(a));
788  }
789 
790  template<typename T>
791  T stddev(const MArray<T>& a)
792  {
793  return sqrt(variance(a));
794  }
795 
796  template<typename T>
797  T stddev(const MArray<T>& a, T mean)
798  {
799  return sqrt(variance(a, mean));
800  }
801 
802  template<typename T>
803  T avdev(const MArray<T>& a, T mean)
804  {
805  Int64 nv = a.nvalid();
806  if (nv == 0) return T();
807  if (! a.hasMask()) return avdev(a.array(), mean);
808  T sum = a.array().contiguousStorage() && a.mask().contiguousStorage() ?
809  accumulateMasked<T>(a.array().cbegin(), a.array().cend(),
810  a.mask().cbegin(), T(), SumAbsDiff<T>(mean)) :
811  accumulateMasked<T>(a.array().begin(), a.array().end(),
812  a.mask().begin(), T(), SumAbsDiff<T>(mean));
813  return T(sum / (1.0*nv));
814  }
815 
816  template<typename T>
817  T avdev(const MArray<T>& a)
818  {
819  return avdev(a, mean(a));
820  }
821 
822  template<typename T>
823  T rms(const MArray<T>& a)
824  {
825  Int64 nv = a.nvalid();
826  if (nv == 0) return T();
827  if (! a.hasMask()) return rms(a.array());
828  T sum = a.array().contiguousStorage() && a.mask().contiguousStorage() ?
829  accumulateMasked<T>(a.array().cbegin(), a.array().cend(),
830  a.mask().cbegin(), T(), SumSqr<T>()) :
831  accumulateMasked<T>(a.array().begin(), a.array().end(),
832  a.mask().begin(), T(), SumSqr<T>());
833  return T(sqrt(sum / (1.0*nv)));
834  }
835 
836  template<typename T>
837  T median(const MArray<T> &a, Bool sorted, Bool takeEvenMean,
838  Bool inPlace=False)
839  {
840  // The normal median function needs at least one element, so shortcut.
841  if (a.empty()) return T();
842  if (! a.hasMask()) return median(a.array(), sorted, takeEvenMean, inPlace);
843  Block<T> buf(a.size());
844  Int64 nv = a.flatten (buf.storage(), buf.size());
845  if (nv == 0) return T();
846  Array<T> arr(IPosition(1, nv), buf.storage(), SHARE);
847  // Median can be taken in place.
848  return median (arr, sorted, takeEvenMean, True);
849  }
850  template<typename T>
851  inline T median(const MArray<T> &a)
852  { return median (a, False, (a.size() <= 100), False); }
853  template<typename T>
854  inline T median(const MArray<T> &a, Bool sorted)
855  { return median (a, sorted, (a.nelements() <= 100), False); }
856  template<typename T>
857  inline T medianInPlace(const MArray<T> &a, Bool sorted = False)
858  { return median (a, sorted, (a.nelements() <= 100), True); }
859 
860  // Return the fractile of an array.
861  // It returns the value at the given fraction of the array.
862  // A fraction of 0.5 is the same as the median, be it that no mean of
863  // the two middle elements is taken if the array has an even nr of elements.
864  // It uses kthLargest if the array is not sorted yet.
865  template<typename T>
866  T fractile(const MArray<T> &a, Float fraction, Bool sorted=False,
867  Bool inPlace=False)
868  {
869  // The normal fractile function needs at least one element, so shortcut.
870  if (a.empty()) return T();
871  if (! a.hasMask()) return fractile(a.array(), fraction, sorted, inPlace);
872  Block<T> buf(a.size());
873  Int64 nv = a.flatten (buf.storage(), a.size());
874  if (nv == 0) return T();
875  Array<T> arr(IPosition(1, nv), buf.storage(), SHARE);
876  return fractile (arr, fraction, sorted, True);
877  }
878  // </group>
879 
880  // Get partial sums, etc.
881  // <group>
882  template<typename T>
884  const IPosition& collapseAxes)
885  {
886  if (a.isNull()) {
887  return MArray<T>();
888  } else if (! a.hasMask()) {
889  return MArray<T>(partialSums (a.array(), collapseAxes));
890  }
891  return partialArrayMath (a, collapseAxes, MSumFunc<T>());
892  }
893  template<typename T>
895  const IPosition& collapseAxes)
896  {
897  if (a.isNull()) {
898  return MArray<T>();
899  } else if (! a.hasMask()) {
900  return MArray<T>(partialArrayMath (a.array(), collapseAxes,
901  SumSqrFunc<T>()));
902  }
903  return partialArrayMath (a, collapseAxes, MSumSqrFunc<T>());
904  }
905  template<typename T>
907  const IPosition& collapseAxes)
908  {
909  if (a.isNull()) {
910  return MArray<T>();
911  } else if (! a.hasMask()) {
912  return MArray<T>(partialProducts (a.array(), collapseAxes));
913  }
914  return partialArrayMath (a, collapseAxes, MProductFunc<T>());
915  }
916  template<typename T>
918  const IPosition& collapseAxes)
919  {
920  if (a.isNull()) {
921  return MArray<T>();
922  } else if (! a.hasMask()) {
923  return MArray<T>(partialMins (a.array(), collapseAxes));
924  }
925  return partialArrayMath (a, collapseAxes, MMinFunc<T>());
926  }
927  template<typename T>
929  const IPosition& collapseAxes)
930  {
931  if (a.isNull()) {
932  return MArray<T>();
933  } else if (! a.hasMask()) {
934  return MArray<T>(partialMaxs (a.array(), collapseAxes));
935  }
936  return partialArrayMath (a, collapseAxes, MMaxFunc<T>());
937  }
938  template<typename T>
940  const IPosition& collapseAxes)
941  {
942  if (a.isNull()) {
943  return MArray<T>();
944  } else if (! a.hasMask()) {
945  return MArray<T>(partialMeans (a.array(), collapseAxes));
946  }
947  return partialArrayMath (a, collapseAxes, MMeanFunc<T>());
948  }
949  template<typename T>
951  const IPosition& collapseAxes)
952  {
953  if (a.isNull()) {
954  return MArray<T>();
955  } else if (! a.hasMask()) {
956  return MArray<T>(partialVariances (a.array(), collapseAxes));
957  }
958  return partialArrayMath (a, collapseAxes, MVarianceFunc<T>());
959  }
960  template<typename T>
962  const IPosition& collapseAxes)
963  {
964  if (a.isNull()) {
965  return MArray<T>();
966  } else if (! a.hasMask()) {
967  return MArray<T>(partialStddevs (a.array(), collapseAxes));
968  }
969  return partialArrayMath (a, collapseAxes, MStddevFunc<T>());
970  }
971  template<typename T>
973  const IPosition& collapseAxes)
974  {
975  if (a.isNull()) {
976  return MArray<T>();
977  } else if (! a.hasMask()) {
978  return MArray<T>(partialAvdevs (a.array(), collapseAxes));
979  }
980  return partialArrayMath (a, collapseAxes, MAvdevFunc<T>());
981  }
982  template<typename T>
984  const IPosition& collapseAxes)
985  {
986  if (a.isNull()) {
987  return MArray<T>();
988  } else if (! a.hasMask()) {
989  return MArray<T>(partialRmss (a.array(), collapseAxes));
990  }
991  return partialArrayMath (a, collapseAxes, MRmsFunc<T>());
992  }
993  template<typename T>
995  const IPosition& collapseAxes,
996  Bool takeEvenMean=False,
997  Bool inPlace=False)
998  {
999  if (a.isNull()) {
1000  return MArray<T>();
1001  } else if (! a.hasMask()) {
1002  return MArray<T>(partialMedians (a.array(), collapseAxes,
1003  takeEvenMean, inPlace));
1004  }
1005  return partialArrayMath (a, collapseAxes,
1006  MMedianFunc<T>(False, takeEvenMean, inPlace));
1007  }
1008  template<typename T>
1010  const IPosition& collapseAxes,
1011  Float fraction,
1012  Bool inPlace=False)
1013  {
1014  if (a.isNull()) {
1015  return MArray<T>();
1016  } else if (! a.hasMask()) {
1017  return MArray<T>(partialFractiles (a.array(), collapseAxes,
1018  fraction, inPlace));
1019  }
1020  return partialArrayMath (a, collapseAxes,
1021  MFractileFunc<T>(fraction, False, inPlace));
1022  }
1023  // </group>
1024 
1025  // Get sliding sums.
1026  // <group>
1027  template<typename T>
1029  const IPosition& halfBoxSize, Bool fillEdge=True)
1030  {
1031  if (a.isNull()) {
1032  return MArray<T>();
1033  } else if (! a.hasMask()) {
1034  return MArray<T>(slidingArrayMath (a.array(), halfBoxSize,
1035  SumFunc<T>(), fillEdge));
1036  }
1037  return slidingArrayMath (a, halfBoxSize, MSumFunc<T>(), fillEdge);
1038  }
1039  template<typename T>
1041  const IPosition& halfBoxSize, Bool fillEdge=True)
1042  {
1043  if (a.isNull()) {
1044  return MArray<T>();
1045  } else if (! a.hasMask()) {
1046  return MArray<T>(slidingArrayMath (a.array(), halfBoxSize,
1047  SumSqrFunc<T>(), fillEdge));
1048  }
1049  return slidingArrayMath (a, halfBoxSize, MSumSqrFunc<T>(), fillEdge);
1050  }
1051  template<typename T>
1053  const IPosition& halfBoxSize, Bool fillEdge=True)
1054  {
1055  if (a.isNull()) {
1056  return MArray<T>();
1057  } else if (! a.hasMask()) {
1058  return MArray<T>(slidingArrayMath (a.array(), halfBoxSize,
1059  ProductFunc<T>(), fillEdge));
1060  }
1061  return slidingArrayMath (a, halfBoxSize, MProductFunc<T>(), fillEdge);
1062  }
1063  template<typename T>
1065  const IPosition& halfBoxSize, Bool fillEdge=True)
1066  {
1067  if (a.isNull()) {
1068  return MArray<T>();
1069  } else if (! a.hasMask()) {
1070  return MArray<T>(slidingArrayMath (a.array(), halfBoxSize,
1071  MinFunc<T>(), fillEdge));
1072  }
1073  return slidingArrayMath (a, halfBoxSize, MMinFunc<T>(), fillEdge);
1074  }
1075  template<typename T>
1077  const IPosition& halfBoxSize, Bool fillEdge=True)
1078  {
1079  if (a.isNull()) {
1080  return MArray<T>();
1081  } else if (! a.hasMask()) {
1082  return MArray<T>(slidingArrayMath (a.array(), halfBoxSize,
1083  MaxFunc<T>(), fillEdge));
1084  }
1085  return slidingArrayMath (a, halfBoxSize, MMaxFunc<T>(), fillEdge);
1086  }
1087  template<typename T>
1089  const IPosition& halfBoxSize, Bool fillEdge=True)
1090  {
1091  if (a.isNull()) {
1092  return MArray<T>();
1093  } else if (! a.hasMask()) {
1094  return MArray<T>(slidingArrayMath (a.array(), halfBoxSize,
1095  MeanFunc<T>(), fillEdge));
1096  }
1097  return slidingArrayMath (a, halfBoxSize, MMeanFunc<T>(), fillEdge);
1098  }
1099  template<typename T>
1101  const IPosition& halfBoxSize, Bool fillEdge=True)
1102  {
1103  if (a.isNull()) {
1104  return MArray<T>();
1105  } else if (! a.hasMask()) {
1106  return MArray<T>(slidingArrayMath (a.array(), halfBoxSize,
1107  VarianceFunc<T>(), fillEdge));
1108  }
1109  return slidingArrayMath (a, halfBoxSize, MVarianceFunc<T>(), fillEdge);
1110  }
1111  template<typename T>
1113  const IPosition& halfBoxSize, 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  StddevFunc<T>(), fillEdge));
1120  }
1121  return slidingArrayMath (a, halfBoxSize, MStddevFunc<T>(), fillEdge);
1122  }
1123  template<typename T>
1125  const IPosition& halfBoxSize, Bool fillEdge=True)
1126  {
1127  if (a.isNull()) {
1128  return MArray<T>();
1129  } else if (! a.hasMask()) {
1130  return MArray<T>(slidingArrayMath (a.array(), halfBoxSize,
1131  AvdevFunc<T>(), fillEdge));
1132  }
1133  return slidingArrayMath (a, halfBoxSize, MAvdevFunc<T>(), fillEdge);
1134  }
1135  template<typename T>
1137  const IPosition& halfBoxSize, Bool fillEdge=True)
1138  {
1139  if (a.isNull()) {
1140  return MArray<T>();
1141  } else if (! a.hasMask()) {
1142  return MArray<T>(slidingArrayMath (a.array(), halfBoxSize,
1143  RmsFunc<T>(), fillEdge));
1144  }
1145  return slidingArrayMath (a, halfBoxSize, MRmsFunc<T>(), fillEdge);
1146  }
1147  template<typename T>
1149  const IPosition& halfBoxSize,
1150  Bool takeEvenMean=False,
1151  Bool inPlace=False,
1152  Bool fillEdge=True)
1153  {
1154  if (a.isNull()) {
1155  return MArray<T>();
1156  } else if (! a.hasMask()) {
1157  return MArray<T>(slidingArrayMath (a.array(), halfBoxSize,
1158  MedianFunc<T>(False, takeEvenMean,
1159  inPlace),
1160  fillEdge));
1161  }
1162  return slidingArrayMath (a, halfBoxSize,
1163  MMedianFunc<T>(False, takeEvenMean, inPlace),
1164  fillEdge);
1165  }
1166  template<typename T>
1168  const IPosition& halfBoxSize,
1169  Float fraction,
1170  Bool inPlace=False,
1171  Bool fillEdge=True)
1172  {
1173  if (a.isNull()) {
1174  return MArray<T>();
1175  } else if (! a.hasMask()) {
1176  return MArray<T>(slidingArrayMath (a.array(), halfBoxSize,
1177  FractileFunc<T>(fraction, False,
1178  inPlace),
1179  fillEdge));
1180  }
1181  return slidingArrayMath (a, halfBoxSize,
1182  MFractileFunc<T>(fraction, False, inPlace),
1183  fillEdge);
1184  }
1185  // </group>
1186 
1187  // Get boxed sums.
1188  // <group>
1189  template<typename T>
1191  const IPosition& boxSize)
1192  {
1193  if (a.isNull()) {
1194  return MArray<T>();
1195  } else if (! a.hasMask()) {
1196  return MArray<T>(boxedArrayMath (a.array(), boxSize, SumFunc<T>()));
1197  }
1198  return boxedArrayMath (a, boxSize, MSumFunc<T>());
1199  }
1200  template<typename T>
1202  const IPosition& boxSize)
1203  {
1204  if (a.isNull()) {
1205  return MArray<T>();
1206  } else if (! a.hasMask()) {
1207  return MArray<T>(boxedArrayMath (a.array(), boxSize, SumSqrFunc<T>()));
1208  }
1209  return boxedArrayMath (a, boxSize, MSumSqrFunc<T>());
1210  }
1211  template<typename T>
1213  const IPosition& boxSize)
1214  {
1215  if (a.isNull()) {
1216  return MArray<T>();
1217  } else if (! a.hasMask()) {
1218  return MArray<T>(boxedArrayMath (a.array(), boxSize, ProductFunc<T>()));
1219  }
1220  return boxedArrayMath (a, boxSize, MProductFunc<T>());
1221  }
1222  template<typename T>
1224  const IPosition& boxSize)
1225  {
1226  if (a.isNull()) {
1227  return MArray<T>();
1228  } else if (! a.hasMask()) {
1229  return MArray<T>(boxedArrayMath (a.array(), boxSize, MinFunc<T>()));
1230  }
1231  return boxedArrayMath (a, boxSize, MMinFunc<T>());
1232  }
1233  template<typename T>
1235  const IPosition& boxSize)
1236  {
1237  if (a.isNull()) {
1238  return MArray<T>();
1239  } else if (! a.hasMask()) {
1240  return MArray<T>(boxedArrayMath (a.array(), boxSize, MaxFunc<T>()));
1241  }
1242  return boxedArrayMath (a, boxSize, MMaxFunc<T>());
1243  }
1244  template<typename T>
1246  const IPosition& boxSize)
1247  {
1248  if (a.isNull()) {
1249  return MArray<T>();
1250  } else if (! a.hasMask()) {
1251  return MArray<T>(boxedArrayMath (a.array(), boxSize, MeanFunc<T>()));
1252  }
1253  return boxedArrayMath (a, boxSize, MMeanFunc<T>());
1254  }
1255  template<typename T>
1257  const IPosition& boxSize)
1258  {
1259  if (a.isNull()) {
1260  return MArray<T>();
1261  } else if (! a.hasMask()) {
1262  return MArray<T>(boxedArrayMath (a.array(), boxSize, VarianceFunc<T>()));
1263  }
1264  return boxedArrayMath (a, boxSize, MVarianceFunc<T>());
1265  }
1266  template<typename T>
1268  const IPosition& boxSize)
1269  {
1270  if (a.isNull()) {
1271  return MArray<T>();
1272  } else if (! a.hasMask()) {
1273  return MArray<T>(boxedArrayMath (a.array(), boxSize, StddevFunc<T>()));
1274  }
1275  return boxedArrayMath (a, boxSize, MStddevFunc<T>());
1276  }
1277  template<typename T>
1279  const IPosition& boxSize)
1280  {
1281  if (a.isNull()) {
1282  return MArray<T>();
1283  } else if (! a.hasMask()) {
1284  return MArray<T>(boxedArrayMath (a.array(), boxSize, AvdevFunc<T>()));
1285  }
1286  return boxedArrayMath (a, boxSize, MAvdevFunc<T>());
1287  }
1288  template<typename T>
1290  const IPosition& boxSize)
1291  {
1292  if (a.isNull()) {
1293  return MArray<T>();
1294  } else if (! a.hasMask()) {
1295  return MArray<T>(boxedArrayMath (a.array(), boxSize, RmsFunc<T>()));
1296  }
1297  return boxedArrayMath (a, boxSize, MRmsFunc<T>());
1298  }
1299  template<typename T>
1301  const IPosition& boxSize,
1302  Bool takeEvenMean=False,
1303  Bool inPlace=False)
1304  {
1305  if (a.isNull()) {
1306  return MArray<T>();
1307  } else if (! a.hasMask()) {
1308  return MArray<T>(boxedArrayMath (a.array(), boxSize,
1309  MedianFunc<T>(False, takeEvenMean,
1310  inPlace)));
1311  }
1312  return boxedArrayMath (a, boxSize,
1313  MMedianFunc<T>(False, takeEvenMean, inPlace));
1314  }
1315  template<typename T>
1317  const IPosition& boxSize,
1318  Float fraction,
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  FractileFunc<T>(fraction, False,
1326  inPlace)));
1327  }
1328  return boxedArrayMath (a, boxSize,
1329  MFractileFunc<T>(fraction, False, inPlace));
1330  }
1331  // </group>
1332 
1333  // </group>
1334 
1335 } //# end namespace
1336 
1337 #endif
MArray< T > slidingRmss(const MArray< T > &a, const IPosition &halfBoxSize, Bool fillEdge=True)
Definition: MArrayMath.h:1136
A Vector of integers, for indexing into Array<T> objects.
Definition: IPosition.h:119
LatticeExprNode log10(const LatticeExprNode &expr)
void setMask(const Array< Bool > &mask)
Set the mask.
Bool isNull() const
Is the array null?
Definition: MArrayBase.h:111
MArray< T > slidingVariances(const MArray< T > &a, const IPosition &halfBoxSize, Bool fillEdge=True)
Definition: MArrayMath.h:1100
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.
Definition: ExprNode.h:56
MArray< T > partialAvdevs(const MArray< T > &a, const IPosition &collapseAxes)
Definition: MArrayMath.h:972
LatticeExprNode log(const LatticeExprNode &expr)
void boxedArrayMath(MArray< RES > &res, const MArray< T > &array, const IPosition &boxShape, const MArrayFunctorBase< T, RES > &funcObj)
Definition: MArrayMath.h:248
MArray< Double > phase(const MArray< DComplex > &arr)
Definition: MArrayMath.h:688
MArray< T > boxedMaxs(const MArray< T > &a, const IPosition &boxSize)
Definition: MArrayMath.h:1234
LatticeExprNode median(const LatticeExprNode &expr)
MArray< T > partialMins(const MArray< T > &a, const IPosition &collapseAxes)
Definition: MArrayMath.h:917
MArray< T > sin(const MArray< T > &a)
Perform mathematical function on each element in an array.
Definition: MArrayMath.h:496
MArray< T > fmod(const T &left, const MArray< T > &right)
Definition: MArrayMath.h:646
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:618
MArray< T > partialMaxs(const MArray< T > &a, const IPosition &collapseAxes)
Definition: MArrayMath.h:928
LatticeExprNode operator/(const LatticeExprNode &left, const LatticeExprNode &right)
MArray< Float > imag(const MArray< Complex > &arr)
Definition: MArrayMath.h:670
LatticeExprNode mask(const LatticeExprNode &expr)
This function returns the mask of the given expression.
T product(const TableVector< T > &tv)
Definition: TabVecMath.h:385
MArray< T > slidingArrayMath(const MArray< T > &array, const IPosition &halfBoxShape, const MArrayFunctorBase< T > &funcObj, Bool fillEdge=True)
Definition: MArrayMath.h:295
LatticeExprNode imag(const LatticeExprNode &expr)
Array< Bool > combineMask(const MArrayBase &other) const
Combine this and the other mask.
MArray< T > boxedFractiles(const MArray< T > &a, const IPosition &boxSize, Float fraction, Bool inPlace=False)
Definition: MArrayMath.h:1316
MFractileFunc(Float fraction, Bool sorted=False, Bool inPlace=False)
Definition: MArrayMath.h:160
void partialArrayMath(MArray< RES > &res, const MArray< T > &a, const IPosition &collapseAxes, const MArrayFunctorBase< T, RES > &funcObj)
Definition: MArrayMath.h:185
MArray< T > atan2(const MArray< T > &left, const MArray< T > &right)
Definition: MArrayMath.h:532
TableExprNode array(const TableExprNode &values, const TableExprNodeSet &shape)
Create an array of the given shape and fill it with the values.
Definition: ExprNode.h:2105
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:1148
TableExprNode phase(const TableExprNode &node)
The phase (i.e.
Definition: ExprNode.h:1624
Vector< T > flatten() const
Flatten the unmasked elements of the array to a vector.
Definition: MArray.h:184
MArray< T > atan2(const MArray< T > &left, const T &right)
Definition: MArrayMath.h:538
MArray< T > partialSumSqrs(const MArray< T > &a, const IPosition &collapseAxes)
Definition: MArrayMath.h:894
MArray< T > pow(const MArray< T > &a, const MArray< T > &exp)
Definition: MArrayMath.h:570
MArray< T > boxedMeans(const MArray< T > &a, const IPosition &boxSize)
Definition: MArrayMath.h:1245
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:1009
T medianInPlace(const MArray< T > &a, Bool sorted=False)
Definition: MArrayMath.h:857
LatticeExprNode exp(const LatticeExprNode &expr)
iterator begin()
Get the begin iterator object for any array.
Definition: Array.h:859
T sum(const MArray< T > &a)
Reduce an array to a scalar using the unmasked elements only.
Definition: MArrayMath.h:697
MArray< T > boxedMedians(const MArray< T > &a, const IPosition &boxSize, Bool takeEvenMean=False, Bool inPlace=False)
Definition: MArrayMath.h:1300
MArray< T > slidingProducts(const MArray< T > &a, const IPosition &halfBoxSize, Bool fillEdge=True)
Definition: MArrayMath.h:1052
MArray< Float > phase(const MArray< Complex > &arr)
Definition: MArrayMath.h:676
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:1212
MArray< T > min(const MArray< T > &left, const T &right)
Definition: MArrayMath.h:590
Define functors to perform a reduction function on an MArray object.
Definition: MArrayMath.h:95
const ssize_t * storage() const
Get the storage.
Definition: IPosition.h:607
MArray< T > partialProducts(const MArray< T > &a, const IPosition &collapseAxes)
Definition: MArrayMath.h:906
MArray< T > slidingFractiles(const MArray< T > &a, const IPosition &halfBoxSize, Float fraction, Bool inPlace=False, Bool fillEdge=True)
Definition: MArrayMath.h:1167
LatticeExprNode cos(const LatticeExprNode &expr)
contiter cbegin()
Get the begin iterator object for a contiguous array.
Definition: Array.h:871
T median(const MArray< T > &a, Bool sorted, Bool takeEvenMean, Bool inPlace=False)
Definition: MArrayMath.h:837
MArray< T > max(const MArray< T > &left, const MArray< T > &right)
Definition: MArrayMath.h:598
const Array< Bool > & mask() const
Get the mask.
Definition: MArrayBase.h:126
MArray< T > fmod(const MArray< T > &left, const MArray< T > &right)
Definition: MArrayMath.h:636
MArray< Float > amplitude(const MArray< Complex > &arr)
Definition: MArrayMath.h:673
void slidingArrayMath(MArray< RES > &res, const MArray< T > &array, const IPosition &halfBoxShape, const MArrayFunctorBase< T, RES > &funcObj, Bool fillEdge=True)
Definition: MArrayMath.h:305
MArray< T > partialArrayMath(const MArray< T > &a, const IPosition &collapseAxes, const MArrayFunctorBase< T > &funcObj)
Do partial reduction of an MArray object.
Definition: MArrayMath.h:176
T * data()
Get a pointer to the beginning of the array.
Definition: Array.h:600
Functor to get minimum of two values.
Definition: Functors.h:581
LatticeExprNode conj(const LatticeExprNode &expr)
Int64 nvalid() const
Return the number of valid array values, thus unflagged elements.
Definition: MArrayBase.h:132
Float pow(Float f1, Float f2)
Definition: math.h:90
T fractile(const MArray< T > &a, Float fraction, Bool sorted=False, Bool inPlace=False)
Return the fractile of an array.
Definition: MArrayMath.h:866
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:1076
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
const Array< T > & array() const
Get access to the array.
Definition: MArray.h:153
MArray< T > partialRmss(const MArray< T > &a, const IPosition &collapseAxes)
Definition: MArrayMath.h:983
size_t nelements() const
Definition: MArrayBase.h:154
MArray< T > floormod(const T &left, const MArray< T > &right)
Definition: MArrayMath.h:660
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:594
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:584
LatticeExprNode tan(const LatticeExprNode &expr)
MArray< T > slidingAvdevs(const MArray< T > &a, const IPosition &halfBoxSize, Bool fillEdge=True)
Definition: MArrayMath.h:1124
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
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:1278
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.
MArray< T > partialVariances(const MArray< T > &a, const IPosition &collapseAxes)
Definition: MArrayMath.h:950
TableExprNode cube(const TableExprNode &node)
Definition: ExprNode.h:1527
LatticeExprNode stddev(const LatticeExprNode &expr)
LatticeExprNode round(const LatticeExprNode &expr)
MArray< T > boxedSumSqrs(const MArray< T > &a, const IPosition &boxSize)
Definition: MArrayMath.h:1201
Iterate a const Array cursor through a const Array.
Definition: ArrayIter.h:174
float Float
Definition: aipstype.h:54
const Bool False
Definition: aipstype.h:44
MArray< T > boxedArrayMath(const MArray< T > &a, const IPosition &boxShape, const MArrayFunctorBase< T > &funcObj)
Definition: MArrayMath.h:239
TableExprNode shape(const TableExprNode &array)
Function operating on any scalar or array resulting in a Double array containing the shape...
Definition: ExprNode.h:2163
size_t size() const
Get the size.
Definition: MArrayBase.h:152
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:1064
TableExprNode operator|(const TableExprNode &left, const TableExprNode &right)
Definition: ExprNode.h:1362
LatticeExprNode atan2(const LatticeExprNode &left, const LatticeExprNode &right)
Numerical 2-argument functions.
simple 1-D array
Definition: ArrayIO.h:47
MArray< T > boxedRmss(const MArray< T > &a, const IPosition &boxSize)
Definition: MArrayMath.h:1289
MArray< T > partialMedians(const MArray< T > &a, const IPosition &collapseAxes, Bool takeEvenMean=False, Bool inPlace=False)
Definition: MArrayMath.h:994
MArray< T > slidingSumSqrs(const MArray< T > &a, const IPosition &halfBoxSize, Bool fillEdge=True)
Definition: MArrayMath.h:1040
LatticeExprNode operator+(const LatticeExprNode &expr)
Global functions operating on a LatticeExprNode.
MArray< T > floormod(const MArray< T > &left, const MArray< T > &right)
Definition: MArrayMath.h:650
LatticeExprNode fmod(const LatticeExprNode &left, const LatticeExprNode &right)
MArray< T > boxedStddevs(const MArray< T > &a, const IPosition &boxSize)
Definition: MArrayMath.h:1267
Bool empty() const
Is the array empty?
Definition: MArrayBase.h:139
MArray< T > boxedVariances(const MArray< T > &a, const IPosition &boxSize)
Definition: MArrayMath.h:1256
Base class for all Casacore library errors.
Definition: Error.h:134
LatticeExprNode asin(const LatticeExprNode &expr)
const IPosition & shape() const
Get the shape.
Definition: MArrayBase.h:147
Share means that the Array will just use the pointer (no copy), however the Array will NOT delete it ...
Definition: ArrayBase.h:64
LatticeExprNode mean(const LatticeExprNode &expr)
MArray< T > partialSums(const MArray< T > &a, const IPosition &collapseAxes)
Get partial sums, etc.
Definition: MArrayMath.h:883
TableExprNode rms(const TableExprNode &array)
Definition: ExprNode.h:1856
LatticeExprNode sinh(const LatticeExprNode &expr)
MArray< Double > amplitude(const MArray< DComplex > &arr)
Definition: MArrayMath.h:685
MArray< T > partialStddevs(const MArray< T > &a, const IPosition &collapseAxes)
Definition: MArrayMath.h:961
Bool hasMask() const
Is there a mask?
Definition: MArrayBase.h:119
LatticeExprNode acos(const LatticeExprNode &expr)
TableExprNode square(const TableExprNode &node)
Definition: ExprNode.h:1522
MArray< T > atan2(const T &left, const MArray< T > &right)
Definition: MArrayMath.h:542
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:1190
MArray< T > max(const MArray< T > &left, const T &right)
Definition: MArrayMath.h:604
MArray< T > fmod(const MArray< T > &left, const T &right)
Definition: MArrayMath.h:642
MArray< T > max(const T &left, const MArray< T > &right)
Definition: MArrayMath.h:608
MArray< T > slidingMeans(const MArray< T > &a, const IPosition &halfBoxSize, Bool fillEdge=True)
Definition: MArrayMath.h:1088
LatticeExprNode operator^(const LatticeExprNode &left, const LatticeExprNode &right)
TableExprNode operator &(const TableExprNode &left, const TableExprNode &right)
Definition: ExprNode.h:1357
MArray< T > partialMeans(const MArray< T > &a, const IPosition &collapseAxes)
Definition: MArrayMath.h:939
LatticeExprNode variance(const LatticeExprNode &expr)
LatticeExprNode ceil(const LatticeExprNode &expr)
MArray< T > pow(const T &a, const MArray< T > &exp)
Definition: MArrayMath.h:576
MArray< Double > real(const MArray< DComplex > &arr)
Definition: MArrayMath.h:679
MArray< Float > real(const MArray< Complex > &arr)
Definition: MArrayMath.h:667
MArray< T > floormod(const MArray< T > &left, const T &right)
Definition: MArrayMath.h:656
const Bool True
Definition: aipstype.h:43
this file contains all the compiler specific defines
Definition: mainpage.dox:28
MVBaseline operator*(const RotMatrix &left, const MVBaseline &right)
Rotate a Baseline vector with rotation matrix and other multiplications.
LatticeExprNode cosh(const LatticeExprNode &expr)
MArray< Double > imag(const MArray< DComplex > &arr)
Definition: MArrayMath.h:682
LatticeExprNode real(const LatticeExprNode &expr)
Functor to add squared diff of right and base value to left.
Definition: Functors.h:606
MArray< T > slidingStddevs(const MArray< T > &a, const IPosition &halfBoxSize, Bool fillEdge=True)
Definition: MArrayMath.h:1112
LatticeExprNode sin(const LatticeExprNode &expr)
Numerical 1-argument functions.
MArray< T > pow(const MArray< T > &a, const Double &exp)
Definition: MArrayMath.h:580
unsigned int uInt
Definition: aipstype.h:51
MMedianFunc(Bool sorted=False, Bool takeEvenMean=True, Bool inPlace=False)
Definition: MArrayMath.h:147
MArray< T > boxedMins(const MArray< T > &a, const IPosition &boxSize)
Definition: MArrayMath.h:1223
MArray< T > slidingSums(const MArray< T > &a, const IPosition &halfBoxSize, Bool fillEdge=True)
Get sliding sums.
Definition: MArrayMath.h:1028
TableExprNode amplitude(const TableExprNode &node)
The amplitude (i.e.
Definition: ExprNode.h:1616