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>
40template <
typename InputIterator1,
typename InputIterator2,
typename BinaryOperator>
41inline void transformInPlace(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2,
43 for (; first1 != last1; ++first1, ++first2) {
44 *first1 = op(*first1, *first2);
51template <
typename InputIterator1,
typename UnaryOperator>
52inline void transformInPlace(InputIterator1 first1, InputIterator1 last1, UnaryOperator op) {
53 for (; first1 != last1; ++first1) {
54 *first1 = op(*first1);
61template <
typename InputIterator,
typename MaskIterator,
typename Accum,
typename BinaryOperator>
63 BinaryOperator op = std::plus<Accum>()) {
73template <
typename InputIterator,
typename MaskIterator,
typename Accum,
typename BinaryOperator>
75 BinaryOperator op = std::plus<Accum>()) {
86template <
typename InputIterator1,
typename InputIterator2,
typename CompareOperator>
87inline bool compareAll(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2,
89 for (; first1 != last1; ++first1, ++first2) {
90 if (!op(*first1, *first2))
return false;
97template <
typename InputIterator1,
typename T,
typename CompareOperator>
98inline bool compareAllLeft(InputIterator1 first1, InputIterator1 last1, T left,
100 for (; first1 != last1; ++first1) {
101 if (!op(left, *first1))
return false;
108template <
typename InputIterator1,
typename T,
typename CompareOperator>
110 CompareOperator op) {
111 for (; first1 != last1; ++first1) {
112 if (!op(*first1, right))
return false;
122template <
typename InputIterator1,
typename InputIterator2,
typename CompareOperator>
123inline bool compareAny(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2,
124 CompareOperator op) {
125 for (; first1 != last1; ++first1, ++first2) {
126 if (op(*first1, *first2))
return true;
133template <
typename InputIterator1,
typename T,
typename CompareOperator>
135 CompareOperator op) {
136 for (; first1 != last1; ++first1) {
137 if (op(left, *first1))
return true;
144template <
typename InputIterator1,
typename T,
typename CompareOperator>
146 CompareOperator op) {
147 for (; first1 != last1; ++first1) {
148 if (op(*first1, right))
return true;
156template <
typename L,
typename R = L,
typename RES = L>
158 RES
operator()(
const L& x,
const R& y)
const {
return RES(x) + y; }
163template <
typename L,
typename R = L,
typename RES = L>
165 RES
operator()(
const L& x,
const R& y)
const {
return RES(x) - y; }
170template <
typename L,
typename R = L,
typename RES = L>
172 RES
operator()(
const L& x,
const R& y)
const {
return RES(x) * y; }
177template <
typename L,
typename R = L,
typename RES = L>
179 RES
operator()(
const L& x,
const R& y)
const {
return RES(x) / y; }
185template <
typename L,
typename R = L,
typename RES = L>
187 RES
operator()(
const L& x,
const R& y)
const {
return RES(x) % y; }
192template <
typename L,
typename R = L,
typename RES = L>
194 RES
operator()(
const L& x,
const R& y)
const {
return floormod(RES(x), RES(y)); }
250template <
typename L,
typename R = L>
260template <
typename L,
typename R = L>
270template <
typename T,
typename RES = T>
276template <
typename T,
typename RES = T>
282template <
typename T,
typename RES = T>
288template <
typename T,
typename RES = T>
294template <
typename T,
typename RES = T>
300template <
typename T,
typename RES = T>
306template <
typename T,
typename RES = T>
312template <
typename T,
typename RES = T>
318template <
typename T,
typename RES = T>
324template <
typename L,
typename R = L,
typename RES = L>
330template <
typename T,
typename RES = T>
336template <
typename T,
typename RES = T>
342template <
typename T,
typename RES = T>
348template <
typename T,
typename RES = T>
354template <
typename T,
typename RES = T>
360template <
typename T,
typename RES = T>
366template <
typename T,
typename RES = T>
372template <
typename T,
typename RES = T>
378template <
typename T,
typename RES = T>
384template <
typename T,
typename RES = T>
390template <
typename T,
typename RES = T>
396template <
typename L,
typename R,
typename RES>
403template <
typename L,
typename R,
typename RES>
410template <
typename L,
typename R,
typename RES>
417template <
typename L,
typename R,
typename RES>
423template <
typename T,
typename RES = T>
429template <
typename T,
typename RES>
435template <
typename T,
typename RES>
441template <
typename T,
typename RES>
447template <
typename T,
typename RES>
453template <
typename T,
typename E = T,
typename RES = T>
455 RES
operator()(T left, E exponent)
const {
return RES(
pow(left, exponent)); }
459template <
typename L,
typename R = L,
typename RES = L>
465template <
typename L,
typename R = L,
typename RES = L>
467 RES
operator()(L left, R right)
const {
return RES(left < right ? left : right); }
471template <
typename L,
typename R = L,
typename RES = L>
473 RES
operator()(L left, R right)
const {
return RES(left < right ? right : left); }
477template <
typename T,
typename Accum = T>
479 Accum
operator()(Accum left, T right)
const {
return left + Accum(right) * Accum(right); }
485template <
typename T,
typename Accum = T>
504 std::complex<T>
operator()(std::complex<T> left, std::complex<T> right)
const {
505 return left + ((right.real() -
itsBase.real()) * (right.real() -
itsBase.real()) +
506 (right.imag() -
itsBase.imag()) * (right.imag() -
itsBase.imag()));
515template <
typename T,
typename Accum = T>
String: the storage and methods of handling collections of characters.
For temporary backward namespace compatibility, use casa as alias for casacore.
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)
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.
String downcase(const std::string &str)
Global function which returns a transformation to lowercase of String.
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.
LatticeExprNode sqrt(const LatticeExprNode &expr)
String upcase(const std::string &str)
Global function which returns a transformation to uppercase of String.
LatticeExprNode pow(const LatticeExprNode &left, const LatticeExprNode &right)
String capitalize(const std::string &str)
Global function which returns a transformation to capitalization of String.
LatticeExprNode log(const LatticeExprNode &expr)
String trim(const std::string &str)
Global function which removes leading and trailing whitespace.
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 cos(const LatticeExprNode &expr)
LatticeExprNode floor(const LatticeExprNode &expr)
NewDelAllocator< T > NewDelAllocator< T >::value
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
NearAbs(double tolerance=1e-13)
bool operator()(L left, R right) const
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
Accum operator()(Accum left, T right) const
std::complex< T > operator()(std::complex< T > left, std::complex< T > right) const
std::complex< T > itsBase
SumSqrDiff(std::complex< T > base)
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