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>
50 #include <blaze/math/Exception.h>
51 #include <blaze/math/proxy/Proxy.h>
52 #include <blaze/math/shims/Clear.h>
56 #include <blaze/math/shims/IsNaN.h>
57 #include <blaze/math/shims/IsOne.h>
60 #include <blaze/math/shims/Reset.h>
67 #include <blaze/util/InvalidType.h>
68 #include <blaze/util/mpl/If.h>
69 #include <blaze/util/Types.h>
71 
72 
73 namespace blaze {
74 
75 //=================================================================================================
76 //
77 // CLASS DEFINITION
78 //
79 //=================================================================================================
80 
81 //*************************************************************************************************
115 template< typename MT > // Type of the adapted matrix
117  : public Proxy< HermitianValue<MT> >
118 {
119  private:
120  //**Type definitions****************************************************************************
121  using IteratorType = typename MT::Iterator;
122  //**********************************************************************************************
123 
124  //**struct BuiltinType**************************************************************************
128  template< typename T >
129  struct BuiltinType { using Type = INVALID_TYPE; };
131  //**********************************************************************************************
132 
133  //**struct ComplexType**************************************************************************
137  template< typename T >
138  struct ComplexType { using Type = typename T::value_type; };
140  //**********************************************************************************************
141 
142  public:
143  //**Type definitions****************************************************************************
145 
148  , ComplexType<RepresentedType>
149  , BuiltinType<RepresentedType> >::Type;
150 
152  //**********************************************************************************************
153 
154  //**Constructors********************************************************************************
157  inline HermitianValue( IteratorType pos, MT* matrix, size_t index );
159  //**********************************************************************************************
160 
161  //**Assignment operators************************************************************************
164  inline HermitianValue& operator= ( const HermitianValue& hv );
165  template< typename T > inline HermitianValue& operator= ( const T& value );
166  template< typename T > inline HermitianValue& operator+=( const T& value );
167  template< typename T > inline HermitianValue& operator-=( const T& value );
168  template< typename T > inline HermitianValue& operator*=( const T& value );
169  template< typename T > inline HermitianValue& operator/=( const T& value );
171  //**********************************************************************************************
172 
173  //**Utility functions***************************************************************************
176  inline void reset () const;
177  inline void clear () const;
178  inline void invert() const;
179 
180  inline RepresentedType get() const noexcept;
182  //**********************************************************************************************
183 
184  //**Conversion operator*************************************************************************
187  inline operator RepresentedType() const noexcept;
189  //**********************************************************************************************
190 
191  //**Complex data access functions***************************************************************
194  inline ValueType real() const;
195  inline void real( ValueType value ) const;
196  inline ValueType imag() const;
197  inline void imag( ValueType value ) const;
199  //**********************************************************************************************
200 
201  private:
202  //**Utility functions***************************************************************************
205  inline void sync() const;
207  //**********************************************************************************************
208 
209  //**Member variables****************************************************************************
211  MT* matrix_;
212  size_t index_;
213  //**********************************************************************************************
214 
215  //**Compile time checks*************************************************************************
229  //**********************************************************************************************
230 };
231 //*************************************************************************************************
232 
233 
234 
235 
236 //=================================================================================================
237 //
238 // CONSTRUCTORS
239 //
240 //=================================================================================================
241 
242 //*************************************************************************************************
249 template< typename MT > // Type of the adapted matrix
250 inline HermitianValue<MT>::HermitianValue( IteratorType pos, MT* matrix, size_t index )
251  : pos_ ( pos ) // Iterator to the current sparse Hermitian matrix element
252  , matrix_( matrix ) // The sparse matrix containing the iterator
253  , index_ ( index ) // The row/column index of the iterator
254 {}
255 //*************************************************************************************************
256 
257 
258 
259 
260 //=================================================================================================
261 //
262 // OPERATORS
263 //
264 //=================================================================================================
265 
266 //*************************************************************************************************
273 template< typename MT > // Type of the adapted matrix
275 {
276  const bool isDiagonal( pos_->index() == index_ );
277 
278  if( IsComplex<RepresentedType>::value && isDiagonal && !isReal( hv.pos_->value() ) ) {
279  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to diagonal matrix element" );
280  }
281 
282  pos_->value() = hv.pos_->value();
283  sync();
284  return *this;
285 }
286 //*************************************************************************************************
287 
288 
289 //*************************************************************************************************
296 template< typename MT > // Type of the adapted matrix
297 template< typename T > // Type of the right-hand side value
299 {
300  const bool isDiagonal( pos_->index() == index_ );
301 
302  if( IsComplex<RepresentedType>::value && isDiagonal && !isReal( value ) ) {
303  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to diagonal matrix element" );
304  }
305 
306  pos_->value() = value;
307  sync();
308  return *this;
309 }
310 //*************************************************************************************************
311 
312 
313 //*************************************************************************************************
320 template< typename MT > // Type of the adapted matrix
321 template< typename T > // Type of the right-hand side value
323 {
324  const bool isDiagonal( pos_->index() == index_ );
325 
326  if( IsComplex<RepresentedType>::value && isDiagonal && !isReal( value ) ) {
327  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to diagonal matrix element" );
328  }
329 
330  pos_->value() += value;
331  sync();
332  return *this;
333 }
334 //*************************************************************************************************
335 
336 
337 //*************************************************************************************************
344 template< typename MT > // Type of the adapted matrix
345 template< typename T > // Type of the right-hand side value
347 {
348  const bool isDiagonal( pos_->index() == index_ );
349 
350  if( IsComplex<RepresentedType>::value && isDiagonal && !isReal( value ) ) {
351  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to diagonal matrix element" );
352  }
353 
354  pos_->value() -= value;
355  sync();
356  return *this;
357 }
358 //*************************************************************************************************
359 
360 
361 //*************************************************************************************************
368 template< typename MT > // Type of the adapted matrix
369 template< typename T > // Type of the right-hand side value
371 {
372  const bool isDiagonal( pos_->index() == index_ );
373 
374  if( IsComplex<RepresentedType>::value && isDiagonal && !isReal( value ) ) {
375  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to diagonal matrix element" );
376  }
377 
378  pos_->value() *= value;
379  sync();
380  return *this;
381 }
382 //*************************************************************************************************
383 
384 
385 //*************************************************************************************************
392 template< typename MT > // Type of the adapted matrix
393 template< typename T > // Type of the right-hand side value
395 {
396  const bool isDiagonal( pos_->index() == index_ );
397 
398  if( IsComplex<RepresentedType>::value && isDiagonal && !isReal( value ) ) {
399  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to diagonal matrix element" );
400  }
401 
402  pos_->value() /= value;
403  sync();
404  return *this;
405 }
406 //*************************************************************************************************
407 
408 
409 
410 
411 //=================================================================================================
412 //
413 // UTILITY FUNCTIONS
414 //
415 //=================================================================================================
416 
417 //*************************************************************************************************
424 template< typename MT > // Type of the adapted matrix
425 inline void HermitianValue<MT>::reset() const
426 {
427  using blaze::reset;
428 
429  reset( pos_->value() );
430 
431  if( pos_->index() != index_ )
432  {
433  const size_t row ( ( IsRowMajorMatrix<MT>::value )?( pos_->index() ):( index_ ) );
434  const size_t column( ( IsRowMajorMatrix<MT>::value )?( index_ ):( pos_->index() ) );
435  const IteratorType pos2( matrix_->find( row, column ) );
436 
437  reset( pos2->value() );
438  }
439 }
440 //*************************************************************************************************
441 
442 
443 //*************************************************************************************************
450 template< typename MT > // Type of the adapted matrix
451 inline void HermitianValue<MT>::clear() const
452 {
453  using blaze::clear;
454 
455  clear( pos_->value() );
456 
457  if( pos_->index() != index_ )
458  {
459  const size_t row ( ( IsRowMajorMatrix<MT>::value )?( pos_->index() ):( index_ ) );
460  const size_t column( ( IsRowMajorMatrix<MT>::value )?( index_ ):( pos_->index() ) );
461  const IteratorType pos2( matrix_->find( row, column ) );
462 
463  clear( pos2->value() );
464  }
465 }
466 //*************************************************************************************************
467 
468 
469 //*************************************************************************************************
474 template< typename MT > // Type of the adapted matrix
475 inline void HermitianValue<MT>::invert() const
476 {
477  using blaze::invert;
478 
479  invert( pos_->value() );
480 
481  if( pos_->index() != index_ )
482  {
483  const size_t row ( ( IsRowMajorMatrix<MT>::value )?( pos_->index() ):( index_ ) );
484  const size_t column( ( IsRowMajorMatrix<MT>::value )?( index_ ):( pos_->index() ) );
485  const IteratorType pos2( matrix_->find( row, column ) );
486 
487  pos2->value() = conj( pos_->value() );
488  }
489 }
490 //*************************************************************************************************
491 
492 
493 //*************************************************************************************************
498 template< typename MT > // Type of the adapted matrix
500 {
501  return pos_->value();
502 }
503 //*************************************************************************************************
504 
505 
506 //*************************************************************************************************
511 template< typename MT > // Type of the adapted matrix
512 inline void HermitianValue<MT>::sync() const
513 {
514  if( pos_->index() == index_ || isDefault( pos_->value() ) )
515  return;
516 
517  const size_t row ( ( IsRowMajorMatrix<MT>::value )?( pos_->index() ):( index_ ) );
518  const size_t column( ( IsRowMajorMatrix<MT>::value )?( index_ ):( pos_->index() ) );
519 
520  matrix_->set( row, column, conj( pos_->value() ) );
521 }
522 //*************************************************************************************************
523 
524 
525 
526 
527 //=================================================================================================
528 //
529 // CONVERSION OPERATOR
530 //
531 //=================================================================================================
532 
533 //*************************************************************************************************
538 template< typename MT > // Type of the adapted matrix
540 {
541  return pos_->value();
542 }
543 //*************************************************************************************************
544 
545 
546 
547 
548 //=================================================================================================
549 //
550 // COMPLEX DATA ACCESS FUNCTIONS
551 //
552 //=================================================================================================
553 
554 //*************************************************************************************************
562 template< typename MT > // Type of the adapted matrix
564 {
565  return pos_->value().real();
566 }
567 //*************************************************************************************************
568 
569 
570 //*************************************************************************************************
579 template< typename MT > // Type of the adapted matrix
580 inline void HermitianValue<MT>::real( ValueType value ) const
581 {
582  pos_->value().real() = value;
583  sync();
584 }
585 //*************************************************************************************************
586 
587 
588 //*************************************************************************************************
596 template< typename MT > // Type of the adapted matrix
598 {
599  return pos_->value.imag();
600 }
601 //*************************************************************************************************
602 
603 
604 //*************************************************************************************************
613 template< typename MT > // Type of the adapted matrix
614 inline void HermitianValue<MT>::imag( ValueType value ) const
615 {
616  pos_->value().imag( value );
617  sync();
618 }
619 //*************************************************************************************************
620 
621 
622 
623 
624 //=================================================================================================
625 //
626 // GLOBAL FUNCTIONS
627 //
628 //=================================================================================================
629 
630 //*************************************************************************************************
633 template< typename MT >
634 inline void reset( const HermitianValue<MT>& value );
635 
636 template< typename MT >
637 inline void clear( const HermitianValue<MT>& value );
638 
639 template< typename MT >
640 inline void invert( const HermitianValue<MT>& value );
641 
642 template< bool RF, typename MT >
643 inline bool isDefault( const HermitianValue<MT>& value );
644 
645 template< bool RF, typename MT >
646 inline bool isReal( const HermitianValue<MT>& value );
647 
648 template< bool RF, typename MT >
649 inline bool isZero( const HermitianValue<MT>& value );
650 
651 template< bool RF, typename MT >
652 inline bool isOne( const HermitianValue<MT>& value );
653 
654 template< typename MT >
655 inline bool isnan( const HermitianValue<MT>& value );
657 //*************************************************************************************************
658 
659 
660 //*************************************************************************************************
669 template< typename MT >
670 inline void reset( const HermitianValue<MT>& value )
671 {
672  value.reset();
673 }
674 //*************************************************************************************************
675 
676 
677 //*************************************************************************************************
686 template< typename MT >
687 inline void clear( const HermitianValue<MT>& value )
688 {
689  value.clear();
690 }
691 //*************************************************************************************************
692 
693 
694 //*************************************************************************************************
701 template< typename MT >
702 inline void invert( const HermitianValue<MT>& value )
703 {
704  value.invert();
705 }
706 //*************************************************************************************************
707 
708 
709 //*************************************************************************************************
719 template< bool RF, typename MT >
720 inline bool isDefault( const HermitianValue<MT>& value )
721 {
722  using blaze::isDefault;
723 
724  return isDefault<RF>( value.get() );
725 }
726 //*************************************************************************************************
727 
728 
729 //*************************************************************************************************
741 template< bool RF, typename MT >
742 inline bool isReal( const HermitianValue<MT>& value )
743 {
744  using blaze::isReal;
745 
746  return isReal<RF>( value.get() );
747 }
748 //*************************************************************************************************
749 
750 
751 //*************************************************************************************************
761 template< bool RF, typename MT >
762 inline bool isZero( const HermitianValue<MT>& value )
763 {
764  using blaze::isZero;
765 
766  return isZero<RF>( value.get() );
767 }
768 //*************************************************************************************************
769 
770 
771 //*************************************************************************************************
781 template< bool RF, typename MT >
782 inline bool isOne( const HermitianValue<MT>& value )
783 {
784  using blaze::isOne;
785 
786  return isOne<RF>( value.get() );
787 }
788 //*************************************************************************************************
789 
790 
791 //*************************************************************************************************
801 template< typename MT >
802 inline bool isnan( const HermitianValue<MT>& value )
803 {
804  using blaze::isnan;
805 
806  return isnan( value.get() );
807 }
808 //*************************************************************************************************
809 
810 } // namespace blaze
811 
812 #endif
bool isReal(const DiagonalProxy< MT > &proxy)
Returns whether the matrix element represents a real number.
Definition: DiagonalProxy.h:650
Header file for the isnan shim.
IteratorType pos_
Iterator to the current sparse Hermitian matrix element.
Definition: HermitianValue.h:210
#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
#define BLAZE_THROW_INVALID_ARGUMENT(MESSAGE)
Macro for the emission of a std::invalid_argument exception.This macro encapsulates the default way o...
Definition: Exception.h:235
Header file for auxiliary alias declarations.
ElementType_< MT > RepresentedType
Type of the represented matrix element.
Definition: HermitianValue.h:144
decltype(auto) column(Matrix< MT, SO > &matrix, RCAs... args)
Creating a view on a specific column of the given matrix.
Definition: Column.h:131
Constraint on the data type.
ValueType imag() const
Returns the imaginary part of the represented complex number.
Definition: HermitianValue.h:597
Header file for basic type definitions.
Proxy base class.The Proxy class is a base class for all proxy classes within the Blaze library that ...
Definition: Forward.h:51
Constraint on the data type.
void reset(const DiagonalProxy< MT > &proxy)
Resetting the represented element to the default initial values.
Definition: DiagonalProxy.h:588
ValueType value_type
Value type of the represented complex element.
Definition: HermitianValue.h:151
#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
Header file for the invert shim.
bool isDiagonal(const DenseMatrix< MT, SO > &dm)
Checks if the give dense matrix is diagonal.
Definition: DenseMatrix.h:1725
size_t index_
The row/column index of the iterator.
Definition: HermitianValue.h:212
Element * Iterator
Iterator over non-constant elements.
Definition: CompressedMatrix.h:3084
RepresentedType get() const noexcept
Access to the represented value.
Definition: HermitianValue.h:499
Constraint on the data type.
ValueType real() const
Returns the real part of the represented complex number.
Definition: HermitianValue.h:563
Header file for the Proxy class.
typename MT::Iterator IteratorType
Type of the underlying sparse matrix iterators.
Definition: HermitianValue.h:121
Constraint on the data type.
Constraint on the data type.
Constraint on the data type.
bool isZero(const DiagonalProxy< MT > &proxy)
Returns whether the represented element is 0.
Definition: DiagonalProxy.h:670
void invert(const HermitianProxy< MT > &proxy)
In-place inversion of the represented element.
Definition: HermitianProxy.h:772
Header file for the clear shim.
Namespace of the Blaze C++ math library.
Definition: Blaze.h:58
Header file for the If class template.
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:79
HermitianValue & operator=(const HermitianValue &hv)
Copy assignment operator for HermitianValue.
Definition: HermitianValue.h:274
Header file for the isZero shim.
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.
void sync() const
Synchronization of the current sparse element to the according paired element.
Definition: HermitianValue.h:512
bool isnan(const DiagonalProxy< MT > &proxy)
Returns whether the represented element is not a number.
Definition: DiagonalProxy.h:710
Header file for the exception macros of the math module.
#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 invert() const
In-place inversion of the Hermitian value.
Definition: HermitianValue.h:475
void clear() const
Clearing the Hermitian value.
Definition: HermitianValue.h:451
void clear(const DiagonalProxy< MT > &proxy)
Clearing the represented element.
Definition: DiagonalProxy.h:608
Representation of two synchronized values within a sparse Hermitian matrix.The HermitianValue class r...
Definition: HermitianValue.h:116
Header file for the isOne shim.
Header file for the conjugate shim.
#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
void reset() const
Reset the Hermitian value to its default initial value.
Definition: HermitianValue.h:425
BLAZE_ALWAYS_INLINE T1 & operator+=(SIMDPack< T1 > &lhs, const SIMDPack< T2 > &rhs)
Addition assignment operator for the addition of two SIMD packs.
Definition: BasicTypes.h:1357
Utility type for generic codes.
Constraint on the data type.
Constraint on the data type.
typename If< T1, T2, T3 >::Type If_
Auxiliary alias declaration for the If class template.The If_ alias declaration provides a convenient...
Definition: If.h:154
decltype(auto) row(Matrix< MT, SO > &, RRAs...)
Creating a view on a specific row of the given matrix.
Definition: Row.h:131
#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
Header file for the reset shim.
#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
bool isOne(const DiagonalProxy< MT > &proxy)
Returns whether the represented element is 1.
Definition: DiagonalProxy.h:690
Header file for the isDefault shim.
Constraint on the data type.
Constraint on the data type.
EnableIf_< IsNumeric< ST >, MT &> operator/=(DenseMatrix< MT, SO > &mat, ST scalar)
Division assignment operator for the division of a dense matrix by a scalar value ( )...
Definition: DenseMatrix.h:655
Compile time check for complex types.This type trait tests whether or not the given template paramete...
Definition: IsComplex.h:76
Header file for the IsRowMajorMatrix type trait.
HermitianValue(IteratorType pos, MT *matrix, size_t index)
Constructor for the HermitianValue class.
Definition: HermitianValue.h:250
#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
Header file for the IsComplex type trait.
bool isDefault(const DiagonalProxy< MT > &proxy)
Returns whether the represented element is in default state.
Definition: DiagonalProxy.h:628
#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
BLAZE_ALWAYS_INLINE T1 & operator-=(SIMDPack< T1 > &lhs, const SIMDPack< T2 > &rhs)
Subtraction assignment operator for the subtraction of two SIMD packs.
Definition: BasicTypes.h:1375
decltype(auto) conj(const DenseMatrix< MT, SO > &dm)
Returns a matrix containing the complex conjugate of each single element of dm.
Definition: DMatMapExpr.h:1321
MT * matrix_
The sparse matrix containing the iterator.
Definition: HermitianValue.h:211
EnableIf_< IsNumeric< ST >, MT &> operator*=(DenseMatrix< MT, SO > &mat, ST scalar)
Multiplication assignment operator for the multiplication of a dense matrix and a scalar value ( )...
Definition: DenseMatrix.h:593
Header file for the isReal shim.
#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
typename If_< IsComplex< RepresentedType >, ComplexType< RepresentedType >, BuiltinType< RepresentedType > >::Type ValueType
Value type of the represented complex element.
Definition: HermitianValue.h:149