HermitianProxy.h
Go to the documentation of this file.
1 //=================================================================================================
33 //=================================================================================================
34 
35 #ifndef _BLAZE_MATH_ADAPTORS_HERMITIANMATRIX_HERMITIANPROXY_H_
36 #define _BLAZE_MATH_ADAPTORS_HERMITIANMATRIX_HERMITIANPROXY_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>
66 #include <blaze/util/InvalidType.h>
67 #include <blaze/util/mpl/If.h>
68 #include <blaze/util/Types.h>
70 
71 
72 namespace blaze {
73 
74 //=================================================================================================
75 //
76 // CLASS DEFINITION
77 //
78 //=================================================================================================
79 
80 //*************************************************************************************************
98 template< typename MT > // Type of the adapted matrix
100  : public Proxy< HermitianProxy<MT> >
101 {
102  private:
103  //**struct BuiltinType**************************************************************************
107  template< typename T >
108  struct BuiltinType { using Type = INVALID_TYPE; };
110  //**********************************************************************************************
111 
112  //**struct ComplexType**************************************************************************
116  template< typename T >
117  struct ComplexType { using Type = typename T::value_type; };
119  //**********************************************************************************************
120 
121  public:
122  //**Type definitions****************************************************************************
127  using ConstPointer = const HermitianProxy*;
128 
131  , ComplexType<RepresentedType>
132  , BuiltinType<RepresentedType> >::Type;
133  //**********************************************************************************************
134 
135  //**Constructors********************************************************************************
138  explicit inline HermitianProxy( MT& matrix, size_t row, size_t column );
139  inline HermitianProxy( const HermitianProxy& hp );
141  //**********************************************************************************************
142 
143  //**Destructor**********************************************************************************
144  // No explicitly declared destructor.
145  //**********************************************************************************************
146 
147  //**Assignment operators************************************************************************
150  inline HermitianProxy& operator= ( const HermitianProxy& hp );
151  template< typename T > inline HermitianProxy& operator= ( const T& value );
152  template< typename T > inline HermitianProxy& operator+=( const T& value );
153  template< typename T > inline HermitianProxy& operator-=( const T& value );
154  template< typename T > inline HermitianProxy& operator*=( const T& value );
155  template< typename T > inline HermitianProxy& operator/=( const T& value );
156  template< typename T > inline HermitianProxy& operator%=( const T& value );
158  //**********************************************************************************************
159 
160  //**Access operators****************************************************************************
163  inline Pointer operator->() noexcept;
164  inline ConstPointer operator->() const noexcept;
166  //**********************************************************************************************
167 
168  //**Utility functions***************************************************************************
171  inline void reset () const;
172  inline void clear () const;
173  inline void invert() const;
174 
175  inline ConstReference get() const noexcept;
177  //**********************************************************************************************
178 
179  //**Conversion operator*************************************************************************
182  inline operator ConstReference() const noexcept;
184  //**********************************************************************************************
185 
186  //**Complex data access functions***************************************************************
189  inline ValueType real() const;
190  inline void real( ValueType value ) const;
191  inline ValueType imag() const;
192  inline void imag( ValueType value ) const;
194  //**********************************************************************************************
195 
196  private:
197  //**Member variables****************************************************************************
202  const bool diagonal_;
203 
207  //**********************************************************************************************
208 
209  //**Compile time checks*************************************************************************
223  //**********************************************************************************************
224 };
225 //*************************************************************************************************
226 
227 
228 
229 
230 //=================================================================================================
231 //
232 // CONSTRUCTORS
233 //
234 //=================================================================================================
235 
236 //*************************************************************************************************
243 template< typename MT > // Type of the adapted matrix
244 inline HermitianProxy<MT>::HermitianProxy( MT& matrix, size_t row, size_t column )
245  : value1_ ( matrix(row,column) ) // Reference to the first accessed matrix element
246  , value2_ ( matrix(column,row) ) // Reference to the second accessed matrix element
247  , diagonal_( row == column ) // Flag for the accessed matrix element
248 {}
249 //*************************************************************************************************
250 
251 
252 //*************************************************************************************************
257 template< typename MT > // Type of the adapted matrix
259  : value1_ ( hp.value1_ ) // Reference to the first accessed matrix element
260  , value2_ ( hp.value2_ ) // Reference to the second accessed matrix element
261  , diagonal_( hp.diagonal_ ) // Flag for the accessed matrix element
262 {}
263 //*************************************************************************************************
264 
265 
266 
267 
268 //=================================================================================================
269 //
270 // OPERATORS
271 //
272 //=================================================================================================
273 
274 //*************************************************************************************************
284 template< typename MT > // Type of the adapted matrix
286 {
287  using ET = ElementType_<MT>;
288 
289  if( IsComplex<ET>::value && diagonal_ && !isReal( hp.value1_ ) ) {
290  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to diagonal matrix element" );
291  }
292 
293  value1_ = hp.value1_;
294  if( !diagonal_ )
295  value2_ = conj( value1_ );
296 
297  return *this;
298 }
299 //*************************************************************************************************
300 
301 
302 //*************************************************************************************************
312 template< typename MT > // Type of the adapted matrix
313 template< typename T > // Type of the right-hand side value
315 {
316  using ET = ElementType_<MT>;
317 
318  if( IsComplex<ET>::value && diagonal_ && !isReal( value ) ) {
319  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to diagonal matrix element" );
320  }
321 
322  value1_ = value;
323  if( !diagonal_ )
324  value2_ = conj( value1_ );
325 
326  return *this;
327 }
328 //*************************************************************************************************
329 
330 
331 //*************************************************************************************************
341 template< typename MT > // Type of the adapted matrix
342 template< typename T > // Type of the right-hand side value
344 {
345  using ET = ElementType_<MT>;
346 
347  if( IsComplex<ET>::value && diagonal_ && !isReal( value ) ) {
348  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to diagonal matrix element" );
349  }
350 
351  value1_ += value;
352  if( !diagonal_ )
353  value2_ = conj( value1_ );
354 
355  return *this;
356 }
357 //*************************************************************************************************
358 
359 
360 //*************************************************************************************************
370 template< typename MT > // Type of the adapted matrix
371 template< typename T > // Type of the right-hand side value
373 {
374  using ET = ElementType_<MT>;
375 
376  if( IsComplex<ET>::value && diagonal_ && !isReal( value ) ) {
377  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to diagonal matrix element" );
378  }
379 
380  value1_ -= value;
381  if( !diagonal_ )
382  value2_ = conj( value1_ );
383 
384  return *this;
385 }
386 //*************************************************************************************************
387 
388 
389 //*************************************************************************************************
399 template< typename MT > // Type of the adapted matrix
400 template< typename T > // Type of the right-hand side value
402 {
403  using ET = ElementType_<MT>;
404 
405  if( IsComplex<ET>::value && diagonal_ && !isReal( value ) ) {
406  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to diagonal matrix element" );
407  }
408 
409  value1_ *= value;
410  if( !diagonal_ )
411  value2_ = conj( value1_ );
412 
413  return *this;
414 }
415 //*************************************************************************************************
416 
417 
418 //*************************************************************************************************
428 template< typename MT > // Type of the adapted matrix
429 template< typename T > // Type of the right-hand side value
431 {
432  using ET = ElementType_<MT>;
433 
434  if( IsComplex<ET>::value && diagonal_ && !isReal( value ) ) {
435  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to diagonal matrix element" );
436  }
437 
438  value1_ /= value;
439  if( !diagonal_ )
440  value2_ = conj( value1_ );
441 
442  return *this;
443 }
444 //*************************************************************************************************
445 
446 
447 //*************************************************************************************************
457 template< typename MT > // Type of the adapted matrix
458 template< typename T > // Type of the right-hand side value
460 {
461  using ET = ElementType_<MT>;
462 
463  if( IsComplex<ET>::value && diagonal_ && !isReal( value ) ) {
464  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to diagonal matrix element" );
465  }
466 
467  value1_ %= value;
468  if( !diagonal_ )
469  value2_ = conj( value1_ );
470 
471  return *this;
472 }
473 //*************************************************************************************************
474 
475 
476 
477 
478 //=================================================================================================
479 //
480 // ACCESS OPERATORS
481 //
482 //=================================================================================================
483 
484 //*************************************************************************************************
489 template< typename MT > // Type of the adapted matrix
491 {
492  return this;
493 }
494 //*************************************************************************************************
495 
496 
497 //*************************************************************************************************
502 template< typename MT > // Type of the adapted matrix
504 {
505  return this;
506 }
507 //*************************************************************************************************
508 
509 
510 
511 
512 //=================================================================================================
513 //
514 // UTILITY FUNCTIONS
515 //
516 //=================================================================================================
517 
518 //*************************************************************************************************
525 template< typename MT > // Type of the adapted matrix
526 inline void HermitianProxy<MT>::reset() const
527 {
528  using blaze::reset;
529 
530  reset( value1_ );
531  if( !diagonal_ )
532  reset( value2_ );
533 }
534 //*************************************************************************************************
535 
536 
537 //*************************************************************************************************
544 template< typename MT > // Type of the adapted matrix
545 inline void HermitianProxy<MT>::clear() const
546 {
547  using blaze::clear;
548 
549  clear( value1_ );
550  if( !diagonal_ )
551  clear( value2_ );
552 }
553 //*************************************************************************************************
554 
555 
556 //*************************************************************************************************
561 template< typename MT > // Type of the adapted matrix
562 inline void HermitianProxy<MT>::invert() const
563 {
564  using blaze::invert;
565 
566  invert( value1_ );
567  if( !diagonal_ )
568  value2_ = conj( value1_ );
569 }
570 //*************************************************************************************************
571 
572 
573 //*************************************************************************************************
578 template< typename MT > // Type of the adapted matrix
580 {
581  return value1_;
582 }
583 //*************************************************************************************************
584 
585 
586 
587 
588 //=================================================================================================
589 //
590 // CONVERSION OPERATOR
591 //
592 //=================================================================================================
593 
594 //*************************************************************************************************
599 template< typename MT > // Type of the adapted matrix
601 {
602  return get();
603 }
604 //*************************************************************************************************
605 
606 
607 
608 
609 //=================================================================================================
610 //
611 // COMPLEX DATA ACCESS FUNCTIONS
612 //
613 //=================================================================================================
614 
615 //*************************************************************************************************
623 template< typename MT > // Type of the adapted matrix
625 {
626  return value1_.real();
627 }
628 //*************************************************************************************************
629 
630 
631 //*************************************************************************************************
639 template< typename MT > // Type of the adapted matrix
640 inline void HermitianProxy<MT>::real( ValueType value ) const
641 {
642  value1_.real( value );
643  if( !diagonal_ )
644  value2_.real( value );
645 }
646 //*************************************************************************************************
647 
648 
649 //*************************************************************************************************
657 template< typename MT > // Type of the adapted matrix
659 {
660  return value1_.imag();
661 }
662 //*************************************************************************************************
663 
664 
665 //*************************************************************************************************
676 template< typename MT > // Type of the adapted matrix
677 inline void HermitianProxy<MT>::imag( ValueType value ) const
678 {
679  if( diagonal_ && !isZero( value ) ) {
680  BLAZE_THROW_INVALID_ARGUMENT( "Invalid setting for diagonal matrix element" );
681  }
682 
683  value1_.imag( value );
684  if( !diagonal_ )
685  value2_.imag( -value );
686 }
687 //*************************************************************************************************
688 
689 
690 
691 
692 //=================================================================================================
693 //
694 // GLOBAL FUNCTIONS
695 //
696 //=================================================================================================
697 
698 //*************************************************************************************************
701 template< typename MT >
702 inline void reset( const HermitianProxy<MT>& proxy );
703 
704 template< typename MT >
705 inline void clear( const HermitianProxy<MT>& proxy );
706 
707 template< typename MT >
708 inline void invert( const HermitianProxy<MT>& proxy );
709 
710 template< bool RF, typename MT >
711 inline bool isDefault( const HermitianProxy<MT>& proxy );
712 
713 template< bool RF, typename MT >
714 inline bool isReal( const HermitianProxy<MT>& proxy );
715 
716 template< bool RF, typename MT >
717 inline bool isZero( const HermitianProxy<MT>& proxy );
718 
719 template< bool RF, typename MT >
720 inline bool isOne( const HermitianProxy<MT>& proxy );
721 
722 template< typename MT >
723 inline bool isnan( const HermitianProxy<MT>& proxy );
725 //*************************************************************************************************
726 
727 
728 //*************************************************************************************************
738 template< typename MT >
739 inline void reset( const HermitianProxy<MT>& proxy )
740 {
741  proxy.reset();
742 }
743 //*************************************************************************************************
744 
745 
746 //*************************************************************************************************
756 template< typename MT >
757 inline void clear( const HermitianProxy<MT>& proxy )
758 {
759  proxy.clear();
760 }
761 //*************************************************************************************************
762 
763 
764 //*************************************************************************************************
771 template< typename MT >
772 inline void invert( const HermitianProxy<MT>& proxy )
773 {
774  proxy.invert();
775 }
776 //*************************************************************************************************
777 
778 
779 //*************************************************************************************************
789 template< bool RF, typename MT >
790 inline bool isDefault( const HermitianProxy<MT>& proxy )
791 {
792  using blaze::isDefault;
793 
794  return isDefault<RF>( proxy.get() );
795 }
796 //*************************************************************************************************
797 
798 
799 //*************************************************************************************************
811 template< bool RF, typename MT >
812 inline bool isReal( const HermitianProxy<MT>& proxy )
813 {
814  using blaze::isReal;
815 
816  return isReal<RF>( proxy.get() );
817 }
818 //*************************************************************************************************
819 
820 
821 //*************************************************************************************************
831 template< bool RF, typename MT >
832 inline bool isZero( const HermitianProxy<MT>& proxy )
833 {
834  using blaze::isZero;
835 
836  return isZero<RF>( proxy.get() );
837 }
838 //*************************************************************************************************
839 
840 
841 //*************************************************************************************************
851 template< bool RF, typename MT >
852 inline bool isOne( const HermitianProxy<MT>& proxy )
853 {
854  using blaze::isOne;
855 
856  return isOne<RF>( proxy.get() );
857 }
858 //*************************************************************************************************
859 
860 
861 //*************************************************************************************************
871 template< typename MT >
872 inline bool isnan( const HermitianProxy<MT>& proxy )
873 {
874  using blaze::isnan;
875 
876  return isnan( proxy.get() );
877 }
878 //*************************************************************************************************
879 
880 } // namespace blaze
881 
882 #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.
#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.
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.
HermitianProxy & operator=(const HermitianProxy &hp)
Copy assignment operator for HermitianProxy.
Definition: HermitianProxy.h:285
Reference value2_
Reference to the second accessed matrix element.
Definition: HermitianProxy.h:201
Reference_< MT > Reference
Reference to the represented element.
Definition: HermitianProxy.h:124
Header file for basic type definitions.
void invert() const
In-place inversion of the represented element.
Definition: HermitianProxy.h:562
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
Access proxy for Hermitian matrices.The HermitianProxy provides controlled access to the elements of ...
Definition: HermitianProxy.h:99
ValueType imag() const
Returns the imaginary part of the represented complex number.
Definition: HermitianProxy.h:658
#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.
ConstReference_< MT > ConstReference
Reference-to-const to the represented element.
Definition: HermitianProxy.h:125
ValueType real() const
Returns the real part of the represented complex number.
Definition: HermitianProxy.h:624
Constraint on the data type.
const bool diagonal_
Flag for the accessed matrix element.
Definition: HermitianProxy.h:202
Pointer operator->() noexcept
Direct access to the represented matrix element.
Definition: HermitianProxy.h:490
Header file for the Proxy class.
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.
#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
Constraint on the data type.
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: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
typename T::Reference Reference_
Alias declaration for nested Reference type definitions.The Reference_ alias declaration provides a c...
Definition: Aliases.h:303
void clear(const DiagonalProxy< MT > &proxy)
Clearing the represented element.
Definition: DiagonalProxy.h:608
Header file for the isOne shim.
Header file for the conjugate shim.
HermitianProxy(MT &matrix, size_t row, size_t column)
Initialization constructor for a HermitianProxy.
Definition: HermitianProxy.h:244
#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
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.
void clear() const
Clearing the represented element.
Definition: HermitianProxy.h:545
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
typename If_< IsComplex< RepresentedType >, ComplexType< RepresentedType >, BuiltinType< RepresentedType > >::Type ValueType
Value type of the represented complex element.
Definition: HermitianProxy.h:132
#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.
ConstReference get() const noexcept
Returning the value of the accessed matrix element.
Definition: HermitianProxy.h:579
Constraint on the data type.
Constraint on the data type.
void reset() const
Reset the represented element to its default initial value.
Definition: HermitianProxy.h:526
Reference value1_
Reference to the first accessed matrix element.
Definition: HermitianProxy.h:200
typename T::ConstReference ConstReference_
Alias declaration for nested ConstReference type definitions.The ConstReference_ alias declaration pr...
Definition: Aliases.h:143
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
#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
ElementType_< MT > RepresentedType
Type of the represented matrix element.
Definition: HermitianProxy.h:123
#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
#define BLAZE_CONSTRAINT_MUST_BE_MATRIX_TYPE(T)
Constraint on the data type.In case the given data type T is not a N-dimensional matrix type...
Definition: Matrix.h:61
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
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.