26#ifndef CASA_FUNCTORS_H
27#define CASA_FUNCTORS_H
29#include <casacore/casa/aips.h>
30#include <casacore/casa/BasicMath/Math.h>
31#include <casacore/casa/BasicSL/Complex.h>
32#include <casacore/casa/BasicSL/String.h>
41 template<
typename InputIterator1,
typename InputIterator2,
typename BinaryOperator>
43 InputIterator2 first2, BinaryOperator op)
45 for (; first1!=last1; ++first1, ++first2) {
46 *first1 = op(*first1, *first2);
53 template<
typename InputIterator1,
typename UnaryOperator>
57 for (; first1!=last1; ++first1) {
58 *first1 = op(*first1);
65 template<
typename InputIterator,
typename MaskIterator,
typename Accum,
typename BinaryOperator>
67 MaskIterator
mask, Accum acc,
68 BinaryOperator op = std::plus<Accum>())
79 template<
typename InputIterator,
typename MaskIterator,
typename Accum,
typename BinaryOperator>
81 MaskIterator
mask, Accum acc,
82 BinaryOperator op = std::plus<Accum>())
94 template<
typename InputIterator1,
typename InputIterator2,
typename CompareOperator>
95 inline bool compareAll (InputIterator1 first1, InputIterator1 last1,
96 InputIterator2 first2, CompareOperator op)
98 for (; first1!=last1; ++first1, ++first2) {
99 if (!op(*first1, *first2))
return false;
106 template<
typename InputIterator1,
typename T,
typename CompareOperator>
108 T left, CompareOperator op)
110 for (; first1!=last1; ++first1) {
111 if (!op(left, *first1))
return false;
118 template<
typename InputIterator1,
typename T,
typename CompareOperator>
120 T right, CompareOperator op)
122 for (; first1!=last1; ++first1) {
123 if (!op(*first1, right))
return false;
133 template<
typename InputIterator1,
typename InputIterator2,
typename CompareOperator>
134 inline bool compareAny (InputIterator1 first1, InputIterator1 last1,
135 InputIterator2 first2, CompareOperator op)
137 for (; first1!=last1; ++first1, ++first2) {
138 if (op(*first1, *first2))
return true;
145 template<
typename InputIterator1,
typename T,
typename CompareOperator>
147 T left, CompareOperator op)
149 for (; first1!=last1; ++first1) {
150 if (op(left, *first1))
return true;
157 template<
typename InputIterator1,
typename T,
typename CompareOperator>
159 T right, CompareOperator op)
161 for (; first1!=last1; ++first1) {
162 if (op(*first1, right))
return true;
172 template <
typename L,
typename R=L,
typename RES=L>
181 template <
typename L,
typename R=L,
typename RES=L>
190 template <
typename L,
typename R=L,
typename RES=L>
199 template <
typename L,
typename R=L,
typename RES=L>
209 template <
typename L,
typename R=L,
typename RES=L>
218 template <
typename L,
typename R=L,
typename RES=L>
222 {
return floormod (RES(x), RES(y)); }
226 template <
typename T>
234 template <
typename T>
242 template <
typename T>
250 template <
typename T>
292 template<
typename L,
typename R=L>
295 explicit Near (
double tolerance=1e-5)
305 template<
typename L,
typename R=L>
319 template<
typename T,
typename RES=T>
327 template<
typename T,
typename RES=T>
335 template<
typename T,
typename RES=T>
343 template<
typename T,
typename RES=T>
351 template<
typename T,
typename RES=T>
359 template<
typename T,
typename RES=T>
367 template<
typename T,
typename RES=T>
375 template<
typename T,
typename RES=T>
383 template<
typename T,
typename RES=T>
391 template<
typename L,
typename R=L,
typename RES=L>
395 {
return RES(
atan2 (left, L(right))); }
399 template<
typename T,
typename RES=T>
407 template<
typename T,
typename RES=T>
415 template<
typename T,
typename RES=T>
423 template<
typename T,
typename RES=T>
431 template<
typename T,
typename RES=T>
439 template<
typename T,
typename RES=T>
447 template<
typename T,
typename RES=T>
455 template<
typename T,
typename RES=T>
463 template<
typename T,
typename RES=T>
471 template<
typename T,
typename RES=T>
479 template<
typename T,
typename RES=T>
487 template<
typename L,
typename R,
typename RES>
491 {
return RES(l, r); }
496 template<
typename L,
typename R,
typename RES>
500 {
return RES(
real(l), r); }
505 template<
typename L,
typename R,
typename RES>
509 {
return RES(l,
imag(r)); }
514 template<
typename L,
typename R,
typename RES>
522 template<
typename T,
typename RES=T>
530 template<
typename T,
typename RES>
538 template<
typename T,
typename RES>
546 template<
typename T,
typename RES>
554 template<
typename T,
typename RES>
558 {
return RES(fabs (
value)); }
562 template<
typename T,
typename E=T,
typename RES=T>
566 {
return RES(
pow (left, exponent)); }
570 template<
typename L,
typename R=L,
typename RES=L>
574 {
return RES(
fmod (left, L(right))); }
578 template<
typename L,
typename R=L,
typename RES=L>
582 {
return RES(left<right ? left : right); }
586 template<
typename L,
typename R=L,
typename RES=L>
590 {
return RES(left<right ? right : left); }
594 template<
typename T,
typename Accum=T>
598 {
return left + Accum(right)*Accum(right); }
604 template<
typename T,
typename Accum=T>
623 std::complex<T>
operator() (std::complex<T> left, std::complex<T> right)
const
624 {
return left + ((right.real() -
itsBase.real()) * (right.real() -
itsBase.real()) +
625 (right.imag() -
itsBase.imag()) * (right.imag() -
itsBase.imag())); }
632 template<
typename T,
typename Accum=T>
String: the storage and methods of handling collections of characters.
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