Collection of Concrete Vector Reduction/Transformation Operator Implementations  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
RTOpPack_ROpMaxIndex.hpp
1 // @HEADER
2 // *****************************************************************************
3 // RTOp: Interfaces and Support Software for Vector Reduction Transformation
4 // Operations
5 //
6 // Copyright 2006 NTESS and the RTOp contributors.
7 // SPDX-License-Identifier: BSD-3-Clause
8 // *****************************************************************************
9 // @HEADER
10 
11 #ifndef RTOPPACK_ROP_MAX_INDEX_HPP
12 #define RTOPPACK_ROP_MAX_INDEX_HPP
13 
14 #include "RTOpPack_RTOpTHelpers.hpp"
15 
16 namespace RTOpPack {
17 
18 
20 template<class Scalar>
22 public:
24  void operator()(const index_type i, const Scalar &v0,
25  ScalarIndex<Scalar> &reduct) const
26  {
27  if(
28  v0 > reduct.scalar
29  ||
30  (v0 == reduct.scalar && i < reduct.index)
31  )
32  {
33  reduct = ScalarIndex<Scalar>(v0, i);
34  }
35  }
36 };
37 
38 
40 template<class Scalar>
42 public:
44  void operator()(
45  const ScalarIndex<Scalar>& in_reduct, ScalarIndex<Scalar>& inout_reduct
46  ) const
47  {
48  if(
49  in_reduct.scalar > inout_reduct.scalar
50  ||
51  (
52  in_reduct.scalar == inout_reduct.scalar
53  &&
54  in_reduct.index < inout_reduct.index
55  )
56  )
57  {
58  inout_reduct = in_reduct;
59  }
60  }
61 };
62 
63 
69 template<class Scalar>
72  Scalar,
73  ScalarIndex<Scalar>,
74  ROpMaxIndexEleWiseReductionOp<Scalar>,
75  ROpMaxIndexReductObjReductionOp<Scalar> >
76 {
77 public:
80  {
81  this->setOpNameBase("ROpMaxIndex");
82  this->initReductObjValue(
83  ScalarIndex<Scalar>(-ScalarTraits<Scalar>::rmax(), -1));
84  }
86  ScalarIndex<Scalar> operator()(const ReductTarget& reduct_obj) const
87  { return this->getRawVal(reduct_obj); }
88 };
89 
90 
91 } // namespace RTOpPack
92 
93 
94 #endif // RTOPPACK_ROP_MAX_INDEX_HPP
Returns the maximum element and its index: result.scalar = x(k) and result.index = k such that x(k) &gt;...
void setOpNameBase(const std::string &op_name_base)
void operator()(const index_type i, const Scalar &v0, ScalarIndex< Scalar > &reduct) const
ScalarIndex< Scalar > operator()(const ReductTarget &reduct_obj) const
void operator()(const ScalarIndex< Scalar > &in_reduct, ScalarIndex< Scalar > &inout_reduct) const