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
116 class HermitianValue : public Proxy< HermitianValue<MT> >
117 {
118  private:
119  //**Type definitions****************************************************************************
120  typedef typename MT::Iterator IteratorType;
121  //**********************************************************************************************
122 
123  //**struct BuiltinType**************************************************************************
127  template< typename T >
128  struct BuiltinType { typedef INVALID_TYPE Type; };
130  //**********************************************************************************************
131 
132  //**struct ComplexType**************************************************************************
136  template< typename T >
137  struct ComplexType { typedef typename T::value_type Type; };
139  //**********************************************************************************************
140 
141  public:
142  //**Type definitions****************************************************************************
144 
146  typedef typename If_< IsComplex<RepresentedType>
147  , ComplexType<RepresentedType>
148  , BuiltinType<RepresentedType> >::Type ValueType;
149 
150  typedef ValueType value_type;
151  //**********************************************************************************************
152 
153  //**Constructors********************************************************************************
156  inline HermitianValue( IteratorType pos, MT* matrix, size_t index );
158  //**********************************************************************************************
159 
160  //**Assignment operators************************************************************************
163  inline HermitianValue& operator= ( const HermitianValue& hv );
164  template< typename T > inline HermitianValue& operator= ( const T& value );
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 );
170  //**********************************************************************************************
171 
172  //**Utility functions***************************************************************************
175  inline void reset () const;
176  inline void clear () const;
177  inline void invert() const;
178 
179  inline RepresentedType get() const noexcept;
181  //**********************************************************************************************
182 
183  //**Conversion operator*************************************************************************
186  inline operator RepresentedType() const noexcept;
188  //**********************************************************************************************
189 
190  //**Complex data access functions***************************************************************
193  inline ValueType real() const;
194  inline void real( ValueType value ) const;
195  inline ValueType imag() const;
196  inline void imag( ValueType value ) const;
198  //**********************************************************************************************
199 
200  private:
201  //**Utility functions***************************************************************************
204  inline void sync() const;
206  //**********************************************************************************************
207 
208  //**Member variables****************************************************************************
209  IteratorType pos_;
210  MT* matrix_;
211  size_t index_;
212  //**********************************************************************************************
213 
214  //**Compile time checks*************************************************************************
226  BLAZE_CONSTRAINT_MUST_BE_NUMERIC_TYPE( RepresentedType );
228  //**********************************************************************************************
229 };
230 //*************************************************************************************************
231 
232 
233 
234 
235 //=================================================================================================
236 //
237 // CONSTRUCTORS
238 //
239 //=================================================================================================
240 
241 //*************************************************************************************************
248 template< typename MT > // Type of the adapted matrix
249 inline HermitianValue<MT>::HermitianValue( IteratorType pos, MT* matrix, size_t index )
250  : pos_ ( pos ) // Iterator to the current sparse Hermitian matrix element
251  , matrix_( matrix ) // The sparse matrix containing the iterator
252  , index_ ( index ) // The row/column index of the iterator
253 {}
254 //*************************************************************************************************
255 
256 
257 
258 
259 //=================================================================================================
260 //
261 // OPERATORS
262 //
263 //=================================================================================================
264 
265 //*************************************************************************************************
272 template< typename MT > // Type of the adapted matrix
274 {
275  const bool isDiagonal( pos_->index() == index_ );
276 
277  if( IsComplex<RepresentedType>::value && isDiagonal && !isReal( hv.pos_->value() ) ) {
278  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to diagonal matrix element" );
279  }
280 
281  pos_->value() = hv.pos_->value();
282  sync();
283  return *this;
284 }
285 //*************************************************************************************************
286 
287 
288 //*************************************************************************************************
295 template< typename MT > // Type of the adapted matrix
296 template< typename T > // Type of the right-hand side value
298 {
299  const bool isDiagonal( pos_->index() == index_ );
300 
301  if( IsComplex<RepresentedType>::value && isDiagonal && !isReal( value ) ) {
302  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to diagonal matrix element" );
303  }
304 
305  pos_->value() = value;
306  sync();
307  return *this;
308 }
309 //*************************************************************************************************
310 
311 
312 //*************************************************************************************************
319 template< typename MT > // Type of the adapted matrix
320 template< typename T > // Type of the right-hand side value
322 {
323  const bool isDiagonal( pos_->index() == index_ );
324 
325  if( IsComplex<RepresentedType>::value && isDiagonal && !isReal( value ) ) {
326  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to diagonal matrix element" );
327  }
328 
329  pos_->value() += value;
330  sync();
331  return *this;
332 }
333 //*************************************************************************************************
334 
335 
336 //*************************************************************************************************
343 template< typename MT > // Type of the adapted matrix
344 template< typename T > // Type of the right-hand side value
346 {
347  const bool isDiagonal( pos_->index() == index_ );
348 
349  if( IsComplex<RepresentedType>::value && 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 //*************************************************************************************************
367 template< typename MT > // Type of the adapted matrix
368 template< typename T > // Type of the right-hand side value
370 {
371  const bool isDiagonal( pos_->index() == index_ );
372 
373  if( IsComplex<RepresentedType>::value && 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 //*************************************************************************************************
391 template< typename MT > // Type of the adapted matrix
392 template< typename T > // Type of the right-hand side value
394 {
395  const bool isDiagonal( pos_->index() == index_ );
396 
397  if( IsComplex<RepresentedType>::value && 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 
409 
410 //=================================================================================================
411 //
412 // UTILITY FUNCTIONS
413 //
414 //=================================================================================================
415 
416 //*************************************************************************************************
423 template< typename MT > // Type of the adapted matrix
424 inline void HermitianValue<MT>::reset() const
425 {
426  using blaze::reset;
427 
428  reset( pos_->value() );
429 
430  if( pos_->index() != index_ )
431  {
432  const size_t row ( ( IsRowMajorMatrix<MT>::value )?( pos_->index() ):( index_ ) );
433  const size_t column( ( IsRowMajorMatrix<MT>::value )?( index_ ):( pos_->index() ) );
434  const IteratorType pos2( matrix_->find( row, column ) );
435 
436  reset( pos2->value() );
437  }
438 }
439 //*************************************************************************************************
440 
441 
442 //*************************************************************************************************
449 template< typename MT > // Type of the adapted matrix
450 inline void HermitianValue<MT>::clear() const
451 {
452  using blaze::clear;
453 
454  clear( pos_->value() );
455 
456  if( pos_->index() != index_ )
457  {
458  const size_t row ( ( IsRowMajorMatrix<MT>::value )?( pos_->index() ):( index_ ) );
459  const size_t column( ( IsRowMajorMatrix<MT>::value )?( index_ ):( pos_->index() ) );
460  const IteratorType pos2( matrix_->find( row, column ) );
461 
462  clear( pos2->value() );
463  }
464 }
465 //*************************************************************************************************
466 
467 
468 //*************************************************************************************************
473 template< typename MT > // Type of the adapted matrix
474 inline void HermitianValue<MT>::invert() const
475 {
476  using blaze::invert;
477 
478  invert( pos_->value() );
479 
480  if( pos_->index() != index_ )
481  {
482  const size_t row ( ( IsRowMajorMatrix<MT>::value )?( pos_->index() ):( index_ ) );
483  const size_t column( ( IsRowMajorMatrix<MT>::value )?( index_ ):( pos_->index() ) );
484  const IteratorType pos2( matrix_->find( row, column ) );
485 
486  pos2->value() = conj( pos_->value() );
487  }
488 }
489 //*************************************************************************************************
490 
491 
492 //*************************************************************************************************
497 template< typename MT > // Type of the adapted matrix
499 {
500  return pos_->value();
501 }
502 //*************************************************************************************************
503 
504 
505 //*************************************************************************************************
510 template< typename MT > // Type of the adapted matrix
511 inline void HermitianValue<MT>::sync() const
512 {
513  if( pos_->index() == index_ || isDefault( pos_->value() ) )
514  return;
515 
516  const size_t row ( ( IsRowMajorMatrix<MT>::value )?( pos_->index() ):( index_ ) );
517  const size_t column( ( IsRowMajorMatrix<MT>::value )?( index_ ):( pos_->index() ) );
518 
519  matrix_->set( row, column, conj( pos_->value() ) );
520 }
521 //*************************************************************************************************
522 
523 
524 
525 
526 //=================================================================================================
527 //
528 // CONVERSION OPERATOR
529 //
530 //=================================================================================================
531 
532 //*************************************************************************************************
537 template< typename MT > // Type of the adapted matrix
539 {
540  return pos_->value();
541 }
542 //*************************************************************************************************
543 
544 
545 
546 
547 //=================================================================================================
548 //
549 // COMPLEX DATA ACCESS FUNCTIONS
550 //
551 //=================================================================================================
552 
553 //*************************************************************************************************
561 template< typename MT > // Type of the adapted matrix
563 {
564  return pos_->value().real();
565 }
566 //*************************************************************************************************
567 
568 
569 //*************************************************************************************************
578 template< typename MT > // Type of the adapted matrix
579 inline void HermitianValue<MT>::real( ValueType value ) const
580 {
581  pos_->value().real() = value;
582  sync();
583 }
584 //*************************************************************************************************
585 
586 
587 //*************************************************************************************************
595 template< typename MT > // Type of the adapted matrix
597 {
598  return pos_->value.imag();
599 }
600 //*************************************************************************************************
601 
602 
603 //*************************************************************************************************
612 template< typename MT > // Type of the adapted matrix
613 inline void HermitianValue<MT>::imag( ValueType value ) const
614 {
615  pos_->value().imag( value );
616  sync();
617 }
618 //*************************************************************************************************
619 
620 
621 
622 
623 //=================================================================================================
624 //
625 // GLOBAL FUNCTIONS
626 //
627 //=================================================================================================
628 
629 //*************************************************************************************************
632 template< typename MT >
633 inline void reset( const HermitianValue<MT>& value );
634 
635 template< typename MT >
636 inline void clear( const HermitianValue<MT>& value );
637 
638 template< typename MT >
639 inline void invert( const HermitianValue<MT>& value );
640 
641 template< typename MT >
642 inline bool isDefault( const HermitianValue<MT>& value );
643 
644 template< typename MT >
645 inline bool isReal( const HermitianValue<MT>& value );
646 
647 template< typename MT >
648 inline bool isZero( const HermitianValue<MT>& value );
649 
650 template< typename MT >
651 inline bool isOne( const HermitianValue<MT>& value );
652 
653 template< typename MT >
654 inline bool isnan( const HermitianValue<MT>& value );
656 //*************************************************************************************************
657 
658 
659 //*************************************************************************************************
668 template< typename MT >
669 inline void reset( const HermitianValue<MT>& value )
670 {
671  value.reset();
672 }
673 //*************************************************************************************************
674 
675 
676 //*************************************************************************************************
685 template< typename MT >
686 inline void clear( const HermitianValue<MT>& value )
687 {
688  value.clear();
689 }
690 //*************************************************************************************************
691 
692 
693 //*************************************************************************************************
700 template< typename MT >
701 inline void invert( const HermitianValue<MT>& value )
702 {
703  value.invert();
704 }
705 //*************************************************************************************************
706 
707 
708 //*************************************************************************************************
718 template< typename MT >
719 inline bool isDefault( const HermitianValue<MT>& value )
720 {
721  using blaze::isDefault;
722 
723  return isDefault( value.get() );
724 }
725 //*************************************************************************************************
726 
727 
728 //*************************************************************************************************
740 template< typename MT >
741 inline bool isReal( const HermitianValue<MT>& value )
742 {
743  using blaze::isReal;
744 
745  return isReal( value.get() );
746 }
747 //*************************************************************************************************
748 
749 
750 //*************************************************************************************************
760 template< typename MT >
761 inline bool isZero( const HermitianValue<MT>& value )
762 {
763  using blaze::isZero;
764 
765  return isZero( value.get() );
766 }
767 //*************************************************************************************************
768 
769 
770 //*************************************************************************************************
780 template< typename MT >
781 inline bool isOne( const HermitianValue<MT>& value )
782 {
783  using blaze::isOne;
784 
785  return isOne( value.get() );
786 }
787 //*************************************************************************************************
788 
789 
790 //*************************************************************************************************
800 template< typename MT >
801 inline bool isnan( const HermitianValue<MT>& value )
802 {
803  using blaze::isnan;
804 
805  return isnan( value.get() );
806 }
807 //*************************************************************************************************
808 
809 } // namespace blaze
810 
811 #endif
Header file for the isnan shim.
IteratorType pos_
Iterator to the current sparse Hermitian matrix element.
Definition: HermitianValue.h:209
#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
If_< IsComplex< RepresentedType >, ComplexType< RepresentedType >, BuiltinType< RepresentedType > >::Type ValueType
Value type of the represented complex element.
Definition: HermitianValue.h:148
bool isOne(const DiagonalProxy< MT > &proxy)
Returns whether the represented element is 1.
Definition: DiagonalProxy.h:635
const DMatForEachExpr< MT, Conj, SO > conj(const DenseMatrix< MT, SO > &dm)
Returns a matrix containing the complex conjugate of each single element of dm.
Definition: DMatForEachExpr.h:1158
Header file for auxiliary alias declarations.
Constraint on the data type.
bool isDiagonal(const DenseMatrix< MT, SO > &dm)
Checks if the give dense matrix is diagonal.
Definition: DenseMatrix.h:1499
Header file for basic type definitions.
ValueType imag() const
Returns the imaginary part of the represented complex number.
Definition: HermitianValue.h:596
Proxy base class.The Proxy class is a base class for all proxy classes within the Blaze library that ...
Definition: Forward.h:51
bool isReal(const DiagonalProxy< MT > &proxy)
Returns whether the matrix element represents a real number.
Definition: DiagonalProxy.h:595
ValueType real() const
Returns the real part of the represented complex number.
Definition: HermitianValue.h:562
Constraint on the data type.
void reset(const DiagonalProxy< MT > &proxy)
Resetting the represented element to the default initial values.
Definition: DiagonalProxy.h:533
void sync() const
Synchronization of the current sparse element to the according paired element.
Definition: HermitianValue.h:511
RepresentedType get() const noexcept
Access to the represented value.
Definition: HermitianValue.h:498
#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.
size_t index_
The row/column index of the iterator.
Definition: HermitianValue.h:211
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
Header file for the Proxy class.
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::Iterator IteratorType
Type of the underlying sparse matrix iterators.
Definition: HermitianValue.h:120
Constraint on the data type.
void invert(const HermitianProxy< MT > &proxy)
In-place inversion of the represented element.
Definition: HermitianProxy.h:741
Header file for the clear shim.
Namespace of the Blaze C++ math library.
Definition: Blaze.h:57
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: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
HermitianValue & operator=(const HermitianValue &hv)
Copy assignment operator for HermitianValue.
Definition: HermitianValue.h:273
ValueType value_type
Value type of the represented complex element.
Definition: HermitianValue.h:150
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.
bool isnan(const DiagonalProxy< MT > &proxy)
Returns whether the represented element is not a number.
Definition: DiagonalProxy.h:655
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 clear() const
Clearing the Hermitian value.
Definition: HermitianValue.h:450
void clear(const DiagonalProxy< MT > &proxy)
Clearing the represented element.
Definition: DiagonalProxy.h:553
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.
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
#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
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:160
#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
Element * Iterator
Iterator over non-constant elements.
Definition: CompressedMatrix.h:2646
Header file for the isDefault shim.
void reset() const
Reset the Hermitian value to its default initial value.
Definition: HermitianValue.h:424
Constraint on the data type.
ElementType_< MT > RepresentedType
Type of the represented matrix element.
Definition: HermitianValue.h:143
Constraint on the data type.
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:249
void invert() const
In-place inversion of the Hermitian value.
Definition: HermitianValue.h:474
#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
bool isZero(const DiagonalProxy< MT > &proxy)
Returns whether the represented element is 0.
Definition: DiagonalProxy.h:615
Header file for the IsComplex type trait.
#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
MT * matrix_
The sparse matrix containing the iterator.
Definition: HermitianValue.h:210
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