RTOpPack_Types.hpp

00001 // @HEADER
00002 // ***********************************************************************
00003 // 
00004 // RTOp: Interfaces and Support Software for Vector Reduction Transformation
00005 //       Operations
00006 //                Copyright (2006) Sandia Corporation
00007 // 
00008 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
00009 // license for use of this work by or on behalf of the U.S. Government.
00010 // 
00011 // This library is free software; you can redistribute it and/or modify
00012 // it under the terms of the GNU Lesser General Public License as
00013 // published by the Free Software Foundation; either version 2.1 of the
00014 // License, or (at your option) any later version.
00015 //  
00016 // This library is distributed in the hope that it will be useful, but
00017 // WITHOUT ANY WARRANTY; without even the implied warranty of
00018 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00019 // Lesser General Public License for more details.
00020 //  
00021 // You should have received a copy of the GNU Lesser General Public
00022 // License along with this library; if not, write to the Free Software
00023 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00024 // USA
00025 // Questions? Contact Roscoe A. Bartlett (rabartl@sandia.gov) 
00026 // 
00027 // ***********************************************************************
00028 // @HEADER
00029 
00030 
00031 #ifndef RTOPPACK_TYPES_HPP
00032 #define RTOPPACK_TYPES_HPP
00033 
00034 
00035 #include "RTOp_ConfigDefs.hpp"
00036 #include "Teuchos_Array.hpp"
00037 #include "Teuchos_RCP.hpp"
00038 #include "Teuchos_ArrayRCP.hpp"
00039 #include "Teuchos_ScalarTraits.hpp"
00040 #include "Teuchos_TypeNameTraits.hpp"
00041 #include "Teuchos_TestForException.hpp"
00042 #include "Teuchos_implicit_cast.hpp"
00043 
00044 
00045 namespace RTOpPack {
00046 
00047 
00048 //
00049 // Basic types
00050 //
00051 
00053 typedef Teuchos_Index Index;
00055 using Teuchos::Ptr;
00057 using Teuchos::RCP;
00059 using Teuchos::ArrayRCP;
00061 using Teuchos::ArrayView;
00063 using Teuchos::Array;
00065 using Teuchos::ScalarTraits;
00067 using Teuchos::TypeNameTraits;
00068 
00070 typedef Teuchos_Index index_type;
00072 typedef char  char_type;
00073 
00074 
00075 //
00076 // Exceptions
00077 //
00078 
00079 
00081 class UnknownError : public std::logic_error
00082 {public: UnknownError(const std::string& what_arg) : std::logic_error(what_arg) {}};
00084 class InvalidUsage : public std::logic_error
00085 {public: InvalidUsage(const std::string& what_arg) : std::logic_error(what_arg) {}};
00087 class InvalidNumVecs : public std::logic_error
00088 {public: InvalidNumVecs(const std::string& what_arg) : std::logic_error(what_arg) {}};
00090 class InvalidNumTargVecs : public std::logic_error
00091 {public: InvalidNumTargVecs(const std::string& what_arg) : std::logic_error(what_arg) {}};
00093 class IncompatibleVecs : public std::logic_error
00094 {public: IncompatibleVecs(const std::string& what_arg) : std::logic_error(what_arg) {}};
00096 class IncompatibleReductObj : public std::logic_error
00097 {public: IncompatibleReductObj(const std::string& what_arg) : std::logic_error(what_arg) {}};
00098 
00099 
00100 //
00101 // VectorBase subviews
00102 //
00103 
00104 
00124 template<class Scalar>
00125 class ConstSubVectorView {
00126 public:
00128   ConstSubVectorView() : globalOffset_(0), subDim_(0), stride_(0) {}
00130   ConstSubVectorView(const ArrayRCP<const Scalar> &values)
00131     :globalOffset_(0), subDim_(0), stride_(0)
00132     { initialize(0, values.size(), values, 1); }
00134   ConstSubVectorView(Teuchos_Index globalOffset, Teuchos_Index subDim,
00135     const ArrayRCP<const Scalar> &values, ptrdiff_t stride)
00136     :globalOffset_(0), subDim_(0), stride_(0)
00137     { initialize(globalOffset, subDim, values, stride); }
00139   ConstSubVectorView( const ConstSubVectorView<Scalar>& sv )
00140     :globalOffset_(sv.globalOffset()), subDim_(sv.subDim()),
00141      values_(sv.values()), stride_(sv.stride()) 
00142     {}
00144   void initialize(Teuchos_Index globalOffset, Teuchos_Index subDim,
00145     const ArrayRCP<const Scalar> &values, ptrdiff_t stride)
00146     {
00147 #ifdef TEUCHOS_DEBUG
00148       TEUCHOS_ASSERT(globalOffset >= 0);
00149       if (!is_null(values)) {
00150         TEUCHOS_ASSERT(subDim >= 0);
00151         TEUCHOS_ASSERT(stride != 0);
00152         TEUCHOS_ASSERT(
00153           subDim*std::abs(Teuchos::as<int>(stride)) - 1 <= values.upperOffset());
00154         TEUCHOS_ASSERT(values.lowerOffset() <= 0);
00155       }
00156       else {
00157         TEUCHOS_ASSERT(stride == 0);
00158         TEUCHOS_ASSERT(subDim==0);
00159       }
00160 #endif
00161       globalOffset_=globalOffset;
00162       subDim_=subDim;
00163       values_=values;
00164       stride_=stride;
00165     }
00167   void uninitialize()
00168     { globalOffset_ = 0; subDim_=0; values_ = Teuchos::null; stride_ = 0; }
00170   void setGlobalOffset(Teuchos_Index globalOffset)
00171     {
00172 #ifdef TEUCHOS_DEBUG
00173       TEUCHOS_ASSERT(globalOffset >= 0);
00174 #endif
00175       globalOffset_ = globalOffset;
00176     } 
00178   Teuchos_Index globalOffset() const { return globalOffset_; }
00180   Teuchos_Index subDim() const { return subDim_; }
00182   const ArrayRCP<const Scalar>  values() const { return values_; }
00184   ptrdiff_t stride() const { return stride_; }
00187   const Scalar& operator[](Teuchos_Index i) const
00188     {
00189 #ifdef TEUCHOS_DEBUG
00190       TEUCHOS_ASSERT_IN_RANGE_UPPER_EXCLUSIVE(i, 0, subDim_);
00191 #endif
00192       return valuesBegin()[stride_*i];
00193     }
00196   const Scalar& operator()(Teuchos_Index i) const { return (*this)[i]; }
00197 private:
00198   Teuchos_Index globalOffset_;
00199   Teuchos_Index subDim_;
00200   ArrayRCP<const Scalar> values_;
00201   ptrdiff_t stride_;
00202   const typename ArrayRCP<const Scalar>::iterator valuesBegin() const
00203     {
00204       if (stride_ > 0)
00205         return values_.begin();
00206       return values_.begin() + (subDim_*std::abs(Teuchos::as<int>(stride_)) - 1);
00207     } 
00208 public:
00210   ConstSubVectorView(Teuchos_Index globalOffset, Teuchos_Index subDim,
00211     const Scalar values[], ptrdiff_t stride)
00212     :globalOffset_(globalOffset), subDim_(subDim),
00213      values_(values,0,subDim*stride,false), stride_(stride) 
00214     {}
00216   void initialize(Teuchos_Index globalOffset, Teuchos_Index subDim,
00217     const Scalar values[], ptrdiff_t stride)
00218     {
00219       globalOffset_=globalOffset; subDim_=subDim;
00220       values_=Teuchos::arcp(values, 0,
00221         subDim*std::abs(Teuchos::as<int>(stride)), false);
00222       stride_=stride;
00223     }
00225   void set_uninitialized()
00226     { uninitialize(); }
00227 };
00228 
00229 
00246 template<class Scalar>
00247 class SubVectorView : public ConstSubVectorView<Scalar> {
00248 public:
00250   SubVectorView() {}
00252   SubVectorView(const ArrayRCP<Scalar> &values)
00253     :ConstSubVectorView<Scalar>(values)
00254     {}
00256   SubVectorView(Teuchos_Index globalOffset, Teuchos_Index subDim,
00257     const ArrayRCP<Scalar> &values, ptrdiff_t stride)
00258     :ConstSubVectorView<Scalar>(globalOffset, subDim, values, stride)
00259     {}
00261   SubVectorView(Teuchos_Index subDim)
00262     :ConstSubVectorView<Scalar>(0, subDim, Teuchos::arcp<Scalar>(subDim), 1)
00263     {}
00265   SubVectorView(const SubVectorView<Scalar> & sv)
00266     :ConstSubVectorView<Scalar>(sv)
00267     {}
00269   void initialize(Teuchos_Index globalOffset, Teuchos_Index subDim,
00270     const ArrayRCP<Scalar> &values, ptrdiff_t stride)
00271     { ConstSubVectorView<Scalar>::initialize(globalOffset, subDim, values, stride); }
00273   const ArrayRCP<Scalar> values() const
00274     { return Teuchos::arcp_const_cast<Scalar>(ConstSubVectorView<Scalar>::values());  }
00277   Scalar& operator[](Teuchos_Index i) const
00278     { return const_cast<Scalar&>(ConstSubVectorView<Scalar>::operator[](i)); }
00281   Scalar& operator()(Teuchos_Index i) const { return (*this)[i]; }
00282 public:
00284   SubVectorView(Teuchos_Index globalOffset, Teuchos_Index subDim,
00285     Scalar values[], ptrdiff_t stride)
00286     :ConstSubVectorView<Scalar>(globalOffset, subDim, values, stride)
00287     {}
00289   void initialize(Teuchos_Index globalOffset, Teuchos_Index subDim,
00290     Scalar values[], ptrdiff_t stride)
00291     { ConstSubVectorView<Scalar>::initialize(globalOffset, subDim, values, stride); }
00292 };
00293 
00294 
00296 template<class Scalar>
00297 void assign_entries( const Ptr<const SubVectorView<Scalar> > &msv,
00298   const ConstSubVectorView<Scalar> &sv )
00299 {
00300 #ifdef TEUCHOS_DEBUG
00301   TEUCHOS_ASSERT_EQUALITY(msv->subDim(), sv.subDim());
00302 #endif
00303   for( int i = 0; i < sv.subDim(); ++i ) {
00304     (*msv)(i) = sv(i);
00305   }
00306 }
00307 
00308 
00313 template<class Scalar>
00314 std::ostream& operator<<(std::ostream &out, const ConstSubVectorView<Scalar> &sv)
00315 {
00316   out
00317     << "{"
00318     << "globalOffset="<<sv.globalOffset()
00319     << ",subDim="<<sv.subDim()
00320     << ",values="<<sv.values()
00321     << ",stride="<<sv.stride()
00322     << "}";
00323   return out;
00324 }
00325 
00326 
00327 //
00328 // MultiVectorBase subviews
00329 //
00330 
00331 
00353 template<class Scalar>
00354 class ConstSubMultiVectorView {
00355 public:
00357   ConstSubMultiVectorView()
00358     :globalOffset_(0), subDim_(0), colOffset_(0), numSubCols_(0),
00359      leadingDim_(0)
00360     {}
00362   ConstSubMultiVectorView(
00363     Teuchos_Index globalOffset, Teuchos_Index subDim,
00364     Teuchos_Index colOffset, Teuchos_Index numSubCols,
00365     const ArrayRCP<const Scalar> &values, Teuchos_Index leadingDim
00366     )
00367     :globalOffset_(0), subDim_(0), colOffset_(0), numSubCols_(0),
00368      leadingDim_(0)
00369     {
00370       initialize(globalOffset, subDim, colOffset, numSubCols, values,
00371         leadingDim);
00372     }
00374   ConstSubMultiVectorView( const ConstSubMultiVectorView<Scalar>& smv )
00375     :globalOffset_(smv.globalOffset()), subDim_(smv.subDim()),
00376      colOffset_(smv.colOffset()), numSubCols_(smv.numSubCols()),
00377      values_(smv.values()), leadingDim_(smv.leadingDim())
00378     {}
00380   void initialize(
00381     Teuchos_Index globalOffset, Teuchos_Index subDim,
00382     Teuchos_Index colOffset, Teuchos_Index numSubCols,
00383     const ArrayRCP<const Scalar> &values, Teuchos_Index leadingDim
00384     )
00385     {
00386 #ifdef TEUCHOS_DEBUG
00387       TEUCHOS_ASSERT(globalOffset >= 0);
00388       TEUCHOS_ASSERT(colOffset >= 0);
00389       if (!is_null(values)) {
00390         TEUCHOS_ASSERT(subDim >= 0);
00391         TEUCHOS_ASSERT(leadingDim >= subDim);
00392         TEUCHOS_ASSERT(numSubCols*leadingDim - 1 <= values.upperOffset());
00393         TEUCHOS_ASSERT(values.lowerOffset() <= 0);
00394       }
00395       else {
00396         TEUCHOS_ASSERT(subDim == 0);
00397         TEUCHOS_ASSERT(leadingDim == 0);
00398         TEUCHOS_ASSERT(numSubCols == 0);
00399       }
00400 #endif
00401       globalOffset_=globalOffset;
00402       subDim_=subDim;
00403       colOffset_=colOffset;
00404       numSubCols_=numSubCols;
00405       values_=values;
00406       leadingDim_=leadingDim;
00407     }
00409   void uninitialize()
00410     {
00411       globalOffset_ = 0; subDim_=0; colOffset_=0, numSubCols_=0;
00412       values_=Teuchos::null; leadingDim_=0;
00413     }
00415   void setGlobalOffset(Teuchos_Index globalOffset)
00416     {
00417 #ifdef TEUCHOS_DEBUG
00418       TEUCHOS_ASSERT(globalOffset >= 0);
00419 #endif
00420       globalOffset_ = globalOffset;
00421     } 
00423   Teuchos_Index globalOffset() const { return globalOffset_; }
00425   Teuchos_Index subDim() const { return subDim_; }
00427   Teuchos_Index colOffset() const { return colOffset_; }
00429   Teuchos_Index numSubCols() const { return numSubCols_; }
00431   const ArrayRCP<const Scalar> values() const { return values_; }
00433   Teuchos_Index leadingDim() const { return leadingDim_; }
00437   const Scalar& operator()(Teuchos_Index i, Teuchos_Index j) const
00438     {
00439 #ifdef TEUCHOS_DEBUG
00440       TEUCHOS_ASSERT_IN_RANGE_UPPER_EXCLUSIVE(i, 0, subDim_);
00441       TEUCHOS_ASSERT_IN_RANGE_UPPER_EXCLUSIVE(j, 0, numSubCols_ );
00442 #endif
00443       return values_[ i + leadingDim_*j ];
00444     }
00448   ConstSubVectorView<Scalar> col( const Teuchos_Index j ) const
00449     {
00450 #ifdef TEUCHOS_DEBUG
00451       TEUCHOS_ASSERT_IN_RANGE_UPPER_EXCLUSIVE(j, 0, numSubCols_ );
00452 #endif
00453       return ConstSubVectorView<Scalar>(
00454         globalOffset(), subDim(), values().persistingView(j*leadingDim(),subDim()), 1 );
00455     }
00456 private:
00457   Teuchos_Index globalOffset_;
00458   Teuchos_Index subDim_;
00459   Teuchos_Index colOffset_;
00460   Teuchos_Index numSubCols_;
00461   ArrayRCP<const Scalar> values_;
00462   Teuchos_Index leadingDim_;
00463 public:
00465   ConstSubMultiVectorView(
00466     Teuchos_Index globalOffset, Teuchos_Index subDim,
00467     Teuchos_Index colOffset, Teuchos_Index numSubCols,
00468     const Scalar values[], Teuchos_Index leadingDim
00469     )
00470     :globalOffset_(globalOffset), subDim_(subDim),
00471      colOffset_(colOffset), numSubCols_(numSubCols),
00472      values_(values,0,numSubCols*leadingDim,false),
00473      leadingDim_(leadingDim)
00474     {}
00476   void initialize(
00477     Teuchos_Index globalOffset, Teuchos_Index subDim,
00478     Teuchos_Index colOffset, Teuchos_Index numSubCols,
00479     const Scalar values[], Teuchos_Index leadingDim
00480     )
00481     {
00482       globalOffset_=globalOffset; subDim_=subDim; colOffset_=colOffset;
00483       numSubCols_=numSubCols;
00484       values_=Teuchos::arcp(values,0,numSubCols*leadingDim,false);
00485       leadingDim_=leadingDim;
00486     }
00488   void set_uninitialized()
00489     { uninitialize(); }
00490 };
00491 
00492 
00509 template<class Scalar>
00510 class SubMultiVectorView : public ConstSubMultiVectorView<Scalar> {
00511 public:
00513   SubMultiVectorView() {}
00515   SubMultiVectorView(
00516     Teuchos_Index numRows, Teuchos_Index numCols
00517     )
00518     :ConstSubMultiVectorView<Scalar>(0, numRows, 0, numCols,
00519       Teuchos::arcp<Scalar>(numRows*numCols), numRows)
00520     {}
00522   SubMultiVectorView(
00523     Teuchos_Index globalOffset, Teuchos_Index subDim,
00524     Teuchos_Index colOffset, Teuchos_Index numSubCols,
00525     const ArrayRCP<Scalar> &values, Teuchos_Index leadingDim
00526     )
00527     :ConstSubMultiVectorView<Scalar>(globalOffset,subDim,colOffset,numSubCols,
00528       values,leadingDim)
00529     {}
00531   SubMultiVectorView( const SubMultiVectorView<Scalar> & smv)
00532     :ConstSubMultiVectorView<Scalar>(smv)
00533     {}
00535  void initialize(
00536    Teuchos_Index globalOffset, Teuchos_Index subDim,
00537    Teuchos_Index colOffset, Teuchos_Index numSubCols,
00538    const ArrayRCP<Scalar> &values, Teuchos_Index leadingDim
00539    )
00540    {
00541      ConstSubMultiVectorView<Scalar>::initialize(globalOffset,subDim,
00542        colOffset,numSubCols,values,leadingDim);
00543    }
00545   const ArrayRCP<Scalar> values() const
00546     {
00547       return Teuchos::arcp_const_cast<Scalar>(
00548         ConstSubMultiVectorView<Scalar>::values());
00549     }
00553   Scalar& operator()(Teuchos_Index i, Teuchos_Index j) const
00554     { return const_cast<Scalar&>(ConstSubMultiVectorView<Scalar>::operator()(i,j)); }
00558   SubVectorView<Scalar> col( const Teuchos_Index j ) const
00559     {
00560 #ifdef TEUCHOS_DEBUG
00561       TEUCHOS_ASSERT_IN_RANGE_UPPER_EXCLUSIVE(j, 0, this->numSubCols());
00562 #endif
00563       return SubVectorView<Scalar>(this->globalOffset(), this->subDim(),
00564         values().persistingView(j*this->leadingDim(),this->subDim()), 1);
00565     }
00566 public:
00568   SubMultiVectorView(
00569     Teuchos_Index globalOffset, Teuchos_Index subDim,
00570     Teuchos_Index colOffset, Teuchos_Index numSubCols,
00571     Scalar values[], Teuchos_Index leadingDim
00572     )
00573     :ConstSubMultiVectorView<Scalar>(globalOffset,subDim,colOffset,numSubCols,
00574       values,leadingDim)
00575     {}
00577  void initialize(
00578    Teuchos_Index globalOffset, Teuchos_Index subDim,
00579    Teuchos_Index colOffset, Teuchos_Index numSubCols,
00580    Scalar values[], Teuchos_Index leadingDim
00581    )
00582    {
00583      ConstSubMultiVectorView<Scalar>::initialize(globalOffset,subDim,
00584        colOffset,numSubCols,values,leadingDim);
00585    }
00586 };
00587 
00588 
00590 template<class Scalar>
00591 void assign_entries( const Ptr<const SubMultiVectorView<Scalar> > &msmv,
00592   const ConstSubMultiVectorView<Scalar> &smv )
00593 {
00594 #ifdef TEUCHOS_DEBUG
00595   TEUCHOS_ASSERT_EQUALITY(msmv->subDim(), smv.subDim());
00596   TEUCHOS_ASSERT_EQUALITY(msmv->numSubCols(), smv.numSubCols());
00597 #endif
00598   for( Teuchos_Index j = 0; j < smv.numSubCols(); ++j ) {
00599     for( Teuchos_Index i = 0; i < smv.subDim(); ++i ) {
00600       (*msmv)(i,j) = smv(i,j);
00601     }
00602   }
00603 }
00604 
00605 
00606 //
00607 // Primitive Type Traits
00608 //
00609 
00610 
00621 template <class Scalar, class ConcreteObj>
00622 class PrimitiveTypeTraits {
00623 public:
00625   typedef Scalar primitiveType;
00627   static int numPrimitiveObjs()
00628     { return Scalar::this_type_is_missing_a_specialization(); }
00630   static int numIndexObjs()
00631     { return Scalar::this_type_is_missing_a_specialization(); }
00633   static int numCharObjs()
00634     { return Scalar::this_type_is_missing_a_specialization(); }
00636   static void extractPrimitiveObjs(
00637     const Scalar &obj,
00638     const ArrayView<primitiveType> &primitiveObjs,
00639     const ArrayView<index_type> &indexObjs,
00640     const ArrayView<char> &charObjs
00641     )
00642     {
00643       Scalar::this_type_is_missing_a_specialization(obj);
00644     }
00646   static void loadPrimitiveObjs(
00647     const ArrayView<const primitiveType> &primitiveObjs,
00648     const ArrayView<const index_type> &indexObjs,
00649     const ArrayView<const char> &charObjs,
00650     const Ptr<Scalar> &obj
00651     )
00652     {
00653       *obj = Scalar::this_type_is_missing_a_specialization();
00654     }
00655 };
00656 
00657 
00658 
00662 template <class Scalar>
00663 class PrimitiveTypeTraits<Scalar, Scalar> {
00664 public:
00666   typedef Scalar primitiveType;
00668   static int numPrimitiveObjs() { return 1; }
00670   static int numIndexObjs() { return 0; }
00672   static int numCharObjs() { return 0; }
00674   static void extractPrimitiveObjs(
00675     const Scalar &obj,
00676     const ArrayView<primitiveType> &primitiveObjs,
00677     const ArrayView<index_type> &indexObjs,
00678     const ArrayView<char> &charObjs
00679     )
00680     {
00681       assertInput(primitiveObjs, indexObjs, charObjs);
00682       primitiveObjs[0] = obj;
00683     }
00685   static void loadPrimitiveObjs(
00686     const ArrayView<const primitiveType> &primitiveObjs,
00687     const ArrayView<const index_type> &indexObjs,
00688     const ArrayView<const char> &charObjs,
00689     const Ptr<Scalar> &obj
00690     )
00691     {
00692       assertInput(primitiveObjs, indexObjs, charObjs);
00693       *obj = primitiveObjs[0];
00694     }
00695 private:
00696   static void assertInput(
00697     const ArrayView<const primitiveType> &primitiveObjs,
00698     const ArrayView<const index_type> &indexObjs,
00699     const ArrayView<const char> &charObjs
00700     )
00701     {
00702 #ifdef TEUCHOS_DEBUG
00703       TEST_FOR_EXCEPT( primitiveObjs.size()!=1 || indexObjs.size()!=0
00704         || charObjs.size()!=0 );
00705 #endif
00706     }
00707 };
00708 
00709 
00711 template <class Scalar>
00712 class PrimitiveTypeTraits<Scalar, index_type> {
00713 public:
00715   typedef PrimitiveTypeTraits<Scalar,Scalar> ScalarPrimitiveTypeTraits;
00717   typedef typename ScalarPrimitiveTypeTraits::primitiveType primitiveType;
00719   static int numPrimitiveObjs() { return 0; }
00721   static int numIndexObjs() { return 1; }
00723   static int numCharObjs() { return 0; }
00725   static void extractPrimitiveObjs(
00726     const index_type &obj,
00727     const ArrayView<primitiveType> &primitiveObjs,
00728     const ArrayView<index_type> &indexObjs,
00729     const ArrayView<char> &charObjs
00730     )
00731     {
00732       assertInput(primitiveObjs, indexObjs, charObjs);
00733       indexObjs[0] = obj;
00734     }
00736   static void loadPrimitiveObjs(
00737     const ArrayView<const primitiveType> &primitiveObjs,
00738     const ArrayView<const index_type> &indexObjs,
00739     const ArrayView<const char> &charObjs,
00740     const Ptr<index_type> &obj
00741     )
00742     {
00743       assertInput(primitiveObjs, indexObjs, charObjs);
00744       *obj = indexObjs[0];
00745     }
00746 private:
00747   static void assertInput(
00748     const ArrayView<const primitiveType> &primitiveObjs,
00749     const ArrayView<const index_type> &indexObjs,
00750     const ArrayView<const char> &charObjs
00751     )
00752     {
00753 #ifdef TEUCHOS_DEBUG
00754       TEST_FOR_EXCEPT( primitiveObjs.size()!=0 || indexObjs.size()!=1
00755         || charObjs.size()!=0 );
00756 #endif
00757     }
00758 };
00759 
00760 
00761 #if defined(HAVE_COMPLEX) && defined(HAVE_TEUCHOS_COMPLEX)
00762 
00763 
00767 template <class Scalar>
00768 class PrimitiveTypeTraits<std::complex<Scalar>, std::complex<Scalar> > {
00769 public:
00771   typedef PrimitiveTypeTraits<Scalar,Scalar> ScalarPrimitiveTypeTraits;
00773   typedef typename ScalarPrimitiveTypeTraits::primitiveType primitiveType;
00775   static int numPrimitiveObjs()
00776     { return 2*ScalarPrimitiveTypeTraits::numPrimitiveObjs(); }
00778   static int numIndexObjs() { return 0; }
00780   static int numCharObjs() { return 0; }
00782   static void extractPrimitiveObjs(
00783     const std::complex<Scalar> &obj,
00784     const ArrayView<primitiveType> &primitiveObjs,
00785     const ArrayView<index_type> &indexObjs,
00786     const ArrayView<char> &charObjs
00787     )
00788     {
00789       using Teuchos::null;
00790       const int numScalarPrimitiveObjs =
00791         ScalarPrimitiveTypeTraits::numPrimitiveObjs();
00792       assertInput(primitiveObjs, indexObjs, charObjs);
00793       ScalarPrimitiveTypeTraits::extractPrimitiveObjs(
00794         obj.real(), primitiveObjs(0,numScalarPrimitiveObjs), null, null );
00795       ScalarPrimitiveTypeTraits::extractPrimitiveObjs(
00796         obj.imag(), primitiveObjs(numScalarPrimitiveObjs,numScalarPrimitiveObjs), null, null );
00797     }
00799   static void loadPrimitiveObjs(
00800     const ArrayView<const primitiveType> &primitiveObjs,
00801     const ArrayView<const index_type> &indexObjs,
00802     const ArrayView<const char> &charObjs,
00803     const Ptr<std::complex<Scalar> > &obj
00804     )
00805     {
00806       using Teuchos::null;
00807       using Teuchos::outArg;
00808       assertInput(primitiveObjs, indexObjs, charObjs);
00809       const int numScalarPrimitiveObjs =
00810         ScalarPrimitiveTypeTraits::numPrimitiveObjs();
00811       Scalar real, imag;
00812       ScalarPrimitiveTypeTraits::loadPrimitiveObjs(
00813         primitiveObjs(0,numScalarPrimitiveObjs), null, null,
00814         outArg(real) );
00815       ScalarPrimitiveTypeTraits::loadPrimitiveObjs(
00816         primitiveObjs(numScalarPrimitiveObjs,numScalarPrimitiveObjs), null, null,
00817         outArg(imag) );
00818       *obj = std::complex<Scalar>( real, imag );
00819     }
00820 private:
00821   static void assertInput(
00822     const ArrayView<const primitiveType> &primitiveObjs,
00823     const ArrayView<const index_type> &indexObjs,
00824     const ArrayView<const char> &charObjs
00825     )
00826     {
00827 #ifdef TEUCHOS_DEBUG
00828       TEST_FOR_EXCEPT(
00829         primitiveObjs.size()!=2*ScalarPrimitiveTypeTraits::numPrimitiveObjs()
00830         || indexObjs.size()!=0
00831         || charObjs.size()!=0 );
00832 #endif
00833     }
00834 };
00835 
00836 
00840 template <class Scalar>
00841 class PrimitiveTypeTraits<std::complex<Scalar>, Scalar> {
00842 public:
00844   typedef PrimitiveTypeTraits<Scalar,Scalar> ScalarPrimitiveTypeTraits;
00846   typedef typename ScalarPrimitiveTypeTraits::primitiveType primitiveType;
00848   static int numPrimitiveObjs()
00849     { return ScalarPrimitiveTypeTraits::numPrimitiveObjs(); }
00851   static int numIndexObjs() { return 0; }
00853   static int numCharObjs() { return 0; }
00855   static void extractPrimitiveObjs(
00856     const Scalar &obj,
00857     const ArrayView<primitiveType> &primitiveObjs,
00858     const ArrayView<index_type> &indexObjs,
00859     const ArrayView<char> &charObjs
00860     )
00861     {
00862       using Teuchos::null;
00863       assertInput(primitiveObjs, indexObjs, charObjs);
00864       ScalarPrimitiveTypeTraits::extractPrimitiveObjs(
00865         obj, primitiveObjs, null, null );
00866     }
00868   static void loadPrimitiveObjs(
00869     const ArrayView<const primitiveType> &primitiveObjs,
00870     const ArrayView<const index_type> &indexObjs,
00871     const ArrayView<const char> &charObjs,
00872     const Ptr<Scalar > &obj
00873     )
00874     {
00875       using Teuchos::null;
00876       assertInput(primitiveObjs, indexObjs, charObjs);
00877       ScalarPrimitiveTypeTraits::loadPrimitiveObjs(
00878         primitiveObjs, null, null, obj );
00879     }
00880 private:
00881   static void assertInput(
00882     const ArrayView<const primitiveType> &primitiveObjs,
00883     const ArrayView<const index_type> &indexObjs,
00884     const ArrayView<const char> &charObjs
00885     )
00886     {
00887 #ifdef TEUCHOS_DEBUG
00888       TEST_FOR_EXCEPT(
00889         primitiveObjs.size()!=ScalarPrimitiveTypeTraits::numPrimitiveObjs()
00890         || indexObjs.size()!=0
00891         || charObjs.size()!=0 );
00892 #endif
00893     }
00894 };
00895 
00896 
00897 #endif // defined(HAVE_COMPLEX) && defined(HAVE_TEUCHOS_COMPLEX)
00898 
00899 
00900 
00901 //
00902 // Forward declaration for templated types
00903 //
00904 
00905 
00907 template<class Scalar>  class RTOpT;
00908 
00909 
00910 } // namespace RTOpPack
00911 
00912 
00913 #endif // RTOPPACK_TYPES_HPP

Generated on Wed May 12 21:41:16 2010 for Fundamental Vector Reduction/Transformation Operator (RTOp) Interfaces by  doxygen 1.4.7