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 
49 #include <blaze/math/proxy/Proxy.h>
50 #include <blaze/math/shims/Clear.h>
54 #include <blaze/math/shims/IsNaN.h>
55 #include <blaze/math/shims/IsOne.h>
58 #include <blaze/math/shims/Reset.h>
65 #include <blaze/util/Exception.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
99 class HermitianProxy : public Proxy< HermitianProxy<MT> >
100 {
101  private:
102  //**struct BuiltinType**************************************************************************
106  template< typename T >
107  struct BuiltinType { typedef INVALID_TYPE Type; };
109  //**********************************************************************************************
110 
111  //**struct ComplexType**************************************************************************
115  template< typename T >
116  struct ComplexType { typedef typename T::value_type Type; };
118  //**********************************************************************************************
119 
120  public:
121  //**Type definitions****************************************************************************
122  typedef typename MT::ElementType RepresentedType;
123  typedef typename MT::Reference Reference;
126  typedef const HermitianProxy* ConstPointer;
127 
129  typedef typename If< IsComplex<RepresentedType>
130  , ComplexType<RepresentedType>
131  , BuiltinType<RepresentedType> >::Type::Type ValueType;
132  //**********************************************************************************************
133 
134  //**Constructors********************************************************************************
137  explicit inline HermitianProxy( MT& matrix, size_t row, size_t column );
138  inline HermitianProxy( const HermitianProxy& hp );
140  //**********************************************************************************************
141 
142  //**Destructor**********************************************************************************
143  // No explicitly declared destructor.
144  //**********************************************************************************************
145 
146  //**Assignment operators************************************************************************
149  inline HermitianProxy& operator= ( const HermitianProxy& hp );
150  template< typename T > inline HermitianProxy& operator= ( const T& value );
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 );
156  //**********************************************************************************************
157 
158  //**Access operators****************************************************************************
161  inline Pointer operator->();
162  inline ConstPointer operator->() const;
164  //**********************************************************************************************
165 
166  //**Utility functions***************************************************************************
169  inline void reset () const;
170  inline void clear () const;
171  inline void invert() const;
172 
173  inline ConstReference get() const;
175  //**********************************************************************************************
176 
177  //**Conversion operator*************************************************************************
180  inline operator ConstReference() const;
182  //**********************************************************************************************
183 
184  //**Complex data access functions***************************************************************
187  inline ValueType real() const;
188  inline void real( ValueType value ) const;
189  inline ValueType imag() const;
190  inline void imag( ValueType value ) const;
192  //**********************************************************************************************
193 
194  private:
195  //**Member variables****************************************************************************
198  Reference value1_;
199  Reference value2_;
200  const bool diagonal_;
201 
205  //**********************************************************************************************
206 
207  //**Compile time checks*************************************************************************
219  BLAZE_CONSTRAINT_MUST_BE_NUMERIC_TYPE ( RepresentedType );
221  //**********************************************************************************************
222 };
223 //*************************************************************************************************
224 
225 
226 
227 
228 //=================================================================================================
229 //
230 // CONSTRUCTORS
231 //
232 //=================================================================================================
233 
234 //*************************************************************************************************
241 template< typename MT > // Type of the adapted matrix
242 inline HermitianProxy<MT>::HermitianProxy( MT& matrix, size_t row, size_t column )
243  : value1_ ( matrix(row,column) ) // Reference to the first accessed matrix element
244  , value2_ ( matrix(column,row) ) // Reference to the second accessed matrix element
245  , diagonal_( row == column ) // Flag for the accessed matrix element
246 {}
247 //*************************************************************************************************
248 
249 
250 //*************************************************************************************************
255 template< typename MT > // Type of the adapted matrix
257  : value1_ ( hp.value1_ ) // Reference to the first accessed matrix element
258  , value2_ ( hp.value2_ ) // Reference to the second accessed matrix element
259  , diagonal_( hp.diagonal_ ) // Flag for the accessed matrix element
260 {}
261 //*************************************************************************************************
262 
263 
264 
265 
266 //=================================================================================================
267 //
268 // OPERATORS
269 //
270 //=================================================================================================
271 
272 //*************************************************************************************************
282 template< typename MT > // Type of the adapted matrix
284 {
285  typedef typename MT::ElementType ET;
286 
287  if( IsComplex<ET>::value && diagonal_ && !isReal( hp.value1_ ) ) {
288  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to diagonal matrix element" );
289  }
290 
291  value1_ = hp.value1_;
292  if( !diagonal_ )
293  value2_ = conj( value1_ );
294 
295  return *this;
296 }
297 //*************************************************************************************************
298 
299 
300 //*************************************************************************************************
310 template< typename MT > // Type of the adapted matrix
311 template< typename T > // Type of the right-hand side value
313 {
314  typedef typename MT::ElementType ET;
315 
316  if( IsComplex<ET>::value && diagonal_ && !isReal( value ) ) {
317  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to diagonal matrix element" );
318  }
319 
320  value1_ = value;
321  if( !diagonal_ )
322  value2_ = conj( value1_ );
323 
324  return *this;
325 }
326 //*************************************************************************************************
327 
328 
329 //*************************************************************************************************
339 template< typename MT > // Type of the adapted matrix
340 template< typename T > // Type of the right-hand side value
342 {
343  typedef typename MT::ElementType ET;
344 
345  if( IsComplex<ET>::value && diagonal_ && !isReal( value ) ) {
346  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to diagonal matrix element" );
347  }
348 
349  value1_ += value;
350  if( !diagonal_ )
351  value2_ = conj( value1_ );
352 
353  return *this;
354 }
355 //*************************************************************************************************
356 
357 
358 //*************************************************************************************************
368 template< typename MT > // Type of the adapted matrix
369 template< typename T > // Type of the right-hand side value
371 {
372  typedef typename MT::ElementType ET;
373 
374  if( IsComplex<ET>::value && diagonal_ && !isReal( value ) ) {
375  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to diagonal matrix element" );
376  }
377 
378  value1_ -= value;
379  if( !diagonal_ )
380  value2_ = conj( value1_ );
381 
382  return *this;
383 }
384 //*************************************************************************************************
385 
386 
387 //*************************************************************************************************
397 template< typename MT > // Type of the adapted matrix
398 template< typename T > // Type of the right-hand side value
400 {
401  typedef typename MT::ElementType ET;
402 
403  if( IsComplex<ET>::value && diagonal_ && !isReal( value ) ) {
404  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to diagonal matrix element" );
405  }
406 
407  value1_ *= value;
408  if( !diagonal_ )
409  value2_ = conj( value1_ );
410 
411  return *this;
412 }
413 //*************************************************************************************************
414 
415 
416 //*************************************************************************************************
426 template< typename MT > // Type of the adapted matrix
427 template< typename T > // Type of the right-hand side value
429 {
430  typedef typename MT::ElementType ET;
431 
432  if( IsComplex<ET>::value && diagonal_ && !isReal( value ) ) {
433  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to diagonal matrix element" );
434  }
435 
436  value1_ /= value;
437  if( !diagonal_ )
438  value2_ = conj( value1_ );
439 
440  return *this;
441 }
442 //*************************************************************************************************
443 
444 
445 
446 
447 //=================================================================================================
448 //
449 // ACCESS OPERATORS
450 //
451 //=================================================================================================
452 
453 //*************************************************************************************************
458 template< typename MT > // Type of the adapted matrix
460 {
461  return this;
462 }
463 //*************************************************************************************************
464 
465 
466 //*************************************************************************************************
471 template< typename MT > // Type of the adapted matrix
473 {
474  return this;
475 }
476 //*************************************************************************************************
477 
478 
479 
480 
481 //=================================================================================================
482 //
483 // UTILITY FUNCTIONS
484 //
485 //=================================================================================================
486 
487 //*************************************************************************************************
494 template< typename MT > // Type of the adapted matrix
495 inline void HermitianProxy<MT>::reset() const
496 {
497  using blaze::reset;
498 
499  reset( value1_ );
500  if( !diagonal_ )
501  reset( value2_ );
502 }
503 //*************************************************************************************************
504 
505 
506 //*************************************************************************************************
513 template< typename MT > // Type of the adapted matrix
514 inline void HermitianProxy<MT>::clear() const
515 {
516  using blaze::clear;
517 
518  clear( value1_ );
519  if( !diagonal_ )
520  clear( value2_ );
521 }
522 //*************************************************************************************************
523 
524 
525 //*************************************************************************************************
530 template< typename MT > // Type of the adapted matrix
531 inline void HermitianProxy<MT>::invert() const
532 {
533  using blaze::invert;
534 
535  invert( value1_ );
536  if( !diagonal_ )
537  value2_ = conj( value1_ );
538 }
539 //*************************************************************************************************
540 
541 
542 //*************************************************************************************************
547 template< typename MT > // Type of the adapted matrix
549 {
550  return value1_;
551 }
552 //*************************************************************************************************
553 
554 
555 
556 
557 //=================================================================================================
558 //
559 // CONVERSION OPERATOR
560 //
561 //=================================================================================================
562 
563 //*************************************************************************************************
568 template< typename MT > // Type of the adapted matrix
570 {
571  return get();
572 }
573 //*************************************************************************************************
574 
575 
576 
577 
578 //=================================================================================================
579 //
580 // COMPLEX DATA ACCESS FUNCTIONS
581 //
582 //=================================================================================================
583 
584 //*************************************************************************************************
592 template< typename MT > // Type of the adapted matrix
594 {
595  return value1_.real();
596 }
597 //*************************************************************************************************
598 
599 
600 //*************************************************************************************************
608 template< typename MT > // Type of the adapted matrix
609 inline void HermitianProxy<MT>::real( ValueType value ) const
610 {
611  value1_.real( value );
612  if( !diagonal_ )
613  value2_.real( value );
614 }
615 //*************************************************************************************************
616 
617 
618 //*************************************************************************************************
626 template< typename MT > // Type of the adapted matrix
628 {
629  return value1_.imag();
630 }
631 //*************************************************************************************************
632 
633 
634 //*************************************************************************************************
645 template< typename MT > // Type of the adapted matrix
646 inline void HermitianProxy<MT>::imag( ValueType value ) const
647 {
648  if( diagonal_ && !isZero( value ) ) {
649  BLAZE_THROW_INVALID_ARGUMENT( "Invalid setting for diagonal matrix element" );
650  }
651 
652  value1_.imag( value );
653  if( !diagonal_ )
654  value2_.imag( -value );
655 }
656 //*************************************************************************************************
657 
658 
659 
660 
661 //=================================================================================================
662 //
663 // GLOBAL FUNCTIONS
664 //
665 //=================================================================================================
666 
667 //*************************************************************************************************
670 template< typename MT >
672  conj( const HermitianProxy<MT>& proxy );
673 
674 template< typename MT >
675 inline void reset( const HermitianProxy<MT>& proxy );
676 
677 template< typename MT >
678 inline void clear( const HermitianProxy<MT>& proxy );
679 
680 template< typename MT >
681 inline void invert( const HermitianProxy<MT>& proxy );
682 
683 template< typename MT >
684 inline bool isDefault( const HermitianProxy<MT>& proxy );
685 
686 template< typename MT >
687 inline bool isReal( const HermitianProxy<MT>& proxy );
688 
689 template< typename MT >
690 inline bool isZero( const HermitianProxy<MT>& proxy );
691 
692 template< typename MT >
693 inline bool isOne( const HermitianProxy<MT>& proxy );
694 
695 template< typename MT >
696 inline bool isnan( const HermitianProxy<MT>& proxy );
698 //*************************************************************************************************
699 
700 
701 //*************************************************************************************************
712 template< typename MT >
714  conj( const HermitianProxy<MT>& proxy )
715 {
716  using blaze::conj;
717 
718  return conj( (~proxy).get() );
719 }
720 //*************************************************************************************************
721 
722 
723 //*************************************************************************************************
733 template< typename MT >
734 inline void reset( const HermitianProxy<MT>& proxy )
735 {
736  proxy.reset();
737 }
738 //*************************************************************************************************
739 
740 
741 //*************************************************************************************************
751 template< typename MT >
752 inline void clear( const HermitianProxy<MT>& proxy )
753 {
754  proxy.clear();
755 }
756 //*************************************************************************************************
757 
758 
759 //*************************************************************************************************
766 template< typename MT >
767 inline void invert( const HermitianProxy<MT>& proxy )
768 {
769  proxy.invert();
770 }
771 //*************************************************************************************************
772 
773 
774 //*************************************************************************************************
784 template< typename MT >
785 inline bool isDefault( const HermitianProxy<MT>& proxy )
786 {
787  using blaze::isDefault;
788 
789  return isDefault( proxy.get() );
790 }
791 //*************************************************************************************************
792 
793 
794 //*************************************************************************************************
806 template< typename MT >
807 inline bool isReal( const HermitianProxy<MT>& proxy )
808 {
809  using blaze::isReal;
810 
811  return isReal( proxy.get() );
812 }
813 //*************************************************************************************************
814 
815 
816 //*************************************************************************************************
826 template< typename MT >
827 inline bool isZero( const HermitianProxy<MT>& proxy )
828 {
829  using blaze::isZero;
830 
831  return isZero( proxy.get() );
832 }
833 //*************************************************************************************************
834 
835 
836 //*************************************************************************************************
846 template< typename MT >
847 inline bool isOne( const HermitianProxy<MT>& proxy )
848 {
849  using blaze::isOne;
850 
851  return isOne( proxy.get() );
852 }
853 //*************************************************************************************************
854 
855 
856 //*************************************************************************************************
866 template< typename MT >
867 inline bool isnan( const HermitianProxy<MT>& proxy )
868 {
869  using blaze::isnan;
870 
871  return isnan( proxy.get() );
872 }
873 //*************************************************************************************************
874 
875 } // namespace blaze
876 
877 #endif
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:116
#define BLAZE_THROW_INVALID_ARGUMENT(MESSAGE)
Macro for the emission of a std::invalid_argument exceptionThis macro encapsulates the default way of...
Definition: Exception.h:187
bool isOne(const DiagonalProxy< MT > &proxy)
Returns whether the represented element is 1.
Definition: DiagonalProxy.h:609
Constraint on the data type.
HermitianProxy & operator=(const HermitianProxy &hp)
Copy assignment operator for HermitianProxy.
Definition: HermitianProxy.h:283
void reset() const
Reset the represented element to its default initial value.
Definition: HermitianProxy.h:495
Reference value2_
Reference to the second accessed matrix element.
Definition: HermitianProxy.h:199
Compile time type selection.The If class template selects one of the two given types T2 and T3 depend...
Definition: If.h:112
Header file for basic type definitions.
Proxy base class.The Proxy class is a base class for all proxy classes within the Blaze library that ...
Definition: Forward.h:51
bool isReal(const DiagonalProxy< MT > &proxy)
Returns whether the matrix element represents a real number.
Definition: DiagonalProxy.h:569
Constraint on the data type.
void reset(const DiagonalProxy< MT > &proxy)
Resetting the represented element to the default initial values.
Definition: DiagonalProxy.h:507
Access proxy for Hermitian matrices.The HermitianProxy provides controlled access to the elements of ...
Definition: HermitianProxy.h:99
DisableIf< Or< IsComputation< MT >, IsTransExpr< MT > >, typename ColumnExprTrait< MT >::Type >::Type column(Matrix< MT, SO > &matrix, size_t index)
Creating a view on a specific column of the given matrix.
Definition: Column.h:107
#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:116
Header file for the invert shim.
Constraint on the data type.
const bool diagonal_
Flag for the accessed matrix element.
Definition: HermitianProxy.h:200
Header file for the Proxy class.
bool isDefault(const DiagonalProxy< MT > &proxy)
Returns whether the represented element is in default state.
Definition: DiagonalProxy.h:547
Constraint on the data type.
Constraint on the data type.
ConjExprTrait< typename DiagonalProxy< MT >::RepresentedType >::Type conj(const DiagonalProxy< MT > &proxy)
Computing the complex conjugate of the represented element.
Definition: DiagonalProxy.h:487
MT::Reference Reference
Reference to the represented element.
Definition: HermitianProxy.h:123
void invert(const HermitianProxy< MT > &proxy)
In-place inversion of the represented element.
Definition: HermitianProxy.h:767
void clear() const
Clearing the represented element.
Definition: HermitianProxy.h:514
Header file for the clear shim.
Namespace of the Blaze C++ math library.
Definition: Blaze.h:57
Header file for the If class template.
MT::ElementType RepresentedType
Type of the represented matrix element.
Definition: HermitianProxy.h:122
#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:116
Constraint on the data type.
Header file for the isZero shim.
Constraint on the data type.
Pointer operator->()
Direct access to the represented matrix element.
Definition: HermitianProxy.h:459
bool isnan(const DiagonalProxy< MT > &proxy)
Returns whether the represented element is not a number.
Definition: DiagonalProxy.h:629
#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:118
Type ElementType
Type of the sparse matrix elements.
Definition: CompressedMatrix.h:2586
const Type & ConstReference
Reference to a constant matrix value.
Definition: CompressedMatrix.h:2590
void clear(const DiagonalProxy< MT > &proxy)
Clearing the represented element.
Definition: DiagonalProxy.h:527
Header file for the isOne shim.
Header file for the conjugate shim.
void invert() const
In-place inversion of the represented element.
Definition: HermitianProxy.h:531
HermitianProxy(MT &matrix, size_t row, size_t column)
Initialization constructor for a HermitianProxy.
Definition: HermitianProxy.h:242
DisableIf< Or< IsComputation< MT >, IsTransExpr< MT > >, typename RowExprTrait< MT >::Type >::Type row(Matrix< MT, SO > &matrix, size_t index)
Creating a view on a specific row of the given matrix.
Definition: Row.h:107
If< IsComplex< RepresentedType >, ComplexType< RepresentedType >, BuiltinType< RepresentedType > >::Type::Type ValueType
Value type of the represented complex element.
Definition: HermitianProxy.h:131
Evaluation of the return type of a complex conjugate expression.Via this type trait it is possible to...
Definition: ConjExprTrait.h:87
#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:116
Utility type for generic codes.
Constraint on the data type.
Constraint on the data type.
ValueType real() const
Returns the real part of the represented complex number.
Definition: HermitianProxy.h:593
#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:79
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:118
#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:116
Header file for the isDefault shim.
Constraint on the data type.
Constraint on the data type.
Reference value1_
Reference to the first accessed matrix element.
Definition: HermitianProxy.h:198
ConstReference get() const
Returning the value of the accessed matrix element.
Definition: HermitianProxy.h:548
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:118
ValueType imag() const
Returns the imaginary part of the represented complex number.
Definition: HermitianProxy.h:627
bool isZero(const DiagonalProxy< MT > &proxy)
Returns whether the represented element is 0.
Definition: DiagonalProxy.h:589
HermitianProxy * Pointer
Pointer to the represented element.
Definition: HermitianProxy.h:125
Header file for the IsComplex type trait.
MatrixAccessProxy< This > Reference
Reference to a non-constant matrix value.
Definition: CompressedMatrix.h:2589
#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:116
const HermitianProxy * ConstPointer
Pointer-to-const to the represented element.
Definition: HermitianProxy.h:126
#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:79
Header file for exception macros.
Header file for the ConjExprTrait class template.
Header file for the isReal shim.
MT::ConstReference ConstReference
Reference-to-const to the represented element.
Definition: HermitianProxy.h:124