SymmetricElement.h
Go to the documentation of this file.
1 //=================================================================================================
33 //=================================================================================================
34 
35 #ifndef _BLAZE_MATH_ADAPTORS_SYMMETRICMATRIX_SYMMETRICELEMENT_H_
36 #define _BLAZE_MATH_ADAPTORS_SYMMETRICMATRIX_SYMMETRICELEMENT_H_
37 
38 
39 //*************************************************************************************************
40 // Includes
41 //*************************************************************************************************
42 
53 #include <blaze/util/Assert.h>
59 #include <blaze/util/Types.h>
60 
61 
62 namespace blaze {
63 
64 //=================================================================================================
65 //
66 // CLASS DEFINITION
67 //
68 //=================================================================================================
69 
70 //*************************************************************************************************
103 template< typename MT > // Type of the adapted matrix
105 {
106  private:
107  //**Type definitions****************************************************************************
108  typedef typename MT::ElementType ElementType;
109  typedef typename MT::Iterator IteratorType;
110  //**********************************************************************************************
111 
112  public:
113  //**Type definitions****************************************************************************
115  typedef size_t IndexType;
119  //**********************************************************************************************
120 
121  //**Constructor*********************************************************************************
124  inline SymmetricElement( IteratorType pos, MT* matrix, size_t idx );
126  //**********************************************************************************************
127 
128  //**Assignment operators************************************************************************
131  template< typename T > inline SymmetricElement& operator= ( const T& v );
132  template< typename T > inline SymmetricElement& operator+=( const T& v );
133  template< typename T > inline SymmetricElement& operator-=( const T& v );
134  template< typename T > inline SymmetricElement& operator*=( const T& v );
135  template< typename T > inline SymmetricElement& operator/=( const T& v );
137  //**********************************************************************************************
138 
139  //**Access operators****************************************************************************
142  inline Pointer operator->();
144  //**********************************************************************************************
145 
146  //**Utility functions***************************************************************************
149  inline Reference value() const;
150  inline IndexType index() const;
152  //**********************************************************************************************
153 
154  private:
155  //**Utility functions***************************************************************************
158  inline void sync();
159  inline bool isSynced() const;
161  //**********************************************************************************************
162 
163  //**Member variables****************************************************************************
164  IteratorType pos_;
165  MT* matrix_;
166  size_t index_;
167  //**********************************************************************************************
168 
169  //**Compile time checks*************************************************************************
183  //**********************************************************************************************
184 };
185 //*************************************************************************************************
186 
187 
188 
189 
190 //=================================================================================================
191 //
192 // CONSTRUCTORS
193 //
194 //=================================================================================================
195 
196 //*************************************************************************************************
203 template< typename MT > // Type of the adapted matrix
204 inline SymmetricElement<MT>::SymmetricElement( IteratorType pos, MT* matrix, size_t idx )
205  : pos_ ( pos ) // Iterator to the current sparse symmetric matrix element
206  , matrix_( matrix ) // The sparse matrix containing the iterator
207  , index_ ( idx ) // The row/column index of the iterator
208 {
209  BLAZE_INTERNAL_ASSERT( isSynced(), "Missing matrix element detected" );
210 }
211 //*************************************************************************************************
212 
213 
214 
215 
216 //=================================================================================================
217 //
218 // OPERATORS
219 //
220 //=================================================================================================
221 
222 //*************************************************************************************************
228 template< typename MT > // Type of the adapted matrix
229 template< typename T > // Type of the right-hand side value
231 {
232  *pos_ = v;
233  sync();
234  return *this;
235 }
236 //*************************************************************************************************
237 
238 
239 //*************************************************************************************************
245 template< typename MT > // Type of the adapted matrix
246 template< typename T > // Type of the right-hand side value
248 {
249  *pos_ += v;
250  sync();
251  return *this;
252 }
253 //*************************************************************************************************
254 
255 
256 //*************************************************************************************************
262 template< typename MT > // Type of the adapted matrix
263 template< typename T > // Type of the right-hand side value
265 {
266  *pos_ -= v;
267  sync();
268  return *this;
269 }
270 //*************************************************************************************************
271 
272 
273 //*************************************************************************************************
279 template< typename MT > // Type of the adapted matrix
280 template< typename T > // Type of the right-hand side value
282 {
283  *pos_ *= v;
284  sync();
285  return *this;
286 }
287 //*************************************************************************************************
288 
289 
290 //*************************************************************************************************
296 template< typename MT > // Type of the adapted matrix
297 template< typename T > // Type of the right-hand side value
299 {
300  *pos_ /= v;
301  sync();
302  return *this;
303 }
304 //*************************************************************************************************
305 
306 
307 
308 
309 //=================================================================================================
310 //
311 // ACCESS OPERATORS
312 //
313 //=================================================================================================
314 
315 //*************************************************************************************************
320 template< typename MT > // Type of the adapted matrix
322 {
323  return this;
324 }
325 //*************************************************************************************************
326 
327 
328 
329 
330 //=================================================================================================
331 //
332 // UTILITY FUNCTIONS
333 //
334 //=================================================================================================
335 
336 //*************************************************************************************************
341 template< typename MT > // Type of the adapted matrix
343 {
344  return Reference( pos_, matrix_, index_ );
345 }
346 //*************************************************************************************************
347 
348 
349 //*************************************************************************************************
354 template< typename MT > // Type of the adapted matrix
356 {
357  return pos_->index();
358 }
359 //*************************************************************************************************
360 
361 
362 //*************************************************************************************************
367 template< typename MT > // Type of the adapted matrix
369 {
370  if( pos_->index() == index_ || isDefault( pos_->value() ) )
371  return;
372 
373  const size_t row ( ( IsRowMajorMatrix<MT>::value )?( pos_->index() ):( index_ ) );
374  const size_t column( ( IsRowMajorMatrix<MT>::value )?( index_ ):( pos_->index() ) );
375 
376  matrix_->set( row, column, pos_->value() );
377 }
378 //*************************************************************************************************
379 
380 
381 //*************************************************************************************************
386 template< typename MT > // Type of the adapted matrix
388 {
389  const size_t row ( ( IsRowMajorMatrix<MT>::value )?( pos_->index() ):( index_ ) );
390  const size_t column( ( IsRowMajorMatrix<MT>::value )?( index_ ):( pos_->index() ) );
391 
392  const IteratorType pos2( matrix_->find( row, column ) );
393  const IteratorType end( matrix_->end( pos_->index() ) );
394 
395  return ( isDefault( pos_->value() ) && ( pos2 == end || isDefault( pos2->value() ) ) ) ||
396  ( pos2 != end && pos_->value() == pos2->value() );
397 }
398 //*************************************************************************************************
399 
400 } // namespace blaze
401 
402 #endif
#define BLAZE_CONSTRAINT_MUST_NOT_BE_CONST(T)
Constraint on the data type.In case the given data type is a const-qualified type, a compilation error is created.
Definition: Const.h:116
Constraint on the data type.
Header file for basic type definitions.
BLAZE_ALWAYS_INLINE MT::Iterator end(Matrix< MT, SO > &matrix, size_t i)
Returns an iterator just past the last element of row/column i.
Definition: Matrix.h:250
SymmetricValue< MT > Reference
Reference return type.
Definition: SymmetricElement.h:116
Constraint on the data type.
IteratorType pos_
Iterator to the current sparse Hermitian matrix element.
Definition: SymmetricElement.h:164
DisableIf< Or< IsComputation< MT >, IsTransExpr< MT > >, typename ColumnExprTrait< MT >::Type >::Type column(Matrix< MT, SO > &matrix, size_t index)
Creating a view on a specific column of the given matrix.
Definition: Column.h:107
#define BLAZE_CONSTRAINT_MUST_NOT_BE_VOLATILE(T)
Constraint on the data type.In case the given data type is a volatile-qualified type, a compilation error is created.
Definition: Volatile.h:116
Constraint on the data type.
SymmetricValue< MT > ValueType
The value type of the value-index-pair.
Definition: SymmetricElement.h:114
size_t IndexType
The index type of the value-index-pair.
Definition: SymmetricElement.h:115
MT::ElementType ElementType
Type of the represented matrix element.
Definition: SymmetricElement.h:108
bool isDefault(const DiagonalProxy< MT > &proxy)
Returns whether the represented element is in default state.
Definition: DiagonalProxy.h:547
Constraint on the data type.
Constraint on the data type.
MT * matrix_
The sparse matrix containing the iterator.
Definition: SymmetricElement.h:165
SymmetricElement(IteratorType pos, MT *matrix, size_t idx)
Constructor for the SymmetricElement class.
Definition: SymmetricElement.h:204
Constraint on the data type.
Namespace of the Blaze C++ math library.
Definition: Blaze.h:57
Compile time check for row-major matrix types.This type trait tests whether or not the given template...
Definition: IsRowMajorMatrix.h:110
#define BLAZE_CONSTRAINT_MUST_NOT_BE_POINTER_TYPE(T)
Constraint on the data type.In case the given data type T is not a pointer type, a compilation error ...
Definition: Pointer.h:116
size_t index_
The row/column index of the iterator.
Definition: SymmetricElement.h:166
Constraint on the data type.
IndexType index() const
Access to the current index of the Hermitian element.
Definition: SymmetricElement.h:355
Header file for the SparseElement base class.
SymmetricElement * Pointer
Pointer return type.
Definition: SymmetricElement.h:118
MT::Iterator IteratorType
Type of the underlying sparse matrix iterators.
Definition: SymmetricElement.h:109
#define BLAZE_CONSTRAINT_MUST_NOT_BE_UPPER_MATRIX_TYPE(T)
Constraint on the data type.In case the given data type T is a upper triangular matrix type...
Definition: Upper.h:118
void sync()
Synchronization of the current sparse element to the according paired element.
Definition: SymmetricElement.h:368
Type ElementType
Type of the sparse matrix elements.
Definition: CompressedMatrix.h:2586
DisableIf< Or< IsComputation< MT >, IsTransExpr< MT > >, typename RowExprTrait< MT >::Type >::Type row(Matrix< MT, SO > &matrix, size_t index)
Creating a view on a specific row of the given matrix.
Definition: Row.h:107
Reference value() const
Access to the current value of the Hermitian element.
Definition: SymmetricElement.h:342
Pointer operator->()
Direct access to the Hermitian element.
Definition: SymmetricElement.h:321
#define BLAZE_CONSTRAINT_MUST_NOT_BE_SYMMETRIC_MATRIX_TYPE(T)
Constraint on the data type.In case the given data type T is a symmetric matrix type, a compilation error is created.
Definition: Symmetric.h:116
Header file for run time assertion macros.
Constraint on the data type.
Constraint on the data type.
#define BLAZE_CONSTRAINT_MUST_BE_NUMERIC_TYPE(T)
Constraint on the data type.In case the given data type T is not a numeric (integral or floating poin...
Definition: Numeric.h:79
Representation of two synchronized values within a sparse symmetric matrix.The SymmetricValue class r...
Definition: SymmetricValue.h:114
#define BLAZE_CONSTRAINT_MUST_NOT_BE_LOWER_MATRIX_TYPE(T)
Constraint on the data type.In case the given data type T is a lower triangular matrix type...
Definition: Lower.h:118
#define BLAZE_CONSTRAINT_MUST_NOT_BE_REFERENCE_TYPE(T)
Constraint on the data type.In case the given data type T is not a reference type, a compilation error is created.
Definition: Reference.h:116
Element * Iterator
Iterator over non-constant elements.
Definition: CompressedMatrix.h:2591
Header file for the isDefault shim.
Header file for the SymmetricValue class.
Constraint on the data type.
Representation of two synchronized elements within the sparse symmetric matrix.The SymmetricElement c...
Definition: SymmetricElement.h:104
Constraint on the data type.
Base class for all sparse element types.The SparseElement class is the base class for all sparse elem...
Definition: SparseElement.h:57
bool isSynced() const
Checking if the current sparse element is in sync.
Definition: SymmetricElement.h:387
Header file for the IsRowMajorMatrix type trait.
const SymmetricValue< MT > ConstReference
Reference-to-const return type.
Definition: SymmetricElement.h:117
#define BLAZE_CONSTRAINT_MUST_NOT_BE_EXPRESSION_TYPE(T)
Constraint on the data type.In case the given data type T is an expression (i.e. a type derived from ...
Definition: Expression.h:118
MatrixAccessProxy< This > Reference
Reference to a non-constant matrix value.
Definition: CompressedMatrix.h:2589
#define BLAZE_CONSTRAINT_MUST_NOT_BE_HERMITIAN_MATRIX_TYPE(T)
Constraint on the data type.In case the given data type T is an Hermitian matrix type, a compilation error is created.
Definition: Hermitian.h:116
Size type of the Blaze library.
#define BLAZE_INTERNAL_ASSERT(expr, msg)
Run time assertion macro for internal checks.In case of an invalid run time expression, the program execution is terminated. The BLAZE_INTERNAL_ASSERT macro can be disabled by setting the BLAZE_USER_ASSERTION flag to zero or by defining NDEBUG during the compilation.
Definition: Assert.h:101
#define BLAZE_CONSTRAINT_MUST_BE_SPARSE_MATRIX_TYPE(T)
Constraint on the data type.In case the given data type T is not a sparse, N-dimensional matrix type...
Definition: SparseMatrix.h:79