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**********************************************************************************
146  ~HermitianProxy() = default;
148  //**********************************************************************************************
149 
150  //**Assignment operators************************************************************************
153  inline HermitianProxy& operator= ( const HermitianProxy& hp );
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 );
157  template< typename T > inline HermitianProxy& operator*=( const T& value );
158  template< typename T > inline HermitianProxy& operator/=( const T& value );
159  template< typename T > inline HermitianProxy& operator%=( const T& value );
161  //**********************************************************************************************
162 
163  //**Access operators****************************************************************************
166  inline Pointer operator->() noexcept;
167  inline ConstPointer operator->() const noexcept;
169  //**********************************************************************************************
170 
171  //**Utility functions***************************************************************************
174  inline void reset () const;
175  inline void clear () const;
176  inline void invert() const;
177 
178  inline ConstReference get() const noexcept;
180  //**********************************************************************************************
181 
182  //**Conversion operator*************************************************************************
185  inline operator ConstReference() const noexcept;
187  //**********************************************************************************************
188 
189  //**Complex data access functions***************************************************************
192  inline ValueType real() const;
193  inline void real( ValueType value ) const;
194  inline ValueType imag() const;
195  inline void imag( ValueType value ) const;
197  //**********************************************************************************************
198 
199  private:
200  //**Member variables****************************************************************************
205  const bool diagonal_;
206 
210  //**********************************************************************************************
211 
212  //**Compile time checks*************************************************************************
226  //**********************************************************************************************
227 };
228 //*************************************************************************************************
229 
230 
231 
232 
233 //=================================================================================================
234 //
235 // CONSTRUCTORS
236 //
237 //=================================================================================================
238 
239 //*************************************************************************************************
246 template< typename MT > // Type of the adapted matrix
247 inline HermitianProxy<MT>::HermitianProxy( MT& matrix, size_t row, size_t column )
248  : value1_ ( matrix(row,column) ) // Reference to the first accessed matrix element
249  , value2_ ( matrix(column,row) ) // Reference to the second accessed matrix element
250  , diagonal_( row == column ) // Flag for the accessed matrix element
251 {}
252 //*************************************************************************************************
253 
254 
255 //*************************************************************************************************
260 template< typename MT > // Type of the adapted matrix
262  : value1_ ( hp.value1_ ) // Reference to the first accessed matrix element
263  , value2_ ( hp.value2_ ) // Reference to the second accessed matrix element
264  , diagonal_( hp.diagonal_ ) // Flag for the accessed matrix element
265 {}
266 //*************************************************************************************************
267 
268 
269 
270 
271 //=================================================================================================
272 //
273 // OPERATORS
274 //
275 //=================================================================================================
276 
277 //*************************************************************************************************
287 template< typename MT > // Type of the adapted matrix
289 {
290  using ET = ElementType_t<MT>;
291 
292  if( IsComplex_v<ET> && diagonal_ && !isReal( hp.value1_ ) ) {
293  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to diagonal matrix element" );
294  }
295 
296  value1_ = hp.value1_;
297  if( !diagonal_ )
298  value2_ = conj( value1_ );
299 
300  return *this;
301 }
302 //*************************************************************************************************
303 
304 
305 //*************************************************************************************************
315 template< typename MT > // Type of the adapted matrix
316 template< typename T > // Type of the right-hand side value
318 {
319  using ET = ElementType_t<MT>;
320 
321  if( IsComplex_v<ET> && diagonal_ && !isReal( value ) ) {
322  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to diagonal matrix element" );
323  }
324 
325  value1_ = value;
326  if( !diagonal_ )
327  value2_ = conj( value1_ );
328 
329  return *this;
330 }
331 //*************************************************************************************************
332 
333 
334 //*************************************************************************************************
344 template< typename MT > // Type of the adapted matrix
345 template< typename T > // Type of the right-hand side value
347 {
348  using ET = ElementType_t<MT>;
349 
350  if( IsComplex_v<ET> && diagonal_ && !isReal( value ) ) {
351  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to diagonal matrix element" );
352  }
353 
354  value1_ += value;
355  if( !diagonal_ )
356  value2_ = conj( value1_ );
357 
358  return *this;
359 }
360 //*************************************************************************************************
361 
362 
363 //*************************************************************************************************
373 template< typename MT > // Type of the adapted matrix
374 template< typename T > // Type of the right-hand side value
376 {
377  using ET = ElementType_t<MT>;
378 
379  if( IsComplex_v<ET> && diagonal_ && !isReal( value ) ) {
380  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to diagonal matrix element" );
381  }
382 
383  value1_ -= value;
384  if( !diagonal_ )
385  value2_ = conj( value1_ );
386 
387  return *this;
388 }
389 //*************************************************************************************************
390 
391 
392 //*************************************************************************************************
402 template< typename MT > // Type of the adapted matrix
403 template< typename T > // Type of the right-hand side value
405 {
406  using ET = ElementType_t<MT>;
407 
408  if( IsComplex_v<ET> && diagonal_ && !isReal( value ) ) {
409  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to diagonal matrix element" );
410  }
411 
412  value1_ *= value;
413  if( !diagonal_ )
414  value2_ = conj( value1_ );
415 
416  return *this;
417 }
418 //*************************************************************************************************
419 
420 
421 //*************************************************************************************************
431 template< typename MT > // Type of the adapted matrix
432 template< typename T > // Type of the right-hand side value
434 {
435  using ET = ElementType_t<MT>;
436 
437  if( IsComplex_v<ET> && diagonal_ && !isReal( value ) ) {
438  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to diagonal matrix element" );
439  }
440 
441  value1_ /= value;
442  if( !diagonal_ )
443  value2_ = conj( value1_ );
444 
445  return *this;
446 }
447 //*************************************************************************************************
448 
449 
450 //*************************************************************************************************
460 template< typename MT > // Type of the adapted matrix
461 template< typename T > // Type of the right-hand side value
463 {
464  using ET = ElementType_t<MT>;
465 
466  if( IsComplex_v<ET> && diagonal_ && !isReal( value ) ) {
467  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to diagonal matrix element" );
468  }
469 
470  value1_ %= value;
471  if( !diagonal_ )
472  value2_ = conj( value1_ );
473 
474  return *this;
475 }
476 //*************************************************************************************************
477 
478 
479 
480 
481 //=================================================================================================
482 //
483 // ACCESS OPERATORS
484 //
485 //=================================================================================================
486 
487 //*************************************************************************************************
492 template< typename MT > // Type of the adapted matrix
494 {
495  return this;
496 }
497 //*************************************************************************************************
498 
499 
500 //*************************************************************************************************
505 template< typename MT > // Type of the adapted matrix
507 {
508  return this;
509 }
510 //*************************************************************************************************
511 
512 
513 
514 
515 //=================================================================================================
516 //
517 // UTILITY FUNCTIONS
518 //
519 //=================================================================================================
520 
521 //*************************************************************************************************
528 template< typename MT > // Type of the adapted matrix
529 inline void HermitianProxy<MT>::reset() const
530 {
531  using blaze::reset;
532 
533  reset( value1_ );
534  if( !diagonal_ )
535  reset( value2_ );
536 }
537 //*************************************************************************************************
538 
539 
540 //*************************************************************************************************
547 template< typename MT > // Type of the adapted matrix
548 inline void HermitianProxy<MT>::clear() const
549 {
550  using blaze::clear;
551 
552  clear( value1_ );
553  if( !diagonal_ )
554  clear( value2_ );
555 }
556 //*************************************************************************************************
557 
558 
559 //*************************************************************************************************
564 template< typename MT > // Type of the adapted matrix
565 inline void HermitianProxy<MT>::invert() const
566 {
567  using blaze::invert;
568 
569  invert( value1_ );
570  if( !diagonal_ )
571  value2_ = conj( value1_ );
572 }
573 //*************************************************************************************************
574 
575 
576 //*************************************************************************************************
581 template< typename MT > // Type of the adapted matrix
583 {
584  return value1_;
585 }
586 //*************************************************************************************************
587 
588 
589 
590 
591 //=================================================================================================
592 //
593 // CONVERSION OPERATOR
594 //
595 //=================================================================================================
596 
597 //*************************************************************************************************
602 template< typename MT > // Type of the adapted matrix
604 {
605  return get();
606 }
607 //*************************************************************************************************
608 
609 
610 
611 
612 //=================================================================================================
613 //
614 // COMPLEX DATA ACCESS FUNCTIONS
615 //
616 //=================================================================================================
617 
618 //*************************************************************************************************
626 template< typename MT > // Type of the adapted matrix
628 {
629  return value1_.real();
630 }
631 //*************************************************************************************************
632 
633 
634 //*************************************************************************************************
642 template< typename MT > // Type of the adapted matrix
643 inline void HermitianProxy<MT>::real( ValueType value ) const
644 {
645  value1_.real( value );
646  if( !diagonal_ )
647  value2_.real( value );
648 }
649 //*************************************************************************************************
650 
651 
652 //*************************************************************************************************
660 template< typename MT > // Type of the adapted matrix
662 {
663  return value1_.imag();
664 }
665 //*************************************************************************************************
666 
667 
668 //*************************************************************************************************
679 template< typename MT > // Type of the adapted matrix
680 inline void HermitianProxy<MT>::imag( ValueType value ) const
681 {
682  if( diagonal_ && !isZero( value ) ) {
683  BLAZE_THROW_INVALID_ARGUMENT( "Invalid setting for diagonal matrix element" );
684  }
685 
686  value1_.imag( value );
687  if( !diagonal_ )
688  value2_.imag( -value );
689 }
690 //*************************************************************************************************
691 
692 
693 
694 
695 //=================================================================================================
696 //
697 // GLOBAL FUNCTIONS
698 //
699 //=================================================================================================
700 
701 //*************************************************************************************************
704 template< typename MT >
705 void reset( const HermitianProxy<MT>& proxy );
706 
707 template< typename MT >
708 void clear( const HermitianProxy<MT>& proxy );
709 
710 template< typename MT >
711 void invert( const HermitianProxy<MT>& proxy );
712 
713 template< bool RF, typename MT >
714 bool isDefault( const HermitianProxy<MT>& proxy );
715 
716 template< bool RF, typename MT >
717 bool isReal( const HermitianProxy<MT>& proxy );
718 
719 template< bool RF, typename MT >
720 bool isZero( const HermitianProxy<MT>& proxy );
721 
722 template< bool RF, typename MT >
723 bool isOne( const HermitianProxy<MT>& proxy );
724 
725 template< typename MT >
726 bool isnan( const HermitianProxy<MT>& proxy );
728 //*************************************************************************************************
729 
730 
731 //*************************************************************************************************
741 template< typename MT >
742 inline void reset( const HermitianProxy<MT>& proxy )
743 {
744  proxy.reset();
745 }
746 //*************************************************************************************************
747 
748 
749 //*************************************************************************************************
759 template< typename MT >
760 inline void clear( const HermitianProxy<MT>& proxy )
761 {
762  proxy.clear();
763 }
764 //*************************************************************************************************
765 
766 
767 //*************************************************************************************************
774 template< typename MT >
775 inline void invert( const HermitianProxy<MT>& proxy )
776 {
777  proxy.invert();
778 }
779 //*************************************************************************************************
780 
781 
782 //*************************************************************************************************
792 template< bool RF, typename MT >
793 inline bool isDefault( const HermitianProxy<MT>& proxy )
794 {
795  using blaze::isDefault;
796 
797  return isDefault<RF>( proxy.get() );
798 }
799 //*************************************************************************************************
800 
801 
802 //*************************************************************************************************
814 template< bool RF, typename MT >
815 inline bool isReal( const HermitianProxy<MT>& proxy )
816 {
817  using blaze::isReal;
818 
819  return isReal<RF>( proxy.get() );
820 }
821 //*************************************************************************************************
822 
823 
824 //*************************************************************************************************
834 template< bool RF, typename MT >
835 inline bool isZero( const HermitianProxy<MT>& proxy )
836 {
837  using blaze::isZero;
838 
839  return isZero<RF>( proxy.get() );
840 }
841 //*************************************************************************************************
842 
843 
844 //*************************************************************************************************
854 template< bool RF, typename MT >
855 inline bool isOne( const HermitianProxy<MT>& proxy )
856 {
857  using blaze::isOne;
858 
859  return isOne<RF>( proxy.get() );
860 }
861 //*************************************************************************************************
862 
863 
864 //*************************************************************************************************
874 template< typename MT >
875 inline bool isnan( const HermitianProxy<MT>& proxy )
876 {
877  using blaze::isnan;
878 
879  return isnan( proxy.get() );
880 }
881 //*************************************************************************************************
882 
883 } // namespace blaze
884 
885 #endif
bool isReal(const DiagonalProxy< MT > &proxy)
Returns whether the matrix element represents a real number.
Definition: DiagonalProxy.h:653
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:133
Constraint on the data type.
HermitianProxy & operator=(const HermitianProxy &hp)
Copy assignment operator for HermitianProxy.
Definition: HermitianProxy.h:288
Reference value2_
Reference to the second accessed matrix element.
Definition: HermitianProxy.h:204
Header file for basic type definitions.
typename If< Condition, T1, T2 >::Type If_t
Auxiliary alias declaration for the If class template.The If_t alias declaration provides a convenien...
Definition: If.h:109
void invert() const
In-place inversion of the represented element.
Definition: HermitianProxy.h:565
Proxy base class.The Proxy class is a base class for all proxy classes within the Blaze library that ...
Definition: Forward.h:51
typename T::Reference Reference_t
Alias declaration for nested Reference type definitions.The Reference_t alias declaration provides a ...
Definition: Aliases.h:330
Header file for the isZero shim.
Constraint on the data type.
void reset(const DiagonalProxy< MT > &proxy)
Resetting the represented element to the default initial values.
Definition: DiagonalProxy.h:591
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:661
const Type & ConstReference
Reference to a constant matrix value.
Definition: CompressedMatrix.h:3084
#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.
typename If_t< IsComplex_v< RepresentedType >, ComplexType< RepresentedType >, BuiltinType< RepresentedType > >::Type ValueType
Value type of the represented complex element.
Definition: HermitianProxy.h:132
Header file for the reset shim.
ValueType real() const
Returns the real part of the represented complex number.
Definition: HermitianProxy.h:627
Constraint on the data type.
const bool diagonal_
Flag for the accessed matrix element.
Definition: HermitianProxy.h:205
Pointer operator->() noexcept
Direct access to the represented matrix element.
Definition: HermitianProxy.h:493
Header file for the Proxy class.
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.
bool isZero(const DiagonalProxy< MT > &proxy)
Returns whether the represented element is 0.
Definition: DiagonalProxy.h:673
void invert(const HermitianProxy< MT > &proxy)
In-place inversion of the represented element.
Definition: HermitianProxy.h:775
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.
Constraint on the data type.
bool isnan(const DiagonalProxy< MT > &proxy)
Returns whether the represented element is not a number.
Definition: DiagonalProxy.h:713
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 DiagonalProxy< MT > &proxy)
Clearing the represented element.
Definition: DiagonalProxy.h:611
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:247
#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.
void clear() const
Clearing the represented element.
Definition: HermitianProxy.h:548
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, 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:693
Header file for the isDefault shim.
ConstReference get() const noexcept
Returning the value of the accessed matrix element.
Definition: HermitianProxy.h:582
Constraint on the data type.
typename T::ConstReference ConstReference_t
Alias declaration for nested ConstReference type definitions.The ConstReference_t alias declaration p...
Definition: Aliases.h:150
Constraint on the data type.
void reset() const
Reset the represented element to its default initial value.
Definition: HermitianProxy.h:529
Reference value1_
Reference to the first accessed matrix element.
Definition: HermitianProxy.h:203
Reference_t< MT > Reference
Reference to the represented element.
Definition: HermitianProxy.h:124
ConstReference_t< MT > ConstReference
Reference-to-const to the represented element.
Definition: HermitianProxy.h:125
#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:631
#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
#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:1326
Header file for the isReal shim.
ElementType_t< MT > RepresentedType
Type of the represented matrix element.
Definition: HermitianProxy.h:123
Header file for the clear shim.