Blaze 3.9
HermitianValue.h
Go to the documentation of this file.
1//=================================================================================================
33//=================================================================================================
34
35#ifndef _BLAZE_MATH_ADAPTORS_HERMITIANMATRIX_HERMITIANVALUE_H_
36#define _BLAZE_MATH_ADAPTORS_HERMITIANMATRIX_HERMITIANVALUE_H_
37
38
39//*************************************************************************************************
40// Includes
41//*************************************************************************************************
42
43#include <blaze/math/Aliases.h>
70#include <blaze/util/mpl/If.h>
71#include <blaze/util/Types.h>
73
74
75namespace blaze {
76
77//=================================================================================================
78//
79// CLASS DEFINITION
80//
81//=================================================================================================
82
83//*************************************************************************************************
117template< typename MT > // Type of the adapted matrix
119 : public Proxy< HermitianValue<MT> >
120{
121 private:
122 //**Type definitions****************************************************************************
123 using IteratorType = typename MT::Iterator;
124 //**********************************************************************************************
125
126 public:
127 //**Type definitions****************************************************************************
129
132
134 //**********************************************************************************************
135
136 //**Constructors********************************************************************************
139 inline HermitianValue( IteratorType pos, MT* matrix, size_t index );
140
141 HermitianValue( const HermitianValue& ) = default;
143 //**********************************************************************************************
144
145 //**Destructor**********************************************************************************
148 ~HermitianValue() = default;
150 //**********************************************************************************************
151
152 //**Assignment operators************************************************************************
155 inline HermitianValue& operator= ( const HermitianValue& hv );
156 template< typename T > inline HermitianValue& operator= ( const T& value );
157 template< typename T > inline HermitianValue& operator+=( const T& value );
158 template< typename T > inline HermitianValue& operator-=( const T& value );
159 template< typename T > inline HermitianValue& operator*=( const T& value );
160 template< typename T > inline HermitianValue& operator/=( const T& value );
162 //**********************************************************************************************
163
164 //**Utility functions***************************************************************************
167 inline void invert() const;
168
169 inline RepresentedType get() const noexcept;
171 //**********************************************************************************************
172
173 //**Conversion operator*************************************************************************
176 inline operator RepresentedType() const noexcept;
178 //**********************************************************************************************
179
180 //**Complex data access functions***************************************************************
183 inline ValueType real() const;
184 inline void real( ValueType value ) const;
185 inline ValueType imag() const;
186 inline void imag( ValueType value ) const;
188 //**********************************************************************************************
189
190 private:
191 //**Utility functions***************************************************************************
194 inline void sync() const;
196 //**********************************************************************************************
197
198 //**Member variables****************************************************************************
201 size_t index_;
202 //**********************************************************************************************
203
204 //**Compile time checks*************************************************************************
220 //**********************************************************************************************
221
222 //**********************************************************************************************
232 friend inline void reset( const HermitianValue& value )
233 {
234 using blaze::reset;
235
236 reset( value.pos_->value() );
237
238 if( value.pos_->index() != value.index_ )
239 {
240 const size_t row ( ( IsRowMajorMatrix_v<MT> )?( value.pos_->index() ):( value.index_ ) );
241 const size_t column( ( IsRowMajorMatrix_v<MT> )?( value.index_ ):( value.pos_->index() ) );
242 const IteratorType pos2( value.matrix_->find( row, column ) );
243
244 reset( pos2->value() );
245 }
246 }
248 //**********************************************************************************************
249
250 //**********************************************************************************************
260 friend inline void clear( const HermitianValue& value )
261 {
262 using blaze::clear;
263
264 clear( value.pos_->value() );
265
266 if( value.pos_->index() != value.index_ )
267 {
268 const size_t row ( ( IsRowMajorMatrix_v<MT> )?( value.pos_->index() ):( value.index_ ) );
269 const size_t column( ( IsRowMajorMatrix_v<MT> )?( value.index_ ):( value.pos_->index() ) );
270 const IteratorType pos2( value.matrix_->find( row, column ) );
271
272 clear( pos2->value() );
273 }
274 }
276 //**********************************************************************************************
277};
278//*************************************************************************************************
279
280
281
282
283//=================================================================================================
284//
285// CONSTRUCTORS
286//
287//=================================================================================================
288
289//*************************************************************************************************
296template< typename MT > // Type of the adapted matrix
297inline HermitianValue<MT>::HermitianValue( IteratorType pos, MT* matrix, size_t index )
298 : pos_ ( pos ) // Iterator to the current sparse Hermitian matrix element
299 , matrix_( matrix ) // The sparse matrix containing the iterator
300 , index_ ( index ) // The row/column index of the iterator
301{}
302//*************************************************************************************************
303
304
305
306
307//=================================================================================================
308//
309// OPERATORS
310//
311//=================================================================================================
312
313//*************************************************************************************************
320template< typename MT > // Type of the adapted matrix
322{
323 const bool isDiagonal( pos_->index() == index_ );
324
325 if( IsComplex_v<RepresentedType> && isDiagonal && !isReal( hv.pos_->value() ) ) {
326 BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to diagonal matrix element" );
327 }
328
329 pos_->value() = hv.pos_->value();
330 sync();
331 return *this;
332}
333//*************************************************************************************************
334
335
336//*************************************************************************************************
343template< typename MT > // Type of the adapted matrix
344template< typename T > // Type of the right-hand side value
346{
347 const bool isDiagonal( pos_->index() == index_ );
348
349 if( IsComplex_v<RepresentedType> && isDiagonal && !isReal( value ) ) {
350 BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to diagonal matrix element" );
351 }
352
353 pos_->value() = value;
354 sync();
355 return *this;
356}
357//*************************************************************************************************
358
359
360//*************************************************************************************************
367template< typename MT > // Type of the adapted matrix
368template< typename T > // Type of the right-hand side value
370{
371 const bool isDiagonal( pos_->index() == index_ );
372
373 if( IsComplex_v<RepresentedType> && isDiagonal && !isReal( value ) ) {
374 BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to diagonal matrix element" );
375 }
376
377 pos_->value() += value;
378 sync();
379 return *this;
380}
381//*************************************************************************************************
382
383
384//*************************************************************************************************
391template< typename MT > // Type of the adapted matrix
392template< typename T > // Type of the right-hand side value
394{
395 const bool isDiagonal( pos_->index() == index_ );
396
397 if( IsComplex_v<RepresentedType> && isDiagonal && !isReal( value ) ) {
398 BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to diagonal matrix element" );
399 }
400
401 pos_->value() -= value;
402 sync();
403 return *this;
404}
405//*************************************************************************************************
406
407
408//*************************************************************************************************
415template< typename MT > // Type of the adapted matrix
416template< typename T > // Type of the right-hand side value
418{
419 const bool isDiagonal( pos_->index() == index_ );
420
421 if( IsComplex_v<RepresentedType> && isDiagonal && !isReal( value ) ) {
422 BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to diagonal matrix element" );
423 }
424
425 pos_->value() *= value;
426 sync();
427 return *this;
428}
429//*************************************************************************************************
430
431
432//*************************************************************************************************
439template< typename MT > // Type of the adapted matrix
440template< typename T > // Type of the right-hand side value
442{
443 const bool isDiagonal( pos_->index() == index_ );
444
445 if( IsComplex_v<RepresentedType> && isDiagonal && !isReal( value ) ) {
446 BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to diagonal matrix element" );
447 }
448
449 pos_->value() /= value;
450 sync();
451 return *this;
452}
453//*************************************************************************************************
454
455
456
457
458//=================================================================================================
459//
460// UTILITY FUNCTIONS
461//
462//=================================================================================================
463
464//*************************************************************************************************
469template< typename MT > // Type of the adapted matrix
470inline void HermitianValue<MT>::invert() const
471{
472 using blaze::invert;
473
474 invert( pos_->value() );
475
476 if( pos_->index() != index_ )
477 {
478 const size_t row ( ( IsRowMajorMatrix_v<MT> )?( pos_->index() ):( index_ ) );
479 const size_t column( ( IsRowMajorMatrix_v<MT> )?( index_ ):( pos_->index() ) );
480 const IteratorType pos2( matrix_->find( row, column ) );
481
482 pos2->value() = conj( pos_->value() );
483 }
484}
485//*************************************************************************************************
486
487
488//*************************************************************************************************
493template< typename MT > // Type of the adapted matrix
495{
496 return pos_->value();
497}
498//*************************************************************************************************
499
500
501//*************************************************************************************************
506template< typename MT > // Type of the adapted matrix
507inline void HermitianValue<MT>::sync() const
508{
509 if( pos_->index() == index_ || isDefault( pos_->value() ) )
510 return;
511
512 const size_t row ( ( IsRowMajorMatrix_v<MT> )?( pos_->index() ):( index_ ) );
513 const size_t column( ( IsRowMajorMatrix_v<MT> )?( index_ ):( pos_->index() ) );
514
515 matrix_->set( row, column, conj( pos_->value() ) );
516}
517//*************************************************************************************************
518
519
520
521
522//=================================================================================================
523//
524// CONVERSION OPERATOR
525//
526//=================================================================================================
527
528//*************************************************************************************************
533template< typename MT > // Type of the adapted matrix
535{
536 return pos_->value();
537}
538//*************************************************************************************************
539
540
541
542
543//=================================================================================================
544//
545// COMPLEX DATA ACCESS FUNCTIONS
546//
547//=================================================================================================
548
549//*************************************************************************************************
557template< typename MT > // Type of the adapted matrix
559{
560 return pos_->value().real();
561}
562//*************************************************************************************************
563
564
565//*************************************************************************************************
574template< typename MT > // Type of the adapted matrix
575inline void HermitianValue<MT>::real( ValueType value ) const
576{
577 pos_->value().real() = value;
578 sync();
579}
580//*************************************************************************************************
581
582
583//*************************************************************************************************
591template< typename MT > // Type of the adapted matrix
593{
594 return pos_->value.imag();
595}
596//*************************************************************************************************
597
598
599//*************************************************************************************************
608template< typename MT > // Type of the adapted matrix
609inline void HermitianValue<MT>::imag( ValueType value ) const
610{
611 pos_->value().imag( value );
612 sync();
613}
614//*************************************************************************************************
615
616
617
618
619//=================================================================================================
620//
621// GLOBAL FUNCTIONS
622//
623//=================================================================================================
624
625//*************************************************************************************************
628template< typename MT >
629void invert( const HermitianValue<MT>& value );
631//*************************************************************************************************
632
633
634//*************************************************************************************************
641template< typename MT >
642inline void invert( const HermitianValue<MT>& value )
643{
644 value.invert();
645}
646//*************************************************************************************************
647
648} // namespace blaze
649
650#endif
Header file for auxiliary alias declarations.
typename T::ElementType ElementType_t
Alias declaration for nested ElementType type definitions.
Definition: Aliases.h:190
Header file for the conjugate shim.
Constraint on the data type.
Constraint on the data type.
Header file for the If class template.
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.
Header file for the UnderlyingBuiltin type trait.
Constraint on the data type.
Constraint on the data type.
Representation of two synchronized values within a sparse Hermitian matrix.
Definition: HermitianValue.h:120
HermitianValue & operator=(const HermitianValue &hv)
Copy assignment operator for HermitianValue.
Definition: HermitianValue.h:321
HermitianValue(IteratorType pos, MT *matrix, size_t index)
Constructor for the HermitianValue class.
Definition: HermitianValue.h:297
typename MT::Iterator IteratorType
Type of the underlying sparse matrix iterators.
Definition: HermitianValue.h:123
ElementType_t< MT > RepresentedType
Type of the represented matrix element.
Definition: HermitianValue.h:128
IteratorType pos_
Iterator to the current sparse Hermitian matrix element.
Definition: HermitianValue.h:199
size_t index_
The row/column index of the iterator.
Definition: HermitianValue.h:201
RepresentedType get() const noexcept
Access to the represented value.
Definition: HermitianValue.h:494
ValueType value_type
Value type of the represented complex element.
Definition: HermitianValue.h:133
UnderlyingBuiltin_t< RepresentedType > ValueType
Value type of the represented complex element.
Definition: HermitianValue.h:131
MT * matrix_
The sparse matrix containing the iterator.
Definition: HermitianValue.h:200
void sync() const
Synchronization of the current sparse element to the according paired element.
Definition: HermitianValue.h:507
void invert() const
In-place inversion of the Hermitian value.
Definition: HermitianValue.h:470
ValueType imag() const
Returns the imaginary part of the represented complex number.
Definition: HermitianValue.h:592
ValueType real() const
Returns the real part of the represented complex number.
Definition: HermitianValue.h:558
Proxy base class.
Definition: Proxy.h:169
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
decltype(auto) conj(const DenseMatrix< MT, SO > &dm)
Returns a matrix containing the complex conjugate of each single element of dm.
Definition: DMatMapExpr.h:1464
bool isDiagonal(const DenseMatrix< MT, SO > &dm)
Checks if the given dense matrix is diagonal.
Definition: DenseMatrix.h:2456
bool isDefault(const DiagonalMatrix< MT, SO, DF > &m)
Returns whether the given diagonal matrix is in default state.
Definition: DiagonalMatrix.h:169
void invert(const HermitianValue< MT > &value)
In-place inversion of the Hermitian value.
Definition: HermitianValue.h:642
#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
typename UnderlyingBuiltin< T >::Type UnderlyingBuiltin_t
Auxiliary alias declaration for the UnderlyingBuiltin type trait.
Definition: UnderlyingBuiltin.h:117
bool isReal(const Proxy< PT, RT > &proxy)
Returns whether the element represents a real number.
Definition: Proxy.h:2297
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
#define BLAZE_THROW_INVALID_ARGUMENT(MESSAGE)
Macro for the emission of a std::invalid_argument exception.
Definition: Exception.h:235
Header file for the exception macros of the math module.
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.