Blaze  3.6
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>
52 #include <blaze/math/Exception.h>
53 #include <blaze/math/proxy/Proxy.h>
54 #include <blaze/math/shims/Clear.h>
58 #include <blaze/math/shims/IsNaN.h>
59 #include <blaze/math/shims/IsOne.h>
62 #include <blaze/math/shims/Reset.h>
69 #include <blaze/util/InvalidType.h>
70 #include <blaze/util/mpl/If.h>
71 #include <blaze/util/Types.h>
73 
74 
75 namespace blaze {
76 
77 //=================================================================================================
78 //
79 // CLASS DEFINITION
80 //
81 //=================================================================================================
82 
83 //*************************************************************************************************
117 template< 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  //**struct BuiltinType**************************************************************************
130  template< typename T >
131  struct BuiltinType { using Type = INVALID_TYPE; };
133  //**********************************************************************************************
134 
135  //**struct ComplexType**************************************************************************
139  template< typename T >
140  struct ComplexType { using Type = typename T::value_type; };
142  //**********************************************************************************************
143 
144  public:
145  //**Type definitions****************************************************************************
147 
150  , ComplexType<RepresentedType>
151  , BuiltinType<RepresentedType> >::Type;
152 
154  //**********************************************************************************************
155 
156  //**Constructors********************************************************************************
159  inline HermitianValue( IteratorType pos, MT* matrix, size_t index );
161  //**********************************************************************************************
162 
163  //**Assignment operators************************************************************************
166  inline HermitianValue& operator= ( const HermitianValue& hv );
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 );
170  template< typename T > inline HermitianValue& operator*=( const T& value );
171  template< typename T > inline HermitianValue& operator/=( const T& value );
173  //**********************************************************************************************
174 
175  //**Utility functions***************************************************************************
178  inline void reset () const;
179  inline void clear () const;
180  inline void invert() const;
181 
182  inline RepresentedType get() const noexcept;
184  //**********************************************************************************************
185 
186  //**Conversion operator*************************************************************************
189  inline operator RepresentedType() const noexcept;
191  //**********************************************************************************************
192 
193  //**Complex data access functions***************************************************************
196  inline ValueType real() const;
197  inline void real( ValueType value ) const;
198  inline ValueType imag() const;
199  inline void imag( ValueType value ) const;
201  //**********************************************************************************************
202 
203  private:
204  //**Utility functions***************************************************************************
207  inline void sync() const;
209  //**********************************************************************************************
210 
211  //**Member variables****************************************************************************
213  MT* matrix_;
214  size_t index_;
215  //**********************************************************************************************
216 
217  //**Compile time checks*************************************************************************
233  //**********************************************************************************************
234 };
235 //*************************************************************************************************
236 
237 
238 
239 
240 //=================================================================================================
241 //
242 // CONSTRUCTORS
243 //
244 //=================================================================================================
245 
246 //*************************************************************************************************
253 template< typename MT > // Type of the adapted matrix
254 inline HermitianValue<MT>::HermitianValue( IteratorType pos, MT* matrix, size_t index )
255  : pos_ ( pos ) // Iterator to the current sparse Hermitian matrix element
256  , matrix_( matrix ) // The sparse matrix containing the iterator
257  , index_ ( index ) // The row/column index of the iterator
258 {}
259 //*************************************************************************************************
260 
261 
262 
263 
264 //=================================================================================================
265 //
266 // OPERATORS
267 //
268 //=================================================================================================
269 
270 //*************************************************************************************************
277 template< typename MT > // Type of the adapted matrix
279 {
280  const bool isDiagonal( pos_->index() == index_ );
281 
282  if( IsComplex_v<RepresentedType> && isDiagonal && !isReal( hv.pos_->value() ) ) {
283  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to diagonal matrix element" );
284  }
285 
286  pos_->value() = hv.pos_->value();
287  sync();
288  return *this;
289 }
290 //*************************************************************************************************
291 
292 
293 //*************************************************************************************************
300 template< typename MT > // Type of the adapted matrix
301 template< typename T > // Type of the right-hand side value
303 {
304  const bool isDiagonal( pos_->index() == index_ );
305 
306  if( IsComplex_v<RepresentedType> && isDiagonal && !isReal( value ) ) {
307  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to diagonal matrix element" );
308  }
309 
310  pos_->value() = value;
311  sync();
312  return *this;
313 }
314 //*************************************************************************************************
315 
316 
317 //*************************************************************************************************
324 template< typename MT > // Type of the adapted matrix
325 template< typename T > // Type of the right-hand side value
327 {
328  const bool isDiagonal( pos_->index() == index_ );
329 
330  if( IsComplex_v<RepresentedType> && isDiagonal && !isReal( value ) ) {
331  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to diagonal matrix element" );
332  }
333 
334  pos_->value() += value;
335  sync();
336  return *this;
337 }
338 //*************************************************************************************************
339 
340 
341 //*************************************************************************************************
348 template< typename MT > // Type of the adapted matrix
349 template< typename T > // Type of the right-hand side value
351 {
352  const bool isDiagonal( pos_->index() == index_ );
353 
354  if( IsComplex_v<RepresentedType> && isDiagonal && !isReal( value ) ) {
355  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to diagonal matrix element" );
356  }
357 
358  pos_->value() -= value;
359  sync();
360  return *this;
361 }
362 //*************************************************************************************************
363 
364 
365 //*************************************************************************************************
372 template< typename MT > // Type of the adapted matrix
373 template< typename T > // Type of the right-hand side value
375 {
376  const bool isDiagonal( pos_->index() == index_ );
377 
378  if( IsComplex_v<RepresentedType> && isDiagonal && !isReal( value ) ) {
379  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to diagonal matrix element" );
380  }
381 
382  pos_->value() *= value;
383  sync();
384  return *this;
385 }
386 //*************************************************************************************************
387 
388 
389 //*************************************************************************************************
396 template< typename MT > // Type of the adapted matrix
397 template< typename T > // Type of the right-hand side value
399 {
400  const bool isDiagonal( pos_->index() == index_ );
401 
402  if( IsComplex_v<RepresentedType> && isDiagonal && !isReal( value ) ) {
403  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to diagonal matrix element" );
404  }
405 
406  pos_->value() /= value;
407  sync();
408  return *this;
409 }
410 //*************************************************************************************************
411 
412 
413 
414 
415 //=================================================================================================
416 //
417 // UTILITY FUNCTIONS
418 //
419 //=================================================================================================
420 
421 //*************************************************************************************************
428 template< typename MT > // Type of the adapted matrix
429 inline void HermitianValue<MT>::reset() const
430 {
431  using blaze::reset;
432 
433  reset( pos_->value() );
434 
435  if( pos_->index() != index_ )
436  {
437  const size_t row ( ( IsRowMajorMatrix_v<MT> )?( pos_->index() ):( index_ ) );
438  const size_t column( ( IsRowMajorMatrix_v<MT> )?( index_ ):( pos_->index() ) );
439  const IteratorType pos2( matrix_->find( row, column ) );
440 
441  reset( pos2->value() );
442  }
443 }
444 //*************************************************************************************************
445 
446 
447 //*************************************************************************************************
454 template< typename MT > // Type of the adapted matrix
455 inline void HermitianValue<MT>::clear() const
456 {
457  using blaze::clear;
458 
459  clear( pos_->value() );
460 
461  if( pos_->index() != index_ )
462  {
463  const size_t row ( ( IsRowMajorMatrix_v<MT> )?( pos_->index() ):( index_ ) );
464  const size_t column( ( IsRowMajorMatrix_v<MT> )?( index_ ):( pos_->index() ) );
465  const IteratorType pos2( matrix_->find( row, column ) );
466 
467  clear( pos2->value() );
468  }
469 }
470 //*************************************************************************************************
471 
472 
473 //*************************************************************************************************
478 template< typename MT > // Type of the adapted matrix
479 inline void HermitianValue<MT>::invert() const
480 {
481  using blaze::invert;
482 
483  invert( pos_->value() );
484 
485  if( pos_->index() != index_ )
486  {
487  const size_t row ( ( IsRowMajorMatrix_v<MT> )?( pos_->index() ):( index_ ) );
488  const size_t column( ( IsRowMajorMatrix_v<MT> )?( index_ ):( pos_->index() ) );
489  const IteratorType pos2( matrix_->find( row, column ) );
490 
491  pos2->value() = conj( pos_->value() );
492  }
493 }
494 //*************************************************************************************************
495 
496 
497 //*************************************************************************************************
502 template< typename MT > // Type of the adapted matrix
504 {
505  return pos_->value();
506 }
507 //*************************************************************************************************
508 
509 
510 //*************************************************************************************************
515 template< typename MT > // Type of the adapted matrix
516 inline void HermitianValue<MT>::sync() const
517 {
518  if( pos_->index() == index_ || isDefault( pos_->value() ) )
519  return;
520 
521  const size_t row ( ( IsRowMajorMatrix_v<MT> )?( pos_->index() ):( index_ ) );
522  const size_t column( ( IsRowMajorMatrix_v<MT> )?( index_ ):( pos_->index() ) );
523 
524  matrix_->set( row, column, conj( pos_->value() ) );
525 }
526 //*************************************************************************************************
527 
528 
529 
530 
531 //=================================================================================================
532 //
533 // CONVERSION OPERATOR
534 //
535 //=================================================================================================
536 
537 //*************************************************************************************************
542 template< typename MT > // Type of the adapted matrix
544 {
545  return pos_->value();
546 }
547 //*************************************************************************************************
548 
549 
550 
551 
552 //=================================================================================================
553 //
554 // COMPLEX DATA ACCESS FUNCTIONS
555 //
556 //=================================================================================================
557 
558 //*************************************************************************************************
566 template< typename MT > // Type of the adapted matrix
568 {
569  return pos_->value().real();
570 }
571 //*************************************************************************************************
572 
573 
574 //*************************************************************************************************
583 template< typename MT > // Type of the adapted matrix
584 inline void HermitianValue<MT>::real( ValueType value ) const
585 {
586  pos_->value().real() = value;
587  sync();
588 }
589 //*************************************************************************************************
590 
591 
592 //*************************************************************************************************
600 template< typename MT > // Type of the adapted matrix
602 {
603  return pos_->value.imag();
604 }
605 //*************************************************************************************************
606 
607 
608 //*************************************************************************************************
617 template< typename MT > // Type of the adapted matrix
618 inline void HermitianValue<MT>::imag( ValueType value ) const
619 {
620  pos_->value().imag( value );
621  sync();
622 }
623 //*************************************************************************************************
624 
625 
626 
627 
628 //=================================================================================================
629 //
630 // GLOBAL FUNCTIONS
631 //
632 //=================================================================================================
633 
634 //*************************************************************************************************
637 template< typename MT >
638 void reset( const HermitianValue<MT>& value );
639 
640 template< typename MT >
641 void clear( const HermitianValue<MT>& value );
642 
643 template< typename MT >
644 void invert( const HermitianValue<MT>& value );
645 
646 template< bool RF, typename MT >
647 bool isDefault( const HermitianValue<MT>& value );
648 
649 template< bool RF, typename MT >
650 bool isReal( const HermitianValue<MT>& value );
651 
652 template< bool RF, typename MT >
653 bool isZero( const HermitianValue<MT>& value );
654 
655 template< bool RF, typename MT >
656 bool isOne( const HermitianValue<MT>& value );
657 
658 template< typename MT >
659 bool isnan( const HermitianValue<MT>& value );
661 //*************************************************************************************************
662 
663 
664 //*************************************************************************************************
673 template< typename MT >
674 inline void reset( const HermitianValue<MT>& value )
675 {
676  value.reset();
677 }
678 //*************************************************************************************************
679 
680 
681 //*************************************************************************************************
690 template< typename MT >
691 inline void clear( const HermitianValue<MT>& value )
692 {
693  value.clear();
694 }
695 //*************************************************************************************************
696 
697 
698 //*************************************************************************************************
705 template< typename MT >
706 inline void invert( const HermitianValue<MT>& value )
707 {
708  value.invert();
709 }
710 //*************************************************************************************************
711 
712 
713 //*************************************************************************************************
723 template< bool RF, typename MT >
724 inline bool isDefault( const HermitianValue<MT>& value )
725 {
726  using blaze::isDefault;
727 
728  return isDefault<RF>( value.get() );
729 }
730 //*************************************************************************************************
731 
732 
733 //*************************************************************************************************
745 template< bool RF, typename MT >
746 inline bool isReal( const HermitianValue<MT>& value )
747 {
748  using blaze::isReal;
749 
750  return isReal<RF>( value.get() );
751 }
752 //*************************************************************************************************
753 
754 
755 //*************************************************************************************************
765 template< bool RF, typename MT >
766 inline bool isZero( const HermitianValue<MT>& value )
767 {
768  using blaze::isZero;
769 
770  return isZero<RF>( value.get() );
771 }
772 //*************************************************************************************************
773 
774 
775 //*************************************************************************************************
785 template< bool RF, typename MT >
786 inline bool isOne( const HermitianValue<MT>& value )
787 {
788  using blaze::isOne;
789 
790  return isOne<RF>( value.get() );
791 }
792 //*************************************************************************************************
793 
794 
795 //*************************************************************************************************
805 template< typename MT >
806 inline bool isnan( const HermitianValue<MT>& value )
807 {
808  using blaze::isnan;
809 
810  return isnan( value.get() );
811 }
812 //*************************************************************************************************
813 
814 } // namespace blaze
815 
816 #endif
bool isReal(const DiagonalProxy< MT > &proxy)
Returns whether the matrix element represents a real number.
Definition: DiagonalProxy.h:657
#define BLAZE_CONSTRAINT_MUST_NOT_BE_TRANSFORMATION_TYPE(T)
Constraint on the data type.In case the given data type T is a transformation expression (i....
Definition: Transformation.h:81
Header file for the isnan shim.
IteratorType pos_
Iterator to the current sparse Hermitian matrix element.
Definition: HermitianValue.h:212
#define BLAZE_CONSTRAINT_MUST_NOT_BE_CONST(T)
Constraint on the data type.In case the given data type is a const-qualified type,...
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
Constraint on the data type.
Header file for auxiliary alias declarations.
decltype(auto) column(Matrix< MT, SO > &matrix, RCAs... args)
Creating a view on a specific column of the given matrix.
Definition: Column.h:133
Constraint on the data type.
Constraint on the data type.
ValueType imag() const
Returns the imaginary part of the represented complex number.
Definition: HermitianValue.h:601
Header file for basic type definitions.
typename If< Condition, T1, T2 >::Type If_t
Auxiliary alias template for the If class template.The If_t alias template provides a convenient shor...
Definition: If.h:109
Proxy base class.The Proxy class is a base class for all proxy classes within the Blaze library that ...
Definition: Forward.h:51
Header file for the isZero shim.
#define BLAZE_CONSTRAINT_MUST_NOT_BE_COMPUTATION_TYPE(T)
Constraint on the data type.In case the given data type T is a computational expression (i....
Definition: Computation.h:81
void reset(const DiagonalProxy< MT > &proxy)
Resetting the represented element to the default initial values.
Definition: DiagonalProxy.h:595
ElementType_t< MT > RepresentedType
Type of the represented matrix element.
Definition: HermitianValue.h:146
ValueType value_type
Value type of the represented complex element.
Definition: HermitianValue.h:153
#define BLAZE_CONSTRAINT_MUST_NOT_BE_VOLATILE(T)
Constraint on the data type.In case the given data type is a volatile-qualified type,...
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:2328
Header file for the reset shim.
size_t index_
The row/column index of the iterator.
Definition: HermitianValue.h:214
RepresentedType get() const noexcept
Access to the represented value.
Definition: HermitianValue.h:503
Constraint on the data type.
ValueType real() const
Returns the real part of the represented complex number.
Definition: HermitianValue.h:567
Header file for the Proxy class.
typename MT::Iterator IteratorType
Type of the underlying sparse matrix iterators.
Definition: HermitianValue.h:123
typename T::ElementType ElementType_t
Alias declaration for nested ElementType type definitions.The ElementType_t alias declaration provide...
Definition: Aliases.h:170
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:677
void invert(const HermitianProxy< MT > &proxy)
In-place inversion of the represented element.
Definition: HermitianProxy.h:779
Namespace of the Blaze C++ math library.
Definition: Blaze.h:58
Header file for the If class template.
#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:278
Constraint on the data type.
void sync() const
Synchronization of the current sparse element to the according paired element.
Definition: HermitianValue.h:516
bool isnan(const DiagonalProxy< MT > &proxy)
Returns whether the represented element is not a number.
Definition: DiagonalProxy.h:717
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:479
void clear() const
Clearing the Hermitian value.
Definition: HermitianValue.h:455
void clear(const DiagonalProxy< MT > &proxy)
Clearing the represented element.
Definition: DiagonalProxy.h:615
Representation of two synchronized values within a sparse Hermitian matrix.The HermitianValue class r...
Definition: HermitianValue.h:118
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,...
Definition: Symmetric.h:79
void reset() const
Reset the Hermitian value to its default initial value.
Definition: HermitianValue.h:429
Utility type for generic codes.
Constraint on the data type.
Constraint on the data type.
decltype(auto) row(Matrix< MT, SO > &, RRAs...)
Creating a view on a specific row of the given matrix.
Definition: Row.h:133
#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
#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,...
Definition: Reference.h:79
bool isOne(const DiagonalProxy< MT > &proxy)
Returns whether the represented element is 1.
Definition: DiagonalProxy.h:697
Header file for the isDefault shim.
Constraint on the data type.
Constraint on the data type.
#define BLAZE_CONSTRAINT_MUST_NOT_BE_VIEW_TYPE(T)
Constraint on the data type.In case the given data type T is a view type (i.e. a subvector,...
Definition: View.h:81
typename If_t< IsComplex_v< RepresentedType >, ComplexType< RepresentedType >, BuiltinType< RepresentedType > >::Type ValueType
Value type of the represented complex element.
Definition: HermitianValue.h:151
Header file for the IsRowMajorMatrix type trait.
HermitianValue(IteratorType pos, MT *matrix, size_t index)
Constructor for the HermitianValue class.
Definition: HermitianValue.h:254
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:635
#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,...
Definition: Hermitian.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:1324
MT * matrix_
The sparse matrix containing the iterator.
Definition: HermitianValue.h:213
Constraint on the data type.
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
Header file for the clear shim.