28 #ifndef CASA_ARRAYMATH_2_H
29 #define CASA_ARRAYMATH_2_H
143 template<
typename _InputIterator1,
typename T,
144 typename _OutputIterator,
typename _BinaryOperation>
147 _OutputIterator __result, T left,
148 _BinaryOperation __binary_op)
150 for ( ; __first1 != __last1; ++__first1, ++__result)
151 *__result = __binary_op(left, *__first1);
154 template<
typename _InputIterator1,
typename T,
155 typename _OutputIterator,
typename _BinaryOperation>
158 _OutputIterator __result, T right,
159 _BinaryOperation __binary_op)
161 for ( ; __first1 != __last1; ++__first1, ++__result)
162 *__result = __binary_op(*__first1, right);
165 template<
typename _InputIterator1,
typename T,
166 typename _BinaryOperation>
170 _BinaryOperation __binary_op)
172 for ( ; __first1 != __last1; ++__first1)
173 *__first1 = __binary_op(*__first1, right);
185 template<
typename L,
typename AllocL,
typename R,
typename AllocR,
typename RES,
typename AllocRES,
typename BinaryOperator>
201 template<
typename L,
typename AllocL,
typename R,
typename RES,
typename AllocRES,
typename BinaryOperator>
208 result.
cbegin(), right, op);
212 myrtransform (left.
begin(), left.
end(),
213 result.
cbegin(), right, op);
221 template<
typename L,
typename R,
typename AllocR,
typename RES,
typename AllocRES,
typename BinaryOperator>
228 result.
cbegin(), left, op);
232 myltransform (right.
begin(), right.
end(),
233 result.
cbegin(), left, op);
241 template<
typename T,
typename Alloc,
typename RES,
typename AllocRES,
typename UnaryOperator>
255 template<
typename L,
typename R,
typename RES,
typename BinaryOperator,
typename AllocL,
typename AllocR,
typename AllocRES>
261 template<
typename L,
typename R,
typename RES,
typename BinaryOperator,
typename Alloc,
typename AllocRES>
267 template<
typename L,
typename R,
typename RES,
typename BinaryOperator,
typename Alloc,
typename AllocRES>
273 template<
typename T,
typename RES,
typename UnaryOperator,
typename Alloc,
typename AllocRES>
279 template<
typename T,
typename BinaryOperator,
typename Alloc>
285 template<
typename T,
typename BinaryOperator,
typename Alloc>
290 template<
typename T,
typename BinaryOperator,
typename Alloc>
295 template<
typename T,
typename UnaryOperator,
typename Alloc>
300 template<
typename L,
typename R,
typename BinaryOperator,
typename AllocL,
typename AllocR>
313 template<
typename L,
typename R,
typename BinaryOperator,
typename Alloc>
317 myiptransform (left.
cbegin(), left.
cend(), right, op);
320 myiptransform (left.
begin(), left.
end(), right, op);
328 template<
typename T,
typename UnaryOperator,
typename Alloc>
348 arrayTransformInPlace (left, other, std::multiplies<T>());
354 arrayTransformInPlace (left, other, std::divides<T>());
366 template<
typename T,
typename Alloc>
void operator+= (
Array<T, Alloc> &left,
const T &other);
367 template<
typename T,
typename Alloc>
void operator-= (
Array<T, Alloc> &left,
const T &other);
368 template<
typename T,
typename Alloc>
void operator*= (
Array<T, Alloc> &left,
const T &other)
370 arrayTransformInPlace (left, other, std::multiplies<T>());
372 template<
typename T,
typename Alloc>
void operator/= (
Array<T, Alloc> &left,
const T &other)
374 arrayTransformInPlace (left, other, std::divides<T>());
376 template<
typename T,
typename Alloc>
void operator%= (
Array<T, Alloc> &left,
const T &other);
377 template<
typename T,
typename Alloc>
void operator&= (
Array<T, Alloc> &left,
const T &other);
378 template<
typename T,
typename Alloc>
void operator|= (
Array<T, Alloc> &left,
const T &other);
379 template<
typename T,
typename Alloc>
void operator^= (
Array<T, Alloc> &left,
const T &other);
393 template<
typename T,
typename Alloc>
395 template<
typename T,
typename Alloc>
397 template<
typename T,
typename Alloc>
401 return arrayTransformResult (left, right, std::multiplies<T>());
403 template<
typename T,
typename Alloc>
405 template<
typename T,
typename Alloc>
407 template<
typename T,
typename Alloc>
409 template<
typename T,
typename Alloc>
411 template<
typename T,
typename Alloc>
419 template<
typename T,
typename Alloc>
421 template<
typename T,
typename Alloc>
423 template<
class T,
typename Alloc>
426 return arrayTransformResult (left, right, std::multiplies<T>());
428 template<
typename T,
typename Alloc>
430 template<
typename T,
typename Alloc>
432 template<
typename T,
typename Alloc>
434 template<
typename T,
typename Alloc>
436 template<
typename T,
typename Alloc>
444 template<
typename T,
typename Alloc>
446 template<
typename T,
typename Alloc>
448 template<
class T,
typename Alloc>
451 return arrayTransformResult (left, right, std::multiplies<T>());
454 template<
typename T,
typename Alloc>
456 template<
typename T,
typename Alloc>
458 template<
typename T,
typename Alloc>
460 template<
typename T,
typename Alloc>
462 template<
typename T,
typename Alloc>
515 template<
typename ScalarType,
typename Alloc>
521 template<
typename ScalarType,
typename Alloc>
526 template<
typename ScalarType,
typename Alloc>
527 void minMaxMasked(ScalarType &minVal, ScalarType &maxVal,
IPosition &minPos,
570 {
max (result, b, a); }
577 {
min (result, b, a); }
581 {
return max(b, a); }
585 {
return min(b, a); }
598 {
indgen(a, T(0), T(1)); }
604 {
indgen(a, start, T(1)); }
620 template<
typename T,
typename Alloc> T sumsqr(
const Array<T, Alloc> &a);
639 template<
typename T,
typename Alloc> T pvariance(
const Array<T, Alloc> &a,
size_t ddof=0);
642 template<
typename T,
typename Alloc> T pvariance(
const Array<T, Alloc> &a, T
mean,
size_t ddof=0);
646 template<
typename T,
typename Alloc> T pstddev(
const Array<T, Alloc> &a,
size_t ddof=0);
648 template<
typename T,
typename Alloc> T pstddev(
const Array<T, Alloc> &a, T
mean,
size_t ddof=0);
684 template<
typename T,
typename Alloc> T
median(
const Array<T, Alloc> &a, std::vector<T> &scratch,
bool sorted,
685 bool takeEvenMean,
bool inPlace=
false);
689 { std::vector<T> scratch;
return median (a, scratch, sorted, takeEvenMean, inPlace); }
703 template<
typename T,
typename Alloc> T madfm(
const Array<T, Alloc> &a, std::vector<T> &tmp,
bool sorted,
704 bool takeEvenMean,
bool inPlace =
false);
708 { std::vector<T> tmp;
return madfm(a, tmp, sorted, takeEvenMean, inPlace); }
710 {
return madfm(a, sorted, (a.
nelements() <= 100),
false); }
712 {
return madfm(a,
false, (a.
nelements() <= 100),
false); }
715 {
return madfm(a, sorted, (a.
nelements() <= 100),
true); }
727 bool sorted=
false,
bool inPlace=
false);
730 bool sorted=
false,
bool inPlace=
false)
731 { std::vector<T> tmp;
return fractile (a, tmp, fraction, sorted, inPlace); }
737 template<
typename T,
typename Alloc> T interFractileRange(
const Array<T, Alloc> &a, std::vector<T> &tmp,
739 bool sorted=
false,
bool inPlace=
false);
742 bool sorted=
false,
bool inPlace=
false)
743 { std::vector<T> tmp;
return interFractileRange(a, tmp, fraction, sorted, inPlace); }
755 bool sorted=
false,
bool inPlace=
false)
756 {
return interFractileRange(a, tmp, 1./6., sorted, inPlace); }
760 {
return interFractileRange(a, 1./6., sorted, inPlace); }
769 bool sorted=
false,
bool inPlace=
false)
770 {
return interFractileRange(a, tmp, 0.25, sorted, inPlace); }
774 {
return interFractileRange(a, 0.25, sorted, inPlace); }
781 template<
typename T,
typename AllocC,
typename AllocR>
785 arrayTransformInPlace (left, other,
786 [](std::complex<T> left, T right) {
return left*right; });
789 template<
typename T,
typename Alloc>
790 void operator*= (
Array<std::complex<T>, Alloc> &left,
const T &other)
792 arrayTransformInPlace (left, other,
793 [](std::complex<T> left, T right) {
return left*right; });
796 template<
typename T,
typename AllocC,
typename AllocR>
800 arrayTransformInPlace (left, other,
801 [](std::complex<T> left, T right) {
return left/right; });
804 template<
typename T,
typename Alloc>
805 void operator/= (
Array<std::complex<T>, Alloc> &left,
const T &other)
807 arrayTransformInPlace (left, other,
808 [](std::complex<T> left, T right) {
return left/right; });
811 template<
typename T,
typename AllocC,
typename AllocR>
817 arrayContTransform (left, right, result,
818 [](std::complex<T> left, T right) {
return left*right; });
821 template<
typename T,
typename Alloc>
826 arrayContTransform (left, other, result,
827 [](std::complex<T> left, T right) {
return left*right; });
830 template<
typename T,
typename Alloc>
835 arrayContTransform (left, other, result,
836 [](std::complex<T> left, T right) {
return left*right; });
840 template<
typename T,
typename AllocC,
typename AllocR>
846 arrayContTransform (left, right, result,
847 [](std::complex<T> l, T r) {
return l/r; });
850 template<
typename T,
typename Alloc>
855 arrayContTransform (left, other, result,
856 [](std::complex<T> left, T right) {
return left/right; });
859 template<
typename T,
typename Alloc>
864 arrayContTransform (left, other, result,
865 [](std::complex<T> left, T right) {
return left/right; });
875 void conj(
Array<std::complex<float>> &rarray,
const Array<std::complex<float>> &carray);
876 void conj(
Array<std::complex<double>> &rarray,
const Array<std::complex<double>> &carray);
887 template<
typename T,
typename Alloc>
889 template<
typename T,
typename Alloc>
891 template<
typename T,
typename Alloc>
896 template<
typename C,
typename R,
typename AllocC,
typename AllocR>
900 template<
typename C,
typename R,
typename AllocC,
typename AllocR>
954 void ComplexToReal(
Array<float> &rarray,
const Array<std::complex<float>> &carray);
966 void RealToComplex(
Array<std::complex<float>> &carray,
const Array<float> &rarray);
974 template<
typename T,
typename U,
typename AllocT,
typename AllocU>
987 const T* in, T* out,
const IPosition& alternate)
992 for (ssize_t j=0; j<mult[0]; ++j) {
994 for (ssize_t i=0; i<shp[0]; ++i) {
1001 for (ssize_t i=0; i<shp[0]; ++i) {
1002 for (ssize_t j=0; j<mult[0]; ++j) {
1009 if (alternate[axis]) {
1010 for (ssize_t j=0; j<mult[axis]; ++j) {
1012 for (ssize_t i=0; i<shp[axis]; ++i) {
1013 out = expandRecursive (axis-1, shp, mult, inSteps,
1014 pin, out, alternate);
1015 pin += inSteps[axis];
1019 for (ssize_t i=0; i<shp[axis]; ++i) {
1020 for (ssize_t j=0; j<mult[axis]; ++j) {
1021 out = expandRecursive (axis-1, shp, mult, inSteps,
1022 in, out, alternate);
1024 in += inSteps[axis];
1042 template<
typename T,
typename Alloc>
1047 IPosition alt = checkExpandArray (mult, inshp,
1051 incp.reference (in.
reform(inshp));
1056 expandRecursive (out.
ndim()-1, inshp, mult, incp.steps(),
1057 incp.data(), outPtr, alt);
1081 #include "ArrayMath.tcc"
T median(const Array< T, Alloc > &a, bool sorted)
A Vector of integers, for indexing into Array<T> objects.
LatticeExprNode log10(const LatticeExprNode &expr)
void arrayTransformInPlace(Array< L, AllocL > &left, const Array< R, AllocR > &right, BinaryOperator op)
Transform left and right in place using the binary operator.
A 1-D Specialization of the Array class.
Array< std::complex< T > > operator*(const std::complex< T > &left, const Array< T, Alloc > &other)
bool contiguousStorage() const
Are the array data contiguous? If they are not contiguous, getStorage (see below) needs to make a cop...
LatticeExprNode log(const LatticeExprNode &expr)
T interHexileRange(const Array< T, Alloc > &a, std::vector< T > &tmp, bool sorted=false, bool inPlace=false)
Return the inter-hexile range of an array.
LatticeExprNode median(const LatticeExprNode &expr)
void arrayTransformInPlace(Array< T, Alloc > &arr, UnaryOperator op)
Transform the array in place using the unary operator.
T madfmInPlace(const Array< T, Alloc > &a, bool sorted=false)
TODO shouldn't take a const Array for in place sorting.
size_t nelements() const
How many elements does this array have? Product of all axis lengths.
LatticeExprNode operator/(const LatticeExprNode &left, const LatticeExprNode &right)
T fractile(const Array< T, Alloc > &a, float fraction, bool sorted=false, bool inPlace=false)
TODO shouldn't take a const Array for in place sorting.
LatticeExprNode mask(const LatticeExprNode &expr)
This function returns the mask of the given expression.
T product(const TableVector< T > &tv)
LatticeExprNode imag(const LatticeExprNode &expr)
void myiptransform(_InputIterator1 __first1, _InputIterator1 __last1, T right, _BinaryOperation __binary_op)
sequence OP= scalar
void myrtransform(_InputIterator1 __first1, _InputIterator1 __last1, _OutputIterator __result, T right, _BinaryOperation __binary_op)
sequence = sequence OP scalar
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)
TableExprNode phase(const TableExprNode &node)
The phase (i.e.
Array< T, Alloc > min(const T &a, const Array< T, Alloc > &b)
Array< T, Alloc > 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 madfm(const Array< T, Alloc > &a)
T interHexileRange(const Array< T, Alloc > &a, bool sorted=false, bool inPlace=false)
TODO shouldn't take a const Array for in place sorting.
T median(const Array< T, Alloc > &a, bool sorted, bool takeEvenMean, bool inPlace=false)
TODO shouldn't take a const Array for in place sorting.
Vector< T, Alloc > 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...
void putStorage(T *&storage, bool deleteAndCopy)
putStorage() is normally called after a call to getStorage() (cf).
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...
T madfm(const Array< T, Alloc > &a, bool sorted, bool takeEvenMean, bool inPlace=false)
TODO shouldn't take a const Array for in place sorting.
void indgen(Array< T, Alloc > &a, T start)
Fills all elements of "array" with a sequence starting with start incremented by one for each positio...
A 2-D Specialization of the Array class.
TableExprNode operator&(const TableExprNode &left, const TableExprNode &right)
LatticeExprNode exp(const LatticeExprNode &expr)
size_t ndim() const
The dimensionality of this array.
LatticeExprNode floor(const LatticeExprNode &expr)
LatticeExprNode cos(const LatticeExprNode &expr)
T interQuartileRange(const Array< T, Alloc > &a, std::vector< T > &tmp, bool sorted=false, bool inPlace=false)
Return the inter-quartile range of an array.
LatticeExprNode conj(const LatticeExprNode &expr)
Array< T, Alloc > max(const T &a, const Array< T, Alloc > &b)
void min(Array< T, Alloc > &result, const T &a, const Array< T, Alloc > &b)
LatticeExprNode tanh(const LatticeExprNode &expr)
LatticeExprNode min(const LatticeExprNode &left, const LatticeExprNode &right)
LatticeExprNode avdev(const LatticeExprNode &expr)
void expandArray(Array< T, Alloc > &out, const Array< T, Alloc > &in, const IPosition &alternate=IPosition())
Expand the values of an array.
LatticeExprNode abs(const LatticeExprNode &expr)
Numerical 1-argument functions which result in a real number regardless of input expression type...
LatticeExprNode length(const LatticeExprNode &expr, const LatticeExprNode &axis)
2-argument function to get the length of an axis.
void arrayContTransform(L left, const Array< R, AllocR > &right, Array< RES, AllocRES > &result, BinaryOperator op)
Transform left and right to a result using the binary operator.
T madfm(const Array< T, Alloc > &a, bool sorted)
Array< T, Alloc > operator*(const Array< T, Alloc > &left, const Array< T, Alloc > &right)
LatticeExprNode sign(const LatticeExprNode &expr)
LatticeExprNode sqrt(const LatticeExprNode &expr)
Array< std::complex< T > > operator/(const std::complex< T > &left, const Array< T, Alloc > &other)
void arrayContTransform(const Array< L, AllocL > &left, R right, Array< RES, AllocRES > &result, BinaryOperator op)
Transform left and right to a result using the binary operator.
LatticeExprNode tan(const LatticeExprNode &expr)
LatticeExprNode atan(const LatticeExprNode &expr)
void max(Array< T, Alloc > &result, const T &a, const Array< T, Alloc > &b)
void minMax(T &min, T &max, const TableVector< T > &tv)
TableExprNode cube(const TableExprNode &node)
LatticeExprNode stddev(const LatticeExprNode &expr)
void arrayContTransform(const Array< L, AllocL > &left, const Array< R, AllocR > &right, Array< RES, AllocRES > &result, BinaryOperator op)
Functions to apply a binary or unary operator to arrays.
LatticeExprNode round(const LatticeExprNode &expr)
A templated N-D Array class with zero origin. Array<T, Alloc> is a templated, N-dimensional, Array class. The origin is zero, but by default indices are zero-based. This Array class is the base class for the Vector, Matrix, and Cube subclasses.
TableExprNode operator|(const TableExprNode &left, const TableExprNode &right)
LatticeExprNode atan2(const LatticeExprNode &left, const LatticeExprNode &right)
Numerical 2-argument functions.
void checkArrayShapes(const ArrayBase &left, const ArrayBase &right, const char *name)
T interQuartileRange(const Array< T, Alloc > &a, bool sorted=false, bool inPlace=false)
TODO shouldn't take a const Array for in place sorting.
void indgen(Array< T, Alloc > &a)
Fills all elements of "array" with a sequence starting with 0 and ending with nelements() - 1...
LatticeExprNode operator+(const LatticeExprNode &expr)
Global functions operating on a LatticeExprNode.
LatticeExprNode fmod(const LatticeExprNode &left, const LatticeExprNode &right)
T median(const Array< T, Alloc > &a)
void indgen(TableVector< T > &tv, T start, T inc)
void arrayTransformInPlace(Array< L, Alloc > &left, R right, BinaryOperator op)
Transform left and right in place using the binary operator.
LatticeExprNode asin(const LatticeExprNode &expr)
LatticeExprNode mean(const LatticeExprNode &expr)
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.
int floormod(int x, int y)
TableExprNode rms(const TableExprNode &array)
T medianInPlace(const Array< T, Alloc > &a, bool sorted=false)
TODO shouldn't take a const Array for in place sorting.
LatticeExprNode sinh(const LatticeExprNode &expr)
LatticeExprNode acos(const LatticeExprNode &expr)
TableExprNode square(const TableExprNode &node)
iterator begin()
Get the begin iterator object for any array.
LatticeExprNode operator-(const LatticeExprNode &expr)
LatticeExprNode operator^(const LatticeExprNode &left, const LatticeExprNode &right)
T * getStorage(bool &deleteIt)
Generally use of this should be shunned, except to use a FORTRAN routine or something similar...
contiter cbegin()
Get the begin iterator object for a contiguous array.
LatticeExprNode variance(const LatticeExprNode &expr)
LatticeExprNode ceil(const LatticeExprNode &expr)
LatticeExprNode pow(const LatticeExprNode &left, const LatticeExprNode &right)
T interFractileRange(const Array< T, Alloc > &a, float fraction, bool sorted=false, bool inPlace=false)
TODO shouldn't take a const Array for in place sorting.
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.
void arrayContTransform(const Array< T, Alloc > &arr, Array< RES, AllocRES > &result, UnaryOperator op)
Transform array to a result using the unary operator.
MVBaseline operator*(const RotMatrix &left, const MVBaseline &right)
Rotate a Baseline vector with rotation matrix and other multiplications.
LatticeExprNode cosh(const LatticeExprNode &expr)
LatticeExprNode real(const LatticeExprNode &expr)
LatticeExprNode sin(const LatticeExprNode &expr)
Numerical 1-argument functions.
const IPosition & shape() const
The length of each axis.
TableExprNode amplitude(const TableExprNode &node)
The amplitude (i.e.