Blaze 3.9
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>
69#include <blaze/util/Types.h>
71
72
73namespace blaze {
74
75//=================================================================================================
76//
77// CLASS DEFINITION
78//
79//=================================================================================================
80
81//*************************************************************************************************
99template< typename MT > // Type of the adapted matrix
101 : public Proxy< HermitianProxy<MT> >
102{
103 public:
104 //**Type definitions****************************************************************************
110
113
116 //**********************************************************************************************
117
118 //**Constructors********************************************************************************
121 inline HermitianProxy( MT& matrix, size_t row, size_t column );
122
123 HermitianProxy( const HermitianProxy& ) = default;
125 //**********************************************************************************************
126
127 //**Destructor**********************************************************************************
130 ~HermitianProxy() = default;
132 //**********************************************************************************************
133
134 //**Assignment operators************************************************************************
137 inline HermitianProxy& operator= ( const HermitianProxy& hp );
138 template< typename T > inline HermitianProxy& operator= ( const T& value );
139 template< typename T > inline HermitianProxy& operator+=( const T& value );
140 template< typename T > inline HermitianProxy& operator-=( const T& value );
141 template< typename T > inline HermitianProxy& operator*=( const T& value );
142 template< typename T > inline HermitianProxy& operator/=( const T& value );
143 template< typename T > inline HermitianProxy& operator%=( const T& value );
145 //**********************************************************************************************
146
147 //**Access operators****************************************************************************
150 inline Pointer operator->() noexcept;
151 inline ConstPointer operator->() const noexcept;
153 //**********************************************************************************************
154
155 //**Utility functions***************************************************************************
158 inline void invert() const;
159
160 inline ConstReference get() const noexcept;
162 //**********************************************************************************************
163
164 //**Conversion operator*************************************************************************
167 inline operator ConstReference() const noexcept;
169 //**********************************************************************************************
170
171 //**Complex data access functions***************************************************************
174 inline ValueType real() const;
175 inline void real( ValueType value ) const;
176 inline ValueType imag() const;
177 inline void imag( ValueType value ) const;
179 //**********************************************************************************************
180
181 private:
182 //**Member variables****************************************************************************
187 const bool diagonal_;
192 //**********************************************************************************************
193
194 //**Compile time checks*************************************************************************
210 //**********************************************************************************************
211
212 //**********************************************************************************************
223 friend inline void reset( const HermitianProxy& proxy )
224 {
225 using blaze::reset;
226
227 reset( proxy.value1_ );
228 if( !proxy.diagonal_ ) {
229 reset( proxy.value2_ );
230 }
231 }
233 //**********************************************************************************************
234
235 //**********************************************************************************************
243 friend inline void clear( const HermitianProxy& proxy )
244 {
245 using blaze::clear;
246
247 clear( proxy.value1_ );
248 if( !proxy.diagonal_ ) {
249 clear( proxy.value2_ );
250 }
251 }
253 //**********************************************************************************************
254};
255//*************************************************************************************************
256
257
258
259
260//=================================================================================================
261//
262// CONSTRUCTORS
263//
264//=================================================================================================
265
266//*************************************************************************************************
273template< typename MT > // Type of the adapted matrix
274inline HermitianProxy<MT>::HermitianProxy( MT& matrix, size_t row, size_t column )
275 : value1_ ( matrix(row,column) ) // Reference to the first accessed matrix element
276 , value2_ ( matrix(column,row) ) // Reference to the second accessed matrix element
277 , diagonal_( row == column ) // Flag for the accessed matrix element
278{}
279//*************************************************************************************************
280
281
282
283
284//=================================================================================================
285//
286// OPERATORS
287//
288//=================================================================================================
289
290//*************************************************************************************************
300template< typename MT > // Type of the adapted matrix
302{
303 using ET = ElementType_t<MT>;
304
305 if( IsComplex_v<ET> && diagonal_ && !isReal( hp.value1_ ) ) {
306 BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to diagonal matrix element" );
307 }
308
309 value1_ = hp.value1_;
310 if( !diagonal_ )
311 value2_ = conj( value1_ );
312
313 return *this;
314}
315//*************************************************************************************************
316
317
318//*************************************************************************************************
328template< typename MT > // Type of the adapted matrix
329template< typename T > // Type of the right-hand side value
331{
332 using ET = ElementType_t<MT>;
333
334 if( IsComplex_v<ET> && diagonal_ && !isReal( value ) ) {
335 BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to diagonal matrix element" );
336 }
337
338 value1_ = value;
339 if( !diagonal_ )
340 value2_ = conj( value1_ );
341
342 return *this;
343}
344//*************************************************************************************************
345
346
347//*************************************************************************************************
357template< typename MT > // Type of the adapted matrix
358template< typename T > // Type of the right-hand side value
360{
361 using ET = ElementType_t<MT>;
362
363 if( IsComplex_v<ET> && diagonal_ && !isReal( value ) ) {
364 BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to diagonal matrix element" );
365 }
366
367 value1_ += value;
368 if( !diagonal_ )
369 value2_ = conj( value1_ );
370
371 return *this;
372}
373//*************************************************************************************************
374
375
376//*************************************************************************************************
386template< typename MT > // Type of the adapted matrix
387template< typename T > // Type of the right-hand side value
389{
390 using ET = ElementType_t<MT>;
391
392 if( IsComplex_v<ET> && diagonal_ && !isReal( value ) ) {
393 BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to diagonal matrix element" );
394 }
395
396 value1_ -= value;
397 if( !diagonal_ )
398 value2_ = conj( value1_ );
399
400 return *this;
401}
402//*************************************************************************************************
403
404
405//*************************************************************************************************
415template< typename MT > // Type of the adapted matrix
416template< typename T > // Type of the right-hand side value
418{
419 using ET = ElementType_t<MT>;
420
421 if( IsComplex_v<ET> && diagonal_ && !isReal( value ) ) {
422 BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to diagonal matrix element" );
423 }
424
425 value1_ *= value;
426 if( !diagonal_ )
427 value2_ = conj( value1_ );
428
429 return *this;
430}
431//*************************************************************************************************
432
433
434//*************************************************************************************************
444template< typename MT > // Type of the adapted matrix
445template< typename T > // Type of the right-hand side value
447{
448 using ET = ElementType_t<MT>;
449
450 if( IsComplex_v<ET> && diagonal_ && !isReal( value ) ) {
451 BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to diagonal matrix element" );
452 }
453
454 value1_ /= value;
455 if( !diagonal_ )
456 value2_ = conj( value1_ );
457
458 return *this;
459}
460//*************************************************************************************************
461
462
463//*************************************************************************************************
473template< typename MT > // Type of the adapted matrix
474template< typename T > // Type of the right-hand side value
476{
477 using ET = ElementType_t<MT>;
478
479 if( IsComplex_v<ET> && diagonal_ && !isReal( value ) ) {
480 BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to diagonal matrix element" );
481 }
482
483 value1_ %= value;
484 if( !diagonal_ )
485 value2_ = conj( value1_ );
486
487 return *this;
488}
489//*************************************************************************************************
490
491
492
493
494//=================================================================================================
495//
496// ACCESS OPERATORS
497//
498//=================================================================================================
499
500//*************************************************************************************************
505template< typename MT > // Type of the adapted matrix
507{
508 return this;
509}
510//*************************************************************************************************
511
512
513//*************************************************************************************************
518template< typename MT > // Type of the adapted matrix
520{
521 return this;
522}
523//*************************************************************************************************
524
525
526
527
528//=================================================================================================
529//
530// UTILITY FUNCTIONS
531//
532//=================================================================================================
533
534//*************************************************************************************************
539template< typename MT > // Type of the adapted matrix
540inline void HermitianProxy<MT>::invert() const
541{
542 using blaze::invert;
543
544 invert( value1_ );
545 if( !diagonal_ )
546 value2_ = conj( value1_ );
547}
548//*************************************************************************************************
549
550
551//*************************************************************************************************
556template< typename MT > // Type of the adapted matrix
558{
559 return value1_;
560}
561//*************************************************************************************************
562
563
564
565
566//=================================================================================================
567//
568// CONVERSION OPERATOR
569//
570//=================================================================================================
571
572//*************************************************************************************************
577template< typename MT > // Type of the adapted matrix
579{
580 return get();
581}
582//*************************************************************************************************
583
584
585
586
587//=================================================================================================
588//
589// COMPLEX DATA ACCESS FUNCTIONS
590//
591//=================================================================================================
592
593//*************************************************************************************************
601template< typename MT > // Type of the adapted matrix
603{
604 return value1_.real();
605}
606//*************************************************************************************************
607
608
609//*************************************************************************************************
617template< typename MT > // Type of the adapted matrix
618inline void HermitianProxy<MT>::real( ValueType value ) const
619{
620 value1_.real( value );
621 if( !diagonal_ )
622 value2_.real( value );
623}
624//*************************************************************************************************
625
626
627//*************************************************************************************************
635template< typename MT > // Type of the adapted matrix
637{
638 return value1_.imag();
639}
640//*************************************************************************************************
641
642
643//*************************************************************************************************
654template< typename MT > // Type of the adapted matrix
655inline void HermitianProxy<MT>::imag( ValueType value ) const
656{
657 if( diagonal_ && !isZero( value ) ) {
658 BLAZE_THROW_INVALID_ARGUMENT( "Invalid setting for diagonal matrix element" );
659 }
660
661 value1_.imag( value );
662 if( !diagonal_ )
663 value2_.imag( -value );
664}
665//*************************************************************************************************
666
667
668
669
670//=================================================================================================
671//
672// GLOBAL FUNCTIONS
673//
674//=================================================================================================
675
676//*************************************************************************************************
679template< typename MT >
680void invert( const HermitianProxy<MT>& proxy );
682//*************************************************************************************************
683
684
685//*************************************************************************************************
692template< typename MT >
693inline void invert( const HermitianProxy<MT>& proxy )
694{
695 proxy.invert();
696}
697//*************************************************************************************************
698
699} // namespace blaze
700
701#endif
Header file for auxiliary alias declarations.
typename T::ConstReference ConstReference_t
Alias declaration for nested ConstReference type definitions.
Definition: Aliases.h:170
typename T::ElementType ElementType_t
Alias declaration for nested ElementType type definitions.
Definition: Aliases.h:190
typename T::Reference Reference_t
Alias declaration for nested Reference type definitions.
Definition: Aliases.h:390
Header file for the conjugate shim.
Constraint on the data type.
Constraint on the data type.
Header file for the invert shim.
Header file for the IsComplex type trait.
Header file for the isDefault shim.
Header file for the isOne shim.
Header file for the isReal shim.
Constraint on the data type.
Constraint on the data type.
Constraint on the data type.
Header file for the relaxation flag enumeration.
Constraint on the data type.
Constraint on the data type.
Header file for the UnderlyingBuiltin type trait.
Constraint on the data type.
Constraint on the data type.
Access proxy for Hermitian matrices.
Definition: HermitianProxy.h:102
HermitianProxy & operator=(const HermitianProxy &hp)
Copy assignment operator for HermitianProxy.
Definition: HermitianProxy.h:301
Reference value2_
Reference to the second accessed matrix element.
Definition: HermitianProxy.h:186
UnderlyingBuiltin_t< RepresentedType > ValueType
Value type of the represented complex element.
Definition: HermitianProxy.h:112
void invert() const
In-place inversion of the represented element.
Definition: HermitianProxy.h:540
ElementType_t< MT > RepresentedType
Type of the represented matrix element.
Definition: HermitianProxy.h:105
ValueType real() const
Returns the real part of the represented complex number.
Definition: HermitianProxy.h:602
ConstReference_t< MT > ConstReference
Reference-to-const to the represented element.
Definition: HermitianProxy.h:107
ValueType value_type
Value type of the represented complex element.
Definition: HermitianProxy.h:115
HermitianProxy(MT &matrix, size_t row, size_t column)
Initialization constructor for a HermitianProxy.
Definition: HermitianProxy.h:274
Reference_t< MT > Reference
Reference to the represented element.
Definition: HermitianProxy.h:106
const bool diagonal_
Flag for the accessed matrix element.
Definition: HermitianProxy.h:187
Pointer operator->() noexcept
Direct access to the represented matrix element.
Definition: HermitianProxy.h:506
ValueType imag() const
Returns the imaginary part of the represented complex number.
Definition: HermitianProxy.h:636
ConstReference get() const noexcept
Returning the value of the accessed matrix element.
Definition: HermitianProxy.h:557
Reference value1_
Reference to the first accessed matrix element.
Definition: HermitianProxy.h:185
Proxy base class.
Definition: Proxy.h:169
Constraint on the data type.
Constraint on the data type.
Constraint on the data type.
Constraint on the data type.
decltype(auto) column(Matrix< MT, SO > &matrix, RCAs... args)
Creating a view on a specific column of the given matrix.
Definition: Column.h:137
#define BLAZE_CONSTRAINT_MUST_NOT_BE_VOLATILE(T)
Constraint on the data type.
Definition: Volatile.h:79
#define BLAZE_CONSTRAINT_MUST_NOT_BE_POINTER_TYPE(T)
Constraint on the data type.
Definition: Pointer.h:79
#define BLAZE_CONSTRAINT_MUST_NOT_BE_CONST(T)
Constraint on the data type.
Definition: Const.h:79
#define BLAZE_CONSTRAINT_MUST_NOT_BE_REFERENCE_TYPE(T)
Constraint on the data type.
Definition: Reference.h:79
decltype(auto) conj(const DenseMatrix< MT, SO > &dm)
Returns a matrix containing the complex conjugate of each single element of dm.
Definition: DMatMapExpr.h:1464
bool isZero(const DenseMatrix< MT, SO > &dm)
Checks if the given dense matrix is a zero matrix.
Definition: DenseMatrix.h:1819
void invert(const HermitianProxy< MT > &proxy)
In-place inversion of the represented element.
Definition: HermitianProxy.h:693
#define BLAZE_CONSTRAINT_MUST_NOT_BE_SYMMETRIC_MATRIX_TYPE(T)
Constraint on the data type.
Definition: Symmetric.h:79
#define BLAZE_CONSTRAINT_MUST_BE_MATRIX_TYPE(T)
Constraint on the data type.
Definition: Matrix.h:61
#define BLAZE_CONSTRAINT_MUST_NOT_BE_VIEW_TYPE(T)
Constraint on the data type.
Definition: View.h:81
#define BLAZE_CONSTRAINT_MUST_NOT_BE_HERMITIAN_MATRIX_TYPE(T)
Constraint on the data type.
Definition: Hermitian.h:79
#define BLAZE_CONSTRAINT_MUST_NOT_BE_UPPER_MATRIX_TYPE(T)
Constraint on the data type.
Definition: Upper.h:81
#define BLAZE_CONSTRAINT_MUST_NOT_BE_COMPUTATION_TYPE(T)
Constraint on the data type.
Definition: Computation.h:81
#define BLAZE_CONSTRAINT_MUST_NOT_BE_LOWER_MATRIX_TYPE(T)
Constraint on the data type.
Definition: Lower.h:81
#define BLAZE_CONSTRAINT_MUST_BE_SCALAR_TYPE(T)
Constraint on the data type.
Definition: Scalar.h:61
#define BLAZE_CONSTRAINT_MUST_NOT_BE_TRANSFORMATION_TYPE(T)
Constraint on the data type.
Definition: Transformation.h:81
typename UnderlyingBuiltin< T >::Type UnderlyingBuiltin_t
Auxiliary alias declaration for the UnderlyingBuiltin type trait.
Definition: UnderlyingBuiltin.h:117
bool isReal(const Proxy< PT, RT > &proxy)
Returns whether the element represents a real number.
Definition: Proxy.h:2297
constexpr void clear(Matrix< MT, SO > &matrix)
Clearing the given matrix.
Definition: Matrix.h:960
constexpr void reset(Matrix< MT, SO > &matrix)
Resetting the given matrix.
Definition: Matrix.h:806
decltype(auto) row(Matrix< MT, SO > &, RRAs...)
Creating a view on a specific row of the given matrix.
Definition: Row.h:137
constexpr Type & get(StaticVector< Type, N, TF, AF, PF, Tag > &v) noexcept
Tuple-like index-based access the contents of a static vector.
Definition: StaticVector.h:3052
#define BLAZE_THROW_INVALID_ARGUMENT(MESSAGE)
Macro for the emission of a std::invalid_argument exception.
Definition: Exception.h:235
Header file for the exception macros of the math module.
Header file for the Proxy class.
Header file for the clear shim.
Header file for the isZero shim.
Header file for the reset shim.
Header file for basic type definitions.