12 #ifndef RTOPPACK_TYPES_HPP
13 #define RTOPPACK_TYPES_HPP
16 #include "RTOp_ConfigDefs.hpp"
19 #include "Teuchos_ArrayRCP.hpp"
23 #include "Teuchos_Assert.hpp"
24 #include "Teuchos_implicit_cast.hpp"
25 #include "Teuchos_FancyOStream.hpp"
36 typedef Teuchos_Ordinal Ordinal;
57 typedef Teuchos_Ordinal index_type;
59 typedef char char_type;
69 {
public:
UnknownError(
const std::string& what_arg) : std::logic_error(what_arg) {}};
72 {
public:
InvalidUsage(
const std::string& what_arg) : std::logic_error(what_arg) {}};
75 {
public:
InvalidNumVecs(
const std::string& what_arg) : std::logic_error(what_arg) {}};
78 {
public:
InvalidNumTargVecs(
const std::string& what_arg) : std::logic_error(what_arg) {}};
81 {
public:
IncompatibleVecs(
const std::string& what_arg) : std::logic_error(what_arg) {}};
111 template<
class Scalar>
118 :globalOffset_(0), subDim_(0), stride_(0)
123 :globalOffset_(0), subDim_(0), stride_(0)
124 {
initialize(globalOffset_in, subDim_in, values_in, stride_in); }
140 subDim_in*std::abs(Teuchos::as<int>(stride_in)) - 1 <= values_in.
upperOffset());
147 globalOffset_=globalOffset_in;
154 { globalOffset_ = 0; subDim_=0; values_ = Teuchos::null; stride_ = 0; }
161 globalOffset_ = globalOffset_in;
166 Ordinal
subDim()
const {
return subDim_; }
170 ptrdiff_t
stride()
const {
return stride_; }
178 return valuesBegin()[stride_*i];
182 const Scalar&
operator()(Ordinal i)
const {
return (*
this)[i]; }
184 Ordinal globalOffset_;
191 return values_.
begin();
192 return values_.
begin() + (subDim_*std::abs(Teuchos::as<int>(stride_)) - 1);
214 template<
class Scalar>
255 template<
class Scalar>
256 void assign_entries(
const Ptr<
const SubVectorView<Scalar> > &msv,
257 const ConstSubVectorView<Scalar> &sv )
262 for(
int i = 0; i < sv.subDim(); ++i ) {
272 template<
class Scalar>
273 std::ostream& operator<<(std::ostream &out, const ConstSubVectorView<Scalar> &sv)
277 <<
"globalOffset="<<sv.globalOffset()
278 <<
",subDim="<<sv.subDim()
279 <<
",values="<<sv.values()
280 <<
",stride="<<sv.stride()
312 template<
class Scalar>
317 :globalOffset_(0), subDim_(0), colOffset_(0), numSubCols_(0),
322 Ordinal globalOffset_in, Ordinal subDim_in,
323 Ordinal colOffset_in, Ordinal numSubCols_in,
326 :globalOffset_(0), subDim_(0), colOffset_(0), numSubCols_(0),
329 initialize(globalOffset_in, subDim_in, colOffset_in, numSubCols_in, values_in,
340 Ordinal globalOffset_in, Ordinal subDim_in,
341 Ordinal colOffset_in, Ordinal numSubCols_in,
358 globalOffset_=globalOffset_in;
360 colOffset_=colOffset_in;
361 numSubCols_=numSubCols_in;
363 leadingDim_=leadingDim_in;
368 globalOffset_ = 0; subDim_=0; colOffset_=0, numSubCols_=0;
369 values_=Teuchos::null; leadingDim_=0;
377 globalOffset_ = globalOffset_in;
382 Ordinal
subDim()
const {
return subDim_; }
400 return values_[ i + leadingDim_*j ];
414 Ordinal globalOffset_;
440 template<
class Scalar>
447 Ordinal numRows_in, Ordinal numCols_in
450 Teuchos::arcp<Scalar>(numRows_in*numCols_in), numRows_in)
454 Ordinal globalOffset_in, Ordinal subDim_in,
455 Ordinal colOffset_in, Ordinal numSubCols_in,
459 colOffset_in, numSubCols_in, values_in, leadingDim_in)
467 Ordinal globalOffset_in, Ordinal subDim_in,
468 Ordinal colOffset_in, Ordinal numSubCols_in,
473 subDim_in, colOffset_in, numSubCols_in, values_in, leadingDim_in);
478 return Teuchos::arcp_const_cast<Scalar>(
502 template<
class Scalar>
503 void assign_entries(
const Ptr<
const SubMultiVectorView<Scalar> > &msmv,
504 const ConstSubMultiVectorView<Scalar> &smv )
510 for( Ordinal j = 0; j < smv.numSubCols(); ++j ) {
511 for( Ordinal i = 0; i < smv.subDim(); ++i ) {
512 (*msmv)(i,j) = smv(i,j);
533 template <
class Scalar,
class ConcreteObj>
540 {
return Scalar::this_type_is_missing_a_specialization(); }
543 {
return Scalar::this_type_is_missing_a_specialization(); }
546 {
return Scalar::this_type_is_missing_a_specialization(); }
555 Scalar::this_type_is_missing_a_specialization(obj);
565 *obj = Scalar::this_type_is_missing_a_specialization();
574 template <
class Scalar>
593 assertInput(primitiveObjs, indexObjs, charObjs);
594 primitiveObjs[0] = obj;
604 assertInput(primitiveObjs, indexObjs, charObjs);
605 *obj = primitiveObjs[0];
608 static void assertInput(
616 || charObjs.
size()!=0 );
627 template <
class Scalar>
642 const index_type &obj,
648 assertInput(primitiveObjs, indexObjs, charObjs);
659 assertInput(primitiveObjs, indexObjs, charObjs);
663 static void assertInput(
671 || charObjs.
size()!=0 );
677 #if defined(HAVE_COMPLEX) && defined(HAVE_TEUCHOS_COMPLEX)
683 template <
class Scalar>
684 class PrimitiveTypeTraits<std::complex<Scalar>, std::complex<Scalar> > {
687 typedef PrimitiveTypeTraits<Scalar,Scalar> ScalarPrimitiveTypeTraits;
689 typedef typename ScalarPrimitiveTypeTraits::primitiveType
primitiveType;
692 {
return 2*ScalarPrimitiveTypeTraits::numPrimitiveObjs(); }
699 const std::complex<Scalar> &obj,
700 const ArrayView<primitiveType> &primitiveObjs,
701 const ArrayView<index_type> &indexObjs,
702 const ArrayView<char> &charObjs
706 const int numScalarPrimitiveObjs =
707 ScalarPrimitiveTypeTraits::numPrimitiveObjs();
708 assertInput(primitiveObjs, indexObjs, charObjs);
709 ScalarPrimitiveTypeTraits::extractPrimitiveObjs(
710 obj.real(), primitiveObjs(0,numScalarPrimitiveObjs), null, null );
711 ScalarPrimitiveTypeTraits::extractPrimitiveObjs(
712 obj.imag(), primitiveObjs(numScalarPrimitiveObjs,numScalarPrimitiveObjs), null, null );
716 const ArrayView<const primitiveType> &primitiveObjs,
717 const ArrayView<const index_type> &indexObjs,
718 const ArrayView<const char> &charObjs,
719 const Ptr<std::complex<Scalar> > &obj
723 using Teuchos::outArg;
724 assertInput(primitiveObjs, indexObjs, charObjs);
725 const int numScalarPrimitiveObjs =
726 ScalarPrimitiveTypeTraits::numPrimitiveObjs();
728 ScalarPrimitiveTypeTraits::loadPrimitiveObjs(
729 primitiveObjs(0,numScalarPrimitiveObjs), null, null,
731 ScalarPrimitiveTypeTraits::loadPrimitiveObjs(
732 primitiveObjs(numScalarPrimitiveObjs,numScalarPrimitiveObjs), null, null,
734 *obj = std::complex<Scalar>( real, imag );
737 static void assertInput(
738 const ArrayView<const primitiveType> &primitiveObjs,
739 const ArrayView<const index_type> &indexObjs,
740 const ArrayView<const char> &charObjs
745 primitiveObjs.size()!=2*ScalarPrimitiveTypeTraits::numPrimitiveObjs()
746 || indexObjs.size()!=0
747 || charObjs.size()!=0 );
756 template <
class Scalar>
757 class PrimitiveTypeTraits<std::complex<Scalar>, Scalar> {
760 typedef PrimitiveTypeTraits<Scalar,Scalar> ScalarPrimitiveTypeTraits;
762 typedef typename ScalarPrimitiveTypeTraits::primitiveType
primitiveType;
765 {
return ScalarPrimitiveTypeTraits::numPrimitiveObjs(); }
773 const ArrayView<primitiveType> &primitiveObjs,
774 const ArrayView<index_type> &indexObjs,
775 const ArrayView<char> &charObjs
779 assertInput(primitiveObjs, indexObjs, charObjs);
780 ScalarPrimitiveTypeTraits::extractPrimitiveObjs(
781 obj, primitiveObjs, null, null );
785 const ArrayView<const primitiveType> &primitiveObjs,
786 const ArrayView<const index_type> &indexObjs,
787 const ArrayView<const char> &charObjs,
788 const Ptr<Scalar > &obj
792 assertInput(primitiveObjs, indexObjs, charObjs);
793 ScalarPrimitiveTypeTraits::loadPrimitiveObjs(
794 primitiveObjs, null, null, obj );
797 static void assertInput(
798 const ArrayView<const primitiveType> &primitiveObjs,
799 const ArrayView<const index_type> &indexObjs,
800 const ArrayView<const char> &charObjs
805 primitiveObjs.size()!=ScalarPrimitiveTypeTraits::numPrimitiveObjs()
806 || indexObjs.size()!=0
807 || charObjs.size()!=0 );
813 #endif // defined(HAVE_COMPLEX) && defined(HAVE_TEUCHOS_COMPLEX)
823 template<
class Scalar>
class RTOpT;
829 #endif // RTOPPACK_TYPES_HPP
ConstSubMultiVectorView(Ordinal globalOffset_in, Ordinal subDim_in, Ordinal colOffset_in, Ordinal numSubCols_in, const ArrayRCP< const Scalar > &values_in, Ordinal leadingDim_in)
Ordinal colOffset() const
Ordinal numSubCols() const
bool is_null(const boost::shared_ptr< T > &p)
ConstSubMultiVectorView()
ArrayRCP< T > persistingView(size_type lowerOffset, size_type size) const
static int numPrimitiveObjs()
static void extractPrimitiveObjs(const Scalar &obj, const ArrayView< primitiveType > &primitiveObjs, const ArrayView< index_type > &indexObjs, const ArrayView< char > &charObjs)
Class for a changeable sub-vector.
SubMultiVectorView(const SubMultiVectorView< Scalar > &smv)
basic_FancyOStream< char > FancyOStream
static void loadPrimitiveObjs(const ArrayView< const primitiveType > &primitiveObjs, const ArrayView< const index_type > &indexObjs, const ArrayView< const char > &charObjs, const Ptr< Scalar > &obj)
size_type upperOffset() const
const ArrayRCP< Scalar > values() const
ConstSubVectorView(Ordinal globalOffset_in, Ordinal subDim_in, const ArrayRCP< const Scalar > &values_in, ptrdiff_t stride_in)
static int numIndexObjs()
SubMultiVectorView(Ordinal globalOffset_in, Ordinal subDim_in, Ordinal colOffset_in, Ordinal numSubCols_in, const ArrayRCP< Scalar > &values_in, Ordinal leadingDim_in)
Class for a non-changeable sub-vector.
Ordinal globalOffset() const
SubVectorView(const ArrayRCP< Scalar > &values_in)
SubMultiVectorView(Ordinal numRows_in, Ordinal numCols_in)
#define TEUCHOS_ASSERT_IN_RANGE_UPPER_EXCLUSIVE(index, lower_inclusive, upper_exclusive)
Scalar & operator()(Ordinal i) const
Zero-based indexing (Preconditions: values()!=NULL && (0 <= i < subDim())).
static int numIndexObjs()
const ArrayRCP< Scalar > values() const
SubVectorView(Ordinal subDim_in)
Specialization where the scalar type is the same as the concrete object type.
A templated traits class for decomposing object into an array of primitive objects.
Ordinal leadingDim() const
static int numPrimitiveObjs()
SubVectorView(const SubVectorView< Scalar > &sv)
Class for a changeable sub-vector.
SubVectorView< Scalar > col(const Ordinal j) const
Return a SubVectorView view of the jth sub-column (Preconditions: values()!=NULL && && (0<=j<numSubCo...
SubVectorView(Ordinal globalOffset_in, Ordinal subDim_in, const ArrayRCP< Scalar > &values_in, ptrdiff_t stride_in)
void initialize(Ordinal globalOffset_in, Ordinal subDim_in, Ordinal colOffset_in, Ordinal numSubCols_in, const ArrayRCP< Scalar > &values_in, Ordinal leadingDim_in)
void initialize(Ordinal globalOffset_in, Ordinal subDim_in, const ArrayRCP< Scalar > &values_in, ptrdiff_t stride_in)
size_type lowerOffset() const
const Scalar & operator[](Ordinal i) const
Zero-based indexing (Preconditions: values()!=NULL && (0 <= i < subDim())).
static void extractPrimitiveObjs(const Scalar &obj, const ArrayView< primitiveType > &primitiveObjs, const ArrayView< index_type > &indexObjs, const ArrayView< char > &charObjs)
void setGlobalOffset(Ordinal globalOffset_in)
ConstSubVectorView(const ConstSubVectorView< Scalar > &sv)
Ordinal globalOffset() const
static int numIndexObjs()
void setGlobalOffset(Ordinal globalOffset_in)
ConstSubVectorView(const ArrayRCP< const Scalar > &values_in)
const ArrayRCP< const Scalar > values() const
static int numPrimitiveObjs()
Class for a non-changeable sub-multi-vector (submatrix).
ScalarPrimitiveTypeTraits::primitiveType primitiveType
void initialize(Ordinal globalOffset_in, Ordinal subDim_in, Ordinal colOffset_in, Ordinal numSubCols_in, const ArrayRCP< const Scalar > &values_in, Ordinal leadingDim_in)
static void loadPrimitiveObjs(const ArrayView< const primitiveType > &primitiveObjs, const ArrayView< const index_type > &indexObjs, const ArrayView< const char > &charObjs, const Ptr< index_type > &obj)
static void loadPrimitiveObjs(const ArrayView< const primitiveType > &primitiveObjs, const ArrayView< const index_type > &indexObjs, const ArrayView< const char > &charObjs, const Ptr< Scalar > &obj)
const Scalar & operator()(Ordinal i) const
Zero-based indexing (Preconditions: values()!=NULL && (0 <= i < subDim())).
ConstSubVectorView< Scalar > col(const Ordinal j) const
Return a ConstSubVectorView view of the jth sub-column (Preconditions: values()!=NULL && (0<=j<numSub...
PrimitiveTypeTraits< Scalar, Scalar > ScalarPrimitiveTypeTraits
#define TEUCHOS_ASSERT(assertion_test)
#define TEUCHOS_ASSERT_EQUALITY(val1, val2)
static void extractPrimitiveObjs(const index_type &obj, const ArrayView< primitiveType > &primitiveObjs, const ArrayView< index_type > &indexObjs, const ArrayView< char > &charObjs)
Scalar & operator[](Ordinal i) const
Zero-based indexing (Preconditions: values()!=NULL && (0 <= i < subDim())).
#define TEUCHOS_TEST_FOR_EXCEPT(throw_exception_test)
ConstSubMultiVectorView(const ConstSubMultiVectorView< Scalar > &smv)
const ArrayRCP< const Scalar > values() const
Scalar & operator()(Ordinal i, Ordinal j) const
Zero-based indexing (Preconditions: values()!=NULL && (0<=i< subDim()) && (0<=j<numSubCols()).
const Scalar & operator()(Ordinal i, Ordinal j) const
Zero-based indexing (Preconditions: values()!=NULL && (0<=i<subDim()) && (0<=j< numSubCols()).
void initialize(Ordinal globalOffset_in, Ordinal subDim_in, const ArrayRCP< const Scalar > &values_in, ptrdiff_t stride_in)