Blaze  3.6
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>
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>
68 #include <blaze/util/InvalidType.h>
69 #include <blaze/util/mpl/If.h>
70 #include <blaze/util/Types.h>
72 
73 
74 namespace blaze {
75 
76 //=================================================================================================
77 //
78 // CLASS DEFINITION
79 //
80 //=================================================================================================
81 
82 //*************************************************************************************************
100 template< typename MT > // Type of the adapted matrix
102  : public Proxy< HermitianProxy<MT> >
103 {
104  private:
105  //**struct BuiltinType**************************************************************************
109  template< typename T >
110  struct BuiltinType { using Type = INVALID_TYPE; };
112  //**********************************************************************************************
113 
114  //**struct ComplexType**************************************************************************
118  template< typename T >
119  struct ComplexType { using Type = typename T::value_type; };
121  //**********************************************************************************************
122 
123  public:
124  //**Type definitions****************************************************************************
129  using ConstPointer = const HermitianProxy*;
130 
133  , ComplexType<RepresentedType>
134  , BuiltinType<RepresentedType> >::Type;
135  //**********************************************************************************************
136 
137  //**Constructors********************************************************************************
140  explicit inline HermitianProxy( MT& matrix, size_t row, size_t column );
141  inline HermitianProxy( const HermitianProxy& hp );
143  //**********************************************************************************************
144 
145  //**Destructor**********************************************************************************
148  ~HermitianProxy() = default;
150  //**********************************************************************************************
151 
152  //**Assignment operators************************************************************************
155  inline HermitianProxy& operator= ( const HermitianProxy& hp );
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 );
160  template< typename T > inline HermitianProxy& operator/=( const T& value );
161  template< typename T > inline HermitianProxy& operator%=( const T& value );
163  //**********************************************************************************************
164 
165  //**Access operators****************************************************************************
168  inline Pointer operator->() noexcept;
169  inline ConstPointer operator->() const noexcept;
171  //**********************************************************************************************
172 
173  //**Utility functions***************************************************************************
176  inline void reset () const;
177  inline void clear () const;
178  inline void invert() const;
179 
180  inline ConstReference get() const noexcept;
182  //**********************************************************************************************
183 
184  //**Conversion operator*************************************************************************
187  inline operator ConstReference() const noexcept;
189  //**********************************************************************************************
190 
191  //**Complex data access functions***************************************************************
194  inline ValueType real() const;
195  inline void real( ValueType value ) const;
196  inline ValueType imag() const;
197  inline void imag( ValueType value ) const;
199  //**********************************************************************************************
200 
201  private:
202  //**Member variables****************************************************************************
207  const bool diagonal_;
208 
212  //**********************************************************************************************
213 
214  //**Compile time checks*************************************************************************
230  //**********************************************************************************************
231 };
232 //*************************************************************************************************
233 
234 
235 
236 
237 //=================================================================================================
238 //
239 // CONSTRUCTORS
240 //
241 //=================================================================================================
242 
243 //*************************************************************************************************
250 template< typename MT > // Type of the adapted matrix
251 inline HermitianProxy<MT>::HermitianProxy( MT& matrix, size_t row, size_t column )
252  : value1_ ( matrix(row,column) ) // Reference to the first accessed matrix element
253  , value2_ ( matrix(column,row) ) // Reference to the second accessed matrix element
254  , diagonal_( row == column ) // Flag for the accessed matrix element
255 {}
256 //*************************************************************************************************
257 
258 
259 //*************************************************************************************************
264 template< typename MT > // Type of the adapted matrix
266  : value1_ ( hp.value1_ ) // Reference to the first accessed matrix element
267  , value2_ ( hp.value2_ ) // Reference to the second accessed matrix element
268  , diagonal_( hp.diagonal_ ) // Flag for the accessed matrix element
269 {}
270 //*************************************************************************************************
271 
272 
273 
274 
275 //=================================================================================================
276 //
277 // OPERATORS
278 //
279 //=================================================================================================
280 
281 //*************************************************************************************************
291 template< typename MT > // Type of the adapted matrix
293 {
294  using ET = ElementType_t<MT>;
295 
296  if( IsComplex_v<ET> && diagonal_ && !isReal( hp.value1_ ) ) {
297  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to diagonal matrix element" );
298  }
299 
300  value1_ = hp.value1_;
301  if( !diagonal_ )
302  value2_ = conj( value1_ );
303 
304  return *this;
305 }
306 //*************************************************************************************************
307 
308 
309 //*************************************************************************************************
319 template< typename MT > // Type of the adapted matrix
320 template< typename T > // Type of the right-hand side value
322 {
323  using ET = ElementType_t<MT>;
324 
325  if( IsComplex_v<ET> && diagonal_ && !isReal( value ) ) {
326  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to diagonal matrix element" );
327  }
328 
329  value1_ = value;
330  if( !diagonal_ )
331  value2_ = conj( value1_ );
332 
333  return *this;
334 }
335 //*************************************************************************************************
336 
337 
338 //*************************************************************************************************
348 template< typename MT > // Type of the adapted matrix
349 template< typename T > // Type of the right-hand side value
351 {
352  using ET = ElementType_t<MT>;
353 
354  if( IsComplex_v<ET> && diagonal_ && !isReal( value ) ) {
355  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to diagonal matrix element" );
356  }
357 
358  value1_ += value;
359  if( !diagonal_ )
360  value2_ = conj( value1_ );
361 
362  return *this;
363 }
364 //*************************************************************************************************
365 
366 
367 //*************************************************************************************************
377 template< typename MT > // Type of the adapted matrix
378 template< typename T > // Type of the right-hand side value
380 {
381  using ET = ElementType_t<MT>;
382 
383  if( IsComplex_v<ET> && diagonal_ && !isReal( value ) ) {
384  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to diagonal matrix element" );
385  }
386 
387  value1_ -= value;
388  if( !diagonal_ )
389  value2_ = conj( value1_ );
390 
391  return *this;
392 }
393 //*************************************************************************************************
394 
395 
396 //*************************************************************************************************
406 template< typename MT > // Type of the adapted matrix
407 template< typename T > // Type of the right-hand side value
409 {
410  using ET = ElementType_t<MT>;
411 
412  if( IsComplex_v<ET> && diagonal_ && !isReal( value ) ) {
413  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to diagonal matrix element" );
414  }
415 
416  value1_ *= value;
417  if( !diagonal_ )
418  value2_ = conj( value1_ );
419 
420  return *this;
421 }
422 //*************************************************************************************************
423 
424 
425 //*************************************************************************************************
435 template< typename MT > // Type of the adapted matrix
436 template< typename T > // Type of the right-hand side value
438 {
439  using ET = ElementType_t<MT>;
440 
441  if( IsComplex_v<ET> && diagonal_ && !isReal( value ) ) {
442  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to diagonal matrix element" );
443  }
444 
445  value1_ /= value;
446  if( !diagonal_ )
447  value2_ = conj( value1_ );
448 
449  return *this;
450 }
451 //*************************************************************************************************
452 
453 
454 //*************************************************************************************************
464 template< typename MT > // Type of the adapted matrix
465 template< typename T > // Type of the right-hand side value
467 {
468  using ET = ElementType_t<MT>;
469 
470  if( IsComplex_v<ET> && diagonal_ && !isReal( value ) ) {
471  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to diagonal matrix element" );
472  }
473 
474  value1_ %= value;
475  if( !diagonal_ )
476  value2_ = conj( value1_ );
477 
478  return *this;
479 }
480 //*************************************************************************************************
481 
482 
483 
484 
485 //=================================================================================================
486 //
487 // ACCESS OPERATORS
488 //
489 //=================================================================================================
490 
491 //*************************************************************************************************
496 template< typename MT > // Type of the adapted matrix
498 {
499  return this;
500 }
501 //*************************************************************************************************
502 
503 
504 //*************************************************************************************************
509 template< typename MT > // Type of the adapted matrix
511 {
512  return this;
513 }
514 //*************************************************************************************************
515 
516 
517 
518 
519 //=================================================================================================
520 //
521 // UTILITY FUNCTIONS
522 //
523 //=================================================================================================
524 
525 //*************************************************************************************************
532 template< typename MT > // Type of the adapted matrix
533 inline void HermitianProxy<MT>::reset() const
534 {
535  using blaze::reset;
536 
537  reset( value1_ );
538  if( !diagonal_ )
539  reset( value2_ );
540 }
541 //*************************************************************************************************
542 
543 
544 //*************************************************************************************************
551 template< typename MT > // Type of the adapted matrix
552 inline void HermitianProxy<MT>::clear() const
553 {
554  using blaze::clear;
555 
556  clear( value1_ );
557  if( !diagonal_ )
558  clear( value2_ );
559 }
560 //*************************************************************************************************
561 
562 
563 //*************************************************************************************************
568 template< typename MT > // Type of the adapted matrix
569 inline void HermitianProxy<MT>::invert() const
570 {
571  using blaze::invert;
572 
573  invert( value1_ );
574  if( !diagonal_ )
575  value2_ = conj( value1_ );
576 }
577 //*************************************************************************************************
578 
579 
580 //*************************************************************************************************
585 template< typename MT > // Type of the adapted matrix
587 {
588  return value1_;
589 }
590 //*************************************************************************************************
591 
592 
593 
594 
595 //=================================================================================================
596 //
597 // CONVERSION OPERATOR
598 //
599 //=================================================================================================
600 
601 //*************************************************************************************************
606 template< typename MT > // Type of the adapted matrix
608 {
609  return get();
610 }
611 //*************************************************************************************************
612 
613 
614 
615 
616 //=================================================================================================
617 //
618 // COMPLEX DATA ACCESS FUNCTIONS
619 //
620 //=================================================================================================
621 
622 //*************************************************************************************************
630 template< typename MT > // Type of the adapted matrix
632 {
633  return value1_.real();
634 }
635 //*************************************************************************************************
636 
637 
638 //*************************************************************************************************
646 template< typename MT > // Type of the adapted matrix
647 inline void HermitianProxy<MT>::real( ValueType value ) const
648 {
649  value1_.real( value );
650  if( !diagonal_ )
651  value2_.real( value );
652 }
653 //*************************************************************************************************
654 
655 
656 //*************************************************************************************************
664 template< typename MT > // Type of the adapted matrix
666 {
667  return value1_.imag();
668 }
669 //*************************************************************************************************
670 
671 
672 //*************************************************************************************************
683 template< typename MT > // Type of the adapted matrix
684 inline void HermitianProxy<MT>::imag( ValueType value ) const
685 {
686  if( diagonal_ && !isZero( value ) ) {
687  BLAZE_THROW_INVALID_ARGUMENT( "Invalid setting for diagonal matrix element" );
688  }
689 
690  value1_.imag( value );
691  if( !diagonal_ )
692  value2_.imag( -value );
693 }
694 //*************************************************************************************************
695 
696 
697 
698 
699 //=================================================================================================
700 //
701 // GLOBAL FUNCTIONS
702 //
703 //=================================================================================================
704 
705 //*************************************************************************************************
708 template< typename MT >
709 void reset( const HermitianProxy<MT>& proxy );
710 
711 template< typename MT >
712 void clear( const HermitianProxy<MT>& proxy );
713 
714 template< typename MT >
715 void invert( const HermitianProxy<MT>& proxy );
716 
717 template< bool RF, typename MT >
718 bool isDefault( const HermitianProxy<MT>& proxy );
719 
720 template< bool RF, typename MT >
721 bool isReal( const HermitianProxy<MT>& proxy );
722 
723 template< bool RF, typename MT >
724 bool isZero( const HermitianProxy<MT>& proxy );
725 
726 template< bool RF, typename MT >
727 bool isOne( const HermitianProxy<MT>& proxy );
728 
729 template< typename MT >
730 bool isnan( const HermitianProxy<MT>& proxy );
732 //*************************************************************************************************
733 
734 
735 //*************************************************************************************************
745 template< typename MT >
746 inline void reset( const HermitianProxy<MT>& proxy )
747 {
748  proxy.reset();
749 }
750 //*************************************************************************************************
751 
752 
753 //*************************************************************************************************
763 template< typename MT >
764 inline void clear( const HermitianProxy<MT>& proxy )
765 {
766  proxy.clear();
767 }
768 //*************************************************************************************************
769 
770 
771 //*************************************************************************************************
778 template< typename MT >
779 inline void invert( const HermitianProxy<MT>& proxy )
780 {
781  proxy.invert();
782 }
783 //*************************************************************************************************
784 
785 
786 //*************************************************************************************************
796 template< bool RF, typename MT >
797 inline bool isDefault( const HermitianProxy<MT>& proxy )
798 {
799  using blaze::isDefault;
800 
801  return isDefault<RF>( proxy.get() );
802 }
803 //*************************************************************************************************
804 
805 
806 //*************************************************************************************************
818 template< bool RF, typename MT >
819 inline bool isReal( const HermitianProxy<MT>& proxy )
820 {
821  using blaze::isReal;
822 
823  return isReal<RF>( proxy.get() );
824 }
825 //*************************************************************************************************
826 
827 
828 //*************************************************************************************************
838 template< bool RF, typename MT >
839 inline bool isZero( const HermitianProxy<MT>& proxy )
840 {
841  using blaze::isZero;
842 
843  return isZero<RF>( proxy.get() );
844 }
845 //*************************************************************************************************
846 
847 
848 //*************************************************************************************************
858 template< bool RF, typename MT >
859 inline bool isOne( const HermitianProxy<MT>& proxy )
860 {
861  using blaze::isOne;
862 
863  return isOne<RF>( proxy.get() );
864 }
865 //*************************************************************************************************
866 
867 
868 //*************************************************************************************************
878 template< typename MT >
879 inline bool isnan( const HermitianProxy<MT>& proxy )
880 {
881  using blaze::isnan;
882 
883  return isnan( proxy.get() );
884 }
885 //*************************************************************************************************
886 
887 } // namespace blaze
888 
889 #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.
#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.
HermitianProxy & operator=(const HermitianProxy &hp)
Copy assignment operator for HermitianProxy.
Definition: HermitianProxy.h:292
Reference value2_
Reference to the second accessed matrix element.
Definition: HermitianProxy.h:206
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
void invert() const
In-place inversion of the represented element.
Definition: HermitianProxy.h:569
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.
#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
Access proxy for Hermitian matrices.The HermitianProxy provides controlled access to the elements of ...
Definition: HermitianProxy.h:101
ValueType imag() const
Returns the imaginary part of the represented complex number.
Definition: HermitianProxy.h:665
#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.
typename If_t< IsComplex_v< RepresentedType >, ComplexType< RepresentedType >, BuiltinType< RepresentedType > >::Type ValueType
Value type of the represented complex element.
Definition: HermitianProxy.h:134
Header file for the reset shim.
ValueType real() const
Returns the real part of the represented complex number.
Definition: HermitianProxy.h:631
Constraint on the data type.
const bool diagonal_
Flag for the accessed matrix element.
Definition: HermitianProxy.h:207
Pointer operator->() noexcept
Direct access to the represented matrix element.
Definition: HermitianProxy.h:497
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: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
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: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 clear(const DiagonalProxy< MT > &proxy)
Clearing the represented element.
Definition: DiagonalProxy.h:615
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:251
#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
Utility type for generic codes.
Constraint on the data type.
void clear() const
Clearing the represented element.
Definition: HermitianProxy.h:552
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.
ConstReference get() const noexcept
Returning the value of the accessed matrix element.
Definition: HermitianProxy.h:586
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.
#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
void reset() const
Reset the represented element to its default initial value.
Definition: HermitianProxy.h:533
Reference value1_
Reference to the first accessed matrix element.
Definition: HermitianProxy.h:205
Reference_t< MT > Reference
Reference to the represented element.
Definition: HermitianProxy.h:126
ConstReference_t< MT > ConstReference
Reference-to-const to the represented element.
Definition: HermitianProxy.h:127
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
#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:1324
Constraint on the data type.
Header file for the isReal shim.
ElementType_t< MT > RepresentedType
Type of the represented matrix element.
Definition: HermitianProxy.h:125
Header file for the clear shim.
constexpr Type & get(StaticVector< Type, N, TF > &v) noexcept
Tuple-like index-based access the contents of a static vector.
Definition: StaticVector.h:2704