Go to the documentation of this file.
28 #ifndef CASA_ARRAYMATH_H
29 #define CASA_ARRAYMATH_H
31 #include <casacore/casa/aips.h>
32 #include <casacore/casa/BasicMath/Math.h>
33 #include <casacore/casa/BasicMath/Functors.h>
34 #include <casacore/casa/Arrays/Array.h>
36 #include <casacore/casa/BasicSL/Complex.h>
37 #include <casacore/casa/Utilities/Assert.h>
38 #include <casacore/casa/Exceptions/Error.h>
44 template<
class T>
class Matrix;
149 template<
typename _InputIterator1,
typename T,
150 typename _OutputIterator,
typename _BinaryOperation>
153 _OutputIterator __result, T left,
154 _BinaryOperation __binary_op)
156 for ( ; __first1 != __last1; ++__first1, ++__result)
157 *__result = __binary_op(left, *__first1);
160 template<
typename _InputIterator1,
typename T,
161 typename _OutputIterator,
typename _BinaryOperation>
164 _OutputIterator __result, T right,
165 _BinaryOperation __binary_op)
167 for ( ; __first1 != __last1; ++__first1, ++__result)
168 *__result = __binary_op(*__first1, right);
171 template<
typename _InputIterator1,
typename T,
172 typename _BinaryOperation>
176 _BinaryOperation __binary_op)
178 for ( ; __first1 != __last1; ++__first1)
179 *__first1 = __binary_op(*__first1, right);
191 template<
typename L,
typename R,
typename RES,
typename BinaryOperator>
207 template<
typename L,
typename R,
typename RES,
typename BinaryOperator>
214 result.
cbegin(), right, op);
218 myrtransform (left.
begin(), left.
end(),
219 result.
cbegin(), right, op);
227 template<
typename L,
typename R,
typename RES,
typename BinaryOperator>
234 result.
cbegin(), left, op);
238 myltransform (right.
begin(), right.
end(),
239 result.
cbegin(), left, op);
247 template<
typename T,
typename RES,
typename UnaryOperator>
261 template<
typename L,
typename R,
typename RES,
typename BinaryOperator>
267 template<
typename L,
typename R,
typename RES,
typename BinaryOperator>
268 void arrayTransform (
const Array<L>& left, R right,
273 template<
typename L,
typename R,
typename RES,
typename BinaryOperator>
274 void arrayTransform (L left,
const Array<R>& right,
279 template<
typename T,
typename RES,
typename UnaryOperator>
280 void arrayTransform (
const Array<T>& arr,
285 template<
typename T,
typename BinaryOperator>
291 template<
typename T,
typename BinaryOperator>
292 Array<T> arrayTransformResult (
const Array<T>& left, T right, BinaryOperator op);
296 template<
typename T,
typename BinaryOperator>
297 Array<T> arrayTransformResult (T left,
const Array<T>& right, BinaryOperator op);
301 template<
typename T,
typename UnaryOperator>
306 template<
typename L,
typename R,
typename BinaryOperator>
319 template<
typename L,
typename R,
typename BinaryOperator>
323 myiptransform (left.
cbegin(), left.
cend(), right, op);
326 myiptransform (left.
begin(), left.
end(), right, op);
334 template<
typename T,
typename UnaryOperator>
363 template<
class T>
void operator+= (
Array<T> &left,
const T &other);
364 template<
class T>
void operator-= (
Array<T> &left,
const T &other);
365 template<
class T>
void operator*= (
Array<T> &left,
const T &other);
366 template<
class T>
void operator/= (
Array<T> &left,
const T &other);
367 template<
class T>
void operator%= (
Array<T> &left,
const T &other);
368 template<
class T>
void operator&= (
Array<T> &left,
const T &other);
369 template<
class T>
void operator|= (
Array<T> &left,
const T &other);
370 template<
class T>
void operator^= (
Array<T> &left,
const T &other);
495 template<
class ScalarType>
501 template<
class ScalarType>
506 template<
class ScalarType>
507 void minMaxMasked(ScalarType &minVal, ScalarType &maxVal,
IPosition &minPos,
550 {
max (result, b, a); }
557 {
min (result, b, a); }
561 {
return max(b, a); }
565 {
return min(b, a); }
578 {
indgen(a, T(0), T(1)); }
584 {
indgen(a, start, T(1)); }
600 template<
class T> T sumsqr(
const Array<T> &a);
619 template<
class T> T pvariance(
const Array<T> &a,
uInt ddof=0);
626 template<
class T> T pstddev(
const Array<T> &a,
uInt ddof=0);
667 {
Block<T> tmp;
return median (a, tmp, sorted, takeEvenMean, inPlace); }
683 {
Block<T> tmp;
return madfm(a, tmp, sorted, takeEvenMean, inPlace); }
713 {
Block<T> tmp;
return interFractileRange(a, tmp, fraction, sorted, inPlace); }
725 {
return interFractileRange(a, tmp, 1./6., sorted, inPlace); }
728 {
return interFractileRange(a, 1./6., sorted, inPlace); }
737 {
return interFractileRange(a, tmp, 0.25, sorted, inPlace); }
740 {
return interFractileRange(a, 0.25, sorted, inPlace); }
748 void operator*= (
Array<std::complex<T> > &left,
const Array<T> &other);
750 void operator*= (
Array<std::complex<T> > &left,
const T &other);
752 void operator/= (
Array<std::complex<T> > &left,
const Array<T> &other);
754 void operator/= (
Array<std::complex<T> > &left,
const T &other);
801 template<
typename L,
typename R>
805 template<
typename R,
typename L>
879 template<
class T,
class U>
void convertArray(
Array<T> &to,
906 const T* in, T* out,
const IPosition& alternate);
927 #ifndef CASACORE_NO_AUTO_TEMPLATES
928 #include <casacore/casa/Arrays/ArrayMath.tcc>
929 #endif //# CASACORE_NO_AUTO_TEMPLATES
LatticeExprNode acos(const LatticeExprNode &expr)
Array< T > tan(const Array< T > &a)
LatticeExprNode stddev(const LatticeExprNode &expr)
void transformInPlace(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, BinaryOperator op)
Define a function to do a binary transform in place.
A Vector of integers, for indexing into Array<T> objects.
LatticeExprNode operator+(const LatticeExprNode &expr)
Global functions operating on a LatticeExprNode.
Mathematical operations for Arrays.
LatticeExprNode variance(const LatticeExprNode &expr)
T fractile(const Array< T > &a, Block< T > &tmp, Float fraction, Bool sorted=False, Bool inPlace=False)
Return the fractile of an array.
Array< T > abs(const Array< T > &a)
Array< T > operator&(const Array< T > &left, const Array< T > &right)
LatticeExprNode log(const LatticeExprNode &expr)
void arrayTransformInPlace(Array< L > &left, R right, BinaryOperator op)
Transform left and right in place using the binary operator.
void arrayTransform(const Array< L > &left, const Array< R > &right, Array< RES > &result, BinaryOperator op)
Transform left and right to a result using the binary operator.
void operator&=(Array< T > &left, const Array< T > &other)
T fractile(const Array< T > &a, Float fraction, Bool sorted=False, Bool inPlace=False)
void operator/=(Array< T > &left, const Array< T > &other)
Array< T > max(const T &a, const Array< T > &b)
LatticeExprNode real(const LatticeExprNode &expr)
LatticeExprNode log10(const LatticeExprNode &expr)
size_t nelements() const
How many elements does this array have? Product of all axis lengths.
Array< T > fmod(const Array< T > &a, const Array< T > &b)
void arrayContTransform(const Array< T > &arr, Array< RES > &result, UnaryOperator op)
Transform array to a result using the unary operator.
LatticeExprNode fmod(const LatticeExprNode &left, const LatticeExprNode &right)
Array< Complex > RealToComplex(const Array< Float > &rarray)
Copy an array of real,imaginary pairs into a complex array.
void myrtransform(_InputIterator1 __first1, _InputIterator1 __last1, _OutputIterator __result, T right, _BinaryOperation __binary_op)
sequence = sequence OP scalar
TableExprNode amplitude(const TableExprNode &node)
The amplitude (i.e.
T madfmInPlace(const Array< T > &a, Bool sorted=False)
void indgen(Array< T > &a)
Fills all elements of "array" with a sequence starting with 0 and ending with nelements() - 1.
void arrayTransformInPlace(Array< L > &left, const Array< R > &right, BinaryOperator op)
Transform left and right in place using the binary operator.
T interQuartileRange(const Array< T > &a, Bool sorted=False, Bool inPlace=False)
Array< Float > phase(const Array< Complex > &carray)
Extracts the phase (i.e.
Array< T > operator/(const Array< T > &left, const Array< T > &right)
Array< T > sqrt(const Array< T > &a)
LatticeExprNode abs(const LatticeExprNode &expr)
Numerical 1-argument functions which result in a real number regardless of input expression type.
Array< Float > amplitude(const Array< Complex > &carray)
Extracts the amplitude (i.e.
void setImag(Array< R > &carray, const Array< L > &rarray)
Set the imaginary part of the left complex array to right real array.
T avdev(const Array< T > &a)
The average deviation of "a" is the sum of abs(a(i) - mean(a))/N.
Array< T > operator%(const Array< T > &left, const Array< T > &right)
LatticeExprNode pow(const LatticeExprNode &left, const LatticeExprNode &right)
Array< std::complex< T > > makeComplex(const Array< T > &real, const Array< T > &imag)
Form an array of complex numbers from the given real arrays.
Array< T > floor(const Array< T > &a)
Array< T > sign(const Array< T > &a)
LatticeExprNode atan(const LatticeExprNode &expr)
T min(const Array< T > &a)
The minimum element of the array.
LatticeExprNode conj(const LatticeExprNode &expr)
LatticeExprNode sqrt(const LatticeExprNode &expr)
Array< T > square(const Array< T > &val)
Returns an array where every element is squared.
T sum(const Array< T > &a)
Sum of every element of the array.
LatticeExprNode mean(const LatticeExprNode &expr)
TableExprNode square(const TableExprNode &node)
LatticeExprNode tan(const LatticeExprNode &expr)
T pvariance(const Array< T > &a, uInt ddof=0)
T madfm(const Array< T > &a)
Array< T > operator-(const Array< T > &a)
T product(const Array< T > &a)
Product of every element of the array.
Array< Float > imag(const Array< Complex > &carray)
Extracts the imaginary part of a complex array into an array of floats.
Array< T > exp(const Array< T > &a)
T median(const Array< T > &a, Bool sorted)
T interHexileRange(const Array< T > &a, Block< T > &tmp, Bool sorted=False, Bool inPlace=False)
Return the inter-hexile range of an array.
Array< T > operator~(const Array< T > &a)
Array< T > sinh(const Array< T > &a)
Array< T > sin(const Array< T > &a)
Array< T > asin(const Array< T > &a)
T product(const TableVector< T > &tv)
LatticeExprNode cos(const LatticeExprNode &expr)
T rms(const Array< T > &a)
The root-mean-square of "a" is the sqrt of sum(a*a)/N.
T stddev(const Array< T > &a)
The standard deviation of "a" is the square root of its variance.
Array< T > tanh(const Array< T > &a)
Array< T > min(const T &a, const Array< T > &b)
void operator|=(Array< T > &left, const Array< T > &other)
Array< T > cube(const Array< T > &val)
Returns an array where every element is cubed.
Array< T > fabs(const Array< T > &a)
iterator begin()
Get the begin iterator object for any array.
#define DebugAssert(expr, exception)
Array< T > log10(const Array< T > &a)
void indgen(TableVector< T > &tv, Int start, Int inc)
T interQuartileRange(const Array< T > &a, Block< T > &tmp, Bool sorted=False, Bool inPlace=False)
Return the inter-quartile range of an array.
void minMax(ScalarType &minVal, ScalarType &maxVal, IPosition &minPos, IPosition &maxPos, const Array< ScalarType > &array)
Find the minimum and maximum values of an array, including their locations.
void minMaxMasked(ScalarType &minVal, ScalarType &maxVal, IPosition &minPos, IPosition &maxPos, const Array< ScalarType > &array, const Array< ScalarType > &weight)
The array * weight is searched
Array< Float > ComplexToReal(const Array< Complex > &carray)
Copy an array of complex into an array of real,imaginary pairs.
LatticeExprNode cosh(const LatticeExprNode &expr)
void convertArray(Array< T > &to, const Array< U > &from)
Make a copy of an array of a different type; for example make an array of doubles from an array of fl...
LatticeExprNode max(const LatticeExprNode &left, const LatticeExprNode &right)
LatticeExprNode atan2(const LatticeExprNode &left, const LatticeExprNode &right)
Numerical 2-argument functions.
LatticeExprNode sin(const LatticeExprNode &expr)
Numerical 1-argument functions.
contiter cbegin()
Get the begin iterator object for a contiguous array.
void max(Array< T > &result, const T &a, const Array< T > &b)
Array< T > log(const Array< T > &a)
void min(Array< T > &result, const T &a, const Array< T > &b)
TableExprNode cube(const TableExprNode &node)
Array< T > cosh(const Array< T > &a)
void arrayContTransform(const Array< L > &left, R right, Array< RES > &result, BinaryOperator op)
Transform left and right to a result using the binary operator.
Array< Complex > conj(const Array< Complex > &carray)
Returns the complex conjugate of a complex array.
T interFractileRange(const Array< T > &a, Float fraction, Bool sorted=False, Bool inPlace=False)
void operator+=(Array< T > &left, const Array< T > &other)
Element by element arithmetic modifying left in-place.
T madfm(const Array< T > &a, Bool sorted)
LatticeExprNode operator/(const LatticeExprNode &left, const LatticeExprNode &right)
LatticeExprNode ceil(const LatticeExprNode &expr)
void myiptransform(_InputIterator1 __first1, _InputIterator1 __last1, T right, _BinaryOperation __binary_op)
sequence OP= scalar
LatticeExprNode min(const LatticeExprNode &left, const LatticeExprNode &right)
Array< T > floormod(const Array< T > &a, const Array< T > &b)
T * expandRecursive(int axis, const IPosition &shp, const IPosition &mult, const IPosition &inSteps, const T *in, T *out, const IPosition &alternate)
Helper function for expandArray using recursion for each axis.
Array< T > operator|(const Array< T > &left, const Array< T > &right)
LatticeExprNode asin(const LatticeExprNode &expr)
this file contains all the compiler specific defines
void operator^=(Array< T > &left, const Array< T > &other)
TableExprNode array(const TableExprNode &values, const TableExprNodeSet &shape)
Create an array of the given shape and fill it with the values.
Array< T > atan2(const Array< T > &y, const Array< T > &x)
LatticeExprNode length(const LatticeExprNode &expr, const LatticeExprNode &axis)
2-argument function to get the length of an axis.
LatticeExprNode median(const LatticeExprNode &expr)
LatticeExprNode imag(const LatticeExprNode &expr)
T pstddev(const Array< T > &a, uInt ddof=0)
T median(const Array< T > &a)
TableExprNode phase(const TableExprNode &node)
The phase (i.e.
void arrayContTransform(const Array< L > &left, const Array< R > &right, Array< RES > &result, BinaryOperator op)
Functions to apply a binary or unary operator to arrays.
Array< T > round(const Array< T > &a)
LatticeExprNode operator%(const LatticeExprNode &left, const LatticeExprNode &right)
T mean(const Array< T > &a)
The mean of "a" is the sum of all elements of "a" divided by the number of elements of "a".
T madfm(const Array< T > &a, Block< T > &tmp, Bool sorted, Bool takeEvenMean, Bool inPlace=False)
The median absolute deviation from the median.
void indgen(Array< T > &a, T start, T inc)
Fills all elements of "array" with a sequence starting with "start" and incrementing by "inc" for eac...
LatticeExprNode mask(const LatticeExprNode &expr)
This function returns the mask of the given expression.
Array< Float > real(const Array< Complex > &carray)
Extracts the real part of a complex array into an array of floats.
LatticeExprNode operator^(const LatticeExprNode &left, const LatticeExprNode &right)
Array< T > cos(const Array< T > &a)
Transcendental function that can be applied to essentially all numeric types.
template <class T, class U> class vector;
LatticeExprNode tanh(const LatticeExprNode &expr)
LatticeExprNode sum(const LatticeExprNode &expr)
T median(const Array< T > &a, Block< T > &tmp, Bool sorted, Bool takeEvenMean, Bool inPlace=False)
The median of "a" is a(n/2).
Array< T > operator+(const Array< T > &a)
Unary arithmetic operation.
void minMax(T &min, T &max, const TableVector< T > &tv)
LatticeExprNode floor(const LatticeExprNode &expr)
bool Bool
Define the standard types used by Casacore.
void arrayTransformInPlace(Array< T > &arr, UnaryOperator op)
Transform the array in place using the unary operator.
Bool contiguousStorage() const
Are the array data contiguous? If they are not contiguous, getStorage (see below) needs to make a cop...
void indgen(Array< T > &a, T start)
Fills all elements of "array" with a sequence starting with start incremented by one for each positio...
IPosition checkExpandArray(IPosition &mult, IPosition &newInShape, const IPosition &inShape, const IPosition &outShape, const IPosition &alternate)
Check array shapes for expandArray.
TableExprNode rms(const TableExprNode &array)
A 1-D Specialization of the Array class.
LatticeExprNode avdev(const LatticeExprNode &expr)
void expandArray(Array< T > &out, const Array< T > &in, const IPosition &alternate=IPosition())
Expand the values of an array.
LatticeExprNode sign(const LatticeExprNode &expr)
T interHexileRange(const Array< T > &a, Bool sorted=False, Bool inPlace=False)
MVBaseline operator*(const RotMatrix &left, const MVBaseline &right)
Rotate a Baseline vector with rotation matrix and other multiplications.
Array< T > operator*(const Array< T > &left, const Array< T > &right)
TableExprNode operator|(const TableExprNode &left, const TableExprNode &right)
void operator-=(Array< T > &left, const Array< T > &other)
LatticeExprNode round(const LatticeExprNode &expr)
LatticeExprNode sinh(const LatticeExprNode &expr)
Base class for all Casacore library errors.
Array< T > operator^(const Array< T > &left, const Array< T > &right)
T madfm(const Array< T > &a, Bool sorted, Bool takeEvenMean, Bool inPlace=False)
TableExprNode operator&(const TableExprNode &left, const TableExprNode &right)
LatticeExprNode operator-(const LatticeExprNode &expr)
LatticeExprNode exp(const LatticeExprNode &expr)
T sumsqr(const Array< T > &a)
Sum the square of every element of the array.
void arrayContTransform(L left, const Array< R > &right, Array< RES > &result, BinaryOperator op)
Transform left and right to a result using the binary operator.
Array< T > arrayTransformResult(const Array< T > &left, const Array< T > &right, BinaryOperator op)
Transform left and right to a result using the binary operator.
Array< T > ceil(const Array< T > &a)
Array< T > acos(const Array< T > &a)
Transcendental function applied to the array on an element-by-element basis.
void setReal(Array< L > &carray, const Array< R > &rarray)
Set the real part of the left complex array to the right real array.
T medianInPlace(const Array< T > &a, Bool sorted=False)
Array< T > atan(const Array< T > &a)
void myltransform(_InputIterator1 __first1, _InputIterator1 __last1, _OutputIterator __result, T left, _BinaryOperation __binary_op)
The myxtransform functions are defined to avoid a bug in g++-4.3.
T max(const Array< T > &a)
The maximum element of the array.
Array< T > pow(const Array< T > &a, const Array< T > &b)
Vector< T > indgen(uInt length, T start, T inc)
Create a Vector of the given length and fill it with the start value incremented with inc for each el...
T interFractileRange(const Array< T > &a, Block< T > &tmp, Float fraction, Bool sorted=False, Bool inPlace=False)
Return the inter-fractile range of an array.
void operator*=(Array< T > &left, const Array< T > &other)
T median(const Array< T > &a, Bool sorted, Bool takeEvenMean, Bool inPlace=False)
T variance(const Array< T > &a)
The variance of "a" is the sum of (a(i) - mean(a))**2/(a.nelements() - ddof).
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.
void operator%=(Array< T > &left, const Array< T > &other)