// @HEADER // ***************************************************************************** // RTOp: Interfaces and Support Software for Vector Reduction Transformation // Operations // // Copyright 2006 NTESS and the RTOp contributors. // SPDX-License-Identifier: BSD-3-Clause // ***************************************************************************** // @HEADER #ifndef RTOPPACK_ROP_MIN_INDEX_GREATER_THAN_BOUND_HPP #define RTOPPACK_ROP_MIN_INDEX_GREATER_THAN_BOUND_HPP #include "RTOpPack_ROpMinIndex.hpp" #include "Teuchos_StandardMemberCompositionMacros.hpp" namespace RTOpPack { /** \brief . */ template class ROpMinIndexGreaterThanBoundEleWiseReductionOp { public: /** \brief . */ ROpMinIndexGreaterThanBoundEleWiseReductionOp( const Scalar &bound = ScalarTraits::zero() ) :bound_(bound) {} /** \brief . */ void operator()(const index_type i, const Scalar &v0, ScalarIndex &reduct) const { if( v0 > bound_ && ( v0 < reduct.scalar || ( v0 == reduct.scalar && i < reduct.index ) ) ) { reduct = ScalarIndex(v0, i); } } private: Scalar bound_; }; /** \brief Returns the minimum element greater than some bound along * with its index: result.scalar = x(k) and result.index * = k such that x(k) <= x(i) for all i where * x(i) > bound and k is the minimum index to break * ties. * * If no element is greater than bound then results.index * < 0. */ template class ROpMinIndexGreaterThanBound : public ROp_1_CoordVariantScalarReduction< Scalar, ScalarIndex, ROpMinIndexGreaterThanBoundEleWiseReductionOp, ROpMinIndexReductObjReductionOp > { public: /** \brief . */ ROpMinIndexGreaterThanBound( const Scalar &bound_in = Teuchos::ScalarTraits::zero() ) { this->setOpNameBase("ROpMinIndexGreaterThanBound"); bound(bound_in); this->initReductObjValue( ScalarIndex(+ScalarTraits::rmax(), -1)); } /** \brief . */ void bound(const Scalar& bound_in) { this->setEleWiseReduction( ROpMinIndexGreaterThanBoundEleWiseReductionOp(bound_in) ); } /** \brief . */ ScalarIndex operator()(const ReductTarget& reduct_obj ) const { return this->getRawVal(reduct_obj); } }; } // namespace RTOpPack #endif // RTOPPACK_ROP_MIN_INDEX_GREATER_THAN_BOUND_HPP