AbstractLinAlgPack: C++ Interfaces For Vectors, Matrices And Related Linear Algebra Objects  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
AbstractLinAlgPack_MatrixCOORTmplItfc.hpp
1 // @HEADER
2 // ***********************************************************************
3 //
4 // Moocho: Multi-functional Object-Oriented arCHitecture for Optimization
5 // Copyright (2003) Sandia Corporation
6 //
7 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8 // license for use of this work by or on behalf of the U.S. Government.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // Questions? Contact Roscoe A. Bartlett (rabartl@sandia.gov)
38 //
39 // ***********************************************************************
40 // @HEADER
41 
42 #ifndef SLAP_MATRIX_COOR_TMPL_ITFC_H
43 #define SLAP_MATRIX_COOR_TMPL_ITFC_H
44 
45 #include <stdexcept>
46 
47 #include "AbstractLinAlgPack_Types.hpp"
48 #include "Teuchos_Assert.hpp"
49 
50 namespace AbstractLinAlgPack {
51 
52 template<class T_Scalar, class T_Index>
54 
55 template<class T_Scalar, class T_Index>
57 
61 template<class T_Scalar, class T_Index>
63 public:
64  typedef T_Index size_type;
65  typedef ptrdiff_t difference_type;
67  typedef T_Scalar value_type;
68  typedef T_Index index_type;
71  size_type rows, size_type cols, size_type nz
72  ,difference_type row_offset, difference_type col_offset
73  ,const T_Scalar *values, const T_Index* row_i, const T_Index* col_j
74  )
75  :rows_(rows), cols_(cols), nz_(nz), row_offset_(row_offset), col_offset_(col_offset)
76  ,values_(values), row_i_(row_i), col_j_(col_j)
77  {}
78  size_type rows() const { return rows_; }
79  size_type cols() const { return cols_; }
80  size_type nz() const { return nz_; }
81  difference_type row_offset() const { return row_offset_; }
82  difference_type col_offset() const { return col_offset_; }
83  const_iterator begin() const;
84  const_iterator end() const;
85 private:
86  size_type rows_;
87  size_type cols_;
88  size_type nz_;
89  difference_type row_offset_;
90  difference_type col_offset_;
91  const T_Scalar *values_;
92  const T_Index *row_i_;
93  const T_Index *col_j_;
94  // Not defined and not to be called
96 }; // end class MatrixCOORTmplItfc
97 
98 
99 // ///////////////////////////////////////////////
100 // Implementatioins, not of the user to look at!
101 
105 template<class T_Scalar, class T_Index>
107 public:
108  typedef T_Scalar value_type;
109  typedef T_Index index_type;
111  const T_Scalar* value, const T_Index* row_i, const T_Index* col_j
112  )
113  : value_(value), row_i_(row_i), col_j_(col_j)
114  {}
115  void increment() { ++value_; ++row_i_; ++col_j_; }
116  bool operator!=(const MatrixCOORTmplItfcItrEleView<T_Scalar,T_Index>& ele) const
117  { return value_ != ele.value_ || row_i_ != ele.row_i_ || col_j_ != ele.col_j_; }
118  T_Scalar value() const { return *value_; }
119  T_Index row_i() const { return *row_i_; }
120  T_Index col_j() const { return *col_j_; }
121 private:
122  const T_Scalar *value_;
123  const T_Index *row_i_;
124  const T_Index *col_j_;
125  // Not defined and not to be called
126  MatrixCOORTmplItfcItrEleView();
127 }; // end class MatrixCOORTmplItfcItrEleView
128 
132 template<class T_Scalar, class T_Index>
133 class MatrixCOORTmplItfcItr {
134 public:
135  MatrixCOORTmplItfcItr( const T_Scalar* value, const T_Index* row_i, const T_Index* col_j, T_Index nz )
136  : ele_(value,row_i,col_j)
137 #ifdef TEUCHOS_DEBUG
138  , nz_left_(nz)
139 #endif
140  {}
141  void operator++() {
142 #ifdef TEUCHOS_DEBUG
143  --nz_left_;
144 #endif
145  ele_.increment();
146  }
147  bool operator!=(const MatrixCOORTmplItfcItr<T_Scalar,T_Index>& itr) const
148  { return ele_ != itr.ele_; }
149  const MatrixCOORTmplItfcItrEleView<T_Scalar,T_Index>* operator->() const
150  { assert_nz(); return &ele_; }
151 private:
152  MatrixCOORTmplItfcItrEleView<T_Scalar,T_Index> ele_;
153 #ifdef TEUCHOS_DEBUG
154  T_Index nz_left_;
155  void assert_nz() const
156  {
158  nz_left_ <= 0, std::logic_error
159  ,"MatrixCOORTmplItfcItr<>::assert_nz: Error, trying to access past storage!" );
160  }
161 #else
162  void assert_nz() const {}
163 #endif
164  // Not defined and not to be called
165  MatrixCOORTmplItfcItr();
166 }; // end class MatrixCOORTmplItfcItr
167 
168 // ///////////////////////////
169 // Inline members
170 
171 // MatrixCOORTmplItfc
172 
173 template<class T_Scalar, class T_Index>
174 inline
175 typename MatrixCOORTmplItfc<T_Scalar,T_Index>::const_iterator
176 MatrixCOORTmplItfc<T_Scalar,T_Index>::begin() const
177 {
178  return MatrixCOORTmplItfcItr<T_Scalar,T_Index>(values_,row_i_,col_j_,nz_);
179 }
180 
181 template<class T_Scalar, class T_Index>
182 inline
183 typename MatrixCOORTmplItfc<T_Scalar,T_Index>::const_iterator
184 MatrixCOORTmplItfc<T_Scalar,T_Index>::end() const
185 {
186  return MatrixCOORTmplItfcItr<T_Scalar,T_Index>(values_+nz_,row_i_+nz_,col_j_+nz_,0);
187 }
188 
189 } // end namespace AbstractLinAlgPack
190 
191 #endif // SLAP_MATRIX_COOR_TMPL_ITFC_H
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Templated class that supports the COOMatrixTemplateInterface template interface.
Templated class for objects that support the SparseCOOElementTemplatInterface specification.
Templated class for iterator returning objects that support the SparseCOOElementTemplatInterface spec...