Blaze 3.9
MatrixAccessProxy.h
Go to the documentation of this file.
1//=================================================================================================
33//=================================================================================================
34
35#ifndef _BLAZE_MATH_SPARSE_MATRIXACCESSPROXY_H_
36#define _BLAZE_MATH_SPARSE_MATRIXACCESSPROXY_H_
37
38
39//*************************************************************************************************
40// Includes
41//*************************************************************************************************
42
43#include <utility>
44#include <blaze/math/Aliases.h>
55#include <blaze/util/Assert.h>
56#include <blaze/util/Types.h>
57
58
59namespace blaze {
60
61//=================================================================================================
62//
63// CLASS DEFINITION
64//
65//=================================================================================================
66
67//*************************************************************************************************
98template< typename MT > // Type of the sparse matrix
100 : public Proxy< MatrixAccessProxy<MT>, ElementType_t<MT> >
101{
102 private:
103 //**Enumerations********************************************************************************
105 static constexpr bool rmm = IsRowMajorMatrix_v<MT>;
106 //**********************************************************************************************
107
108 public:
109 //**Type definitions****************************************************************************
112 //**********************************************************************************************
113
114 //**Constructors********************************************************************************
117 explicit inline MatrixAccessProxy( MT& sm, size_t i, size_t j );
118
119 MatrixAccessProxy( const MatrixAccessProxy& ) = default;
121 //**********************************************************************************************
122
123 //**Destructor**********************************************************************************
126 inline ~MatrixAccessProxy();
128 //**********************************************************************************************
129
130 //**Operators***********************************************************************************
133 inline const MatrixAccessProxy& operator=( const MatrixAccessProxy& map ) const;
134
135 template< typename T >
136 inline const MatrixAccessProxy& operator=( initializer_list<T> list ) const;
137
138 template< typename T >
139 inline const MatrixAccessProxy& operator=( initializer_list< initializer_list<T> > list ) const;
140
141 template< typename T > inline const MatrixAccessProxy& operator= ( const T& value ) const;
142 template< typename T > inline const MatrixAccessProxy& operator+=( const T& value ) const;
143 template< typename T > inline const MatrixAccessProxy& operator-=( const T& value ) const;
144 template< typename T > inline const MatrixAccessProxy& operator*=( const T& value ) const;
145 template< typename T > inline const MatrixAccessProxy& operator/=( const T& value ) const;
146 template< typename T > inline const MatrixAccessProxy& operator%=( const T& value ) const;
148 //**********************************************************************************************
149
150 //**Utility functions***************************************************************************
153 inline RawReference get() const noexcept;
154 inline bool isRestricted() const noexcept;
156 //**********************************************************************************************
157
158 //**Conversion operator*************************************************************************
161 inline operator RawReference() const noexcept;
163 //**********************************************************************************************
164
165 private:
166 //**Member variables****************************************************************************
169 MT& sm_;
170 size_t i_;
171 size_t j_;
173 //**********************************************************************************************
174
175 //**Forbidden operations************************************************************************
178 void* operator&() const;
180 //**********************************************************************************************
181
182 //**Compile time checks*************************************************************************
186 //**********************************************************************************************
187};
188//*************************************************************************************************
189
190
191
192
193//=================================================================================================
194//
195// CONSTRUCTORS
196//
197//=================================================================================================
198
199//*************************************************************************************************
206template< typename MT > // Type of the sparse matrix
207inline MatrixAccessProxy<MT>::MatrixAccessProxy( MT& sm, size_t i, size_t j )
208 : sm_( sm ) // Reference to the accessed sparse matrix
209 , i_ ( i ) // Row-index of the accessed sparse matrix element
210 , j_ ( j ) // Column-index of the accessed sparse matrix element
211{
212 const Iterator_t<MT> element( sm_.find( i_, j_ ) );
213 const size_t index( rmm ? i_ : j_ );
214 if( element == sm_.end(index) )
215 sm_.insert( i_, j_, RepresentedType{} );
216}
217//*************************************************************************************************
218
219
220
221
222//=================================================================================================
223//
224// DESTRUCTORS
225//
226//=================================================================================================
227
228//*************************************************************************************************
231template< typename MT > // Type of the sparse matrix
233{
234 const Iterator_t<MT> element( sm_.find( i_, j_ ) );
235 const size_t index( rmm ? i_ : j_ );
236 if( element != sm_.end( index ) && isDefault<strict>( element->value() ) )
237 sm_.erase( index, element );
238}
239//*************************************************************************************************
240
241
242
243
244//=================================================================================================
245//
246// OPERATORS
247//
248//=================================================================================================
249
250//*************************************************************************************************
256template< typename MT > // Type of the sparse matrix
258{
259 const Iterator_t<MT> element( map.sm_.find( map.i_, map.j_ ) );
260 const size_t index( rmm ? map.i_ : map.j_ );
261 const auto& source( element != map.sm_.end( index ) ? element->value() : RepresentedType{} );
262
263 get() = source;
264 return *this;
265}
266//*************************************************************************************************
267
268
269//*************************************************************************************************
275template< typename VT > // Type of the sparse matrix
276template< typename T > // Type of the right-hand side elements
277inline const MatrixAccessProxy<VT>&
278 MatrixAccessProxy<VT>::operator=( initializer_list<T> list ) const
279{
280 get() = list;
281 return *this;
282}
283//*************************************************************************************************
284
285
286//*************************************************************************************************
292template< typename VT > // Type of the sparse matrix
293template< typename T > // Type of the right-hand side elements
294inline const MatrixAccessProxy<VT>&
295 MatrixAccessProxy<VT>::operator=( initializer_list< initializer_list<T> > list ) const
296{
297 get() = list;
298 return *this;
299}
300//*************************************************************************************************
301
302
303//*************************************************************************************************
309template< typename MT > // Type of the sparse matrix
310template< typename T > // Type of the right-hand side value
311inline const MatrixAccessProxy<MT>& MatrixAccessProxy<MT>::operator=( const T& value ) const
312{
313 get() = value;
314 return *this;
315}
316//*************************************************************************************************
317
318
319//*************************************************************************************************
325template< typename MT > // Type of the sparse matrix
326template< typename T > // Type of the right-hand side value
327inline const MatrixAccessProxy<MT>& MatrixAccessProxy<MT>::operator+=( const T& value ) const
328{
329 get() += value;
330 return *this;
331}
332//*************************************************************************************************
333
334
335//*************************************************************************************************
341template< typename MT > // Type of the sparse matrix
342template< typename T > // Type of the right-hand side value
343inline const MatrixAccessProxy<MT>& MatrixAccessProxy<MT>::operator-=( const T& value ) const
344{
345 get() -= value;
346 return *this;
347}
348//*************************************************************************************************
349
350
351//*************************************************************************************************
357template< typename MT > // Type of the sparse matrix
358template< typename T > // Type of the right-hand side value
359inline const MatrixAccessProxy<MT>& MatrixAccessProxy<MT>::operator*=( const T& value ) const
360{
361 get() *= value;
362 return *this;
363}
364//*************************************************************************************************
365
366
367//*************************************************************************************************
373template< typename MT > // Type of the sparse matrix
374template< typename T > // Type of the right-hand side value
375inline const MatrixAccessProxy<MT>& MatrixAccessProxy<MT>::operator/=( const T& value ) const
376{
377 get() /= value;
378 return *this;
379}
380//*************************************************************************************************
381
382
383//*************************************************************************************************
393template< typename MT > // Type of the sparse matrix
394template< typename T > // Type of the right-hand side value
395inline const MatrixAccessProxy<MT>& MatrixAccessProxy<MT>::operator%=( const T& value ) const
396{
397 get() %= value;
398 return *this;
399}
400//*************************************************************************************************
401
402
403
404
405//=================================================================================================
406//
407// UTILITY FUNCTIONS
408//
409//=================================================================================================
410
411//*************************************************************************************************
416template< typename MT > // Type of the sparse matrix
418{
419 Iterator_t<MT> element( sm_.find( i_, j_ ) );
420 const size_t index( rmm ? i_ : j_ );
421 if( element == sm_.end(index) )
422 element = sm_.insert( i_, j_, RepresentedType{} );
423 BLAZE_INTERNAL_ASSERT( element != sm_.end(index), "Missing matrix element detected" );
424 return element->value();
425}
426//*************************************************************************************************
427
428
429//*************************************************************************************************
434template< typename MT > // Type of the sparse matrix
435inline bool MatrixAccessProxy<MT>::isRestricted() const noexcept
436{
437 return false;
438}
439//*************************************************************************************************
440
441
442
443
444//=================================================================================================
445//
446// CONVERSION OPERATOR
447//
448//=================================================================================================
449
450//*************************************************************************************************
455template< typename MT > // Type of the sparse matrix
457{
458 return get();
459}
460//*************************************************************************************************
461
462
463
464
465//=================================================================================================
466//
467// GLOBAL FUNCTIONS
468//
469//=================================================================================================
470
471//*************************************************************************************************
474template< typename MT >
475void swap( const MatrixAccessProxy<MT>& a, const MatrixAccessProxy<MT>& b ) noexcept;
476
477template< typename MT, typename T >
478void swap( const MatrixAccessProxy<MT>& a, T& b ) noexcept;
479
480template< typename T, typename MT >
481void swap( T& a, const MatrixAccessProxy<MT>& v ) noexcept;
483//*************************************************************************************************
484
485
486//*************************************************************************************************
494template< typename MT >
495inline void swap( const MatrixAccessProxy<MT>& a, const MatrixAccessProxy<MT>& b ) noexcept
496{
497 using std::swap;
498
499 swap( a.get(), b.get() );
500}
501//*************************************************************************************************
502
503
504//*************************************************************************************************
512template< typename MT, typename T >
513inline void swap( const MatrixAccessProxy<MT>& a, T& b ) noexcept
514{
515 using std::swap;
516
517 swap( a.get(), b );
518}
519//*************************************************************************************************
520
521
522//*************************************************************************************************
530template< typename T, typename MT >
531inline void swap( T& a, const MatrixAccessProxy<MT>& b ) noexcept
532{
533 using std::swap;
534
535 swap( a, b.get() );
536}
537//*************************************************************************************************
538
539} // namespace blaze
540
541#endif
Header file for auxiliary alias declarations.
typename T::ElementType ElementType_t
Alias declaration for nested ElementType type definitions.
Definition: Aliases.h:190
typename T::Iterator Iterator_t
Alias declaration for nested Iterator type definitions.
Definition: Aliases.h:210
Header file for run time assertion macros.
Header file for the isDefault shim.
Header file for the isOne shim.
Header file for the isReal shim.
Header file for the IsRowMajorMatrix type trait.
Header file for the relaxation flag enumeration.
Access proxy for sparse, matrices.
Definition: MatrixAccessProxy.h:101
static constexpr bool rmm
Compile time flag indicating whether the given matrix type is a row-major matrix.
Definition: MatrixAccessProxy.h:105
MT & sm_
Reference to the accessed sparse matrix.
Definition: MatrixAccessProxy.h:169
~MatrixAccessProxy()
The destructor for MatrixAccessProxy.
Definition: MatrixAccessProxy.h:232
size_t i_
Row-index of the accessed sparse matrix element.
Definition: MatrixAccessProxy.h:170
bool isRestricted() const noexcept
Returns whether the proxy represents a restricted sparse matrix element..
Definition: MatrixAccessProxy.h:435
MatrixAccessProxy(MT &sm, size_t i, size_t j)
Initialization constructor for a MatrixAccessProxy.
Definition: MatrixAccessProxy.h:207
RawReference get() const noexcept
Returning the value of the accessed sparse matrix element.
Definition: MatrixAccessProxy.h:417
ElementType_t< MT > RepresentedType
Type of the represented sparse matrix element.
Definition: MatrixAccessProxy.h:110
const MatrixAccessProxy & operator=(const MatrixAccessProxy &map) const
Copy assignment operator for MatrixAccessProxy.
Definition: MatrixAccessProxy.h:257
RepresentedType & RawReference
Raw reference to the represented element.
Definition: MatrixAccessProxy.h:111
size_t j_
Column-index of the accessed sparse matrix element.
Definition: MatrixAccessProxy.h:171
Proxy base class.
Definition: Proxy.h:169
Constraint on the data type.
decltype(auto) map(const DenseMatrix< MT1, SO > &lhs, const DenseMatrix< MT2, SO > &rhs, OP op)
Elementwise evaluation of the given binary operation on each single element of the dense matrices lhs...
Definition: DMatDMatMapExpr.h:1144
#define BLAZE_CONSTRAINT_MUST_BE_SPARSE_MATRIX_TYPE(T)
Constraint on the data type.
Definition: SparseMatrix.h:61
#define BLAZE_INTERNAL_ASSERT(expr, msg)
Run time assertion macro for internal checks.
Definition: Assert.h:101
void swap(T &a, const MatrixAccessProxy< MT > &v) noexcept
Swapping the contents of an access proxy with another element.
Definition: MatrixAccessProxy.h:531
Header file for the extended initializer_list functionality.
Header file for the Proxy class.
Header file for the clear shim.
Header file for the isZero shim.
Header file for basic type definitions.