All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MatrixAccessProxy.h
Go to the documentation of this file.
1 //=================================================================================================
20 //=================================================================================================
21 
22 #ifndef _BLAZE_MATH_SPARSE_MATRIXACCESSPROXY_H_
23 #define _BLAZE_MATH_SPARSE_MATRIXACCESSPROXY_H_
24 
25 
26 //*************************************************************************************************
27 // Includes
28 //*************************************************************************************************
29 
31 #include <blaze/util/Types.h>
32 
33 
34 namespace blaze {
35 
36 //=================================================================================================
37 //
38 // CLASS DEFINITION
39 //
40 //=================================================================================================
41 
42 //*************************************************************************************************
72 template< typename MT > // Type of the sparse matrix
74 {
75  private:
76  //**Enumerations********************************************************************************
78  enum { rmm = IsRowMajorMatrix<MT>::value };
79  //**********************************************************************************************
80 
81  public:
82  //**Type definitions****************************************************************************
83  typedef MT MatrixType;
84  typedef typename MT::ElementType ElementType;
86  typedef const ElementType& ConstReference;
87  typedef typename MT::Iterator Iterator;
88  //**********************************************************************************************
89 
90  //**Constructors********************************************************************************
93  explicit inline MatrixAccessProxy( MT& sv, size_t i, size_t j );
94  inline MatrixAccessProxy( const MatrixAccessProxy& vap );
96  //**********************************************************************************************
97 
98  //**Destructor**********************************************************************************
99  // No explicitly declared destructor.
100  //**********************************************************************************************
101 
102  //**Operators***********************************************************************************
105  inline MatrixAccessProxy& operator= ( const MatrixAccessProxy& vap );
106  template< typename T > inline MatrixAccessProxy& operator= ( const T& value );
107  template< typename T > inline MatrixAccessProxy& operator+=( const T& value );
108  template< typename T > inline MatrixAccessProxy& operator-=( const T& value );
109  template< typename T > inline MatrixAccessProxy& operator*=( const T& value );
110  template< typename T > inline MatrixAccessProxy& operator/=( const T& value );
112  //**********************************************************************************************
113 
114  //**Conversion operator*************************************************************************
117  inline operator Reference() const;
119  //**********************************************************************************************
120 
121  private:
122  //**Utility functions***************************************************************************
125  Reference get() const;
126  void set( ConstReference value ) const;
128  //**********************************************************************************************
129 
130  //**Member variables****************************************************************************
133  MT& sm_;
134  size_t i_;
135  size_t j_;
136 
137  //**********************************************************************************************
138 };
139 //*************************************************************************************************
140 
141 
142 
143 
144 //=================================================================================================
145 //
146 // CONSTRUCTORS
147 //
148 //=================================================================================================
149 
150 //*************************************************************************************************
157 template< typename MT > // Type of the sparse matrix
158 inline MatrixAccessProxy<MT>::MatrixAccessProxy( MT& sv, size_t i, size_t j )
159  : sm_( sv ) // Reference to the accessed sparse matrix
160  , i_ ( i ) // Row-index of the accessed sparse matrix element
161  , j_ ( j ) // Column-index of the accessed sparse matrix element
162 {
163  const Iterator element( sm_.find( i_, j_ ) );
164  if( element == ( rmm ? sm_.end(i_) : sm_.end(j_) ) )
165  sm_.insert( i_, j_, ElementType() );
166 }
167 //*************************************************************************************************
168 
169 
170 //*************************************************************************************************
175 template< typename MT > // Type of the sparse matrix
177  : sm_( map.sm_ ) // Reference to the accessed sparse matrix
178  , i_ ( map.i_ ) // Row-index of the accessed sparse matrix element
179  , j_ ( map.j_ ) // Column-index of the accessed sparse matrix element
180 {
181  BLAZE_INTERNAL_ASSERT( sm_.find(i_,j_) != ( rmm ? sm_.end(i_) : sm_.end(j_) ), "Missing matrix element detected" );
182 }
183 //*************************************************************************************************
184 
185 
186 
187 
188 //=================================================================================================
189 //
190 // OPERATORS
191 //
192 //=================================================================================================
193 
194 //*************************************************************************************************
200 template< typename MT > // Type of the sparse matrix
202 {
203  set( map.get() );
204  return *this;
205 }
206 //*************************************************************************************************
207 
208 
209 //*************************************************************************************************
215 template< typename MT > // Type of the sparse matrix
216 template< typename T > // Type of the right-hand side value
218 {
219  set( value );
220  return *this;
221 }
222 //*************************************************************************************************
223 
224 
225 //*************************************************************************************************
231 template< typename MT > // Type of the sparse matrix
232 template< typename T > // Type of the right-hand side value
234 {
235  get() += value;
236  return *this;
237 }
238 //*************************************************************************************************
239 
240 
241 //*************************************************************************************************
247 template< typename MT > // Type of the sparse matrix
248 template< typename T > // Type of the right-hand side value
250 {
251  get() -= value;
252  return *this;
253 }
254 //*************************************************************************************************
255 
256 
257 //*************************************************************************************************
263 template< typename MT > // Type of the sparse matrix
264 template< typename T > // Type of the right-hand side value
266 {
267  get() *= value;
268  return *this;
269 }
270 //*************************************************************************************************
271 
272 
273 //*************************************************************************************************
279 template< typename MT > // Type of the sparse matrix
280 template< typename T > // Type of the right-hand side value
282 {
283  get() /= value;
284  return *this;
285 }
286 //*************************************************************************************************
287 
288 
289 
290 
291 //=================================================================================================
292 //
293 // CONVERSION OPERATOR
294 //
295 //=================================================================================================
296 
297 //*************************************************************************************************
302 template< typename MT > // Type of the sparse matrix
304 {
305  return get();
306 }
307 //*************************************************************************************************
308 
309 
310 
311 
312 //=================================================================================================
313 //
314 // UTILITY FUNCTIONS
315 //
316 //=================================================================================================
317 
318 //*************************************************************************************************
323 template< typename MT > // Type of the sparse matrix
325 {
326  const Iterator element( sm_.find( i_, j_ ) );
327  BLAZE_INTERNAL_ASSERT( element != ( rmm ? sm_.end(i_) : sm_.end(j_) ), "Missing matrix element detected" );
328  return element->value();
329 }
330 //*************************************************************************************************
331 
332 
333 //*************************************************************************************************
339 template< typename MT > // Type of the sparse matrix
340 inline void MatrixAccessProxy<MT>::set( ConstReference value ) const
341 {
342  const Iterator element( sm_.find( i_, j_ ) );
343  BLAZE_INTERNAL_ASSERT( element != ( rmm ? sm_.end(i_) : sm_.end(j_) ), "Missing matrix element detected" );
344  element->value() = value;
345 }
346 //*************************************************************************************************
347 
348 } // namespace blaze
349 
350 #endif