11 #ifndef RTOPPACK_RTOP_T_HELPERS_DECL_HPP
12 #define RTOPPACK_RTOP_T_HELPERS_DECL_HPP
21 #include "RTOpPack_RTOpT.hpp"
28 #ifdef RTOPPACK_RTOPT_HELPER_DUMP_OUTPUT
30 namespace RTOpPack {
extern bool rtop_helpers_dump_all; }
31 #endif // RTOPPACK_RTOPT_HELPER_DUMP_OUTPUT
41 template<
class Scalar>
62 template<
class Scalar>
63 std::ostream& operator<<(std::ostream &out, const ScalarIndex<Scalar> &scalarIndex)
65 out <<
"{"<<scalarIndex.scalar<<
","<<scalarIndex.index<<
"}";
73 template <
class Scalar>
81 static int numPrimitiveObjs() {
return ScalarPrimitiveTypeTraits::numPrimitiveObjs(); }
94 assertInput(primitiveObjs, indexObjs, charObjs);
95 ScalarPrimitiveTypeTraits::extractPrimitiveObjs(
97 indexObjs[0] = obj.
index;
107 assertInput(primitiveObjs, indexObjs, charObjs);
108 ScalarPrimitiveTypeTraits::loadPrimitiveObjs(
110 Teuchos::outArg(obj->scalar) );
111 obj->index = indexObjs[0];
122 primitiveObjs.
size()!=ScalarPrimitiveTypeTraits::numPrimitiveObjs()
123 || indexObjs.
size()!=1
124 || charObjs.
size()!=0 );
138 template<
class ConcreteReductObj>
146 void set(
const ConcreteReductObj &concreteReductObj )
149 const ConcreteReductObj&
get()
const
162 template<
class ConcreteReductObj>
193 template<
class Scalar>
196 const int allowed_num_sub_vecs,
197 const int allowed_num_targ_sub_vecs,
198 const bool expect_reduct_obj,
215 template<
class ConcreteReductObj,
int ReductionType>
219 inline void operator()(
const ConcreteReductObj& in_reduct, ConcreteReductObj& inout_reduct)
const
221 return in_reduct.this_reduction_type_needs_a_specialization();
227 template<
class ConcreteReductObj>
231 inline void operator()(
const ConcreteReductObj& in_reduct, ConcreteReductObj& inout_reduct)
const
233 inout_reduct += in_reduct;
239 template<
class ConcreteReductObj>
243 inline void operator()(
const ConcreteReductObj& in_reduct, ConcreteReductObj& inout_reduct)
const
245 inout_reduct = std::max(inout_reduct, in_reduct);
251 template<
class ConcreteReductObj>
255 inline void operator()(
const ConcreteReductObj& in_reduct, ConcreteReductObj& inout_reduct)
const
257 inout_reduct = std::min(inout_reduct, in_reduct);
263 template<
class Scalar>
267 inline void operator()(
const Scalar& in_reduct, Scalar& inout_reduct)
const
269 inout_reduct += in_reduct;
278 template<
class Scalar,
class ConcreteReductObj,
class ReductObjReduction>
292 ReductObjReduction reductObjReduction_in = ReductObjReduction()
294 : initReductObjValue_(initReductObjValue_in),
331 *num_values = PTT::numPrimitiveObjs();
332 *num_indexes = PTT::numIndexObjs();
333 *num_chars = PTT::numCharObjs();
348 const ConcreteReductObj scalar_in_reduct_obj = this->
getRawVal(in_reduct_obj);
349 ConcreteReductObj scalar_inout_reduct_obj = this->
getRawVal(*inout_reduct_obj);
351 this->
setRawVal( scalar_inout_reduct_obj, inout_reduct_obj );
357 setRawVal( initReductObjValue(), reduct_obj );
369 PTT::extractPrimitiveObjs(
getRawVal(reduct_obj),
370 value_data, index_data, char_data );
382 ConcreteReductObj concrete_reduct_obj;
383 PTT::loadPrimitiveObjs( value_data, index_data, char_data,
384 Teuchos::outArg(concrete_reduct_obj) );
385 this->
setRawVal( concrete_reduct_obj, reduct_obj );
408 template<
class Scalar,
class ConcreteReductObj,
class EleWiseReduction,
420 const ConcreteReductObj &initReductObjValue_in = ConcreteReductObj(),
421 EleWiseReduction eleWiseReduction_in = EleWiseReduction(),
422 ReductObjReduction reductObjReduction_in = ReductObjReduction()
424 :
base_t(initReductObjValue_in, reductObjReduction_in),
442 validate_apply_op<Scalar>(*
this, 1, 0,
true,
443 sub_vecs, targ_sub_vecs, reduct_obj_inout.
getConst());
450 ConcreteReductObj reduct = reduct_obj.
get();
454 const_iter_t v0_val = sub_vecs[0].values().begin();
455 const ptrdiff_t v0_s = sub_vecs[0].stride();
466 reduct_obj.set(reduct);
480 #define RTOP_ROP_1_REDUCT_SCALAR_CUSTOM_DEFAULT( ROP_CLASS_NAME, REDUCT_SCALAR, \
481 BASIC_REDUCT_TYPE_ENUM, CUSTOM_DEFAULT \
484 template<class Scalar, class ReductScalar> \
485 class ROP_CLASS_NAME ## EleWiseReduction \
488 inline void operator()( \
490 ReductScalar &reduct \
495 template<class Scalar> \
496 class ROP_CLASS_NAME \
497 : public RTOpPack::ROp_1_ScalarReduction< \
500 ROP_CLASS_NAME ## EleWiseReduction<Scalar, REDUCT_SCALAR >, \
501 RTOpPack::BasicReductObjReductionOp<REDUCT_SCALAR, BASIC_REDUCT_TYPE_ENUM> > \
503 typedef RTOpPack::ROp_1_ScalarReduction< \
506 ROP_CLASS_NAME ## EleWiseReduction<Scalar, REDUCT_SCALAR >, \
507 RTOpPack::BasicReductObjReductionOp<REDUCT_SCALAR, BASIC_REDUCT_TYPE_ENUM> > \
511 : base_t(CUSTOM_DEFAULT) \
513 this->setOpNameBase( #ROP_CLASS_NAME ); \
518 template<class Scalar, class ReductScalar> \
519 void ROP_CLASS_NAME ## EleWiseReduction<Scalar, ReductScalar>::operator()( \
520 const Scalar &v0, ReductScalar &reduct \
525 #define RTOP_ROP_1_REDUCT_SCALAR( ROP_CLASS_NAME, REDUCT_SCALAR, \
526 BASIC_REDUCT_TYPE_ENUM \
528 RTOP_ROP_1_REDUCT_SCALAR_CUSTOM_DEFAULT(ROP_CLASS_NAME, REDUCT_SCALAR, \
529 BASIC_REDUCT_TYPE_ENUM, Teuchos::ScalarTraits<REDUCT_SCALAR >::zero() )
542 class EleWiseReduction,
543 class ReductObjReduction = SumScalarReductObjReduction<ReductScalar>
558 const ReductScalar &initReductObjValue_in = ReductScalar(),
559 EleWiseReduction eleWiseReduction_in = EleWiseReduction(),
560 ReductObjReduction reductObjReduction_in = ReductObjReduction()
562 :
base_t(initReductObjValue_in, reductObjReduction_in),
593 validate_apply_op<Scalar>(*
this, 1, 0,
true,
594 sub_vecs, targ_sub_vecs, reduct_obj_inout);
601 ReductScalar reduct = reduct_obj.
get();
605 const_iter_t v0_val = sub_vecs[0].values().begin();
606 const ptrdiff_t v0_s = sub_vecs[0].stride();
615 for(
Teuchos_Ordinal i = 0; i < subDim; ++i, v0_val += v0_s, ++global_i )
619 reduct_obj.set(reduct);
641 class EleWiseReduction,
655 const ReductScalar &initReductObjValue_in = ReductScalar(),
656 EleWiseReduction eleWiseReduction_in = EleWiseReduction(),
657 ReductObjReduction reductObjReduction_in = ReductObjReduction()
659 :
base_t(initReductObjValue_in, reductObjReduction_in),
677 validate_apply_op<Scalar>(*
this, 2, 0,
true,
678 sub_vecs, targ_sub_vecs, reduct_obj_inout.
getConst());
685 Scalar reduct = reduct_obj.
get();
689 const_iter_t v0_val = sub_vecs[0].values().begin();
690 const ptrdiff_t v0_s = sub_vecs[0].stride();
691 const_iter_t v1_val = sub_vecs[1].values().begin();
692 const ptrdiff_t v1_s = sub_vecs[1].stride();
694 if( v0_s == 1 && v1_s == 1 ) {
699 for(
Teuchos_Ordinal i = 0; i < subDim; ++i, v0_val += v0_s, v1_val += v1_s )
703 reduct_obj.set(reduct);
719 #define RTOP_ROP_2_REDUCT_SCALAR( ROP_CLASS_NAME, REDUCT_SCALAR, \
720 BASIC_REDUCT_TYPE_ENUM \
723 template<class Scalar, class ReductScalar> \
724 class ROP_CLASS_NAME ## EleWiseReduction \
727 inline void operator()(const Scalar &v0, \
729 ReductScalar &reduct \
734 template<class Scalar> \
735 class ROP_CLASS_NAME \
736 : public RTOpPack::ROp_2_ScalarReduction< \
739 ROP_CLASS_NAME ## EleWiseReduction<Scalar, REDUCT_SCALAR >, \
740 RTOpPack::BasicReductObjReductionOp<REDUCT_SCALAR, BASIC_REDUCT_TYPE_ENUM> > \
745 this->setOpNameBase( #ROP_CLASS_NAME ); \
746 this->initReductObjValue(ScalarTraits<REDUCT_SCALAR >::zero()); \
750 template<class Scalar, class ReductScalar> \
751 void ROP_CLASS_NAME ## EleWiseReduction<Scalar, ReductScalar>::operator()( \
752 const Scalar &v0, const Scalar &v1, ReductScalar &reduct) const
761 template<
class Scalar,
class EleWiseTransformation>
768 EleWiseTransformation eleWiseTransformation = EleWiseTransformation()
786 validate_apply_op<Scalar>(*
this, 0, 1,
false,
787 sub_vecs, targ_sub_vecs, reduct_obj_inout.
getConst());
790 (void)reduct_obj_inout;
795 iter_t z0_val = targ_sub_vecs[0].values().begin();
796 const ptrdiff_t z0_s = targ_sub_vecs[0].stride();
820 template<
class Scalar,
class EleWiseTransformation>
827 EleWiseTransformation eleWiseTransformation = EleWiseTransformation()
860 validate_apply_op<Scalar>(*
this, 0, 1,
false,
861 sub_vecs, targ_sub_vecs, reduct_obj_inout.
getConst());
864 (void)reduct_obj_inout;
869 iter_t z0_val = targ_sub_vecs[0].values().begin();
870 const ptrdiff_t z0_s = targ_sub_vecs[0].stride();
879 for(
Teuchos_Ordinal i = 0; i < subDim; ++i, z0_val += z0_s, ++global_i )
900 template<
class Scalar,
class EleWiseTransformation>
907 EleWiseTransformation eleWiseTransformation = EleWiseTransformation()
926 validate_apply_op<Scalar>(*
this, 1, 1,
false,
927 sub_vecs, targ_sub_vecs, reduct_obj_inout.
getConst());
929 (void)reduct_obj_inout;
934 const_iter_t v0_val = sub_vecs[0].values().begin();
935 const ptrdiff_t v0_s = sub_vecs[0].stride();
937 iter_t z0_val = targ_sub_vecs[0].values().begin();
938 const ptrdiff_t z0_s = targ_sub_vecs[0].stride();
940 if ( v0_s == 1 && z0_s == 1 ) {
945 for(
Teuchos_Ordinal i = 0; i < subDim; ++i, v0_val += v0_s, z0_val += z0_s )
961 #define RTOP_TOP_1_1( TOP_CLASS_NAME ) \
963 template<class Scalar> \
964 class TOP_CLASS_NAME ## EleWiseTransformation \
967 inline void operator()( const Scalar &v0, Scalar &z0 ) const; \
971 template<class Scalar> \
972 class TOP_CLASS_NAME \
973 : public RTOpPack::TOp_1_1_Base< Scalar, \
974 TOP_CLASS_NAME ## EleWiseTransformation<Scalar> > \
979 this->setOpNameBase( #TOP_CLASS_NAME ); \
984 template<class Scalar> \
985 void TOP_CLASS_NAME ## EleWiseTransformation<Scalar>::operator()( \
986 const Scalar &v0, Scalar &z0 \
996 template<
class Scalar,
class EleWiseTransformation>
1003 EleWiseTransformation eleWiseTransformation = EleWiseTransformation()
1021 #ifdef TEUCHOS_DEBUG
1022 validate_apply_op<Scalar>(*
this, 2, 1,
false,
1023 sub_vecs, targ_sub_vecs, reduct_obj_inout);
1025 (void)reduct_obj_inout;
1030 const_iter_t v0_val = sub_vecs[0].values().begin();
1031 const ptrdiff_t v0_s = sub_vecs[0].stride();
1033 const_iter_t v1_val = sub_vecs[1].values().begin();
1034 const ptrdiff_t v1_s = sub_vecs[1].stride();
1036 iter_t z0_val = targ_sub_vecs[0].values().begin();
1037 const ptrdiff_t z0_s = targ_sub_vecs[0].stride();
1039 if ( v0_s == 1 && v1_s == 1 && z0_s == 1 ) {
1047 ++i, v0_val += v0_s, v1_val += v1_s, z0_val += z0_s
1066 template<
class Scalar,
class EleWiseTransformation>
1073 EleWiseTransformation eleWiseTransformation = EleWiseTransformation()
1091 #ifdef TEUCHOS_DEBUG
1092 validate_apply_op<Scalar>(*
this, 3, 1,
false,
1093 sub_vecs, targ_sub_vecs, reduct_obj_inout);
1098 const_iter_t v0_val = sub_vecs[0].values().begin();
1099 const ptrdiff_t v0_s = sub_vecs[0].stride();
1101 const_iter_t v1_val = sub_vecs[1].values().begin();
1102 const ptrdiff_t v1_s = sub_vecs[1].stride();
1104 const_iter_t v2_val = sub_vecs[2].values().begin();
1105 const ptrdiff_t v2_s = sub_vecs[2].stride();
1107 iter_t z0_val = targ_sub_vecs[0].values().begin();
1108 const ptrdiff_t z0_s = targ_sub_vecs[0].stride();
1110 if ( v0_s == 1 && v1_s == 1 && v2_s == 1 && z0_s == 1 ) {
1118 ++i, v0_val += v0_s, v1_val += v1_s, v2_val += v2_s, z0_val += z0_s
1139 #endif // RTOPPACK_RTOP_T_HELPERS_DECL_HPP
void get_reduct_type_num_entries_impl(const Ptr< int > &num_values, const Ptr< int > &num_indexes, const Ptr< int > &num_chars) const
Base class for scalar reduction RTOps with one input vector.
void apply_op_impl(const ArrayView< const ConstSubVectorView< Scalar > > &sub_vecs, const ArrayView< const SubVectorView< Scalar > > &targ_sub_vecs, const Ptr< ReductTarget > &reduct_obj_inout) const
Base class for coordinate-variant scalar reduction RTOps with one input vector.
void apply_op_impl(const ArrayView< const ConstSubVectorView< Scalar > > &sub_vecs, const ArrayView< const SubVectorView< Scalar > > &targ_sub_vecs, const Ptr< ReductTarget > &reduct_obj_inout) const
Simple ReductTarget subclass for simple scalar objects.
ROp_2_ScalarReduction(const ReductScalar &initReductObjValue_in=ReductScalar(), EleWiseReduction eleWiseReduction_in=EleWiseReduction(), ReductObjReduction reductObjReduction_in=ReductObjReduction())
Null reduction object reduction operator.
TOp_0_1_CoordVariantBase(EleWiseTransformation eleWiseTransformation=EleWiseTransformation())
bool coord_invariant_impl() const
This RTOp is NOT coordinate invariant! .
static void assertInput(const ArrayView< const primitiveType > &primitiveObjs, const ArrayView< const index_type > &indexObjs, const ArrayView< const char > &charObjs)
std::string description() const
const RCP< DefaultReductTarget< ConcreteReductObj > > defaultReductTarget(const ConcreteReductObj &concreteReductObj)
Nonmember constructor.
void apply_op_impl(const ArrayView< const ConstSubVectorView< Scalar > > &sub_vecs, const ArrayView< const SubVectorView< Scalar > > &targ_sub_vecs, const Ptr< ReductTarget > &reduct_obj_inout) const
STANDARD_MEMBER_COMPOSITION_MEMBERS(ConcreteReductObj, initReductObjValue)
const EleWiseReduction & getEleWiseReduction() const
void apply_op_impl(const ArrayView< const ConstSubVectorView< Scalar > > &sub_vecs, const ArrayView< const SubVectorView< Scalar > > &targ_sub_vecs, const Ptr< ReductTarget > &reduct_obj_inout) const
Base class for coordinate variant transformations for 0 input and 1 output vector.
ConcreteReductObj operator()(const ReductTarget &reduct_obj) const
Class for a changeable sub-vector.
EleWiseReduction eleWiseReduction_
Base class for transformations for 2 input and 1 output vector.
DefaultReductTarget(const ConcreteReductObj &concreteReductObj)
void operator()(const Scalar &in_reduct, Scalar &inout_reduct) const
void setEleWiseReduction(EleWiseReduction eleWiseReduction_in)
ROp_1_ScalarReduction(const ConcreteReductObj &initReductObjValue_in=ConcreteReductObj(), EleWiseReduction eleWiseReduction_in=EleWiseReduction(), ReductObjReduction reductObjReduction_in=ReductObjReduction())
Base class for transformations for 0 input and 1 output vector.
TOp_0_1_Base(EleWiseTransformation eleWiseTransformation=EleWiseTransformation())
void set(const ConcreteReductObj &concreteReductObj)
Teuchos_Ordinal index_type
const ConcreteReductObj & get() const
PrimitiveTypeTraits< Scalar, Scalar > ScalarPrimitiveTypeTraits
void operator()(const ConcreteReductObj &in_reduct, ConcreteReductObj &inout_reduct) const
Base class for transformations for 1 input and 1 output vector.
EleWiseTransformation eleWiseTransformation_
TOp_1_1_Base(EleWiseTransformation eleWiseTransformation=EleWiseTransformation())
Class for a non-changeable sub-vector.
void apply_op_impl(const ArrayView< const ConstSubVectorView< Scalar > > &sub_vecs, const ArrayView< const SubVectorView< Scalar > > &targ_sub_vecs, const Ptr< ReductTarget > &reduct_obj_inout) const
ROpScalarReductionWithOpBase< Scalar, ConcreteReductObj, ReductObjReduction > base_t
Teuchos::RCP< ReductTarget > reduct_obj_create_impl() const
Templated interface to vector reduction/transformation operators {abstract}.
Simple struct for a Scalar and an Ordinal object.
TEUCHOS_ORDINAL_TYPE Teuchos_Ordinal
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Specialization where the scalar type is the same as the concrete object type.
void setEleWiseTransformation(EleWiseTransformation eleWiseTransformation)
A templated traits class for decomposing object into an array of primitive objects.
void operator()(const ConcreteReductObj &in_reduct, ConcreteReductObj &inout_reduct) const
ROpScalarReductionWithOpBase(const ConcreteReductObj &initReductObjValue_in=ScalarTraits< Scalar >::zero(), ReductObjReduction reductObjReduction_in=ReductObjReduction())
T_To & dyn_cast(T_From &from)
ReductObjReduction reductObjReduction_
EleWiseReduction eleWiseReduction_
TOp_2_1_Base(EleWiseTransformation eleWiseTransformation=EleWiseTransformation())
PrimitiveTypeTraits< Scalar, Scalar >::primitiveType primitive_value_type
void apply_op_impl(const ArrayView< const ConstSubVectorView< Scalar > > &sub_vecs, const ArrayView< const SubVectorView< Scalar > > &targ_sub_vecs, const Ptr< ReductTarget > &reduct_obj_inout) const
virtual void reduce_reduct_objs_impl(const ReductTarget &in_reduct_obj, const Ptr< ReductTarget > &inout_reduct_obj) const
Base class for scalar reduction RTOps with two input vectors.
Abstract base class for all reduction objects.
ROpScalarReductionWithOpBase< Scalar, ReductScalar, ReductObjReduction > base_t
void apply_op_impl(const ArrayView< const ConstSubVectorView< Scalar > > &sub_vecs, const ArrayView< const SubVectorView< Scalar > > &targ_sub_vecs, const Ptr< ReductTarget > &reduct_obj_inout) const
EleWiseTransformation eleWiseTransformation_
EleWiseTransformation eleWiseTransformation_
ConcreteReductObj concreteReductObj_
void apply_op_impl(const ArrayView< const ConstSubVectorView< Scalar > > &sub_vecs, const ArrayView< const SubVectorView< Scalar > > &targ_sub_vecs, const Ptr< ReductTarget > &reduct_obj_inout) const
EleWiseReduction eleWiseReduction_
static void loadPrimitiveObjs(const ArrayView< const primitiveType > &primitiveObjs, const ArrayView< const index_type > &indexObjs, const ArrayView< const char > &charObjs, const Ptr< ScalarIndex< Scalar > > &obj)
static int numPrimitiveObjs()
void extract_reduct_obj_state_impl(const ReductTarget &reduct_obj, const ArrayView< primitive_value_type > &value_data, const ArrayView< index_type > &index_data, const ArrayView< char_type > &char_data) const
TOp_3_1_Base(EleWiseTransformation eleWiseTransformation=EleWiseTransformation())
static int numIndexObjs()
void load_reduct_obj_state_impl(const ArrayView< const primitive_value_type > &value_data, const ArrayView< const index_type > &index_data, const ArrayView< const char_type > &char_data, const Ptr< ReductTarget > &reduct_obj) const
void operator()(const ConcreteReductObj &in_reduct, ConcreteReductObj &inout_reduct) const
bool coord_invariant_impl() const
This RTOp is NOT coordinate invariant! .
static void extractPrimitiveObjs(const ScalarIndex< Scalar > &obj, const ArrayView< primitiveType > &primitiveObjs, const ArrayView< index_type > &indexObjs, const ArrayView< char > &charObjs)
ROpScalarReductionWithOpBase< Scalar, ReductScalar, ReductObjReduction > base_t
void operator()(const ConcreteReductObj &in_reduct, ConcreteReductObj &inout_reduct) const
RTOpT< Scalar >::primitive_value_type primitive_value_type
void setRawVal(const ConcreteReductObj &rawVal, const Ptr< ReductTarget > &reduct_obj) const
void validate_apply_op(const RTOpT< Scalar > &op, const int allowed_num_sub_vecs, const int allowed_num_targ_sub_vecs, const bool expect_reduct_obj, const ArrayView< const ConstSubVectorView< Scalar > > &sub_vecs, const ArrayView< const SubVectorView< Scalar > > &targ_sub_vecs, const Ptr< const ReductTarget > &reduct_obj)
Validate the input to an apply_op(...) function.
Base class for transformations for 3 input and 1 output vector.
EleWiseTransformation eleWiseTransformation_
const ConcreteReductObj & getRawVal(const ReductTarget &reduct_obj) const
ScalarIndex(const Scalar &_scalar, const Ordinal &_index)
Ptr< const T > getConst() const
void reduct_obj_reinit_impl(const Ptr< ReductTarget > &reduct_obj) const
const EleWiseTransformation & getEleWiseTransformation() const
ScalarPrimitiveTypeTraits::primitiveType primitiveType
ROp_1_CoordVariantScalarReduction(const ReductScalar &initReductObjValue_in=ReductScalar(), EleWiseReduction eleWiseReduction_in=EleWiseReduction(), ReductObjReduction reductObjReduction_in=ReductObjReduction())
EleWiseTransformation eleWiseTransformation_
#define TEUCHOS_TEST_FOR_EXCEPT(throw_exception_test)