28 #ifndef CASA_FUNCTORS_H
29 #define CASA_FUNCTORS_H
31 #include <casacore/casa/aips.h>
32 #include <casacore/casa/BasicMath/Math.h>
33 #include <casacore/casa/BasicSL/Complex.h>
34 #include <casacore/casa/BasicSL/String.h>
43 template<
typename InputIterator1,
typename InputIterator2,
typename BinaryOperator>
45 InputIterator2 first2, BinaryOperator op)
47 for (; first1!=last1; ++first1, ++first2) {
48 *first1 = op(*first1, *first2);
55 template<
typename InputIterator1,
typename UnaryOperator>
59 for (; first1!=last1; ++first1) {
60 *first1 = op(*first1);
67 template<
typename InputIterator,
typename MaskIterator,
typename Accum,
typename BinaryOperator>
69 MaskIterator
mask, Accum acc,
70 BinaryOperator op = std::plus<Accum>())
81 template<
typename InputIterator,
typename MaskIterator,
typename Accum,
typename BinaryOperator>
83 MaskIterator
mask, Accum acc,
84 BinaryOperator op = std::plus<Accum>())
96 template<
typename InputIterator1,
typename InputIterator2,
typename CompareOperator>
97 inline bool compareAll (InputIterator1 first1, InputIterator1 last1,
98 InputIterator2 first2, CompareOperator op)
100 for (; first1!=last1; ++first1, ++first2) {
101 if (!op(*first1, *first2))
return false;
108 template<
typename InputIterator1,
typename T,
typename CompareOperator>
110 T left, CompareOperator op)
112 for (; first1!=last1; ++first1) {
113 if (!op(left, *first1))
return false;
120 template<
typename InputIterator1,
typename T,
typename CompareOperator>
122 T right, CompareOperator op)
124 for (; first1!=last1; ++first1) {
125 if (!op(*first1, right))
return false;
135 template<
typename InputIterator1,
typename InputIterator2,
typename CompareOperator>
136 inline bool compareAny (InputIterator1 first1, InputIterator1 last1,
137 InputIterator2 first2, CompareOperator op)
139 for (; first1!=last1; ++first1, ++first2) {
140 if (op(*first1, *first2))
return true;
147 template<
typename InputIterator1,
typename T,
typename CompareOperator>
149 T left, CompareOperator op)
151 for (; first1!=last1; ++first1) {
152 if (op(left, *first1))
return true;
159 template<
typename InputIterator1,
typename T,
typename CompareOperator>
161 T right, CompareOperator op)
163 for (; first1!=last1; ++first1) {
164 if (op(*first1, right))
return true;
174 template <
typename L,
typename R=L,
typename RES=L>
183 template <
typename L,
typename R=L,
typename RES=L>
192 template <
typename L,
typename R=L,
typename RES=L>
201 template <
typename L,
typename R=L,
typename RES=L>
211 template <
typename L,
typename R=L,
typename RES=L>
220 template <
typename L,
typename R=L,
typename RES=L>
224 {
return floormod (RES(x), RES(y)); }
228 template <
typename T>
236 template <
typename T>
244 template <
typename T>
252 template <
typename T>
294 template<
typename L,
typename R=L>
297 explicit Near (
double tolerance=1
e-5)
307 template<
typename L,
typename R=L>
321 template<
typename T,
typename RES=T>
329 template<
typename T,
typename RES=T>
337 template<
typename T,
typename RES=T>
345 template<
typename T,
typename RES=T>
353 template<
typename T,
typename RES=T>
361 template<
typename T,
typename RES=T>
369 template<
typename T,
typename RES=T>
377 template<
typename T,
typename RES=T>
385 template<
typename T,
typename RES=T>
393 template<
typename L,
typename R=L,
typename RES=L>
397 {
return RES(
atan2 (left, L(right))); }
401 template<
typename T,
typename RES=T>
409 template<
typename T,
typename RES=T>
417 template<
typename T,
typename RES=T>
425 template<
typename T,
typename RES=T>
433 template<
typename T,
typename RES=T>
441 template<
typename T,
typename RES=T>
449 template<
typename T,
typename RES=T>
457 template<
typename T,
typename RES=T>
465 template<
typename T,
typename RES=T>
473 template<
typename T,
typename RES=T>
481 template<
typename T,
typename RES=T>
489 template<
typename L,
typename R,
typename RES>
493 {
return RES(l, r); }
498 template<
typename L,
typename R,
typename RES>
502 {
return RES(
real(l), r); }
507 template<
typename L,
typename R,
typename RES>
511 {
return RES(l,
imag(r)); }
516 template<
typename L,
typename R,
typename RES>
524 template<
typename T,
typename RES=T>
532 template<
typename T,
typename RES>
540 template<
typename T,
typename RES>
548 template<
typename T,
typename RES>
556 template<
typename T,
typename RES>
560 {
return RES(fabs (
value)); }
564 template<
typename T,
typename E=T,
typename RES=T>
568 {
return RES(
pow (left, exponent)); }
572 template<
typename L,
typename R=L,
typename RES=L>
576 {
return RES(
fmod (left, L(right))); }
580 template<
typename L,
typename R=L,
typename RES=L>
584 {
return RES(left<right ? left : right); }
588 template<
typename L,
typename R=L,
typename RES=L>
592 {
return RES(left<right ? right : left); }
596 template<
typename T,
typename Accum=T>
600 {
return left + Accum(right)*Accum(right); }
606 template<
typename T,
typename Accum=T>
625 std::complex<T>
operator() (std::complex<T> left, std::complex<T> right)
const
626 {
return left + ((right.real() -
itsBase.real()) * (right.real() -
itsBase.real()) +
627 (right.imag() -
itsBase.imag()) * (right.imag() -
itsBase.imag())); }
634 template<
typename T,
typename Accum=T>
String: the storage and methods of handling collections of characters.
const Double e
e and functions thereof:
int floormod(int x, int y)
this file contains all the compiler specific defines
bool compareAnyLeft(InputIterator1 first1, InputIterator1 last1, T left, CompareOperator op)
For use with a constant left value.
LatticeExprNode exp(const LatticeExprNode &expr)
LatticeExprNode isNaN(const LatticeExprNode &expr)
Test if a value is a NaN.
LatticeExprNode asin(const LatticeExprNode &expr)
bool compareAny(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, CompareOperator op)
Define a function to compare all elements of two sequences.
LatticeExprNode fmod(const LatticeExprNode &left, const LatticeExprNode &right)
LatticeExprNode acos(const LatticeExprNode &expr)
TableExprNode upcase(const TableExprNode &node)
bool compareAllLeft(InputIterator1 first1, InputIterator1 last1, T left, CompareOperator op)
For use with a constant left value.
TableExprNode isFinite(const TableExprNode &node)
Function to test if a scalar or array is finite.
LatticeExprNode cosh(const LatticeExprNode &expr)
LatticeExprNode atan(const LatticeExprNode &expr)
LatticeExprNode tanh(const LatticeExprNode &expr)
LatticeExprNode arg(const LatticeExprNode &expr)
bool compareAll(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, CompareOperator op)
Define a function to compare all elements of two sequences.
LatticeExprNode log10(const LatticeExprNode &expr)
LatticeExprNode conj(const LatticeExprNode &expr)
LatticeExprNode sinh(const LatticeExprNode &expr)
TableExprNode nearAbs(const TableExprNode &left, const TableExprNode &right)
TableExprNode isInf(const TableExprNode &node)
LatticeExprNode abs(const LatticeExprNode &expr)
Numerical 1-argument functions which result in a real number regardless of input expression type.
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.
bool compareAnyRight(InputIterator1 first1, InputIterator1 last1, T right, CompareOperator op)
For use with a constant right value.
LatticeExprNode atan2(const LatticeExprNode &left, const LatticeExprNode &right)
Numerical 2-argument functions.
TableExprNode capitalize(const TableExprNode &node)
TableExprNode downcase(const TableExprNode &node)
LatticeExprNode sqrt(const LatticeExprNode &expr)
LatticeExprNode pow(const LatticeExprNode &left, const LatticeExprNode &right)
LatticeExprNode log(const LatticeExprNode &expr)
Accum accumulateFalse(InputIterator first, InputIterator last, MaskIterator mask, Accum acc, BinaryOperator op=std::plus< Accum >())
Define a function (similar to std::accumulate) to do accumulation of elements for which the correspon...
Accum accumulateTrue(InputIterator first, InputIterator last, MaskIterator mask, Accum acc, BinaryOperator op=std::plus< Accum >())
Define a function (similar to std::accumulate) to do accumulation of elements for which the correspon...
LatticeExprNode value(const LatticeExprNode &expr)
This function returns the value of the expression without a mask.
TableExprNode trim(const TableExprNode &node)
LatticeExprNode cos(const LatticeExprNode &expr)
LatticeExprNode floor(const LatticeExprNode &expr)
void transformInPlace(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, BinaryOperator op)
Define a function to do a binary transform in place.
Bool near(const GaussianBeam &left, const GaussianBeam &other, const Double relWidthTol, const Quantity &absPaTol)
bool compareAllRight(InputIterator1 first1, InputIterator1 last1, T right, CompareOperator op)
For use with a constant right value.
LatticeExprNode ceil(const LatticeExprNode &expr)
LatticeExprNode real(const LatticeExprNode &expr)
LatticeExprNode imag(const LatticeExprNode &expr)
Define real & complex conjugation for non-complex types and put comparisons into std namespace.
RES operator()(T value) const
RES operator()(T value) const
RES operator()(T value) const
RES operator()(L left, R right) const
RES operator()(T value) const
Functor for bitwise and of (integer) values.
T operator()(const T &x, const T &y) const
Functor for bitwise negate of (integer) values.
T operator()(const T &x) const
Functor for bitwise or of (integer) values.
T operator()(const T &x, const T &y) const
Functor for bitwise xor of (integer) values.
T operator()(const T &x, const T &y) const
Functor to apply complex function fabs.
RES operator()(T value) const
Functor to apply complex function arg.
RES operator()(T value) const
Functor to capitalize a std::string.
String operator()(const std::string &value) const
RES operator()(T value) const
Functor to apply complex function conj.
RES operator()(T value) const
RES operator()(T value) const
RES operator()(T value) const
Functor to divide variables of possibly different types.
RES operator()(const L &x, const R &y) const
Functor to downcase a std::string.
String operator()(const std::string &value) const
RES operator()(T value) const
Functor to take modulo of variables of possibly different types using the floor modulo (% as used in ...
RES operator()(const L &x, const R &y) const
RES operator()(T value) const
RES operator()(R left, L right) const
Functor to apply complex function imag.
RES operator()(T value) const
Functor to test for finiteness.
bool operator()(T value) const
Functor to test for infinity.
bool operator()(T value) const
bool operator()(T value) const
RES operator()(T value) const
RES operator()(T value) const
Functor to form a complex number from the left value and the imaginary part of the right value.
RES operator()(L l, R r) const
Functor to form a complex number from the real part of the left value and the imaginary part of the r...
RES operator()(L l, R r) const
Functor to form a complex number from the real part of the left value and the right value.
RES operator()(L l, R r) const
Functor to form a complex number from the left and right value.
RES operator()(L l, R r) const
Functor to get maximum of two values.
RES operator()(L left, R right) const
Functor to get minimum of two values.
RES operator()(L left, R right) const
Functor to subtract variables of possibly different types.
RES operator()(const L &x, const R &y) const
Functor to take modulo of (integer) variables of possibly different types in the C way.
RES operator()(const L &x, const R &y) const
Functor to multiply variables of possibly different types.
RES operator()(const L &x, const R &y) const
Functor to test for if two values are absolutely near each other.
NearAbs(double tolerance=1e-13)
bool operator()(L left, R right) const
Functor to test if two values are relatively near each other.
bool operator()(L left, R right) const
Near(double tolerance=1e-5)
Functor to add variables of possibly different types.
RES operator()(const L &x, const R &y) const
Functor to apply a power of 3.
RES operator()(T value) const
RES operator()(T left, E exponent) const
Functor to apply complex function real.
RES operator()(T value) const
Functor to apply round (e.g.
RES operator()(T value) const
Functor to apply sign (result is -1, 0, or 1).
RES operator()(T value) const
RES operator()(T value) const
RES operator()(T value) const
Functor to apply sqr (power of 2).
RES operator()(T value) const
RES operator()(T value) const
Functor to add absolute diff of right and base value to left.
Accum operator()(Accum left, T right) const
std::complex< T > itsBase
SumSqrDiff(std::complex< T > base)
Functor to add squared diff of right and base value to left.
Accum operator()(Accum left, T right) const
Functor to add square of right to left.
Accum operator()(Accum left, T right) const
RES operator()(T value) const
RES operator()(T value) const
Functor to trim a std::string.
String operator()(const std::string &value) const
Functor to upcase a std::string.
String operator()(const std::string &value) const