26#ifndef CASA_MARRAYMATHBASE_H
27#define CASA_MARRAYMATHBASE_H
29#include <casacore/casa/aips.h>
30#include <casacore/casa/Arrays/ArrayMathBase.h>
69template <
typename T,
typename ARRAYITER,
typename MASKITER,
typename OPER>
72 for (; abegin != aend; ++abegin, ++mbegin) {
80 for (; abegin != aend; ++abegin, ++mbegin) {
81 if (!*mbegin) accum = oper(accum, *abegin);
88template <
typename T,
typename ARRAYITER,
typename MASKITER,
typename OPER>
89T
accumulateMasked(ARRAYITER abegin, ARRAYITER aend, MASKITER mbegin, T accum, OPER oper) {
90 for (; abegin != aend; ++abegin, ++mbegin) {
91 if (!*mbegin) accum = oper(accum, *abegin);
99template <
typename T,
typename ARRAYITER,
typename MASKITER>
102 for (; abegin != aend; ++abegin, ++mbegin) {
103 if (!*mbegin && *abegin ==
value) ++n;
110template <
typename T,
typename ARRAYITER,
typename MASKITER>
113 for (; abegin != aend; ++abegin, ++mbegin) {
114 if (!*mbegin && *abegin !=
value) ++n;
124template <
typename InputIterator1,
typename InputIterator2,
typename MaskIterator,
125 typename CompareOperator>
126inline bool compareAllMasked(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2,
127 MaskIterator mask1, MaskIterator mask2, CompareOperator op) {
128 for (; first1 != last1; ++first1, ++first2, ++mask1, ++mask2) {
129 if (!*mask1 && !*mask2) {
130 if (!op(*first1, *first2))
return False;
135template <
typename InputIterator1,
typename InputIterator2,
typename MaskIterator,
136 typename CompareOperator>
137inline bool compareAllMasked(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2,
138 MaskIterator mask1, CompareOperator op) {
139 for (; first1 != last1; ++first1, ++first2, ++mask1) {
141 if (!op(*first1, *first2))
return False;
149template <
typename InputIterator1,
typename T,
typename MaskIterator,
typename CompareOperator>
151 MaskIterator mask1, CompareOperator op) {
152 for (; first1 != last1; ++first1, ++mask1) {
154 if (!op(left, *first1))
return False;
162template <
typename InputIterator1,
typename T,
typename MaskIterator,
typename CompareOperator>
164 MaskIterator mask1, CompareOperator op) {
165 for (; first1 != last1; ++first1, ++mask1) {
167 if (!op(*first1, right))
return False;
179template <
typename InputIterator1,
typename InputIterator2,
typename MaskIterator,
180 typename CompareOperator>
181inline bool compareAnyMasked(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2,
182 MaskIterator mask1, MaskIterator mask2, CompareOperator op) {
183 for (; first1 != last1; ++first1, ++first2, ++mask1, ++mask2) {
184 if (!*mask1 && !*mask2) {
185 if (op(*first1, *first2))
return true;
190template <
typename InputIterator1,
typename InputIterator2,
typename MaskIterator,
191 typename CompareOperator>
192inline bool compareAnyMasked(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2,
193 MaskIterator mask1, CompareOperator op) {
194 for (; first1 != last1; ++first1, ++first2, ++mask1) {
196 if (op(*first1, *first2))
return true;
204template <
typename InputIterator1,
typename T,
typename MaskIterator,
typename CompareOperator>
206 MaskIterator mask1, CompareOperator op) {
207 for (; first1 != last1; ++first1, ++mask1) {
209 if (op(left, *first1))
return true;
217template <
typename InputIterator1,
typename T,
typename MaskIterator,
typename CompareOperator>
219 MaskIterator mask1, CompareOperator op) {
220 for (; first1 != last1; ++first1, ++mask1) {
222 if (op(*first1, right))
return true;
231template <
typename T,
typename RES = T>
Define the base class for functors to perform a reduction function on an MArray object.
virtual ~MArrayFunctorBase()
virtual RES operator()(const MArray< T > &) const =0
For temporary backward namespace compatibility, use casa as alias for casacore.
NewDelAllocator< T > NewDelAllocator< T >::value
T accumulateMasked(ARRAYITER abegin, ARRAYITER aend, MASKITER mbegin, OPER oper)
Define STL-like accumulate function operating on arrays with masks.
bool compareAnyRightMasked(InputIterator1 first1, InputIterator1 last1, T right, MaskIterator mask1, CompareOperator op)
For use with a constant right value.
bool compareAnyLeftMasked(InputIterator1 first1, InputIterator1 last1, T left, MaskIterator mask1, CompareOperator op)
For use with a constant left value.
bool compareAllRightMasked(InputIterator1 first1, InputIterator1 last1, T right, MaskIterator mask1, CompareOperator op)
For use with a constant right value.
size_t countNEMasked(ARRAYITER abegin, ARRAYITER aend, MASKITER mbegin, const T &value)
Count the number of unmasked values not matching the given value.
bool compareAllMasked(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, MaskIterator mask1, MaskIterator mask2, CompareOperator op)
Define a function to compare the unmasked elements of two sequences.
bool compareAnyMasked(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, MaskIterator mask1, MaskIterator mask2, CompareOperator op)
Define a function to compare the unmasked elements of two sequences.
T accumulateMasked(ARRAYITER abegin, ARRAYITER aend, MASKITER mbegin, T accum, OPER oper)
The second function uses an externally initialized accumulator (e.g.
bool compareAllMasked(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, MaskIterator mask1, CompareOperator op)
bool compareAllLeftMasked(InputIterator1 first1, InputIterator1 last1, T left, MaskIterator mask1, CompareOperator op)
For use with a constant left value.
bool compareAnyMasked(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, MaskIterator mask1, CompareOperator op)
size_t countMasked(ARRAYITER abegin, ARRAYITER aend, MASKITER mbegin, const T &value)
Count the number of unmasked values matching the given value.