All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Types | Private Types | List of all members
blaze::MatrixAccessProxy< MT > Class Template Reference

Access proxy for sparse, $ M \times N $ matrices.The MatrixAccessProxy provides safe access to the elements of a non-const sparse matrices.
The proxied access to the elements of a sparse matrix is necessary since it may be possible that several insertion operations happen in the same statement. The following code illustrates this with two examples by means of the CompressedMatrix class: More...

#include <MatrixAccessProxy.h>

Public Types

typedef MT MatrixType
 Type of the accessed sparse matrix.
 
typedef MT::ElementType ElementType
 Type of the accessed sparse matrix element.
 
typedef ElementTypeReference
 Reference type of the accessed element.
 
typedef const ElementTypeConstReference
 Reference type of the accessed constant element.
 
typedef MT::Iterator Iterator
 Iterator type of the accessed sparse matrix.
 

Public Member Functions

Constructors
 MatrixAccessProxy (MT &sv, size_t i, size_t j)
 Initialization constructor for a MatrixAccessProxy.
 
 MatrixAccessProxy (const MatrixAccessProxy &vap)
 The copy constructor for MatrixAccessProxy.
 
Operators
MatrixAccessProxyoperator= (const MatrixAccessProxy &vap)
 Copy assignment operator for MatrixAccessProxy.
 
template<typename T >
MatrixAccessProxyoperator= (const T &value)
 Assignment to the accessed sparse matrix element.
 
template<typename T >
MatrixAccessProxyoperator+= (const T &value)
 Addition assignment to the accessed sparse matrix element.
 
template<typename T >
MatrixAccessProxyoperator-= (const T &value)
 Subtraction assignment to the accessed sparse matrix element.
 
template<typename T >
MatrixAccessProxyoperator*= (const T &value)
 Multiplication assignment to the accessed sparse matrix element.
 
template<typename T >
MatrixAccessProxyoperator/= (const T &value)
 Division assignment to the accessed sparse matrix element.
 
Conversion operator
 operator Reference () const
 Conversion to the accessed sparse matrix element.
 

Private Types

enum  { rmm = IsRowMajorMatrix<MT>::value }
 Compile time flag indicating whether the given matrix type is a row-major matrix.
 

Private Member Functions

Utility functions
Reference get () const
 Returning the value of the accessed sparse matrix element.
 
void set (ConstReference value) const
 Setting the value of the accessed sparse matrix element.
 

Private Attributes

Member variables
MT & sm_
 Reference to the accessed sparse matrix.
 
size_t i_
 Row-index of the accessed sparse matrix element.
 
size_t j_
 Column-index of the accessed sparse matrix element.
 

Detailed Description

template<typename MT>
class blaze::MatrixAccessProxy< MT >

Access proxy for sparse, $ M \times N $ matrices.

The MatrixAccessProxy provides safe access to the elements of a non-const sparse matrices.
The proxied access to the elements of a sparse matrix is necessary since it may be possible that several insertion operations happen in the same statement. The following code illustrates this with two examples by means of the CompressedMatrix class:

CompressedMatrix<real> A( 4, 4 );
// Standard usage of the function call operator to initialize a matrix element.
// Only a single sparse matrix element is accessed!
A(0,1) = 1.0;
// Initialization of a matrix element via another matrix element.
// Two sparse matrix accesses in one statement!
// Multiple accesses to elements of the sparse matrix in one statement!
const real result = A(0,2) + A(1,2) + A(2,2);

The problem (especially with the last statement) is that several insertion operations might take place due to the access via the function call operator. If the function call operator would return a direct reference to one of the accessed elements, this reference might be invalidated during the evaluation of a subsequent function call operator, which results in undefined behavior. This class provides the necessary functionality to guarantee a safe access to the sparse matrix elements while preserving the intuitive use of the function call operator.

Constructor & Destructor Documentation

template<typename MT >
blaze::MatrixAccessProxy< MT >::MatrixAccessProxy ( MT &  sv,
size_t  i,
size_t  j 
)
inlineexplicit

Initialization constructor for a MatrixAccessProxy.

Parameters
svReference to the accessed sparse matrix.
iThe row-index of the accessed sparse matrix element.
jThe column-index of the accessed sparse matrix element.
template<typename MT >
blaze::MatrixAccessProxy< MT >::MatrixAccessProxy ( const MatrixAccessProxy< MT > &  map)
inline

The copy constructor for MatrixAccessProxy.

Parameters
mapSparse matrix access proxy to be copied.

Member Function Documentation

template<typename MT >
MatrixAccessProxy< MT >::Reference blaze::MatrixAccessProxy< MT >::get ( ) const
inlineprivate

Returning the value of the accessed sparse matrix element.

Returns
Reference to the accessed sparse matrix element.
template<typename MT >
blaze::MatrixAccessProxy< MT >::operator Reference ( ) const
inline

Conversion to the accessed sparse matrix element.

Returns
Reference to the accessed sparse matrix element.
template<typename MT >
template<typename T >
MatrixAccessProxy< MT > & blaze::MatrixAccessProxy< MT >::operator*= ( const T &  value)
inline

Multiplication assignment to the accessed sparse matrix element.

Parameters
valueThe right-hand side value for the multiplication.
Returns
Reference to the assigned access proxy.
template<typename MT >
template<typename T >
MatrixAccessProxy< MT > & blaze::MatrixAccessProxy< MT >::operator+= ( const T &  value)
inline

Addition assignment to the accessed sparse matrix element.

Parameters
valueThe right-hand side value to be added to the sparse matrix element.
Returns
Reference to the assigned access proxy.
template<typename MT >
template<typename T >
MatrixAccessProxy< MT > & blaze::MatrixAccessProxy< MT >::operator-= ( const T &  value)
inline

Subtraction assignment to the accessed sparse matrix element.

Parameters
valueThe right-hand side value to be subtracted from the sparse matrix element.
Returns
Reference to the assigned access proxy.
template<typename MT >
template<typename T >
MatrixAccessProxy< MT > & blaze::MatrixAccessProxy< MT >::operator/= ( const T &  value)
inline

Division assignment to the accessed sparse matrix element.

Parameters
valueThe right-hand side value for the division.
Returns
Reference to the assigned access proxy.
template<typename MT >
MatrixAccessProxy< MT > & blaze::MatrixAccessProxy< MT >::operator= ( const MatrixAccessProxy< MT > &  map)
inline

Copy assignment operator for MatrixAccessProxy.

Parameters
mapSparse matrix access proxy to be copied.
Returns
Reference to the assigned access proxy.
template<typename MT >
template<typename T >
MatrixAccessProxy< MT > & blaze::MatrixAccessProxy< MT >::operator= ( const T &  value)
inline

Assignment to the accessed sparse matrix element.

Parameters
valueThe new value of the sparse matrix element.
Returns
Reference to the assigned access proxy.
template<typename MT >
void blaze::MatrixAccessProxy< MT >::set ( ConstReference  value) const
inlineprivate

Setting the value of the accessed sparse matrix element.

Parameters
valueReference to the new value of the sparse matrix element.
Returns
void

The documentation for this class was generated from the following file: