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**********************************************************************************
101  inline ~MatrixAccessProxy();
103  //**********************************************************************************************
104 
105  //**Operators***********************************************************************************
108  inline MatrixAccessProxy& operator= ( const MatrixAccessProxy& vap );
109  template< typename T > inline MatrixAccessProxy& operator= ( const T& value );
110  template< typename T > inline MatrixAccessProxy& operator+=( const T& value );
111  template< typename T > inline MatrixAccessProxy& operator-=( const T& value );
112  template< typename T > inline MatrixAccessProxy& operator*=( const T& value );
113  template< typename T > inline MatrixAccessProxy& operator/=( const T& value );
115  //**********************************************************************************************
116 
117  //**Conversion operator*************************************************************************
120  inline operator Reference() const;
122  //**********************************************************************************************
123 
124  private:
125  //**Utility functions***************************************************************************
128  Reference get() const;
129  void set( ConstReference value ) const;
131  //**********************************************************************************************
132 
133  //**Member variables****************************************************************************
136  MT& sm_;
137  size_t i_;
138  size_t j_;
139 
140  //**********************************************************************************************
141 };
142 //*************************************************************************************************
143 
144 
145 
146 
147 //=================================================================================================
148 //
149 // CONSTRUCTORS
150 //
151 //=================================================================================================
152 
153 //*************************************************************************************************
160 template< typename MT > // Type of the sparse matrix
161 inline MatrixAccessProxy<MT>::MatrixAccessProxy( MT& sv, size_t i, size_t j )
162  : sm_( sv ) // Reference to the accessed sparse matrix
163  , i_ ( i ) // Row-index of the accessed sparse matrix element
164  , j_ ( j ) // Column-index of the accessed sparse matrix element
165 {
166  const Iterator element( sm_.find( i_, j_ ) );
167  const size_t index( rmm ? i_ : j_ );
168  if( element == sm_.end(index) )
169  sm_.insert( i_, j_, ElementType() );
170 }
171 //*************************************************************************************************
172 
173 
174 //*************************************************************************************************
179 template< typename MT > // Type of the sparse matrix
181  : sm_( map.sm_ ) // Reference to the accessed sparse matrix
182  , i_ ( map.i_ ) // Row-index of the accessed sparse matrix element
183  , j_ ( map.j_ ) // Column-index of the accessed sparse matrix element
184 {
185  BLAZE_INTERNAL_ASSERT( sm_.find(i_,j_) != sm_.end( rmm ? i_ : j_ ), "Missing matrix element detected" );
186 }
187 //*************************************************************************************************
188 
189 
190 
191 
192 //=================================================================================================
193 //
194 // CONSTRUCTORS
195 //
196 //=================================================================================================
197 
198 //*************************************************************************************************
201 template< typename MT > // Type of the sparse matrix
203 {
204  const Iterator element( sm_.find( i_, j_ ) );
205  const size_t index( rmm ? i_ : j_ );
206  BLAZE_INTERNAL_ASSERT( element != sm_.end(index), "Missing matrix element detected" );
207  if( isDefault( element->value() ) )
208  sm_.erase( index, element );
209 }
210 //*************************************************************************************************
211 
212 
213 
214 
215 //=================================================================================================
216 //
217 // OPERATORS
218 //
219 //=================================================================================================
220 
221 //*************************************************************************************************
227 template< typename MT > // Type of the sparse matrix
229 {
230  set( map.get() );
231  return *this;
232 }
233 //*************************************************************************************************
234 
235 
236 //*************************************************************************************************
242 template< typename MT > // Type of the sparse matrix
243 template< typename T > // Type of the right-hand side value
245 {
246  set( value );
247  return *this;
248 }
249 //*************************************************************************************************
250 
251 
252 //*************************************************************************************************
258 template< typename MT > // Type of the sparse matrix
259 template< typename T > // Type of the right-hand side value
261 {
262  get() += value;
263  return *this;
264 }
265 //*************************************************************************************************
266 
267 
268 //*************************************************************************************************
274 template< typename MT > // Type of the sparse matrix
275 template< typename T > // Type of the right-hand side value
277 {
278  get() -= value;
279  return *this;
280 }
281 //*************************************************************************************************
282 
283 
284 //*************************************************************************************************
290 template< typename MT > // Type of the sparse matrix
291 template< typename T > // Type of the right-hand side value
293 {
294  get() *= value;
295  return *this;
296 }
297 //*************************************************************************************************
298 
299 
300 //*************************************************************************************************
306 template< typename MT > // Type of the sparse matrix
307 template< typename T > // Type of the right-hand side value
309 {
310  get() /= value;
311  return *this;
312 }
313 //*************************************************************************************************
314 
315 
316 
317 
318 //=================================================================================================
319 //
320 // CONVERSION OPERATOR
321 //
322 //=================================================================================================
323 
324 //*************************************************************************************************
329 template< typename MT > // Type of the sparse matrix
331 {
332  return get();
333 }
334 //*************************************************************************************************
335 
336 
337 
338 
339 //=================================================================================================
340 //
341 // UTILITY FUNCTIONS
342 //
343 //=================================================================================================
344 
345 //*************************************************************************************************
350 template< typename MT > // Type of the sparse matrix
352 {
353  const Iterator element( sm_.find( i_, j_ ) );
354  BLAZE_INTERNAL_ASSERT( element != sm_.end( rmm ? i_ : j_ ), "Missing matrix element detected" );
355  return element->value();
356 }
357 //*************************************************************************************************
358 
359 
360 //*************************************************************************************************
366 template< typename MT > // Type of the sparse matrix
367 inline void MatrixAccessProxy<MT>::set( ConstReference value ) const
368 {
369  const Iterator element( sm_.find( i_, j_ ) );
370  BLAZE_INTERNAL_ASSERT( element != sm_.end( rmm ? i_ : j_ ), "Missing matrix element detected" );
371  element->value() = value;
372 }
373 //*************************************************************************************************
374 
375 } // namespace blaze
376 
377 #endif