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 
43 #include <blaze/math/Aliases.h>
54 #include <blaze/util/Assert.h>
60 #include <blaze/util/Types.h>
61 
62 
63 namespace blaze {
64 
65 //=================================================================================================
66 //
67 // CLASS DEFINITION
68 //
69 //=================================================================================================
70 
71 //*************************************************************************************************
104 template< typename MT > // Type of the adapted matrix
106 {
107  private:
108  //**Type definitions****************************************************************************
111  //**********************************************************************************************
112 
113  public:
114  //**Type definitions****************************************************************************
116  typedef size_t IndexType;
120  //**********************************************************************************************
121 
122  //**Constructor*********************************************************************************
125  inline SymmetricElement( IteratorType pos, MT* matrix, size_t idx );
127  //**********************************************************************************************
128 
129  //**Assignment operators************************************************************************
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 );
136  template< typename T > inline SymmetricElement& operator/=( const T& v );
138  //**********************************************************************************************
139 
140  //**Access operators****************************************************************************
143  inline Pointer operator->() noexcept;
145  //**********************************************************************************************
146 
147  //**Utility functions***************************************************************************
150  inline Reference value() const;
151  inline IndexType index() const;
153  //**********************************************************************************************
154 
155  private:
156  //**Utility functions***************************************************************************
159  inline void sync();
160  inline bool isSynced() const;
162  //**********************************************************************************************
163 
164  //**Member variables****************************************************************************
165  IteratorType pos_;
166  MT* matrix_;
167  size_t index_;
168  //**********************************************************************************************
169 
170  //**Compile time checks*************************************************************************
184  //**********************************************************************************************
185 };
186 //*************************************************************************************************
187 
188 
189 
190 
191 //=================================================================================================
192 //
193 // CONSTRUCTORS
194 //
195 //=================================================================================================
196 
197 //*************************************************************************************************
204 template< typename MT > // Type of the adapted matrix
205 inline SymmetricElement<MT>::SymmetricElement( IteratorType pos, MT* matrix, size_t idx )
206  : pos_ ( pos ) // Iterator to the current sparse symmetric matrix element
207  , matrix_( matrix ) // The sparse matrix containing the iterator
208  , index_ ( idx ) // The row/column index of the iterator
209 {
210  BLAZE_INTERNAL_ASSERT( isSynced(), "Missing matrix element detected" );
211 }
212 //*************************************************************************************************
213 
214 
215 
216 
217 //=================================================================================================
218 //
219 // OPERATORS
220 //
221 //=================================================================================================
222 
223 //*************************************************************************************************
229 template< typename MT > // Type of the adapted matrix
230 template< typename T > // Type of the right-hand side value
232 {
233  *pos_ = v;
234  sync();
235  return *this;
236 }
237 //*************************************************************************************************
238 
239 
240 //*************************************************************************************************
246 template< typename MT > // Type of the adapted matrix
247 template< typename T > // Type of the right-hand side value
249 {
250  *pos_ += v;
251  sync();
252  return *this;
253 }
254 //*************************************************************************************************
255 
256 
257 //*************************************************************************************************
263 template< typename MT > // Type of the adapted matrix
264 template< typename T > // Type of the right-hand side value
266 {
267  *pos_ -= v;
268  sync();
269  return *this;
270 }
271 //*************************************************************************************************
272 
273 
274 //*************************************************************************************************
280 template< typename MT > // Type of the adapted matrix
281 template< typename T > // Type of the right-hand side value
283 {
284  *pos_ *= v;
285  sync();
286  return *this;
287 }
288 //*************************************************************************************************
289 
290 
291 //*************************************************************************************************
297 template< typename MT > // Type of the adapted matrix
298 template< typename T > // Type of the right-hand side value
300 {
301  *pos_ /= v;
302  sync();
303  return *this;
304 }
305 //*************************************************************************************************
306 
307 
308 
309 
310 //=================================================================================================
311 //
312 // ACCESS OPERATORS
313 //
314 //=================================================================================================
315 
316 //*************************************************************************************************
321 template< typename MT > // Type of the adapted matrix
323 {
324  return this;
325 }
326 //*************************************************************************************************
327 
328 
329 
330 
331 //=================================================================================================
332 //
333 // UTILITY FUNCTIONS
334 //
335 //=================================================================================================
336 
337 //*************************************************************************************************
342 template< typename MT > // Type of the adapted matrix
344 {
345  return Reference( pos_, matrix_, index_ );
346 }
347 //*************************************************************************************************
348 
349 
350 //*************************************************************************************************
355 template< typename MT > // Type of the adapted matrix
357 {
358  return pos_->index();
359 }
360 //*************************************************************************************************
361 
362 
363 //*************************************************************************************************
368 template< typename MT > // Type of the adapted matrix
370 {
371  if( pos_->index() == index_ || isDefault( pos_->value() ) )
372  return;
373 
374  const size_t row ( ( IsRowMajorMatrix<MT>::value )?( pos_->index() ):( index_ ) );
375  const size_t column( ( IsRowMajorMatrix<MT>::value )?( index_ ):( pos_->index() ) );
376 
377  matrix_->set( row, column, pos_->value() );
378 }
379 //*************************************************************************************************
380 
381 
382 //*************************************************************************************************
387 template< typename MT > // Type of the adapted matrix
389 {
390  const size_t row ( ( IsRowMajorMatrix<MT>::value )?( pos_->index() ):( index_ ) );
391  const size_t column( ( IsRowMajorMatrix<MT>::value )?( index_ ):( pos_->index() ) );
392 
393  const IteratorType pos2( matrix_->find( row, column ) );
394  const IteratorType end( matrix_->end( pos_->index() ) );
395 
396  return ( isDefault( pos_->value() ) && ( pos2 == end || isDefault( pos2->value() ) ) ) ||
397  ( pos2 != end && pos_->value() == pos2->value() );
398 }
399 //*************************************************************************************************
400 
401 } // namespace blaze
402 
403 #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:79
Header file for auxiliary alias declarations.
Constraint on the data type.
Header file for basic type definitions.
SymmetricValue< MT > Reference
Reference return type.
Definition: SymmetricElement.h:117
Constraint on the data type.
IteratorType pos_
Iterator to the current sparse Hermitian matrix element.
Definition: SymmetricElement.h:165
#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:79
Constraint on the data type.
DisableIf_< Or< IsComputation< MT >, IsTransExpr< MT > >, ColumnExprTrait_< MT > > column(Matrix< MT, SO > &matrix, size_t index)
Creating a view on a specific column of the given matrix.
Definition: Column.h:126
SymmetricValue< MT > ValueType
The value type of the value-index-pair.
Definition: SymmetricElement.h:115
size_t IndexType
The index type of the value-index-pair.
Definition: SymmetricElement.h:116
bool isDefault(const DiagonalProxy< MT > &proxy)
Returns whether the represented element is in default state.
Definition: DiagonalProxy.h:573
Constraint on the data type.
Constraint on the data type.
MT * matrix_
The sparse matrix containing the iterator.
Definition: SymmetricElement.h:166
Iterator_< MT > IteratorType
Type of the underlying sparse matrix iterators.
Definition: SymmetricElement.h:110
SymmetricElement(IteratorType pos, MT *matrix, size_t idx)
Constructor for the SymmetricElement class.
Definition: SymmetricElement.h:205
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:83
#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:79
size_t index_
The row/column index of the iterator.
Definition: SymmetricElement.h:167
typename T::ElementType ElementType_
Alias declaration for nested ElementType type definitions.The ElementType_ alias declaration provides...
Definition: Aliases.h:163
Constraint on the data type.
IndexType index() const
Access to the current index of the Hermitian element.
Definition: SymmetricElement.h:356
Header file for the SparseElement base class.
SymmetricElement * Pointer
Pointer return type.
Definition: SymmetricElement.h:119
Pointer operator->() noexcept
Direct access to the Hermitian element.
Definition: SymmetricElement.h:322
#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:81
void sync()
Synchronization of the current sparse element to the according paired element.
Definition: SymmetricElement.h:369
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:254
DisableIf_< Or< IsComputation< MT >, IsTransExpr< MT > >, RowExprTrait_< MT > > row(Matrix< MT, SO > &matrix, size_t index)
Creating a view on a specific row of the given matrix.
Definition: Row.h:126
Reference value() const
Access to the current value of the Hermitian element.
Definition: SymmetricElement.h:343
#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:79
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:61
Representation of two synchronized values within a sparse symmetric matrix.The SymmetricValue class r...
Definition: SymmetricValue.h:113
#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:81
#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:79
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:105
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:388
typename T::Iterator Iterator_
Alias declaration for nested Iterator type definitions.The Iterator_ alias declaration provides a con...
Definition: Aliases.h:183
Header file for the IsRowMajorMatrix type trait.
const SymmetricValue< MT > ConstReference
Reference-to-const return type.
Definition: SymmetricElement.h:118
#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:81
#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:79
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:61
ElementType_< MT > ElementType
Type of the represented matrix element.
Definition: SymmetricElement.h:109