28 #ifndef CASA_MARRAYMATH_H
29 #define CASA_MARRAYMATH_H
95 template<
typename T>
class MSumFunc :
public MArrayFunctorBase<T> {
100 template<
typename T>
class MSumSqrFunc :
public MArrayFunctorBase<T> {
105 template<
typename T>
class MProductFunc :
public MArrayFunctorBase<T> {
110 template<
typename T>
class MMinFunc :
public MArrayFunctorBase<T> {
115 template<
typename T>
class MMaxFunc :
public MArrayFunctorBase<T> {
120 template<
typename T>
class MMeanFunc :
public MArrayFunctorBase<T> {
134 template<
typename T>
class MStddevFunc :
public MArrayFunctorBase<T> {
143 template<
typename T>
class MAvdevFunc :
public MArrayFunctorBase<T> {
148 template<
typename T>
class MRmsFunc :
public MArrayFunctorBase<T> {
153 template<
typename T>
class MMedianFunc :
public MArrayFunctorBase<T> {
157 : itsSorted(sorted), itsTakeEvenMean(takeEvenMean), itsInPlace(inPlace) {}
160 {
return median(arr, itsSorted, itsTakeEvenMean, itsInPlace); }
170 : itsFraction(fraction), itsSorted(sorted), itsInPlace(inPlace) {}
173 {
return fractile(arr, itsFraction, itsSorted, itsInPlace); }
186 const MArrayFunctorBase<T>& funcObj)
189 partialArrayMath (res, a, collapseAxes, funcObj);
192 template<
typename T,
typename RES>
196 const MArrayFunctorBase<T,RES>& funcObj)
230 while (!aiter.pastEnd()) {
231 if (allTrue(miter.array())) {
236 *data++ = funcObj(
MArray<T> (aiter.array(), miter.array()));
249 const MArrayFunctorBase<T>& funcObj)
255 template<
typename T,
typename RES>
259 const MArrayFunctorBase<T,RES>& funcObj)
275 if (allTrue(subMask)) {
283 for (ax=0; ax<
ndim; ++ax) {
284 blc[ax] += fullBoxShape[ax];
285 if (blc[ax] < shape[ax]) {
286 trc[ax] += fullBoxShape[ax];
287 if (trc[ax] >= shape[ax]) {
288 trc[ax] = shape[ax]-1;
293 trc[ax] = fullBoxShape[ax]-1;
302 template <
typename T>
305 const MArrayFunctorBase<T>& funcObj,
312 template <
typename T,
typename RES>
316 const MArrayFunctorBase<T,RES>& funcObj,
337 resa.reference (resa(boxEnd2, resShape+boxEnd2-1));
338 resm.reference (resm(boxEnd2, resShape+boxEnd2-1));
348 if (allTrue(subMask)) {
358 for (ax=0; ax<
ndim; ++ax) {
359 if (++pos[ax] < resShape[ax]) {
366 trc[ax] = boxEnd[ax];
709 accumulateMasked<T>(a.
array().cbegin(), a.
array().cend(),
711 accumulateMasked<T>(a.
array().begin(), a.
array().end(),
722 accumulateMasked<T>(a.
array().cbegin(), a.
array().cend(),
724 accumulateMasked<T>(a.
array().begin(), a.
array().end(),
727 return sumsqr(a.
array());
735 accumulateMasked<T>(a.
array().cbegin(), a.
array().cend(),
737 accumulateMasked<T>(a.
array().begin(), a.
array().end(),
748 accumulateMasked<T>(a.
array().cbegin(), a.
array().cend(),
750 accumulateMasked<T>(a.
array().begin(), a.
array().end(),
761 accumulateMasked<T>(a.
array().cbegin(), a.
array().cend(),
763 accumulateMasked<T>(a.
array().begin(), a.
array().end(),
773 if (nv == 0)
return T();
775 return T(
sum(a) / (1.0*nv));
782 if (nv < ddof+1)
return T();
785 accumulateMasked<T>(a.
array().cbegin(), a.
array().cend(),
787 accumulateMasked<T>(a.
array().begin(), a.
array().end(),
789 return T(sum / (1.0*nv - ddof));
814 if (nv == 0)
return T();
817 accumulateMasked<T>(a.
array().cbegin(), a.
array().cend(),
819 accumulateMasked<T>(a.
array().begin(), a.
array().end(),
821 return T(sum / (1.0*nv));
834 if (nv == 0)
return T();
837 accumulateMasked<T>(a.
array().cbegin(), a.
array().cend(),
839 accumulateMasked<T>(a.
array().begin(), a.
array().end(),
841 return T(
sqrt(sum / (1.0*nv)));
849 if (a.
empty())
return T();
853 if (nv == 0)
return T();
856 return median (arr, sorted, takeEvenMean,
True);
878 if (a.
empty())
return T();
882 if (nv == 0)
return T();
899 return partialArrayMath (a, collapseAxes,
MSumFunc<T>());
933 return partialArrayMath (a, collapseAxes,
MMinFunc<T>());
944 return partialArrayMath (a, collapseAxes,
MMaxFunc<T>());
955 return partialArrayMath (a, collapseAxes,
MMeanFunc<T>());
965 return MArray<T>(partialVariances (a.
array(), collapseAxes, ddof));
1001 return partialArrayMath (a, collapseAxes,
MRmsFunc<T>());
1003 template<
typename T>
1013 takeEvenMean, inPlace));
1015 return partialArrayMath (a, collapseAxes,
1018 template<
typename T>
1028 fraction, inPlace));
1030 return partialArrayMath (a, collapseAxes,
1037 template<
typename T>
1045 SumFunc<T>(), fillEdge));
1049 template<
typename T>
1057 SumSqrFunc<T>(), fillEdge));
1061 template<
typename T>
1069 ProductFunc<T>(), fillEdge));
1073 template<
typename T>
1081 MinFunc<T>(), fillEdge));
1085 template<
typename T>
1093 MaxFunc<T>(), fillEdge));
1097 template<
typename T>
1105 MeanFunc<T>(), fillEdge));
1109 template<
typename T>
1119 VarianceFunc<T>(ddof), fillEdge));
1123 template<
typename T>
1133 StddevFunc<T>(ddof), fillEdge));
1137 template<
typename T>
1145 AvdevFunc<T>(), fillEdge));
1149 template<
typename T>
1157 RmsFunc<T>(), fillEdge));
1161 template<
typename T>
1172 MedianFunc<T>(
False, takeEvenMean,
1180 template<
typename T>
1191 FractileFunc<T>(fraction,
False,
1203 template<
typename T>
1214 template<
typename T>
1225 template<
typename T>
1236 template<
typename T>
1247 template<
typename T>
1258 template<
typename T>
1269 template<
typename T>
1281 template<
typename T>
1293 template<
typename T>
1304 template<
typename T>
1315 template<
typename T>
1325 MedianFunc<T>(
False, takeEvenMean,
1331 template<
typename T>
1341 FractileFunc<T>(fraction,
False,
MArray< T > slidingRmss(const MArray< T > &a, const IPosition &halfBoxSize, Bool fillEdge=True)
A Vector of integers, for indexing into Array<T> objects.
LatticeExprNode log10(const LatticeExprNode &expr)
void setMask(const Array< Bool > &mask)
Set the mask.
MArray< T > exp(const MArray< T > &a)
long long Int64
Define the extra non-standard types used by Casacore (like proposed uSize, Size)
Class to handle an Array with an optional mask.
MArray< T > partialAvdevs(const MArray< T > &a, const IPosition &collapseAxes)
MVarianceFunc(uInt ddof=0)
LatticeExprNode log(const LatticeExprNode &expr)
Share means that the Array will just use the pointer (no copy), however the Array will NOT delete it ...
size_t size() const
Get the size.
void boxedArrayMath(MArray< RES > &res, const MArray< T > &array, const IPosition &boxShape, const MArrayFunctorBase< T, RES > &funcObj)
MArray< T > slidingStddevs(const MArray< T > &a, const IPosition &halfBoxSize, uInt ddof, Bool fillEdge=True)
MArray< Double > phase(const MArray< DComplex > &arr)
MArray< T > boxedMaxs(const MArray< T > &a, const IPosition &boxSize)
LatticeExprNode median(const LatticeExprNode &expr)
MArray< T > partialMins(const MArray< T > &a, const IPosition &collapseAxes)
MArray< T > sin(const MArray< T > &a)
Perform mathematical function on each element in an array.
MArray< T > fmod(const T &left, const MArray< T > &right)
Functor to add square of right to left.
Functor to add absolute diff of right and base value to left.
MArray< T > partialMaxs(const MArray< T > &a, const IPosition &collapseAxes)
LatticeExprNode operator/(const LatticeExprNode &left, const LatticeExprNode &right)
MArray< Float > imag(const MArray< Complex > &arr)
LatticeExprNode mask(const LatticeExprNode &expr)
This function returns the mask of the given expression.
Bool isNull() const
Is the array null?
MArray< T > slidingArrayMath(const MArray< T > &array, const IPosition &halfBoxShape, const MArrayFunctorBase< T > &funcObj, Bool fillEdge=True)
LatticeExprNode imag(const LatticeExprNode &expr)
MArray< T > boxedFractiles(const MArray< T > &a, const IPosition &boxSize, Float fraction, Bool inPlace=False)
MFractileFunc(Float fraction, Bool sorted=False, Bool inPlace=False)
void partialArrayMath(MArray< RES > &res, const MArray< T > &a, const IPosition &collapseAxes, const MArrayFunctorBase< T, RES > &funcObj)
MArray< T > atan2(const MArray< T > &left, const MArray< T > &right)
MArray< T > sinh(const MArray< T > &a)
MArray< T > tanh(const MArray< T > &a)
TableExprNode array(const TableExprNode &values, const TableExprNodeSet &shape)
Create an array of the given shape and fill it with the values.
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.
MArray< T > slidingMedians(const MArray< T > &a, const IPosition &halfBoxSize, Bool takeEvenMean=False, Bool inPlace=False, Bool fillEdge=True)
TableExprNode phase(const TableExprNode &node)
The phase (i.e.
MArray< T > atan2(const MArray< T > &left, const T &right)
MArray< T > boxedStddevs(const MArray< T > &a, const IPosition &boxSize, uInt ddof)
Vector< T > flatten() const
Flatten the unmasked elements of the array to a vector.
MArray< T > partialSumSqrs(const MArray< T > &a, const IPosition &collapseAxes)
T median(const MArray< T > &a, Bool sorted)
MArray< T > pow(const MArray< T > &a, const MArray< T > &exp)
MArray< T > boxedMeans(const MArray< T > &a, const IPosition &boxSize)
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)
T medianInPlace(const MArray< T > &a, Bool sorted=False)
T avdev(const MArray< T > &a, T mean)
TableExprNode operator&(const TableExprNode &left, const TableExprNode &right)
MArray< T > asin(const MArray< T > &a)
LatticeExprNode exp(const LatticeExprNode &expr)
iterator begin()
Get the begin iterator object for any array.
MArray< T > acos(const MArray< T > &a)
T sum(const MArray< T > &a)
Reduce an array to a scalar using the unmasked elements only.
MArray< T > boxedMedians(const MArray< T > &a, const IPosition &boxSize, Bool takeEvenMean=False, Bool inPlace=False)
MArray< T > slidingProducts(const MArray< T > &a, const IPosition &halfBoxSize, Bool fillEdge=True)
MArray< Float > phase(const MArray< Complex > &arr)
T variance(const MArray< T > &a, T mean, uInt ddof)
Bool contiguousStorage() const
Are the array data contiguous? If they are not contiguous, getStorage (see below) needs to make a cop...
MArray< T > floor(const MArray< T > &a)
LatticeExprNode floor(const LatticeExprNode &expr)
T stddev(const MArray< T > &a, uInt ddof)
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)
MArray< T > min(const MArray< T > &left, const T &right)
Define functors to perform a reduction function on an MArray object.
MArray< T > partialProducts(const MArray< T > &a, const IPosition &collapseAxes)
T sumsqr(const MArray< T > &a)
MArray< T > slidingFractiles(const MArray< T > &a, const IPosition &halfBoxSize, Float fraction, Bool inPlace=False, Bool fillEdge=True)
MVEarthMagnetic operator*(const RotMatrix &left, const MVEarthMagnetic &right)
Rotate a EarthMagnetic vector with rotation matrix and other multiplications.
LatticeExprNode cos(const LatticeExprNode &expr)
contiter cbegin()
Get the begin iterator object for a contiguous array.
T median(const MArray< T > &a, Bool sorted, Bool takeEvenMean, Bool inPlace=False)
MArray< T > max(const MArray< T > &left, const MArray< T > &right)
MArray< T > fmod(const MArray< T > &left, const MArray< T > &right)
MArray< Float > amplitude(const MArray< Complex > &arr)
ABSTRACT CLASSES Deliberately vague to be general enough to allow for many different types of data
void slidingArrayMath(MArray< RES > &res, const MArray< T > &array, const IPosition &halfBoxShape, const MArrayFunctorBase< T, RES > &funcObj, Bool fillEdge=True)
MArray< T > partialArrayMath(const MArray< T > &a, const IPosition &collapseAxes, const MArrayFunctorBase< T > &funcObj)
Do partial reduction of an MArray object.
MArray< T > partialVariances(const MArray< T > &a, const IPosition &collapseAxes, uInt ddof)
T * data()
Get a pointer to the beginning of the array.
Functor to get minimum of two values.
LatticeExprNode conj(const LatticeExprNode &expr)
T max(const MArray< T > &a)
Array< Bool > combineMask(const MArrayBase &other) const
Combine this and the other mask.
const ssize_t * storage() const
Get the storage.
MArray< T > tan(const MArray< T > &a)
T fractile(const MArray< T > &a, Float fraction, Bool sorted=False, Bool inPlace=False)
Return the fractile of an array.
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)
MArray< T > cube(const MArray< T > &a)
MArray< T > partialRmss(const MArray< T > &a, const IPosition &collapseAxes)
MArray< T > floormod(const T &left, const MArray< T > &right)
LatticeExprNode abs(const LatticeExprNode &expr)
Numerical 1-argument functions which result in a real number regardless of input expression type...
MArray< T > abs(const MArray< T > &a)
MArray< T > min(const T &left, const MArray< T > &right)
LatticeExprNode ndim(const LatticeExprNode &expr)
1-argument function to get the dimensionality of a lattice.
T median(const MArray< T > &a)
Bool fillSlidingShape(const IPosition &shape, const IPosition &halfBoxSize, IPosition &boxEnd, IPosition &resultShape)
Determine the box end and shape of result for a sliding operation.
MArray< T > sign(const MArray< T > &a)
LatticeExprNode sign(const LatticeExprNode &expr)
LatticeExprNode sqrt(const LatticeExprNode &expr)
MArray< T > min(const MArray< T > &left, const MArray< T > &right)
MArray< T > log10(const MArray< T > &a)
LatticeExprNode tan(const LatticeExprNode &expr)
MArray< T > slidingAvdevs(const MArray< T > &a, const IPosition &halfBoxSize, Bool fillEdge=True)
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...
T rms(const MArray< T > &a)
TableExprNode product(const TableExprNode &array)
bool Bool
Define the standard types used by Casacore.
T product(const MArray< T > &a)
MArray< T > boxedAvdevs(const MArray< T > &a, const IPosition &boxSize)
MaskedArray< T > boxedArrayMath(const MaskedArray< T > &array, const IPosition &boxSize, const FuncType &funcObj)
Apply the given ArrayMath reduction function objects to each box in the array.
TableExprNode cube(const TableExprNode &node)
LatticeExprNode stddev(const LatticeExprNode &expr)
MArray< T > atan(const MArray< T > &a)
MArray< T > cos(const MArray< T > &a)
LatticeExprNode round(const LatticeExprNode &expr)
MArray< T > boxedSumSqrs(const MArray< T > &a, const IPosition &boxSize)
MArray< T > cosh(const MArray< T > &a)
Iterate a const Array cursor through a const Array.
casacore::Bool empty() const
MArray< T > boxedArrayMath(const MArray< T > &a, const IPosition &boxShape, const MArrayFunctorBase< T > &funcObj)
TableExprNode shape(const TableExprNode &array)
Function operating on any scalar or array resulting in a Double array containing the shape...
void resize(const IPosition &shape, Bool useMask)
Resize the array and optionally the mask.
MArray< T > slidingMins(const MArray< T > &a, const IPosition &halfBoxSize, Bool fillEdge=True)
T variance(const MArray< T > &a, uInt ddof)
TableExprNode operator|(const TableExprNode &left, const TableExprNode &right)
LatticeExprNode atan2(const LatticeExprNode &left, const LatticeExprNode &right)
Numerical 2-argument functions.
MArray< T > boxedVariances(const MArray< T > &a, const IPosition &boxSize, uInt ddof)
MArray< T > round(const MArray< T > &a)
T stddev(const MArray< T > &a, T mean, uInt ddof)
MArray< T > boxedRmss(const MArray< T > &a, const IPosition &boxSize)
MArray< T > partialMedians(const MArray< T > &a, const IPosition &collapseAxes, Bool takeEvenMean=False, Bool inPlace=False)
T min(const MArray< T > &a)
MArray< T > slidingSumSqrs(const MArray< T > &a, const IPosition &halfBoxSize, Bool fillEdge=True)
MArray< T > conj(const MArray< T > &arr)
const Array< T > & array() const
Get access to the array.
LatticeExprNode operator+(const LatticeExprNode &expr)
Global functions operating on a LatticeExprNode.
Int64 nvalid() const
Return the number of valid array values, thus unflagged elements.
virtual casacore::Bool operator()(Flux< casacore::Double > &value, Flux< casacore::Double > &error, const casacore::MFrequency &mfreq, const casacore::Bool updatecoeffs)=0
MArray< T > floormod(const MArray< T > &left, const MArray< T > &right)
LatticeExprNode fmod(const LatticeExprNode &left, const LatticeExprNode &right)
Base class for all Casacore library errors.
LatticeExprNode asin(const LatticeExprNode &expr)
LatticeExprNode mean(const LatticeExprNode &expr)
MArray< T > partialSums(const MArray< T > &a, const IPosition &collapseAxes)
Get partial sums, etc.
TableExprNode rms(const TableExprNode &array)
LatticeExprNode sinh(const LatticeExprNode &expr)
MArray< Double > amplitude(const MArray< DComplex > &arr)
Bool hasMask() const
Is there a mask?
LatticeExprNode acos(const LatticeExprNode &expr)
TableExprNode square(const TableExprNode &node)
MArray< T > atan2(const T &left, const MArray< T > &right)
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 > ceil(const MArray< T > &a)
MArray< T > boxedSums(const MArray< T > &a, const IPosition &boxSize)
Get boxed sums.
MArray< T > max(const MArray< T > &left, const T &right)
MArray< T > fmod(const MArray< T > &left, const T &right)
MArray< T > max(const T &left, const MArray< T > &right)
MArray< T > slidingMeans(const MArray< T > &a, const IPosition &halfBoxSize, Bool fillEdge=True)
LatticeExprNode operator^(const LatticeExprNode &left, const LatticeExprNode &right)
MArray< T > slidingVariances(const MArray< T > &a, const IPosition &halfBoxSize, uInt ddof, Bool fillEdge=True)
MArray< T > log(const MArray< T > &a)
MArray< T > partialMeans(const MArray< T > &a, const IPosition &collapseAxes)
MArray< T > sqrt(const MArray< T > &a)
LatticeExprNode variance(const LatticeExprNode &expr)
LatticeExprNode ceil(const LatticeExprNode &expr)
LatticeExprNode pow(const LatticeExprNode &left, const LatticeExprNode &right)
MArray< T > pow(const T &a, const MArray< T > &exp)
MArray< Double > real(const MArray< DComplex > &arr)
MArray< Float > real(const MArray< Complex > &arr)
Bool empty() const
Is the array empty?
MArray< T > floormod(const MArray< T > &left, const T &right)
MArray< T > square(const MArray< T > &a)
T mean(const MArray< T > &a)
LatticeExprNode cosh(const LatticeExprNode &expr)
MArray< Double > imag(const MArray< DComplex > &arr)
const IPosition & shape() const
Get the shape.
T avdev(const MArray< T > &a)
LatticeExprNode real(const LatticeExprNode &expr)
Functor to add squared diff of right and base value to left.
MArray< T > partialStddevs(const MArray< T > &a, const IPosition &collapseAxes, uInt ddof)
LatticeExprNode sin(const LatticeExprNode &expr)
Numerical 1-argument functions.
MArray< T > pow(const MArray< T > &a, const Double &exp)
MArray< T > boxedMins(const MArray< T > &a, const IPosition &boxSize)
const Array< Bool > & mask() const
Get the mask.
MArray< T > slidingSums(const MArray< T > &a, const IPosition &halfBoxSize, Bool fillEdge=True)
Get sliding sums.
MArray< T > fabs(const MArray< T > &a)
#define casacore
<X11/Intrinsic.h> #defines true, false, casacore::Bool, and String.
TableExprNode amplitude(const TableExprNode &node)
The amplitude (i.e.