|
AbstractLinAlgPack: C++ Interfaces For Vectors, Matrices And Related Linear Algebra Objects Version of the Day
|
00001 // @HEADER 00002 // *********************************************************************** 00003 // 00004 // Moocho: Multi-functional Object-Oriented arCHitecture for Optimization 00005 // Copyright (2003) Sandia Corporation 00006 // 00007 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive 00008 // license for use of this work by or on behalf of the U.S. Government. 00009 // 00010 // This library is free software; you can redistribute it and/or modify 00011 // it under the terms of the GNU Lesser General Public License as 00012 // published by the Free Software Foundation; either version 2.1 of the 00013 // License, or (at your option) any later version. 00014 // 00015 // This library is distributed in the hope that it will be useful, but 00016 // WITHOUT ANY WARRANTY; without even the implied warranty of 00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00018 // Lesser General Public License for more details. 00019 // 00020 // You should have received a copy of the GNU Lesser General Public 00021 // License along with this library; if not, write to the Free Software 00022 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 00023 // USA 00024 // Questions? Contact Roscoe A. Bartlett (rabartl@sandia.gov) 00025 // 00026 // *********************************************************************** 00027 // @HEADER 00028 00029 #ifndef SLAP_MATRIX_COOR_TMPL_ITFC_H 00030 #define SLAP_MATRIX_COOR_TMPL_ITFC_H 00031 00032 #include <stdexcept> 00033 00034 #include "AbstractLinAlgPack_Types.hpp" 00035 #include "Teuchos_TestForException.hpp" 00036 00037 namespace AbstractLinAlgPack { 00038 00039 template<class T_Scalar, class T_Index> 00040 class MatrixCOORTmplItfcItrEleView; 00041 00042 template<class T_Scalar, class T_Index> 00043 class MatrixCOORTmplItfcItr; 00044 00048 template<class T_Scalar, class T_Index> 00049 class MatrixCOORTmplItfc { 00050 public: 00051 typedef T_Index size_type; 00052 typedef ptrdiff_t difference_type; 00053 typedef MatrixCOORTmplItfcItrEleView<T_Scalar,T_Index> element_type; 00054 typedef T_Scalar value_type; 00055 typedef T_Index index_type; 00056 typedef MatrixCOORTmplItfcItr<T_Scalar,T_Index> const_iterator; 00057 MatrixCOORTmplItfc( 00058 size_type rows, size_type cols, size_type nz 00059 ,difference_type row_offset, difference_type col_offset 00060 ,const T_Scalar *values, const T_Index* row_i, const T_Index* col_j 00061 ) 00062 :rows_(rows), cols_(cols), nz_(nz), row_offset_(row_offset), col_offset_(col_offset) 00063 ,values_(values), row_i_(row_i), col_j_(col_j) 00064 {} 00065 size_type rows() const { return rows_; } 00066 size_type cols() const { return cols_; } 00067 size_type nz() const { return nz_; } 00068 difference_type row_offset() const { return row_offset_; } 00069 difference_type col_offset() const { return col_offset_; } 00070 const_iterator begin() const; 00071 const_iterator end() const; 00072 private: 00073 size_type rows_; 00074 size_type cols_; 00075 size_type nz_; 00076 difference_type row_offset_; 00077 difference_type col_offset_; 00078 const T_Scalar *values_; 00079 const T_Index *row_i_; 00080 const T_Index *col_j_; 00081 // Not defined and not to be called 00082 MatrixCOORTmplItfc(); 00083 }; // end class MatrixCOORTmplItfc 00084 00085 00086 // /////////////////////////////////////////////// 00087 // Implementatioins, not of the user to look at! 00088 00092 template<class T_Scalar, class T_Index> 00093 class MatrixCOORTmplItfcItrEleView { 00094 public: 00095 typedef T_Scalar value_type; 00096 typedef T_Index index_type; 00097 MatrixCOORTmplItfcItrEleView( 00098 const T_Scalar* value, const T_Index* row_i, const T_Index* col_j 00099 ) 00100 : value_(value), row_i_(row_i), col_j_(col_j) 00101 {} 00102 void increment() { ++value_; ++row_i_; ++col_j_; } 00103 bool operator!=(const MatrixCOORTmplItfcItrEleView<T_Scalar,T_Index>& ele) const 00104 { return value_ != ele.value_ || row_i_ != ele.row_i_ || col_j_ != ele.col_j_; } 00105 T_Scalar value() const { return *value_; } 00106 T_Index row_i() const { return *row_i_; } 00107 T_Index col_j() const { return *col_j_; } 00108 private: 00109 const T_Scalar *value_; 00110 const T_Index *row_i_; 00111 const T_Index *col_j_; 00112 // Not defined and not to be called 00113 MatrixCOORTmplItfcItrEleView(); 00114 }; // end class MatrixCOORTmplItfcItrEleView 00115 00119 template<class T_Scalar, class T_Index> 00120 class MatrixCOORTmplItfcItr { 00121 public: 00122 MatrixCOORTmplItfcItr( const T_Scalar* value, const T_Index* row_i, const T_Index* col_j, T_Index nz ) 00123 : ele_(value,row_i,col_j) 00124 #ifdef TEUCHOS_DEBUG 00125 , nz_left_(nz) 00126 #endif 00127 {} 00128 void operator++() { 00129 #ifdef TEUCHOS_DEBUG 00130 --nz_left_; 00131 #endif 00132 ele_.increment(); 00133 } 00134 bool operator!=(const MatrixCOORTmplItfcItr<T_Scalar,T_Index>& itr) const 00135 { return ele_ != itr.ele_; } 00136 const MatrixCOORTmplItfcItrEleView<T_Scalar,T_Index>* operator->() const 00137 { assert_nz(); return &ele_; } 00138 private: 00139 MatrixCOORTmplItfcItrEleView<T_Scalar,T_Index> ele_; 00140 #ifdef TEUCHOS_DEBUG 00141 T_Index nz_left_; 00142 void assert_nz() const 00143 { 00144 TEST_FOR_EXCEPTION( 00145 nz_left_ <= 0, std::logic_error 00146 ,"MatrixCOORTmplItfcItr<>::assert_nz: Error, trying to access past storage!" ); 00147 } 00148 #else 00149 void assert_nz() const {} 00150 #endif 00151 // Not defined and not to be called 00152 MatrixCOORTmplItfcItr(); 00153 }; // end class MatrixCOORTmplItfcItr 00154 00155 // /////////////////////////// 00156 // Inline members 00157 00158 // MatrixCOORTmplItfc 00159 00160 template<class T_Scalar, class T_Index> 00161 inline 00162 typename MatrixCOORTmplItfc<T_Scalar,T_Index>::const_iterator 00163 MatrixCOORTmplItfc<T_Scalar,T_Index>::begin() const 00164 { 00165 return MatrixCOORTmplItfcItr<T_Scalar,T_Index>(values_,row_i_,col_j_,nz_); 00166 } 00167 00168 template<class T_Scalar, class T_Index> 00169 inline 00170 typename MatrixCOORTmplItfc<T_Scalar,T_Index>::const_iterator 00171 MatrixCOORTmplItfc<T_Scalar,T_Index>::end() const 00172 { 00173 return MatrixCOORTmplItfcItr<T_Scalar,T_Index>(values_+nz_,row_i_+nz_,col_j_+nz_,0); 00174 } 00175 00176 } // end namespace AbstractLinAlgPack 00177 00178 #endif // SLAP_MATRIX_COOR_TMPL_ITFC_H
1.7.4