- edited description
- changed title to CarpetLib's minval and maxval always return first element
CarpetLib's minval and maxval always return first element
Issue #2493
resolved
This code:
ivect tst; for(int i = 0 ; i < 3 ; i++) tst[i] = 3-i; std::cerr<<"tst: "<<tst<<" minval: "<<minval(tst)<<"\n";
outputs:
tst: [3,2,1] minval: 3
and as far as I an tell this is due to the DECLARE_REDUCTION_FUNCTION_1
macro used in
DECLARE_REDUCTION_FUNCTION_1(minval, a[0], min, ID)
which assumes that max
behaves like *=
i.e. accumulates. See vect_helpers.hh
:
#define DECLARE_REDUCTION_FUNCTION_1(fn, init, op, final) \ } \ namespace CarpetLib_vect { \ template <typename T> inline void fn(T &r, const T &a) { \ using namespace std; \ using namespace CarpetLib; \ op(r, a); \ } \ } \ namespace CarpetLib { \ template <typename T, int D> inline T fn(const vect<T, D> &a) { \ T r(init); \ for (int d = 0; d < D; ++d) \ /* op(r, a[d]); */ \ CarpetLib_vect::fn(r, a[d]); \ return final(r); \ }
and for just a plain ivect
the operator op
ends up being std::min
.
Comments (5)
-
reporter -
reporter -
reporter Approved by @Erik Schnetter in https://bitbucket.org/eschnett/carpet/commits/f97d02b43d3ccff4ba424b567e9ac28f6d208663#comment-9894404
-
reporter -
reporter - changed status to resolved
- Log in to comment