00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #ifndef RTOPPACK_TYPES_HPP
00030 #define RTOPPACK_TYPES_HPP
00031
00032 #include "RTOp_config.h"
00033 #include "Teuchos_TestForException.hpp"
00034
00035 namespace RTOpPack {
00036
00037
00038
00039
00040
00042 typedef RTOp_value_type value_type;
00044 typedef RTOp_index_type index_type;
00046 typedef RTOp_char_type char_type;
00048 typedef RTOp_index_type Index;
00049
00050
00051
00052
00053
00055 class UnknownError : public std::logic_error
00056 {public: UnknownError(const std::string& what_arg) : std::logic_error(what_arg) {}};
00058 class InvalidUsage : public std::logic_error
00059 {public: InvalidUsage(const std::string& what_arg) : std::logic_error(what_arg) {}};
00061 class InvalidNumVecs : public std::logic_error
00062 {public: InvalidNumVecs(const std::string& what_arg) : std::logic_error(what_arg) {}};
00064 class InvalidNumTargVecs : public std::logic_error
00065 {public: InvalidNumTargVecs(const std::string& what_arg) : std::logic_error(what_arg) {}};
00067 class IncompatibleVecs : public std::logic_error
00068 {public: IncompatibleVecs(const std::string& what_arg) : std::logic_error(what_arg) {}};
00069
00070
00071
00072
00073
00094 template<class Scalar>
00095 class SubVectorT {
00096 public:
00098 SubVectorT() : globalOffset_(0), subDim_(0), values_(NULL), stride_(0) {}
00100 SubVectorT(RTOp_index_type globalOffset, RTOp_index_type subDim, const Scalar *values, ptrdiff_t stride)
00101 :globalOffset_(globalOffset), subDim_(subDim), values_(values), stride_(stride)
00102 {}
00104 SubVectorT( const SubVectorT<Scalar>& sv )
00105 :globalOffset_(sv.globalOffset()), subDim_(sv.subDim()), values_(sv.values()), stride_(sv.stride())
00106 {}
00108 void initialize(RTOp_index_type globalOffset, RTOp_index_type subDim, const Scalar *values, ptrdiff_t stride)
00109 { globalOffset_=globalOffset; subDim_=subDim; values_=values; stride_=stride; }
00111 void set_uninitialized()
00112 { globalOffset_ = 0; subDim_=0; values_=NULL; stride_ = 0; }
00114 void setGlobalOffset(RTOp_index_type globalOffset) { globalOffset_ = globalOffset; }
00116 RTOp_index_type globalOffset() const { return globalOffset_; }
00118 RTOp_index_type subDim() const { return subDim_; }
00120 const Scalar* values() const { return values_; }
00122 ptrdiff_t stride() const { return stride_; }
00124 const Scalar& operator[](RTOp_index_type i) const { return values_[ stride_*i ]; }
00126 const Scalar& operator()(RTOp_index_type i) const { return values_[ stride_*(i-1) ]; }
00127 private:
00128 RTOp_index_type globalOffset_;
00129 RTOp_index_type subDim_;
00130 const Scalar *values_;
00131 ptrdiff_t stride_;
00132 };
00133
00146 template<class Scalar>
00147 class MutableSubVectorT : public SubVectorT<Scalar> {
00148 public:
00150 MutableSubVectorT() {}
00152 MutableSubVectorT(RTOp_index_type globalOffset, RTOp_index_type subDim, Scalar *values, ptrdiff_t stride)
00153 :SubVectorT<Scalar>(globalOffset, subDim, values, stride)
00154 {}
00156 MutableSubVectorT( const MutableSubVectorT<Scalar> & sv)
00157 :SubVectorT<Scalar>(sv)
00158 {}
00160 void initialize(RTOp_index_type globalOffset, RTOp_index_type subDim, Scalar *values, ptrdiff_t stride)
00161 { SubVectorT<Scalar>::initialize(globalOffset, subDim, values, stride); }
00163 void set_uninitialized()
00164 { SubVectorT<Scalar>::set_uninitialized(); }
00166 Scalar* values() const { return const_cast<Scalar*>(SubVectorT<Scalar>::values()); }
00168 Scalar& operator[](RTOp_index_type i) const { return const_cast<Scalar&>(SubVectorT<Scalar>::operator[](i)); }
00170 Scalar& operator()(RTOp_index_type i) const { return const_cast<Scalar&>(SubVectorT<Scalar>::operator()(i)); }
00171 };
00172
00248 template<class Scalar>
00249 class SparseSubVectorT {
00250 public:
00252 SparseSubVectorT()
00253 :globalOffset_(0),subDim_(0),subNz_(0)
00254 ,values_(NULL),valuesStride_(0),indices_(NULL)
00255 ,indicesStride_(0),localOffset_(0),isSorted_(0)
00256 {}
00258 SparseSubVectorT(
00259 RTOp_index_type globalOffset, RTOp_index_type subDim, RTOp_index_type subNz
00260 ,const Scalar values[], ptrdiff_t valuesStride
00261 ,const RTOp_index_type indices[], ptrdiff_t indicesStride
00262 ,ptrdiff_t localOffset, int isSorted
00263 )
00264 :globalOffset_(globalOffset),subDim_(subDim),subNz_(subNz)
00265 ,values_(values),valuesStride_(valuesStride),indices_(indices)
00266 ,indicesStride_(indicesStride),localOffset_(localOffset),isSorted_(isSorted)
00267 {}
00269 SparseSubVectorT(
00270 RTOp_index_type globalOffset, RTOp_index_type subDim
00271 ,const Scalar values[], ptrdiff_t valuesStride
00272 )
00273 :globalOffset_(globalOffset),subDim_(subDim),subNz_(subDim)
00274 ,values_(values),valuesStride_(valuesStride),indices_(NULL)
00275 ,indicesStride_(0),localOffset_(0),isSorted_(0)
00276 {}
00278 SparseSubVectorT( const SubVectorT<Scalar>& sv )
00279 :globalOffset_(sv.globalOffset()), subDim_(sv.subDim()), subNz_(sv.subDim()), values_(sv.values())
00280 ,valuesStride_(sv.stride()), indices_(NULL),indicesStride_(0),localOffset_(0),isSorted_(0)
00281 {}
00283 void initialize(
00284 RTOp_index_type globalOffset, RTOp_index_type subDim, RTOp_index_type subNz
00285 ,const Scalar values[], ptrdiff_t valuesStride
00286 ,const RTOp_index_type indices[], ptrdiff_t indicesStride
00287 ,ptrdiff_t localOffset, int isSorted
00288 )
00289 {
00290 globalOffset_ = globalOffset; subDim_ = subDim; subNz_ = subNz;
00291 values_ = values; valuesStride_ = valuesStride; indices_ = indices;
00292 indicesStride_ = indicesStride; localOffset_ = localOffset; isSorted_ = isSorted;
00293 }
00295 void initialize(
00296 RTOp_index_type globalOffset, RTOp_index_type subDim
00297 ,const Scalar values[], ptrdiff_t valuesStride
00298 )
00299 {
00300 globalOffset_ = globalOffset; subDim_ = subDim; subNz_ = subDim;
00301 values_ = values; valuesStride_ = valuesStride; indices_ = NULL;
00302 indicesStride_ = 0; localOffset_ = 0; isSorted_ = 1;
00303 }
00305 void set_uninitialized()
00306 {
00307 globalOffset_ = 0; subDim_ = 0; subNz_ = 0;
00308 values_ = NULL; valuesStride_ = 0; indices_ = NULL;
00309 indicesStride_ = 0; localOffset_ = 0; isSorted_ = 1;
00310 }
00312 void setGlobalOffset(RTOp_index_type globalOffset) { globalOffset_ = globalOffset; }
00314 RTOp_index_type globalOffset() const { return globalOffset_; }
00316 RTOp_index_type subDim() const { return subDim_; }
00318 RTOp_index_type subNz() const { return subNz_; }
00320 const Scalar* values() const { return values_; }
00322 ptrdiff_t valuesStride() const { return valuesStride_; }
00326 const RTOp_index_type* indices() const { return indices_; }
00328 ptrdiff_t indicesStride() const { return indicesStride_; }
00330 ptrdiff_t localOffset() const { return localOffset_; }
00332 int isSorted() const { return isSorted_; }
00333 private:
00334 RTOp_index_type globalOffset_;
00335 RTOp_index_type subDim_;
00336 RTOp_index_type subNz_;
00337 const Scalar *values_;
00338 ptrdiff_t valuesStride_;
00339 const RTOp_index_type *indices_;
00340 ptrdiff_t indicesStride_;
00341 ptrdiff_t localOffset_;
00342 int isSorted_;
00343 };
00344
00345
00346 template<class Scalar>
00347 void assign_entries( const MutableSubVectorT<Scalar> *msv, const SubVectorT<Scalar> &sv )
00348 {
00349 #ifdef _DEBUG
00350 TEST_FOR_EXCEPT(msv==NULL);
00351 TEST_FOR_EXCEPT(msv->subDim() != sv.subDim());
00352 #endif
00353 for( int i = 1; i <= sv.subDim(); ++i ) {
00354 (*msv)(i) = sv(i);
00355 }
00356 }
00357
00358
00359
00360
00361
00382 template<class Scalar>
00383 class SubMultiVectorT {
00384 public:
00386 SubMultiVectorT()
00387 :globalOffset_(0), subDim_(0), colOffset_(0), numSubCols_(0)
00388 ,values_(NULL), leadingDim_(0)
00389 {}
00391 SubMultiVectorT(
00392 RTOp_index_type globalOffset, RTOp_index_type subDim
00393 ,RTOp_index_type colOffset, RTOp_index_type numSubCols
00394 ,const Scalar *values, RTOp_index_type leadingDim
00395 )
00396 :globalOffset_(globalOffset), subDim_(subDim)
00397 ,colOffset_(colOffset), numSubCols_(numSubCols)
00398 ,values_(values), leadingDim_(leadingDim)
00399 {}
00401 SubMultiVectorT( const SubMultiVectorT<Scalar>& smv )
00402 :globalOffset_(smv.globalOffset()), subDim_(smv.subDim())
00403 ,colOffset_(smv.colOffset()), numSubCols_(smv.numSubCols())
00404 ,values_(smv.values()), leadingDim_(smv.leadingDim())
00405 {}
00407 void initialize(
00408 RTOp_index_type globalOffset, RTOp_index_type subDim
00409 ,RTOp_index_type colOffset, RTOp_index_type numSubCols
00410 ,const Scalar *values, RTOp_index_type leadingDim
00411 )
00412 { globalOffset_=globalOffset; subDim_=subDim; colOffset_=colOffset; numSubCols_=numSubCols;
00413 values_=values; leadingDim_=leadingDim; }
00415 void set_uninitialized()
00416 { globalOffset_ = 0; subDim_=0; colOffset_=0, numSubCols_=0; values_=NULL; leadingDim_=0; }
00418 void setGlobalOffset(RTOp_index_type globalOffset) { globalOffset_ = globalOffset; }
00420 RTOp_index_type globalOffset() const { return globalOffset_; }
00422 RTOp_index_type subDim() const { return subDim_; }
00424 RTOp_index_type colOffset() const { return colOffset_; }
00426 RTOp_index_type numSubCols() const { return numSubCols_; }
00428 const Scalar* values() const { return values_; }
00430 RTOp_index_type leadingDim() const { return leadingDim_; }
00432 const Scalar& operator()(RTOp_index_type i, RTOp_index_type j) const
00433 { return values_[ (i-1) + leadingDim_*(j-1) ]; }
00435 SubVectorT<Scalar> col( const RTOp_index_type j ) const
00436 { return SubVectorT<Scalar>(globalOffset(),subDim(),values()+(j-1)*leadingDim(),1); }
00437 private:
00438 RTOp_index_type globalOffset_;
00439 RTOp_index_type subDim_;
00440 RTOp_index_type colOffset_;
00441 RTOp_index_type numSubCols_;
00442 const Scalar *values_;
00443 RTOp_index_type leadingDim_;
00444 };
00445
00458 template<class Scalar>
00459 class MutableSubMultiVectorT : public SubMultiVectorT<Scalar> {
00460 public:
00462 MutableSubMultiVectorT() {}
00464 MutableSubMultiVectorT(
00465 RTOp_index_type globalOffset, RTOp_index_type subDim
00466 ,RTOp_index_type colOffset, RTOp_index_type numSubCols
00467 ,const Scalar *values, RTOp_index_type leadingDim
00468 )
00469 :SubMultiVectorT<Scalar>(globalOffset,subDim,colOffset,numSubCols,values,leadingDim)
00470 {}
00472 MutableSubMultiVectorT( const MutableSubMultiVectorT<Scalar> & smv)
00473 :SubMultiVectorT<Scalar>(smv)
00474 {}
00476 void initialize(
00477 RTOp_index_type globalOffset, RTOp_index_type subDim
00478 ,RTOp_index_type colOffset, RTOp_index_type numSubCols
00479 ,const Scalar *values, RTOp_index_type leadingDim
00480 )
00481 { SubMultiVectorT<Scalar>::initialize(globalOffset,subDim,colOffset,numSubCols,values,leadingDim); }
00483 void set_uninitialized()
00484 { SubMultiVectorT<Scalar>::set_uninitialized(); }
00486 Scalar* values() const { return const_cast<Scalar*>(SubMultiVectorT<Scalar>::values()); }
00488 Scalar& operator()(RTOp_index_type i, RTOp_index_type j) const
00489 { return const_cast<Scalar&>(SubMultiVectorT<Scalar>::operator()(i,j)); }
00491 MutableSubVectorT<Scalar> col( const RTOp_index_type j ) const
00492 { return MutableSubVectorT<Scalar>(SubMultiVectorT<Scalar>::globalOffset(),SubMultiVectorT<Scalar>::subDim(),values()+(j-1)*SubMultiVectorT<Scalar>::leadingDim(),1); }
00493 };
00494
00495 template<class Scalar>
00496 void assign_entries( const MutableSubMultiVectorT<Scalar> *msmv, const SubMultiVectorT<Scalar> &smv )
00497 {
00498 #ifdef _DEBUG
00499 TEST_FOR_EXCEPT(msmv==NULL);
00500 TEST_FOR_EXCEPT(msmv->subDim() != smv.subDim());
00501 TEST_FOR_EXCEPT(msmv->numSubCols() != smv.numSubCols());
00502 #endif
00503 for( RTOp_index_type j = 1; j <= smv.numSubCols(); ++j ) {
00504 for( RTOp_index_type i = 1; i <= smv.subDim(); ++i ) {
00505 (*msmv)(i,j) = smv(i,j);
00506 }
00507 }
00508 }
00509
00510
00511
00512
00513
00515 template<class Scalar> class RTOpT;
00516
00517
00518
00519
00520
00522 typedef SubVectorT<RTOp_value_type> SubVector;
00524 typedef MutableSubVectorT<RTOp_value_type> MutableSubVector;
00526 typedef SparseSubVectorT<RTOp_value_type> SparseSubVector;
00528 typedef SubMultiVectorT<RTOp_value_type> SubMultiVector;
00530 typedef MutableSubMultiVectorT<RTOp_value_type> MutableSubMultiVector;
00532 typedef RTOpT<RTOp_value_type> RTOp;
00533
00534 }
00535
00536 #endif // RTOPPACK_TYPES_HPP
00537