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