Blaze 3.9
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>
57#include <blaze/util/Assert.h>
62#include <blaze/util/Types.h>
63
64
65namespace blaze {
66
67//=================================================================================================
68//
69// CLASS DEFINITION
70//
71//=================================================================================================
72
73//*************************************************************************************************
106template< typename MT > // Type of the adapted matrix
108 : private SparseElement
109{
110 private:
111 //**Type definitions****************************************************************************
114 //**********************************************************************************************
115
116 public:
117 //**Type definitions****************************************************************************
119 using IndexType = size_t;
123 //**********************************************************************************************
124
125 //**Constructor*********************************************************************************
128 inline SymmetricElement( IteratorType pos, MT* matrix, size_t idx );
130 //**********************************************************************************************
131
132 //**Assignment operators************************************************************************
135 template< typename T > inline SymmetricElement& operator= ( const T& v );
136 template< typename T > inline SymmetricElement& operator+=( const T& v );
137 template< typename T > inline SymmetricElement& operator-=( const T& v );
138 template< typename T > inline SymmetricElement& operator*=( const T& v );
139 template< typename T > inline SymmetricElement& operator/=( const T& v );
141 //**********************************************************************************************
142
143 //**Access operators****************************************************************************
146 inline Pointer operator->() noexcept;
148 //**********************************************************************************************
149
150 //**Utility functions***************************************************************************
153 inline Reference value() const;
154 inline IndexType index() const;
156 //**********************************************************************************************
157
158 private:
159 //**Utility functions***************************************************************************
162 inline void sync();
163 inline bool isSynced() const;
165 //**********************************************************************************************
166
167 //**Member variables****************************************************************************
170 size_t index_;
171 //**********************************************************************************************
172
173 //**Compile time checks*************************************************************************
189 //**********************************************************************************************
190};
191//*************************************************************************************************
192
193
194
195
196//=================================================================================================
197//
198// CONSTRUCTORS
199//
200//=================================================================================================
201
202//*************************************************************************************************
209template< typename MT > // Type of the adapted matrix
210inline SymmetricElement<MT>::SymmetricElement( IteratorType pos, MT* matrix, size_t idx )
211 : pos_ ( pos ) // Iterator to the current sparse symmetric matrix element
212 , matrix_( matrix ) // The sparse matrix containing the iterator
213 , index_ ( idx ) // The row/column index of the iterator
214{
215 BLAZE_INTERNAL_ASSERT( isSynced(), "Missing matrix element detected" );
216}
217//*************************************************************************************************
218
219
220
221
222//=================================================================================================
223//
224// OPERATORS
225//
226//=================================================================================================
227
228//*************************************************************************************************
234template< typename MT > // Type of the adapted matrix
235template< typename T > // Type of the right-hand side value
237{
238 *pos_ = v;
239 sync();
240 return *this;
241}
242//*************************************************************************************************
243
244
245//*************************************************************************************************
251template< typename MT > // Type of the adapted matrix
252template< typename T > // Type of the right-hand side value
254{
255 *pos_ += v;
256 sync();
257 return *this;
258}
259//*************************************************************************************************
260
261
262//*************************************************************************************************
268template< typename MT > // Type of the adapted matrix
269template< typename T > // Type of the right-hand side value
271{
272 *pos_ -= v;
273 sync();
274 return *this;
275}
276//*************************************************************************************************
277
278
279//*************************************************************************************************
285template< typename MT > // Type of the adapted matrix
286template< typename T > // Type of the right-hand side value
288{
289 *pos_ *= v;
290 sync();
291 return *this;
292}
293//*************************************************************************************************
294
295
296//*************************************************************************************************
302template< typename MT > // Type of the adapted matrix
303template< typename T > // Type of the right-hand side value
305{
306 *pos_ /= v;
307 sync();
308 return *this;
309}
310//*************************************************************************************************
311
312
313
314
315//=================================================================================================
316//
317// ACCESS OPERATORS
318//
319//=================================================================================================
320
321//*************************************************************************************************
326template< typename MT > // Type of the adapted matrix
328{
329 return this;
330}
331//*************************************************************************************************
332
333
334
335
336//=================================================================================================
337//
338// UTILITY FUNCTIONS
339//
340//=================================================================================================
341
342//*************************************************************************************************
347template< typename MT > // Type of the adapted matrix
349{
350 return Reference( pos_, matrix_, index_ );
351}
352//*************************************************************************************************
353
354
355//*************************************************************************************************
360template< typename MT > // Type of the adapted matrix
362{
363 return pos_->index();
364}
365//*************************************************************************************************
366
367
368//*************************************************************************************************
373template< typename MT > // Type of the adapted matrix
375{
376 if( pos_->index() == index_ || isDefault( pos_->value() ) )
377 return;
378
379 const size_t row ( ( IsRowMajorMatrix_v<MT> )?( pos_->index() ):( index_ ) );
380 const size_t column( ( IsRowMajorMatrix_v<MT> )?( index_ ):( pos_->index() ) );
381
382 matrix_->set( row, column, pos_->value() );
383}
384//*************************************************************************************************
385
386
387//*************************************************************************************************
392template< typename MT > // Type of the adapted matrix
394{
395 const size_t row ( ( IsRowMajorMatrix_v<MT> )?( pos_->index() ):( index_ ) );
396 const size_t column( ( IsRowMajorMatrix_v<MT> )?( index_ ):( pos_->index() ) );
397
398 const IteratorType pos2( matrix_->find( row, column ) );
399 const IteratorType end( matrix_->end( pos_->index() ) );
400
401 return ( isDefault( pos_->value() ) && ( pos2 == end || isDefault( pos2->value() ) ) ) ||
402 ( pos2 != end && pos_->value() == pos2->value() );
403}
404//*************************************************************************************************
405
406} // namespace blaze
407
408#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.
Constraint on the data type.
Constraint on the data type.
Header file for the isDefault shim.
Header file for the IsRowMajorMatrix type trait.
Constraint on the data type.
Constraint on the data type.
Constraint on the data type.
Constraint on the data type.
Header file for the SymmetricValue class.
Constraint on the data type.
Constraint on the data type.
Constraint on the data type.
Representation of two synchronized elements within the sparse symmetric matrix.
Definition: SymmetricElement.h:109
Pointer operator->() noexcept
Direct access to the Hermitian element.
Definition: SymmetricElement.h:327
MT * matrix_
The sparse matrix containing the iterator.
Definition: SymmetricElement.h:169
Reference value() const
Access to the current value of the Hermitian element.
Definition: SymmetricElement.h:348
bool isSynced() const
Checking if the current sparse element is in sync.
Definition: SymmetricElement.h:393
Iterator_t< MT > IteratorType
Type of the underlying sparse matrix iterators.
Definition: SymmetricElement.h:113
size_t index_
The row/column index of the iterator.
Definition: SymmetricElement.h:170
IndexType index() const
Access to the current index of the Hermitian element.
Definition: SymmetricElement.h:361
void sync()
Synchronization of the current sparse element to the according paired element.
Definition: SymmetricElement.h:374
size_t IndexType
The index type of the value-index-pair.
Definition: SymmetricElement.h:119
SymmetricValue< MT > Reference
Reference return type.
Definition: SymmetricElement.h:120
IteratorType pos_
Iterator to the current sparse Hermitian matrix element.
Definition: SymmetricElement.h:168
ElementType_t< MT > ElementType
Type of the represented matrix element.
Definition: SymmetricElement.h:112
SymmetricElement(IteratorType pos, MT *matrix, size_t idx)
Constructor for the SymmetricElement class.
Definition: SymmetricElement.h:210
Representation of two synchronized values within a sparse symmetric matrix.
Definition: SymmetricValue.h:117
Constraint on the data type.
Constraint on the data type.
Constraint on the data type.
Constraint on the data type.
decltype(auto) column(Matrix< MT, SO > &matrix, RCAs... args)
Creating a view on a specific column of the given matrix.
Definition: Column.h:137
#define BLAZE_CONSTRAINT_MUST_NOT_BE_VOLATILE(T)
Constraint on the data type.
Definition: Volatile.h:79
#define BLAZE_CONSTRAINT_MUST_NOT_BE_POINTER_TYPE(T)
Constraint on the data type.
Definition: Pointer.h:79
#define BLAZE_CONSTRAINT_MUST_NOT_BE_CONST(T)
Constraint on the data type.
Definition: Const.h:79
#define BLAZE_CONSTRAINT_MUST_NOT_BE_REFERENCE_TYPE(T)
Constraint on the data type.
Definition: Reference.h:79
bool isDefault(const DiagonalMatrix< MT, SO, DF > &m)
Returns whether the given diagonal matrix is in default state.
Definition: DiagonalMatrix.h:169
#define BLAZE_CONSTRAINT_MUST_NOT_BE_SYMMETRIC_MATRIX_TYPE(T)
Constraint on the data type.
Definition: Symmetric.h:79
#define BLAZE_CONSTRAINT_MUST_NOT_BE_VIEW_TYPE(T)
Constraint on the data type.
Definition: View.h:81
#define BLAZE_CONSTRAINT_MUST_NOT_BE_HERMITIAN_MATRIX_TYPE(T)
Constraint on the data type.
Definition: Hermitian.h:79
#define BLAZE_CONSTRAINT_MUST_NOT_BE_UPPER_MATRIX_TYPE(T)
Constraint on the data type.
Definition: Upper.h:81
#define BLAZE_CONSTRAINT_MUST_NOT_BE_COMPUTATION_TYPE(T)
Constraint on the data type.
Definition: Computation.h:81
#define BLAZE_CONSTRAINT_MUST_BE_SPARSE_MATRIX_TYPE(T)
Constraint on the data type.
Definition: SparseMatrix.h:61
#define BLAZE_CONSTRAINT_MUST_NOT_BE_LOWER_MATRIX_TYPE(T)
Constraint on the data type.
Definition: Lower.h:81
#define BLAZE_CONSTRAINT_MUST_BE_SCALAR_TYPE(T)
Constraint on the data type.
Definition: Scalar.h:61
#define BLAZE_CONSTRAINT_MUST_NOT_BE_TRANSFORMATION_TYPE(T)
Constraint on the data type.
Definition: Transformation.h:81
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:584
decltype(auto) row(Matrix< MT, SO > &, RRAs...)
Creating a view on a specific row of the given matrix.
Definition: Row.h:137
#define BLAZE_INTERNAL_ASSERT(expr, msg)
Run time assertion macro for internal checks.
Definition: Assert.h:101
Header file for the SparseElement base class.
Base class for all sparse element types.
Definition: SparseElement.h:58
Header file for basic type definitions.