RTOp Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
RTOpPack_TOpUnaryFuncPtr.hpp
Go to the documentation of this file.
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_UNARY_FUNC_PTR_HPP
12 #define RTOPPACK_UNARY_FUNC_PTR_HPP
13 
15 
16 namespace RTOpPack {
17 
18 template<class Scalar>
20  :RTOpT<Scalar>("TOpUnaryFuncPtr")
21 {
23 }
24 
25 template<class Scalar>
27  unary_func_ptr_t unary_func_ptr
28  ,const std::string &op_name
29  )
30  :RTOpT<Scalar>("TOpUnaryFuncPtr")
31 {
32  initialize(unary_func_ptr,op_name);
33 }
34 
35 template<class Scalar>
37  unary_func_ptr_t unary_func_ptr
38  ,const std::string &op_name
39  )
40 {
41  TEUCHOS_TEST_FOR_EXCEPTION( unary_func_ptr==NULL, std::invalid_argument, "Error!" );
42  unary_func_ptr_ = unary_func_ptr;
43  op_name_ = op_name;
44 }
45 
46 template<class Scalar>
48  unary_func_ptr_t *unary_func_ptr
49  ,std::string *op_name
50  )
51 {
52  if(unary_func_ptr) *unary_func_ptr = unary_func_ptr_;
53  if(op_name) *op_name = op_name_;
54 
55  unary_func_ptr_ = NULL;
56  op_name_ = "uninitialized()";
57 }
58 
59 // Overridden from RTOpT
60 
61 template<class Scalar>
63 {
64  return op_name_.c_str();
65 }
66 
67 template<class Scalar>
69  const int num_vecs, const ConstSubVectorView<Scalar> sub_vecs[]
70  ,const int num_targ_vecs, const SubVectorView<Scalar> targ_sub_vecs[]
71  ,ReductTarget *reduct_obj
72  ) const
73 {
74  TEUCHOS_TEST_FOR_EXCEPTION( num_vecs != 1 || sub_vecs == NULL, std::invalid_argument, "Error!" );
75  TEUCHOS_TEST_FOR_EXCEPTION( num_targ_vecs != 1 || targ_sub_vecs == NULL, std::invalid_argument, "Error!" );
76  TEUCHOS_TEST_FOR_EXCEPTION( reduct_obj != NULL, std::invalid_argument, "Error!" );
77  TEUCHOS_TEST_FOR_EXCEPTION( sub_vecs[0].stride() != 1, std::invalid_argument, "Error, can't handle non-unit strides here!" );
78  TEUCHOS_TEST_FOR_EXCEPTION( targ_sub_vecs[0].stride() != 1, std::invalid_argument, "Error, can't handle non-unit strides here!" );
79  TEUCHOS_TEST_FOR_EXCEPTION( sub_vecs[0].subDim() != targ_sub_vecs[0].subDim(), std::invalid_argument, "Error!" );
80  TEUCHOS_TEST_FOR_EXCEPTION( sub_vecs[0].globalOffset() != targ_sub_vecs[0].globalOffset(), std::invalid_argument, "Error!" );
81 
82  unary_func_ptr_( sub_vecs[0].values(), sub_vecs[0].subDim(), targ_sub_vecs[0].values() );
83 
84 }
85 
86 } // end namespace RTOpPack
87 
88 #endif // RTOPPACK_UNARY_FUNC_PTR_HPP
Class for a changeable sub-vector.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Class for a non-changeable sub-vector.
Templated interface to vector reduction/transformation operators {abstract}.
Abstract base class for all reduction objects.
void set_initialized(unary_func_ptr_t *unary_func_ptr=NULL, std::string *op_name=NULL)
Set uninitialized.
TOpUnaryFuncPtr()
Construct to uninitialized.
void initialize(unary_func_ptr_t unary_func_ptr, const std::string &op_name)
Initialize.
void apply_op(const int num_vecs, const ConstSubVectorView< Scalar > sub_vecs[], const int num_targ_vecs, const SubVectorView< Scalar > targ_sub_vecs[], ReductTarget *reduct_obj) const