Blaze 3.9
SymmetricValue.h
Go to the documentation of this file.
1//=================================================================================================
33//=================================================================================================
34
35#ifndef _BLAZE_MATH_ADAPTORS_SYMMETRICMATRIX_SYMMETRICVALUE_H_
36#define _BLAZE_MATH_ADAPTORS_SYMMETRICMATRIX_SYMMETRICVALUE_H_
37
38
39//*************************************************************************************************
40// Includes
41//*************************************************************************************************
42
43#include <blaze/math/Aliases.h>
68#include <blaze/util/mpl/If.h>
69#include <blaze/util/Types.h>
71
72
73namespace blaze {
74
75//=================================================================================================
76//
77// CLASS DEFINITION
78//
79//=================================================================================================
80
81//*************************************************************************************************
114template< typename MT > // Type of the adapted matrix
116 : public Proxy< SymmetricValue<MT> >
117{
118 private:
119 //**Type definitions****************************************************************************
120 using IteratorType = typename MT::Iterator;
121 //**********************************************************************************************
122
123 //**struct BuiltinType**************************************************************************
127 template< typename T >
128 struct BuiltinType { using Type = INVALID_TYPE; };
130 //**********************************************************************************************
131
132 //**struct ComplexType**************************************************************************
136 template< typename T >
137 struct ComplexType { using Type = typename T::value_type; };
139 //**********************************************************************************************
140
141 public:
142 //**Type definitions****************************************************************************
144
147 , ComplexType<RepresentedType>
148 , BuiltinType<RepresentedType> >::Type;
149
151 //**********************************************************************************************
152
153 //**Constructors********************************************************************************
156 inline SymmetricValue( IteratorType pos, MT* matrix, size_t index );
157
158 SymmetricValue( const SymmetricValue& ) = default;
160 //**********************************************************************************************
161
162 //**Destructor**********************************************************************************
165 ~SymmetricValue() = default;
167 //**********************************************************************************************
168
169 //**Assignment operators************************************************************************
172 inline SymmetricValue& operator= ( const SymmetricValue& sv );
173 template< typename T > inline SymmetricValue& operator= ( const T& value );
174 template< typename T > inline SymmetricValue& operator+=( const T& value );
175 template< typename T > inline SymmetricValue& operator-=( const T& value );
176 template< typename T > inline SymmetricValue& operator*=( const T& value );
177 template< typename T > inline SymmetricValue& operator/=( const T& value );
179 //**********************************************************************************************
180
181 //**Utility functions***************************************************************************
184 inline void invert() const;
185
186 inline RepresentedType get() const noexcept;
188 //**********************************************************************************************
189
190 //**Conversion operator*************************************************************************
193 inline operator RepresentedType() const noexcept;
195 //**********************************************************************************************
196
197 //**Complex data access functions***************************************************************
200 inline ValueType real() const;
201 inline void real( ValueType value ) const;
202 inline ValueType imag() const;
203 inline void imag( ValueType value ) const;
205 //**********************************************************************************************
206
207 private:
208 //**Utility functions***************************************************************************
211 inline void sync() const;
213 //**********************************************************************************************
214
215 //**Member variables****************************************************************************
218 size_t index_;
219 //**********************************************************************************************
220
221 //**Compile time checks*************************************************************************
237 //**********************************************************************************************
238
239 //**********************************************************************************************
249 friend inline void reset( const SymmetricValue& value )
250 {
251 using blaze::reset;
252
253 reset( value.pos_->value() );
254
255 if( value.pos_->index() != value.index_ )
256 {
257 const size_t row ( ( IsRowMajorMatrix_v<MT> )?( value.pos_->index() ):( value.index_ ) );
258 const size_t column( ( IsRowMajorMatrix_v<MT> )?( value.index_ ):( value.pos_->index() ) );
259 const IteratorType pos2( value.matrix_->find( row, column ) );
260
261 reset( pos2->value() );
262 }
263 }
265 //**********************************************************************************************
266
267 //**********************************************************************************************
277 friend inline void clear( const SymmetricValue& value )
278 {
279 using blaze::clear;
280
281 clear( value.pos_->value() );
282
283 if( value.pos_->index() != value.index_ )
284 {
285 const size_t row ( ( IsRowMajorMatrix_v<MT> )?( value.pos_->index() ):( value.index_ ) );
286 const size_t column( ( IsRowMajorMatrix_v<MT> )?( value.index_ ):( value.pos_->index() ) );
287 const IteratorType pos2( value.matrix_->find( row, column ) );
288
289 clear( pos2->value() );
290 }
291 }
293 //**********************************************************************************************
294};
295//*************************************************************************************************
296
297
298
299
300//=================================================================================================
301//
302// CONSTRUCTORS
303//
304//=================================================================================================
305
306//*************************************************************************************************
313template< typename MT > // Type of the adapted matrix
314inline SymmetricValue<MT>::SymmetricValue( IteratorType pos, MT* matrix, size_t index )
315 : pos_ ( pos ) // Iterator to the current sparse symmetric matrix element
316 , matrix_( matrix ) // The sparse matrix containing the iterator
317 , index_ ( index ) // The row/column index of the iterator
318{}
319//*************************************************************************************************
320
321
322
323
324//=================================================================================================
325//
326// OPERATORS
327//
328//=================================================================================================
329
330//*************************************************************************************************
336template< typename MT > // Type of the adapted matrix
338{
339 pos_->value() = sv.pos_->value();
340 sync();
341 return *this;
342}
343//*************************************************************************************************
344
345
346//*************************************************************************************************
352template< typename MT > // Type of the adapted matrix
353template< typename T > // Type of the right-hand side value
355{
356 pos_->value() = value;
357 sync();
358 return *this;
359}
360//*************************************************************************************************
361
362
363//*************************************************************************************************
370template< typename MT > // Type of the adapted matrix
371template< typename T > // Type of the right-hand side value
373{
374 pos_->value() += value;
375 sync();
376 return *this;
377}
378//*************************************************************************************************
379
380
381//*************************************************************************************************
387template< typename MT > // Type of the adapted matrix
388template< typename T > // Type of the right-hand side value
390{
391 pos_->value() -= value;
392 sync();
393 return *this;
394}
395//*************************************************************************************************
396
397
398//*************************************************************************************************
404template< typename MT > // Type of the adapted matrix
405template< typename T > // Type of the right-hand side value
407{
408 pos_->value() *= value;
409 sync();
410 return *this;
411}
412//*************************************************************************************************
413
414
415//*************************************************************************************************
421template< typename MT > // Type of the adapted matrix
422template< typename T > // Type of the right-hand side value
424{
425 pos_->value() /= value;
426 sync();
427 return *this;
428}
429//*************************************************************************************************
430
431
432
433
434//=================================================================================================
435//
436// UTILITY FUNCTIONS
437//
438//=================================================================================================
439
440//*************************************************************************************************
445template< typename MT > // Type of the adapted matrix
446inline void SymmetricValue<MT>::invert() const
447{
448 using blaze::invert;
449
450 invert( pos_->value() );
451
452 if( pos_->index() != index_ )
453 {
454 const size_t row ( ( IsRowMajorMatrix_v<MT> )?( pos_->index() ):( index_ ) );
455 const size_t column( ( IsRowMajorMatrix_v<MT> )?( index_ ):( pos_->index() ) );
456 const IteratorType pos2( matrix_->find( row, column ) );
457
458 pos2->value() = pos_->value();
459 }
460}
461//*************************************************************************************************
462
463
464//*************************************************************************************************
469template< typename MT > // Type of the adapted matrix
471{
472 return pos_->value();
473}
474//*************************************************************************************************
475
476
477//*************************************************************************************************
482template< typename MT > // Type of the adapted matrix
483inline void SymmetricValue<MT>::sync() const
484{
485 if( pos_->index() == index_ || isDefault( pos_->value() ) )
486 return;
487
488 const size_t row ( ( IsRowMajorMatrix_v<MT> )?( pos_->index() ):( index_ ) );
489 const size_t column( ( IsRowMajorMatrix_v<MT> )?( index_ ):( pos_->index() ) );
490
491 matrix_->set( row, column, pos_->value() );
492}
493//*************************************************************************************************
494
495
496
497
498//=================================================================================================
499//
500// CONVERSION OPERATOR
501//
502//=================================================================================================
503
504//*************************************************************************************************
509template< typename MT > // Type of the adapted matrix
511{
512 return pos_->value();
513}
514//*************************************************************************************************
515
516
517
518
519//=================================================================================================
520//
521// COMPLEX DATA ACCESS FUNCTIONS
522//
523//=================================================================================================
524
525//*************************************************************************************************
533template< typename MT > // Type of the adapted matrix
535{
536 return pos_->value().real();
537}
538//*************************************************************************************************
539
540
541//*************************************************************************************************
550template< typename MT > // Type of the adapted matrix
551inline void SymmetricValue<MT>::real( ValueType value ) const
552{
553 pos_->value().real() = value;
554 sync();
555}
556//*************************************************************************************************
557
558
559//*************************************************************************************************
567template< typename MT > // Type of the adapted matrix
569{
570 return pos_->value.imag();
571}
572//*************************************************************************************************
573
574
575//*************************************************************************************************
584template< typename MT > // Type of the adapted matrix
585inline void SymmetricValue<MT>::imag( ValueType value ) const
586{
587 pos_->value().imag( value );
588 sync();
589}
590//*************************************************************************************************
591
592
593
594
595//=================================================================================================
596//
597// GLOBAL FUNCTIONS
598//
599//=================================================================================================
600
601//*************************************************************************************************
604template< typename MT >
605void invert( const SymmetricValue<MT>& value );
607//*************************************************************************************************
608
609
610//*************************************************************************************************
617template< typename MT >
618inline void invert( const SymmetricValue<MT>& value )
619{
620 value.invert();
621}
622//*************************************************************************************************
623
624} // namespace blaze
625
626#endif
Header file for auxiliary alias declarations.
typename T::ElementType ElementType_t
Alias declaration for nested ElementType type definitions.
Definition: Aliases.h:190
Constraint on the data type.
Constraint on the data type.
Header file for the If class template.
Utility type for generic codes.
Header file for the invert shim.
Header file for the IsComplex type trait.
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.
Constraint on the data type.
Constraint on the data type.
Constraint on the data type.
Header file for the relaxation flag enumeration.
Constraint on the data type.
Constraint on the data type.
Constraint on the data type.
Constraint on the data type.
Proxy base class.
Definition: Proxy.h:169
Representation of two synchronized values within a sparse symmetric matrix.
Definition: SymmetricValue.h:117
ValueType real() const
Returns the real part of the represented complex number.
Definition: SymmetricValue.h:534
RepresentedType get() const noexcept
Access to the represented value.
Definition: SymmetricValue.h:470
SymmetricValue & operator=(const SymmetricValue &sv)
Copy assignment operator for SymmetricValue.
Definition: SymmetricValue.h:337
ValueType imag() const
Returns the imaginary part of the represented complex number.
Definition: SymmetricValue.h:568
size_t index_
The row/column index of the iterator.
Definition: SymmetricValue.h:218
SymmetricValue(IteratorType pos, MT *matrix, size_t index)
Constructor for the SymmetricValue class.
Definition: SymmetricValue.h:314
typename If_t< IsComplex_v< RepresentedType >, ComplexType< RepresentedType >, BuiltinType< RepresentedType > >::Type ValueType
Value type of the represented complex element.
Definition: SymmetricValue.h:148
ValueType value_type
Value type of the represented complex element.
Definition: SymmetricValue.h:150
typename MT::Iterator IteratorType
Type of the underlying sparse matrix iterators.
Definition: SymmetricValue.h:120
ElementType_t< MT > RepresentedType
Type of the represented matrix element.
Definition: SymmetricValue.h:143
IteratorType pos_
Iterator to the current sparse symmetric matrix element.
Definition: SymmetricValue.h:216
MT * matrix_
The sparse matrix containing the iterator.
Definition: SymmetricValue.h:217
void sync() const
Synchronization of the current sparse element to the according paired element.
Definition: SymmetricValue.h:483
void invert() const
In-place inversion of the symmetric value.
Definition: SymmetricValue.h:446
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
constexpr void clear(Matrix< MT, SO > &matrix)
Clearing the given matrix.
Definition: Matrix.h:960
constexpr void reset(Matrix< MT, SO > &matrix)
Resetting the given matrix.
Definition: Matrix.h:806
decltype(auto) row(Matrix< MT, SO > &, RRAs...)
Creating a view on a specific row of the given matrix.
Definition: Row.h:137
void invert(const SymmetricValue< MT > &value)
In-place inversion of the symmetric value.
Definition: SymmetricValue.h:618
typename If< Condition >::template Type< T1, T2 > If_t
Auxiliary alias template for the If class template.
Definition: If.h:108
Header file for the Proxy class.
Header file for the clear shim.
Header file for the isZero shim.
Header file for the reset shim.
Header file for basic type definitions.