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_ROpNorm2.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_NORM2_HPP
12 #define RTOPPACK_ROP_NORM2_HPP
13 
14 #include "RTOpPack_RTOpTHelpers.hpp"
15 
16 
17 namespace RTOpPack {
18 
19 
21 template<class Scalar>
23 {
24 public:
25  void operator()( const Scalar &v0, Scalar &reduct ) const
26  {
27  reduct += ScalarTraits<Scalar>::conjugate(v0)*v0;
28  }
29 };
30 
31 
35 template<class Scalar>
36 class ROpNorm2
37  : public ROp_1_ScalarReduction<Scalar, Scalar, ROpNorm2EleWiseReduction<Scalar> >
38 {
39 public:
44  {
45  this->setOpNameBase("ROpNorm2");
46  }
48  typename ST::magnitudeType operator()(const ReductTarget& reduct_obj) const
49  {
50  const Scalar sqrt_reduct = ST::squareroot(this->getRawVal(reduct_obj));
51  return ST::magnitude(sqrt_reduct);
52  }
53 };
54 
55 
56 } // namespace RTOpPack
57 
58 
59 #endif // RTOPPACK_ROP_NORM2_HPP
static T squareroot(T x)
ST::magnitudeType operator()(const ReductTarget &reduct_obj) const
Two (Euclidean) norm reduction operator: result = sqrt( sum( conj(v0[i])*v0[i], i=0...n-1 ) ).
void setOpNameBase(const std::string &op_name_base)
static magnitudeType magnitude(T a)
const ConcreteReductObj & getRawVal(const ReductTarget &reduct_obj) const
Teuchos::ScalarTraits< Scalar > ST