26#ifndef CASA_ARRAYMATH_2_H
27#define CASA_ARRAYMATH_2_H
141 template<
typename _InputIterator1,
typename T,
142 typename _OutputIterator,
typename _BinaryOperation>
145 _OutputIterator __result, T left,
146 _BinaryOperation __binary_op)
148 for ( ; __first1 != __last1; ++__first1, ++__result)
149 *__result = __binary_op(left, *__first1);
152 template<
typename _InputIterator1,
typename T,
153 typename _OutputIterator,
typename _BinaryOperation>
156 _OutputIterator __result, T right,
157 _BinaryOperation __binary_op)
159 for ( ; __first1 != __last1; ++__first1, ++__result)
160 *__result = __binary_op(*__first1, right);
163 template<
typename _InputIterator1,
typename T,
164 typename _BinaryOperation>
168 _BinaryOperation __binary_op)
170 for ( ; __first1 != __last1; ++__first1)
171 *__first1 = __binary_op(*__first1, right);
183template<
typename L,
typename R,
typename RES,
typename BinaryOperator>
199template<
typename L,
typename R,
typename RES,
typename BinaryOperator>
206 result.
cbegin(), right, op);
211 result.
cbegin(), right, op);
219template<
typename L,
typename R,
typename RES,
typename BinaryOperator>
226 result.
cbegin(), left, op);
231 result.
cbegin(), left, op);
239template<
typename T,
typename RES,
typename UnaryOperator>
253template<
typename L,
typename R,
typename RES,
typename BinaryOperator>
259template<
typename L,
typename R,
typename RES,
typename BinaryOperator>
265template<
typename L,
typename R,
typename RES,
typename BinaryOperator>
271template<
typename T,
typename RES,
typename UnaryOperator>
277template<
typename T,
typename BinaryOperator>
283template<
typename T,
typename BinaryOperator>
288template<
typename T,
typename BinaryOperator>
293template<
typename T,
typename UnaryOperator>
298template<
typename L,
typename R,
typename BinaryOperator>
311template<
typename L,
typename R,
typename BinaryOperator>
326template<
typename T,
typename UnaryOperator>
365template<
typename T>
void operator-= (
Array<T> &left,
const T &other);
366template<
typename T>
void operator*= (
Array<T> &left,
const T &other)
370template<
typename T>
void operator/= (
Array<T> &left,
const T &other)
374template<
typename T>
void operator%= (
Array<T> &left,
const T &other);
375template<
typename T>
void operator&= (
Array<T> &left,
const T &other);
376template<
typename T>
void operator|= (
Array<T> &left,
const T &other);
377template<
typename T>
void operator^= (
Array<T> &left,
const T &other);
514template<
typename ScalarType>
520template<
typename ScalarType>
525template<
typename ScalarType>
569 {
max (result, b, a); }
576 {
min (result, b, a); }
580 {
return max(b, a); }
584 {
return min(b, a); }
597 {
indgen(a, T(0), T(1)); }
603 {
indgen(a, start, T(1)); }
683template<
typename T> T
median(
const Array<T> &a, std::vector<T> &scratch,
bool sorted,
684 bool takeEvenMean,
bool inPlace=
false);
688 { std::vector<T> scratch;
return median (a, scratch, sorted, takeEvenMean, inPlace); }
702template<
typename T> T
madfm(
const Array<T> &a, std::vector<T> &tmp,
bool sorted,
703 bool takeEvenMean,
bool inPlace =
false);
705template<
typename T> T
madfm(
const Array<T> &a,
bool sorted,
bool takeEvenMean,
707 { std::vector<T> tmp;
return madfm(a, tmp, sorted, takeEvenMean, inPlace); }
726 bool sorted=
false,
bool inPlace=
false);
729 bool sorted=
false,
bool inPlace=
false)
730 { std::vector<T> tmp;
return fractile (a, tmp, fraction, sorted, inPlace); }
738 bool sorted=
false,
bool inPlace=
false);
741 bool sorted=
false,
bool inPlace=
false)
754 bool sorted=
false,
bool inPlace=
false)
768 bool sorted=
false,
bool inPlace=
false)
785 [](std::complex<T> left, T right) {
return left*right; });
789void operator*= (
Array<std::complex<T>> &left,
const T &other)
792 [](std::complex<T> left, T right) {
return left*right; });
800 [](std::complex<T> left, T right) {
return left/right; });
804void operator/= (
Array<std::complex<T>> &left,
const T &other)
807 [](std::complex<T> left, T right) {
return left/right; });
817 [](std::complex<T> left, T right) {
return left*right; });
826 [](std::complex<T> left, T right) {
return left*right; });
835 [](std::complex<T> left, T right) {
return left*right; });
846 [](std::complex<T> l, T r) {
return l/r; });
855 [](std::complex<T> left, T right) {
return left/right; });
864 [](std::complex<T> left, T right) {
return left/right; });
874void conj(
Array<std::complex<float>> &rarray,
const Array<std::complex<float>> &carray);
875void conj(
Array<std::complex<double>> &rarray,
const Array<std::complex<double>> &carray);
895template<
typename C,
typename R>
899template<
typename C,
typename R>
973template<
typename T,
typename U>
986 const T* in, T* out,
const IPosition& alternate)
991 for (ssize_t j=0; j<mult[0]; ++j) {
993 for (ssize_t i=0; i<shp[0]; ++i) {
1000 for (ssize_t i=0; i<shp[0]; ++i) {
1001 for (ssize_t j=0; j<mult[0]; ++j) {
1008 if (alternate[axis]) {
1009 for (ssize_t j=0; j<mult[axis]; ++j) {
1011 for (ssize_t i=0; i<shp[axis]; ++i) {
1013 pin, out, alternate);
1014 pin += inSteps[axis];
1018 for (ssize_t i=0; i<shp[axis]; ++i) {
1019 for (ssize_t j=0; j<mult[axis]; ++j) {
1021 in, out, alternate);
1023 in += inSteps[axis];
1056 incp.
data(), outPtr, alt);
1080#include "ArrayMath.tcc"
const IPosition & steps() const
Return steps to be made if stepping one element in a dimension.
size_t ndim() const
The dimensionality of this array.
size_t nelements() const
How many elements does this array have?
bool contiguousStorage() const
Are the array data contiguous?
const IPosition & shape() const
The length of each axis.
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.
void putStorage(T *&storage, bool deleteAndCopy)
putStorage() is normally called after a call to getStorage() (cf).
virtual void reference(const Array< T > &other)
After invocation, this array and other reference the same storage.
Array< T > reform(const IPosition &shape) const
It is occasionally useful to have an array which access the same storage appear to have a different s...
T * getStorage(bool &deleteIt)
Generally use of this should be shunned, except to use a FORTRAN routine or something similar.
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.
TableExprNode operator|(const TableExprNode &left, const TableExprNode &right)
void checkArrayShapes(const ArrayBase &left, const ArrayBase &right, const char *name)
LatticeExprNode max(const LatticeExprNode &left, const LatticeExprNode &right)
void indgen(TableVector< T > &tv, T start, T inc)
TableExprNode operator&(const TableExprNode &left, const TableExprNode &right)
LatticeExprNode operator%(const LatticeExprNode &left, const LatticeExprNode &right)
LatticeExprNode operator+(const LatticeExprNode &expr)
Global functions operating on a LatticeExprNode.
TYPE * array
the allocated array
LatticeExprNode min(const LatticeExprNode &left, const LatticeExprNode &right)
LatticeExprNode operator-(const LatticeExprNode &expr)
LatticeExprNode mask(const LatticeExprNode &expr)
This function returns the mask of the given expression.
LatticeExprNode operator/(const LatticeExprNode &left, const LatticeExprNode &right)
LatticeExprNode length(const LatticeExprNode &expr, const LatticeExprNode &axis)
2-argument function to get the length of an axis.
StatAcc & operator+=(const StatAcc &)
T & operator*()
Provide access to the field's value.
LatticeExprNode operator^(const LatticeExprNode &left, const LatticeExprNode &right)
void transformInPlace(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, BinaryOperator op)
Define a function to do a binary transform in place.
LatticeExprNode median(const LatticeExprNode &expr)
void max(Array< T > &result, const T &a, const Array< T > &b)
Array< T > operator/(const Array< T > &left, const Array< T > &right)
Array< T > operator+(const Array< T > &a)
Unary arithmetic operation.
Array< double > amplitude(const Array< std::complex< double > > &carray)
Array< double > imag(const Array< std::complex< double > > &carray)
Array< T > arrayTransformResult(const Array< T > &left, T right, BinaryOperator op)
Transform left and right to a result using the binary operator.
Array< std::complex< T > > makeComplex(const Array< T > &real, const T &imag)
Array< T > log(const Array< T > &a)
void ComplexToReal(Array< float > &rarray, const Array< std::complex< float > > &carray)
Modify the array "rarray" in place.
void imag(Array< float > &rarray, const Array< std::complex< float > > &carray)
Modifies rarray in place.
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.
T interHexileRange(const Array< T > &a, bool sorted=false, bool inPlace=false)
TODO shouldn't take a const Array for in place sorting.
Array< float > phase(const Array< std::complex< float > > &carray)
Extracts the phase (i.e.
Array< T > operator-(const Array< T > &a)
Array< T > abs(const Array< T > &a)
Array< std::complex< T > > operator*(const std::complex< T > &left, const Array< T > &other)
Array< float > real(const Array< std::complex< float > > &carray)
Extracts the real part of a complex array into an array of floats.
T pvariance(const Array< T > &a, size_t ddof=0)
void arrayTransformInPlace(Array< T > &arr, UnaryOperator op)
Transform the array in place using the unary operator.
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".
void RealToComplex(Array< std::complex< double > > &carray, const Array< double > &rarray)
Array< T > operator|(const Array< T > &left, const Array< T > &right)
Vector< T > indgen(size_t 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...
Array< T > min(const T &a, const Array< T > &b)
T min(const Array< T > &a)
The minimum element of the array.
Array< double > ComplexToReal(const Array< std::complex< double > > &carray)
void min(Array< T > &result, const Array< T > &a, const Array< T > &b)
"result" contains the minimum of "a" and "b" at each position.
void conj(Array< std::complex< float > > &rarray, const Array< std::complex< float > > &carray)
Modifies rarray in place.
T interHexileRange(const Array< T > &a, std::vector< T > &tmp, bool sorted=false, bool inPlace=false)
Return the inter-hexile range of an array.
T median(const Array< T > &a, bool sorted, bool takeEvenMean, bool inPlace=false)
TODO shouldn't take a const Array for in place sorting.
T variance(const Array< T > &a)
The variance of "a" is the sum of (a(i) - mean(a))**2/(a.nelements() - ddof).
Array< T > floormod(const Array< T > &a, const T &b)
Array< T > pow(const Array< T > &a, const T &b)
T madfm(const Array< T > &a, std::vector< T > &tmp, bool sorted, bool takeEvenMean, bool inPlace=false)
The median absolute deviation from the median.
T avdev(const Array< T > &a)
The average deviation of "a" is the sum of abs(a(i) - mean(a))/N.
Array< T > fabs(const Array< T > &a)
void myiptransform(_InputIterator1 __first1, _InputIterator1 __last1, T right, _BinaryOperation __binary_op)
sequence OP= scalar
void operator/=(Array< T > &left, const Array< T > &other)
T fractile(const Array< T > &a, std::vector< T > &tmp, float fraction, bool sorted=false, bool inPlace=false)
Return the fractile of an array.
T interFractileRange(const Array< T > &a, std::vector< 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)
Array< double > phase(const Array< std::complex< double > > &carray)
Array< T > sin(const Array< T > &a)
Array< T > asin(const Array< T > &a)
Array< T > fmod(const Array< T > &a, const T &b)
void arrayContTransform(const Array< T > &arr, Array< RES > &result, UnaryOperator op)
Transform array to a result using the unary operator.
void arrayTransform(const Array< L > &left, R right, Array< RES > &result, BinaryOperator op)
Transform left and right to a result using the binary operator.
Array< T > floor(const Array< T > &a)
Array< T > sinh(const Array< T > &a)
Array< T > pow(const T &a, const Array< T > &b)
T madfm(const Array< T > &a, bool sorted, bool takeEvenMean, bool inPlace=false)
TODO shouldn't take a const Array for in place sorting.
T median(const Array< T > &a, bool sorted)
void operator|=(Array< T > &left, const Array< T > &other)
Array< T > arrayTransformResult(const Array< T > &left, const Array< T > &right, BinaryOperator op)
Transform left and right to a result using the binary operator.
void amplitude(Array< double > &rarray, const Array< std::complex< double > > &carray)
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...
T interQuartileRange(const Array< T > &a, bool sorted=false, bool inPlace=false)
TODO shouldn't take a const Array for in place sorting.
void arrayTransform(const Array< T > &arr, Array< RES > &result, UnaryOperator op)
Transform array to a result using the unary operator.
T madfm(const Array< T > &a)
Array< std::complex< float > > conj(const Array< std::complex< float > > &carray)
Returns the complex conjugate of a complex array.
T pstddev(const Array< T > &a, size_t ddof=0)
void setReal(Array< C > &carray, const Array< R > &rarray)
Set the real part of the left complex array to the right real array.
void ComplexToReal(Array< double > &rarray, const Array< std::complex< double > > &carray)
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...
void operator+=(Array< T > &left, const Array< T > &other)
Element by element arithmetic modifying left in-place.
void real(Array< float > &rarray, const Array< std::complex< float > > &carray)
Modifies rarray in place.
Array< T > pow(const Array< T > &a, const Array< T > &b)
Array< T > arrayTransformResult(const Array< T > &arr, UnaryOperator op)
Transform array to a result using the unary operator.
T medianInPlace(const Array< T > &a, bool sorted=false)
TODO shouldn't take a const Array for in place sorting.
void arrayTransformInPlace(Array< L > &left, R right, BinaryOperator op)
Transform left and right in place using the binary operator.
IPosition checkExpandArray(IPosition &mult, IPosition &newInShape, const IPosition &inShape, const IPosition &outShape, const IPosition &alternate)
Check array shapes for expandArray.
Array< T > ceil(const Array< T > &a)
Array< T > arrayTransformResult(T left, const Array< T > &right, BinaryOperator op)
Transform left and right to a result using the binary operator.
Array< float > amplitude(const Array< std::complex< float > > &carray)
Extracts the amplitude (i.e.
Array< T > atan2(const T &y, const Array< T > &x)
void arrayTransformInPlace(Array< L > &left, const Array< R > &right, BinaryOperator op)
Transform left and right in place using the binary operator.
T sumsqr(const Array< T > &a)
Sum the square of every element of the array.
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.
Array< float > imag(const Array< std::complex< float > > &carray)
Extracts the imaginary part of a complex array into an array of floats.
void phase(Array< double > &rarray, const Array< std::complex< double > > &carray)
Array< double > real(const Array< std::complex< double > > &carray)
Matrix< std::complex< float > > conj(const Matrix< std::complex< float > > &carray)
Array< std::complex< T > > pow(const Array< std::complex< T > > &a, const T &b)
Array< T > min(const Array< T > &a, const T &b)
Return an array that contains the minimum of "a" and "b" at each position.
Matrix< std::complex< double > > conj(const Matrix< std::complex< double > > &carray)
void minMax(T &min, T &max, const Array< T > &a)
The "min" and "max" functions require that the type "T" have comparison operators.
Array< T > max(const T &a, const Array< T > &b)
Array< T > operator*(const Array< T > &left, const Array< T > &right)
Array< T > tanh(const Array< T > &a)
Array< T > acos(const Array< T > &a)
Transcendental function applied to the array on an element-by-element basis.
Array< std::complex< float > > RealToComplex(const Array< float > &rarray)
Copy an array of real,imaginary pairs into a complex array.
Array< T > max(const Array< T > &a, const T &b)
Return an array that contains the maximum of "a" and "b" at each position.
void max(Array< T > &result, const Array< T > &a, const Array< T > &b)
"result" contains the maximum of "a" and "b" at each position.
Array< T > operator%(const Array< T > &left, const Array< T > &right)
void minMaxMasked(ScalarType &minVal, ScalarType &maxVal, IPosition &minPos, IPosition &maxPos, const Array< ScalarType > &array, const Array< ScalarType > &weight)
The array * weight is searched.
Array< T > cos(const Array< T > &a)
Transcendental function that can be applied to essentially all numeric types.
Array< T > sqrt(const Array< T > &a)
T stddev(const Array< T > &a, T mean)
Array< T > tan(const Array< T > &a)
void operator&=(Array< T > &left, const Array< T > &other)
T avdev(const Array< T > &a, T mean)
The average deviation of "a" is the sum of abs(a(i) - mean(a))/N.
T pvariance(const Array< T > &a, T mean, size_t ddof=0)
void expandArray(Array< T > &out, const Array< T > &in, const IPosition &alternate=IPosition())
Expand the values of an array.
void operator-=(Array< T > &left, const Array< T > &other)
Array< std::complex< T > > operator/(const std::complex< T > &left, const Array< T > &other)
T interQuartileRange(const Array< T > &a, std::vector< T > &tmp, bool sorted=false, bool inPlace=false)
Return the inter-quartile range of an array.
Array< T > sign(const Array< T > &a)
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.
Array< T > atan2(const Array< T > &y, const T &x)
Array< T > max(const Array< T > &a, const Array< T > &b)
Return an array that contains the maximum of "a" and "b" at each position.
void indgen(Array< T > &a, T start)
Fills all elements of "array" with a sequence starting with start incremented by one for each positio...
void imag(Array< double > &rarray, const Array< std::complex< double > > &carray)
Array< T > atan2(const Array< T > &y, const Array< T > &x)
T stddev(const Array< T > &a)
The standard deviation of "a" is the square root of its variance.
void myrtransform(_InputIterator1 __first1, _InputIterator1 __last1, _OutputIterator __result, T right, _BinaryOperation __binary_op)
sequence = sequence OP scalar
void max(Array< T > &result, const Array< T > &a, const T &b)
"result" contains the maximum of "a" and "b" at each position.
T sum(const Array< T > &a)
Sum of every element of the array.
void phase(Array< float > &rarray, const Array< std::complex< float > > &carray)
Modifies rarray in place.
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< std::complex< double > > RealToComplex(const Array< double > &rarray)
Array< T > round(const Array< T > &a)
void RealToComplex(Array< std::complex< float > > &carray, const Array< float > &rarray)
Modify the array "carray" in place.
T max(const Array< T > &a)
The maximum element of the array.
Array< T > square(const Array< T > &val)
Returns an array where every element is squared.
T madfm(const Array< T > &a, bool sorted)
T pstddev(const Array< T > &a, T mean, size_t ddof=0)
T product(const Array< T > &a)
Product of every element of the array.
void arrayTransform(L left, const Array< R > &right, Array< RES > &result, BinaryOperator op)
Transform left and right to a result using the binary operator.
Array< T > floormod(const T &a, const Array< T > &b)
void min(Array< T > &result, const T &a, const Array< T > &b)
T interFractileRange(const Array< T > &a, float fraction, bool sorted=false, bool inPlace=false)
TODO shouldn't take a const Array for in place sorting.
Array< T > operator&(const Array< T > &left, const Array< T > &right)
void arrayContTransform(const Array< L > &left, R right, Array< RES > &result, BinaryOperator op)
Transform left and right to a result using the binary operator.
void arrayContTransform(L left, const Array< R > &right, Array< RES > &result, BinaryOperator op)
Transform left and right to a result using the binary operator.
T median(const Array< T > &a, std::vector< T > &scratch, bool sorted, bool takeEvenMean, bool inPlace=false)
The median of "a" is a(n/2).
Array< T > floormod(const Array< T > &a, const Array< T > &b)
Array< std::complex< T > > makeComplex(const T &real, const Array< T > &imag)
void indgen(Array< T > &a)
Fills all elements of "array" with a sequence starting with 0 and ending with nelements() - 1.
T variance(const Array< T > &a, T mean)
Rather than using a computed mean, use the supplied value.
Array< T > operator~(const Array< T > &a)
Array< T > atan(const Array< T > &a)
Array< T > min(const Array< T > &a, const Array< T > &b)
Return an array that contains the minimum of "a" and "b" at each position.
void operator^=(Array< T > &left, const Array< T > &other)
Array< T > exp(const Array< T > &a)
T madfmInPlace(const Array< T > &a, bool sorted=false)
TODO shouldn't take a const Array for in place sorting.
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 operator*=(Array< T > &left, const Array< T > &other)
T fractile(const Array< T > &a, float fraction, bool sorted=false, bool inPlace=false)
TODO shouldn't take a const Array for in place sorting.
Array< T > cosh(const Array< T > &a)
void minMax(ScalarType &minVal, ScalarType &maxVal, IPosition &minPos, IPosition &maxPos, const Array< ScalarType > &array, const Array< bool > &mask, bool valid=true)
The array is searched at locations where the mask equals valid.
void min(Array< T > &result, const Array< T > &a, const T &b)
"result" contains the minimum of "a" and "b" at each position.
void amplitude(Array< float > &rarray, const Array< std::complex< float > > &carray)
Modifies rarray in place.
Array< T > cube(const Array< T > &val)
Returns an array where every element is cubed.
void real(Array< double > &rarray, const Array< std::complex< double > > &carray)
T median(const Array< T > &a)
Array< std::complex< double > > conj(const Array< std::complex< double > > &carray)
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< float > ComplexToReal(const Array< std::complex< float > > &carray)
Copy an array of complex into an array of real,imaginary pairs.
Array< T > fmod(const Array< T > &a, const Array< T > &b)
Array< T > log10(const Array< T > &a)
void setImag(Array< C > &carray, const Array< R > &rarray)
Set the imaginary part of the left complex array to right real array.
Array< T > operator^(const Array< T > &left, const Array< T > &right)
T rms(const Array< T > &a)
The root-mean-square of "a" is the sqrt of sum(a*a)/N.
void conj(Array< std::complex< double > > &rarray, const Array< std::complex< double > > &carray)
Array< T > fmod(const T &a, const Array< T > &b)