28 #ifndef CASA_MARRAYMATH_H
29 #define CASA_MARRAYMATH_H
32 #include <casacore/casa/aips.h>
33 #include <casacore/tables/TaQL/MArray.h>
34 #include <casacore/tables/TaQL/MArrayMathBase.h>
35 #include <casacore/casa/Arrays/ArrayPartMath.h>
36 #include <casacore/casa/Arrays/ArrayIter.h>
37 #include <casacore/casa/BasicMath/Functors.h>
38 #include <casacore/casa/Exceptions/Error.h>
39 #include <casacore/casa/Utilities/Assert.h>
40 #include <casacore/casa/Containers/Block.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)
235 if (allTrue(miter.
array())) {
253 const MArrayFunctorBase<T>& funcObj)
259 template<
typename T,
typename RES>
263 const MArrayFunctorBase<T,RES>& funcObj)
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,
#define AlwaysAssert(expr, exception)
These marcos are provided for use instead of simply using the constructors of assert_ to allow additi...
const IPosition & shape() const
The length of each axis.
bool contiguousStorage() const
Are the array data contiguous? If they are not contiguous, getStorage (see below) needs to make a cop...
virtual void reference(const Array< T, Alloc > &other)
After invocation, this array and other reference the same storage.
contiter cbegin()
Get the begin iterator object for a contiguous array.
iterator begin()
Get the begin iterator object for any array.
T * data()
Get a pointer to the beginning of the array.
T * storage()
If you really, really, need a "raw" pointer to the beginning of the storage area this will give it to...
IPosition removeAxes(const IPosition &axes) const
Return an IPosition where the given axes are reoved.
Int64 nvalid() const
Return the number of valid array values, thus unflagged elements.
Bool empty() const
Is the array empty?
Array< Bool > combineMask(const MArrayBase &other) const
Combine this and the other mask.
Bool isNull() const
Is the array null?
void setMask(const Array< Bool > &mask)
Set the mask.
size_t size() const
Get the size.
const Array< Bool > & mask() const
Get the mask.
Bool hasMask() const
Is there a mask?
MFractileFunc(Float fraction, Bool sorted=False, Bool inPlace=False)
Define functors to perform a reduction function on an MArray object.
MVarianceFunc(uInt ddof=0)
Vector< T > flatten() const
Flatten the unmasked elements of the array to a vector.
void resize(const IPosition &shape, Bool useMask)
Resize the array and optionally the mask.
const Array< T > & array() const
Get access to the array.
Iterate a const Array cursor through a const Array.
const Array< T, Alloc > & array()
Return the cursor.
void next()
Move the cursor to the next position.
@ SHARE
Share means that the Array will just use the pointer (no copy), however the Array will NOT delete it ...
int floormod(int x, int y)
this file contains all the compiler specific defines
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.
LatticeExprNode exp(const LatticeExprNode &expr)
TableExprNode operator|(const TableExprNode &left, const TableExprNode &right)
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)
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)
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.
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.
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 phase(const TableExprNode &node)
The phase (i.e.
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.
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.
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)
TableExprNode square(const TableExprNode &node)
LatticeExprNode sqrt(const LatticeExprNode &expr)
T product(const TableVector< T > &tv)
TableExprNode cube(const TableExprNode &node)
LatticeExprNode avdev(const LatticeExprNode &expr)
LatticeExprNode pow(const LatticeExprNode &left, const LatticeExprNode &right)
LatticeExprNode log(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...
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.
LatticeExprNode operator^(const LatticeExprNode &left, const LatticeExprNode &right)
LatticeExprNode cos(const LatticeExprNode &expr)
LatticeExprNode floor(const LatticeExprNode &expr)
LatticeExprNode median(const LatticeExprNode &expr)
LatticeExprNode round(const LatticeExprNode &expr)
LatticeExprNode ceil(const LatticeExprNode &expr)
LatticeExprNode real(const LatticeExprNode &expr)
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)
MArray< Double > real(const MArray< DComplex > &arr)
MArray< T > exp(const MArray< T > &a)
MArray< Float > real(const MArray< Complex > &arr)
MArray< T > partialSumSqrs(const MArray< T > &a, const IPosition &collapseAxes)
MArray< T > pow(const MArray< T > &a, const MArray< T > &exp)
MArray< T > max(const T &left, const MArray< T > &right)
MArray< Double > amplitude(const MArray< DComplex > &arr)
MArray< T > slidingVariances(const MArray< T > &a, const IPosition &halfBoxSize, uInt ddof, Bool fillEdge=True)
T medianInPlace(const MArray< T > &a, Bool sorted=False)
MArray< T > floormod(const MArray< T > &left, const T &right)
MArray< T > ceil(const MArray< T > &a)
MArray< T > boxedAvdevs(const MArray< T > &a, const IPosition &boxSize)
MArray< T > min(const T &left, const MArray< T > &right)
MArray< T > slidingMedians(const MArray< T > &a, const IPosition &halfBoxSize, Bool takeEvenMean=False, Bool inPlace=False, Bool fillEdge=True)
MArray< T > cos(const MArray< T > &a)
MArray< Double > phase(const MArray< DComplex > &arr)
MArray< T > partialMins(const MArray< T > &a, const IPosition &collapseAxes)
T product(const MArray< T > &a)
MArray< T > min(const MArray< T > &left, const MArray< T > &right)
void slidingArrayMath(MArray< RES > &res, const MArray< T > &array, const IPosition &halfBoxShape, const MArrayFunctorBase< T, RES > &funcObj, Bool fillEdge=True)
MArray< T > max(const MArray< T > &left, const MArray< T > &right)
MArray< T > boxedFractiles(const MArray< T > &a, const IPosition &boxSize, Float fraction, Bool inPlace=False)
MArray< T > partialStddevs(const MArray< T > &a, const IPosition &collapseAxes, uInt ddof)
T sum(const MArray< T > &a)
Reduce an array to a scalar using the unmasked elements only.
MArray< T > abs(const MArray< T > &a)
MArray< T > slidingFractiles(const MArray< T > &a, const IPosition &halfBoxSize, Float fraction, Bool inPlace=False, Bool fillEdge=True)
MArray< T > slidingArrayMath(const MArray< T > &array, const IPosition &halfBoxShape, const MArrayFunctorBase< T > &funcObj, Bool fillEdge=True)
MArray< T > partialMaxs(const MArray< T > &a, const IPosition &collapseAxes)
MArray< T > boxedSums(const MArray< T > &a, const IPosition &boxSize)
Get boxed sums.
MArray< T > slidingMeans(const MArray< T > &a, const IPosition &halfBoxSize, Bool fillEdge=True)
MArray< T > floormod(const T &left, const MArray< T > &right)
MArray< T > atan2(const MArray< T > &left, const T &right)
MArray< Float > phase(const MArray< Complex > &arr)
MArray< T > slidingProducts(const MArray< T > &a, const IPosition &halfBoxSize, Bool fillEdge=True)
MArray< T > slidingMaxs(const MArray< T > &a, const IPosition &halfBoxSize, Bool fillEdge=True)
MArray< T > floormod(const MArray< T > &left, const MArray< T > &right)
MArray< T > square(const MArray< T > &a)
MArray< T > boxedRmss(const MArray< T > &a, const IPosition &boxSize)
MArray< T > fmod(const MArray< T > &left, const T &right)
T avdev(const MArray< T > &a)
MArray< T > partialMedians(const MArray< T > &a, const IPosition &collapseAxes, Bool takeEvenMean=False, Bool inPlace=False)
MArray< T > sqrt(const MArray< T > &a)
MArray< T > tanh(const MArray< T > &a)
MArray< T > min(const MArray< T > &left, const T &right)
MArray< T > boxedMeans(const MArray< T > &a, const IPosition &boxSize)
MArray< Double > imag(const MArray< DComplex > &arr)
T rms(const MArray< T > &a)
MArray< T > slidingAvdevs(const MArray< T > &a, const IPosition &halfBoxSize, Bool fillEdge=True)
MArray< T > asin(const MArray< T > &a)
MArray< T > boxedSumSqrs(const MArray< T > &a, const IPosition &boxSize)
MArray< T > slidingSumSqrs(const MArray< T > &a, const IPosition &halfBoxSize, Bool fillEdge=True)
MArray< T > fmod(const MArray< T > &left, const MArray< T > &right)
MArray< T > log10(const MArray< T > &a)
MArray< T > sinh(const MArray< T > &a)
MArray< T > partialMeans(const MArray< T > &a, const IPosition &collapseAxes)
MArray< T > partialAvdevs(const MArray< T > &a, const IPosition &collapseAxes)
MArray< T > atan2(const MArray< T > &left, const MArray< T > &right)
MArray< T > slidingSums(const MArray< T > &a, const IPosition &halfBoxSize, Bool fillEdge=True)
Get sliding sums.
MArray< Float > imag(const MArray< Complex > &arr)
T variance(const MArray< T > &a, T mean, uInt ddof)
MArray< T > partialRmss(const MArray< T > &a, const IPosition &collapseAxes)
T median(const MArray< T > &a, Bool sorted)
MArray< T > pow(const T &a, const MArray< T > &exp)
T max(const MArray< T > &a)
MArray< T > partialFractiles(const MArray< T > &a, const IPosition &collapseAxes, Float fraction, Bool inPlace=False)
T avdev(const MArray< T > &a, T mean)
MArray< T > fmod(const T &left, const MArray< T > &right)
MArray< T > boxedMedians(const MArray< T > &a, const IPosition &boxSize, Bool takeEvenMean=False, Bool inPlace=False)
MArray< T > tan(const MArray< T > &a)
T min(const MArray< T > &a)
MArray< T > sin(const MArray< T > &a)
Perform mathematical function on each element in an array.
MArray< T > boxedStddevs(const MArray< T > &a, const IPosition &boxSize, uInt ddof)
MArray< T > partialVariances(const MArray< T > &a, const IPosition &collapseAxes, uInt ddof)
MArray< T > partialArrayMath(const MArray< T > &a, const IPosition &collapseAxes, const MArrayFunctorBase< T > &funcObj)
Do partial reduction of an MArray object.
MArray< T > log(const MArray< T > &a)
T stddev(const MArray< T > &a, T mean, uInt ddof)
MArray< T > atan(const MArray< T > &a)
MArray< T > slidingMins(const MArray< T > &a, const IPosition &halfBoxSize, Bool fillEdge=True)
MArray< T > atan2(const T &left, const MArray< T > &right)
MArray< Float > amplitude(const MArray< Complex > &arr)
MArray< T > slidingStddevs(const MArray< T > &a, const IPosition &halfBoxSize, uInt ddof, Bool fillEdge=True)
MArray< T > sign(const MArray< T > &a)
T sumsqr(const MArray< T > &a)
T mean(const MArray< T > &a)
MArray< T > boxedVariances(const MArray< T > &a, const IPosition &boxSize, uInt ddof)
MArray< T > cube(const MArray< T > &a)
MArray< T > max(const MArray< T > &left, const T &right)
MArray< T > boxedArrayMath(const MArray< T > &a, const IPosition &boxShape, const MArrayFunctorBase< T > &funcObj)
T median(const MArray< T > &a)
MArray< T > boxedMins(const MArray< T > &a, const IPosition &boxSize)
void boxedArrayMath(MArray< RES > &res, const MArray< T > &array, const IPosition &boxShape, const MArrayFunctorBase< T, RES > &funcObj)
MArray< T > conj(const MArray< T > &arr)
MArray< T > floor(const MArray< T > &a)
T fractile(const MArray< T > &a, Float fraction, Bool sorted=False, Bool inPlace=False)
Return the fractile of an array.
MArray< T > acos(const MArray< T > &a)
MArray< T > pow(const MArray< T > &a, const Double &exp)
MArray< T > partialSums(const MArray< T > &a, const IPosition &collapseAxes)
Get partial sums, etc.
MArray< T > boxedMaxs(const MArray< T > &a, const IPosition &boxSize)
MArray< T > cosh(const MArray< T > &a)
void partialArrayMath(MArray< RES > &res, const MArray< T > &a, const IPosition &collapseAxes, const MArrayFunctorBase< T, RES > &funcObj)
T variance(const MArray< T > &a, uInt ddof)
MArray< T > slidingRmss(const MArray< T > &a, const IPosition &halfBoxSize, Bool fillEdge=True)
MArray< T > fabs(const MArray< T > &a)
MArray< T > round(const MArray< T > &a)
T stddev(const MArray< T > &a, uInt ddof)
T median(const MArray< T > &a, Bool sorted, Bool takeEvenMean, Bool inPlace=False)
MArray< T > boxedProducts(const MArray< T > &a, const IPosition &boxSize)
MArray< T > partialProducts(const MArray< T > &a, const IPosition &collapseAxes)
Functor to get maximum of two values.
Functor to get minimum of two values.
Functor to add absolute diff of right and base value to left.
Functor to add squared diff of right and base value to left.
Functor to add square of right to left.