26#ifndef CASA_MARRAYMATH_H
27#define CASA_MARRAYMATH_H
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>
200 const MArrayFunctorBase<T>& funcObj) {
205template <
typename T,
typename RES>
207 const MArrayFunctorBase<T, RES>& funcObj) {
229 for (Int64 i=0; i<nr; ++i) {
230 IPosition pos = findPos(i);
231 IPosition endPos = pos + cursorShape - 1;
232 *data[pos] = funcObj(MArray<T>(a.array()(pos,endPos), a.mask()(pos,endpos)));
238 RES* data = res.
array().data();
241 if (allTrue(miter.
array())) {
257 const MArrayFunctorBase<T>& funcObj) {
262template <
typename T,
typename RES>
264 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;
308 const MArrayFunctorBase<T>& funcObj,
Bool fillEdge =
True) {
313template <
typename T,
typename RES>
315 const MArrayFunctorBase<T, RES>& funcObj,
Bool fillEdge =
True) {
334 resa.
reference(resa(boxEnd2, resShape + boxEnd2 - 1));
335 resm.
reference(resm(boxEnd2, resShape + boxEnd2 - 1));
345 if (allTrue(subMask)) {
355 for (ax = 0; ax <
ndim; ++ax) {
356 if (++pos[ax] < resShape[ax]) {
363 trc[ax] = boxEnd[ax];
806 std::multiplies<T>())
808 std::multiplies<T>());
840 if (nv == 0)
return T();
842 return T(
sum(a) / (1.0 * nv));
848 if (nv < ddof + 1)
return T();
855 return T(
sum / (1.0 * nv - ddof));
876 if (nv == 0)
return T();
883 return T(
sum / (1.0 * nv));
894 if (nv == 0)
return T();
901 return T(
sqrt(
sum / (1.0 * nv)));
907 if (a.
empty())
return T();
911 if (nv == 0)
return T();
914 return median(arr, sorted, takeEvenMean,
True);
937 if (a.
empty())
return T();
941 if (nv == 0)
return T();
1003template <
typename T>
1012template <
typename T>
1021template <
typename T>
1030template <
typename T>
1039template <
typename T>
1049template <
typename T>
1063template <
typename T>
1072template <
typename T>
1081template <
typename T>
1090template <
typename T>
1099template <
typename T>
1108template <
typename T>
1117template <
typename T>
1127template <
typename T>
1137template <
typename T>
1146template <
typename T>
1155template <
typename T>
1162 MedianFunc<T>(
False, takeEvenMean, inPlace), fillEdge));
1166template <
typename T>
1173 FractileFunc<T>(fraction,
False, inPlace), fillEdge));
1181template <
typename T>
1190template <
typename T>
1199template <
typename T>
1208template <
typename T>
1217template <
typename T>
1226template <
typename T>
1235template <
typename T>
1244template <
typename T>
1253template <
typename T>
1262template <
typename T>
1271template <
typename T>
1282template <
typename T>
#define AlwaysAssert(expr, exception)
These marcos are provided for use instead of simply using the assert_ function directly.
bool contiguousStorage() const
Are the array data contiguous?
T * data()
Get a pointer to the beginning of the array.
iterator begin()
Get the begin iterator object for any array.
contiter cbegin()
Get the begin iterator object for a contiguous array.
virtual void reference(const Array< T > &other)
After invocation, this array and other reference the same storage.
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.
const Array< Bool > & mask() const
Get the mask.
size_t size() const
Get the size.
Bool hasMask() const
Is there a mask?
T operator()(const MArray< T > &arr) const
MFractileFunc(Float fraction, Bool sorted=False, Bool inPlace=False)
T operator()(const MArray< T > &arr) const
T operator()(const MArray< T > &arr) const
T operator()(const MArray< T > &arr) const
T operator()(const MArray< T > &arr) const
T operator()(const MArray< T > &arr) const
T operator()(const MArray< T > &arr) const
T operator()(const MArray< T > &arr) const
Define functors to perform a reduction function on an MArray object.
T operator()(const MArray< T > &arr) const
T operator()(const MArray< T > &arr) const
MVarianceFunc(uInt ddof=0)
T operator()(const MArray< T > &arr) const
Vector< T > flatten() const
Flatten the unmasked elements of the array to a vector.
const Array< T > & array() const
Get access to the array.
void resize(const IPosition &shape, Bool useMask)
Resize the array and optionally the mask.
Iterate a const Array cursor through a const Array.
const Array< T > & 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 ...
For temporary backward namespace compatibility, use casa as alias for casacore.
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)
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)
LatticeExprNode tanh(const LatticeExprNode &expr)
LatticeExprNode sign(const LatticeExprNode &expr)
LatticeExprNode log10(const LatticeExprNode &expr)
LatticeExprNode conj(const LatticeExprNode &expr)
LatticeExprNode sinh(const LatticeExprNode &expr)
LatticeExprNode sum(const LatticeExprNode &expr)
T * array
The actual storage.
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.
TableExprNode phase(const TableExprNode &node)
The phase (i.e.
LatticeExprNode tan(const LatticeExprNode &expr)
LatticeExprNode mask(const LatticeExprNode &expr)
This function returns the mask of the given expression.
LatticeExprNode sin(const LatticeExprNode &expr)
Numerical 1-argument functions.
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)
Bool empty() const
Is the block empty (i.e.
LatticeExprNode sqrt(const LatticeExprNode &expr)
IPosition shape(const RecordFieldId &) const
Get the actual shape of this field.
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)
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 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)
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)
MArray< T > operator&(const T &left, const MArray< T > &right)
MArray< T > operator&(const MArray< T > &left, const T &right)
MArray< T > sqrt(const MArray< T > &a)
MArray< T > atan2(const MArray< T > &left, const T &right)
MArray< T > floormod(const MArray< T > &left, const T &right)
MArray< T > operator^(const MArray< T > &left, const MArray< T > &right)
T medianInPlace(const MArray< T > &a, Bool sorted=False)
MArray< T > floor(const MArray< T > &a)
MArray< Double > amplitude(const MArray< DComplex > &arr)
MArray< T > fmod(const MArray< T > &left, const T &right)
MArray< T > atan2(const T &left, const MArray< T > &right)
MArray< T > max(const T &left, const MArray< T > &right)
MArray< Double > phase(const MArray< DComplex > &arr)
MArray< T > pow(const MArray< T > &a, const T &exp)
MArray< T > operator|(const MArray< T > &left, const T &right)
T product(const MArray< T > &a)
MArray< T > operator*(const T &left, const MArray< T > &right)
MArray< T > partialRmss(const MArray< T > &a, const IPosition &collapseAxes)
MArray< T > tan(const MArray< T > &a)
MArray< T > cube(const MArray< T > &a)
MArray< T > max(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 > operator^(const T &left, const MArray< T > &right)
MArray< T > log10(const MArray< T > &a)
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.
T sum(const MArray< T > &a)
Reduce an array to a scalar using the unmasked elements only.
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 > square(const MArray< T > &a)
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 > cosh(const MArray< T > &a)
MArray< T > min(const MArray< T > &left, const T &right)
MArray< Float > phase(const MArray< Complex > &arr)
MArray< T > partialArrayMath(const MArray< T > &a, const IPosition &collapseAxes, const MArrayFunctorBase< T > &funcObj)
Do partial reduction of an MArray object.
MArray< std::complex< T > > pow(const MArray< std::complex< T > > &a, const T &exp)
MArray< T > operator%(const T &left, const MArray< T > &right)
MArray< T > operator%(const MArray< T > &left, const MArray< T > &right)
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.
MArray< T > operator/(const MArray< T > &left, const MArray< T > &right)
T avdev(const MArray< T > &a)
MArray< T > fmod(const T &left, const MArray< T > &right)
MArray< T > sign(const MArray< T > &a)
MArray< T > operator/(const MArray< T > &left, const T &right)
MArray< T > boxedArrayMath(const MArray< T > &a, const IPosition &boxShape, const MArrayFunctorBase< T > &funcObj)
MArray< T > abs(const MArray< T > &a)
MArray< T > operator*(const MArray< T > &left, const T &right)
MArray< T > floormod(const T &left, const MArray< T > &right)
MArray< T > boxedMeans(const MArray< T > &a, const IPosition &boxSize)
MArray< T > cos(const MArray< T > &a)
T rms(const MArray< T > &a)
MArray< T > operator+(const MArray< T > &left, const T &right)
MArray< T > boxedAvdevs(const MArray< T > &a, const IPosition &boxSize)
MArray< T > operator*(const MArray< T > &left, const MArray< T > &right)
MArray< T > log(const MArray< T > &a)
MArray< T > slidingSumSqrs(const MArray< T > &a, const IPosition &halfBoxSize, Bool fillEdge=True)
MArray< T > partialSumSqrs(const MArray< T > &a, const IPosition &collapseAxes)
MArray< T > operator&(const MArray< T > &left, const MArray< T > &right)
MArray< T > slidingArrayMath(const MArray< T > &array, const IPosition &halfBoxShape, const MArrayFunctorBase< T > &funcObj, Bool fillEdge=True)
T variance(const MArray< T > &a, T mean, uInt ddof)
T median(const MArray< T > &a, Bool sorted)
MArray< Double > imag(const MArray< DComplex > &arr)
MArray< T > operator+(const T &left, const MArray< T > &right)
MArray< T > operator%(const MArray< T > &left, const T &right)
MArray< T > acos(const MArray< T > &a)
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 > exp(const MArray< T > &a)
MArray< T > fmod(const MArray< T > &left, const MArray< T > &right)
MArray< T > boxedFractiles(const MArray< T > &a, const IPosition &boxSize, Float fraction, Bool inPlace=False)
T max(const MArray< T > &a)
MArray< T > sin(const MArray< T > &a)
Perform mathematical function on each element in an array.
MArray< T > partialMaxs(const MArray< T > &a, const IPosition &collapseAxes)
MArray< Double > real(const MArray< DComplex > &arr)
MArray< T > tanh(const MArray< T > &a)
T avdev(const MArray< T > &a, T mean)
MArray< T > min(const T &left, const MArray< T > &right)
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 > round(const MArray< T > &a)
MArray< T > operator^(const MArray< T > &left, const T &right)
MArray< T > slidingFractiles(const MArray< T > &a, const IPosition &halfBoxSize, Float fraction, Bool inPlace=False, Bool fillEdge=True)
MArray< T > ceil(const MArray< T > &a)
T min(const MArray< T > &a)
MArray< Float > amplitude(const MArray< Complex > &arr)
MArray< Float > imag(const MArray< Complex > &arr)
MArray< T > slidingStddevs(const MArray< T > &a, const IPosition &halfBoxSize, uInt ddof, Bool fillEdge=True)
MArray< T > operator-(const MArray< T > &left, const T &right)
MArray< T > partialStddevs(const MArray< T > &a, const IPosition &collapseAxes, uInt ddof)
T stddev(const MArray< T > &a, T mean, uInt ddof)
MArray< T > atan2(const MArray< T > &left, const MArray< T > &right)
MArray< T > asin(const MArray< T > &a)
MArray< T > operator-(const MArray< T > &a)
Negate the elements in an array.
MArray< T > boxedVariances(const MArray< T > &a, const IPosition &boxSize, uInt ddof)
T sumsqr(const MArray< T > &a)
MArray< T > boxedMaxs(const MArray< T > &a, const IPosition &boxSize)
T mean(const MArray< T > &a)
MArray< T > slidingMins(const MArray< T > &a, const IPosition &halfBoxSize, Bool fillEdge=True)
MArray< T > partialAvdevs(const MArray< T > &a, const IPosition &collapseAxes)
MArray< T > boxedSums(const MArray< T > &a, const IPosition &boxSize)
Get boxed sums.
MArray< T > atan(const MArray< T > &a)
MArray< T > partialMins(const MArray< T > &a, const IPosition &collapseAxes)
MArray< T > max(const MArray< T > &left, const T &right)
T median(const MArray< T > &a)
void boxedArrayMath(MArray< RES > &res, const MArray< T > &array, const IPosition &boxShape, const MArrayFunctorBase< T, RES > &funcObj)
MArray< T > operator-(const MArray< T > &left, const MArray< T > &right)
MArray< T > conj(const MArray< T > &arr)
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)
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.
MArray< T > partialMeans(const MArray< T > &a, const IPosition &collapseAxes)
MArray< T > operator|(const MArray< T > &left, const MArray< T > &right)
MArray< T > pow(const T &a, const MArray< T > &exp)
MArray< T > operator~(const MArray< T > &a)
Take the complement of the elements in an array.
MArray< T > partialVariances(const MArray< T > &a, const IPosition &collapseAxes, uInt ddof)
MArray< T > fabs(const MArray< T > &a)
MArray< T > min(const MArray< T > &left, const MArray< T > &right)
MArray< T > operator/(const T &left, const MArray< T > &right)
void partialArrayMath(MArray< RES > &res, const MArray< T > &a, const IPosition &collapseAxes, const MArrayFunctorBase< T, RES > &funcObj)
MArray< T > partialProducts(const MArray< T > &a, const IPosition &collapseAxes)
T variance(const MArray< T > &a, uInt ddof)
MArray< T > sinh(const MArray< T > &a)
T stddev(const MArray< T > &a, uInt ddof)
MArray< T > operator-(const T &left, const MArray< T > &right)
T median(const MArray< T > &a, Bool sorted, Bool takeEvenMean, Bool inPlace=False)
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)
MArray< T > slidingSums(const MArray< T > &a, const IPosition &halfBoxSize, Bool fillEdge=True)
Get sliding sums.
MArray< T > operator|(const T &left, const MArray< T > &right)
MArray< T > floormod(const MArray< T > &left, const MArray< T > &right)
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.