28 #ifndef CASA_MARRAYMATH_H
29 #define CASA_MARRAYMATH_H
99 template<
typename T>
class MSumFunc :
public MArrayFunctorBase<T> {
104 template<
typename T>
class MSumSqrFunc :
public MArrayFunctorBase<T> {
107 T operator() (
const MArray<T>& arr)
const {
return sumsqr(arr); }
109 template<
typename T>
class MProductFunc :
public MArrayFunctorBase<T> {
114 template<
typename T>
class MMinFunc :
public MArrayFunctorBase<T> {
119 template<
typename T>
class MMaxFunc :
public MArrayFunctorBase<T> {
124 template<
typename T>
class MMeanFunc :
public MArrayFunctorBase<T> {
138 template<
typename T>
class MStddevFunc :
public MArrayFunctorBase<T> {
147 template<
typename T>
class MAvdevFunc :
public MArrayFunctorBase<T> {
152 template<
typename T>
class MRmsFunc :
public MArrayFunctorBase<T> {
157 template<
typename T>
class MMedianFunc :
public MArrayFunctorBase<T> {
161 : itsSorted(sorted), itsTakeEvenMean(takeEvenMean), itsInPlace(inPlace) {}
164 {
return median(arr, itsSorted, itsTakeEvenMean, itsInPlace); }
174 : itsFraction(fraction), itsSorted(sorted), itsInPlace(inPlace) {}
177 {
return fractile(arr, itsFraction, itsSorted, itsInPlace); }
190 const MArrayFunctorBase<T>& funcObj)
193 partialArrayMath (res, a, collapseAxes, funcObj);
196 template<
typename T,
typename RES>
200 const MArrayFunctorBase<T,RES>& funcObj)
232 RES* data = res.
array().data();
234 while (!aiter.pastEnd()) {
235 if (allTrue(miter.array())) {
240 *data++ = funcObj(
MArray<T> (aiter.array(), miter.array()));
253 const MArrayFunctorBase<T>& funcObj)
259 template<
typename T,
typename RES>
263 const MArrayFunctorBase<T,RES>& funcObj)
272 RES* data = res.
array().data();
279 if (allTrue(subMask)) {
287 for (ax=0; ax<
ndim; ++ax) {
288 blc[ax] += fullBoxShape[ax];
289 if (blc[ax] < shape[ax]) {
290 trc[ax] += fullBoxShape[ax];
291 if (trc[ax] >= shape[ax]) {
292 trc[ax] = shape[ax]-1;
297 trc[ax] = fullBoxShape[ax]-1;
306 template <
typename T>
309 const MArrayFunctorBase<T>& funcObj,
316 template <
typename T,
typename RES>
320 const MArrayFunctorBase<T,RES>& funcObj,
341 resa.reference (resa(boxEnd2, resShape+boxEnd2-1));
342 resm.reference (resm(boxEnd2, resShape+boxEnd2-1));
352 if (allTrue(subMask)) {
362 for (ax=0; ax<
ndim; ++ax) {
363 if (++pos[ax] < resShape[ax]) {
370 trc[ax] = boxEnd[ax];
731 return sumsqr(a.
array());
777 if (nv == 0)
return T();
779 return T(
sum(a) / (1.0*nv));
786 if (nv < ddof+1)
return T();
793 return T(sum / (1.0*nv - ddof));
818 if (nv == 0)
return T();
825 return T(sum / (1.0*nv));
838 if (nv == 0)
return T();
845 return T(
sqrt(sum / (1.0*nv)));
853 if (a.
empty())
return T();
857 if (nv == 0)
return T();
860 return median (arr, sorted, takeEvenMean,
True);
882 if (a.
empty())
return T();
886 if (nv == 0)
return T();
903 return partialArrayMath (a, collapseAxes,
MSumFunc<T>());
937 return partialArrayMath (a, collapseAxes,
MMinFunc<T>());
948 return partialArrayMath (a, collapseAxes,
MMaxFunc<T>());
959 return partialArrayMath (a, collapseAxes,
MMeanFunc<T>());
969 return MArray<T>(partialVariances (a.
array(), collapseAxes, ddof));
1005 return partialArrayMath (a, collapseAxes,
MRmsFunc<T>());
1007 template<
typename T>
1017 takeEvenMean, inPlace));
1019 return partialArrayMath (a, collapseAxes,
1022 template<
typename T>
1032 fraction, inPlace));
1034 return partialArrayMath (a, collapseAxes,
1041 template<
typename T>
1049 SumFunc<T>(), fillEdge));
1053 template<
typename T>
1061 SumSqrFunc<T>(), fillEdge));
1065 template<
typename T>
1073 ProductFunc<T>(), fillEdge));
1077 template<
typename T>
1085 MinFunc<T>(), fillEdge));
1089 template<
typename T>
1097 MaxFunc<T>(), fillEdge));
1101 template<
typename T>
1109 MeanFunc<T>(), fillEdge));
1113 template<
typename T>
1123 VarianceFunc<T>(ddof), fillEdge));
1127 template<
typename T>
1137 StddevFunc<T>(ddof), fillEdge));
1141 template<
typename T>
1149 AvdevFunc<T>(), fillEdge));
1153 template<
typename T>
1161 RmsFunc<T>(), fillEdge));
1165 template<
typename T>
1176 MedianFunc<T>(
False, takeEvenMean,
1184 template<
typename T>
1195 FractileFunc<T>(fraction,
False,
1207 template<
typename T>
1218 template<
typename T>
1229 template<
typename T>
1240 template<
typename T>
1251 template<
typename T>
1262 template<
typename T>
1273 template<
typename T>
1285 template<
typename T>
1297 template<
typename T>
1308 template<
typename T>
1319 template<
typename T>
1329 MedianFunc<T>(
False, takeEvenMean,
1335 template<
typename T>
1345 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.
bool contiguousStorage() const
Are the array data contiguous? If they are not contiguous, getStorage (see below) needs to make a cop...
MArray< T > partialAvdevs(const MArray< T > &a, const IPosition &collapseAxes)
MVarianceFunc(uInt ddof=0)
LatticeExprNode log(const LatticeExprNode &expr)
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.
T product(const TableVector< T > &tv)
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)
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 > 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)
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)
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)
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...
T sumsqr(const MArray< T > &a)
MArray< T > slidingFractiles(const MArray< T > &a, const IPosition &halfBoxSize, Float fraction, Bool inPlace=False, Bool fillEdge=True)
LatticeExprNode cos(const LatticeExprNode &expr)
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)
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)
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.
IPosition removeAxes(const IPosition &axes) const
Return an IPosition where the given axes are reoved.
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)
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)
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.
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.
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)
Share means that the Array will just use the pointer (no copy), however the Array will NOT delete it ...
LatticeExprNode mean(const LatticeExprNode &expr)
int floormod(int x, int y)
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)
iterator begin()
Get the begin iterator object for any array.
MArray< T > atan2(const T &left, const MArray< T > &right)
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)
contiter cbegin()
Get the begin iterator object for a contiguous array.
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)
T * data()
Get a pointer to the beginning of the array.
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)
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)
const IPosition & shape() const
The length of each axis.
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)
TableExprNode amplitude(const TableExprNode &node)
The amplitude (i.e.