Blaze 3.9
ScalarProxy.h
Go to the documentation of this file.
1//=================================================================================================
33//=================================================================================================
34
35#ifndef _BLAZE_MATH_ADAPTORS_SYMMETRICMATRIX_SCALARPROXY_H_
36#define _BLAZE_MATH_ADAPTORS_SYMMETRICMATRIX_SCALARPROXY_H_
37
38
39//*************************************************************************************************
40// Includes
41//*************************************************************************************************
42
43#include <blaze/math/Aliases.h>
67#include <blaze/util/mpl/If.h>
68#include <blaze/util/Types.h>
70
71
72namespace blaze {
73
74//=================================================================================================
75//
76// CLASS DEFINITION
77//
78//=================================================================================================
79
80//*************************************************************************************************
99template< typename MT > // Type of the adapted matrix
101 : public Proxy< ScalarProxy<MT> >
102{
103 private:
104 //**struct BuiltinType**************************************************************************
108 template< typename T >
109 struct BuiltinType { using Type = INVALID_TYPE; };
111 //**********************************************************************************************
112
113 //**struct ComplexType**************************************************************************
117 template< typename T >
118 struct ComplexType { using Type = typename T::value_type; };
120 //**********************************************************************************************
121
122 public:
123 //**Type definitions****************************************************************************
128 using ConstPointer = const ScalarProxy*;
129
132 , ComplexType<RepresentedType>
133 , BuiltinType<RepresentedType> >::Type;
134 //**********************************************************************************************
135
136 //**Constructors********************************************************************************
139 inline ScalarProxy( MT& matrix, size_t row, size_t column );
140
141 ScalarProxy( const ScalarProxy& ) = default;
143 //**********************************************************************************************
144
145 //**Destructor**********************************************************************************
148 ~ScalarProxy() = default;
150 //**********************************************************************************************
151
152 //**Assignment operators************************************************************************
155 inline ScalarProxy& operator= ( const ScalarProxy& sp );
156 template< typename T > inline ScalarProxy& operator= ( const T& value );
157 template< typename T > inline ScalarProxy& operator+=( const T& value );
158 template< typename T > inline ScalarProxy& operator-=( const T& value );
159 template< typename T > inline ScalarProxy& operator*=( const T& value );
160 template< typename T > inline ScalarProxy& operator/=( const T& value );
161 template< typename T > inline ScalarProxy& operator%=( const T& value );
163 //**********************************************************************************************
164
165 //**Access operators****************************************************************************
168 inline Pointer operator->();
169 inline ConstPointer operator->() const;
171 //**********************************************************************************************
172
173 //**Utility functions***************************************************************************
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****************************************************************************
204 size_t row_;
205 size_t column_;
207 //**********************************************************************************************
208
209 //**Compile time checks*************************************************************************
225 //**********************************************************************************************
226
227 //**********************************************************************************************
238 friend inline void reset( const ScalarProxy& proxy )
239 {
240 using blaze::reset;
241
242 reset( proxy.matrix_( proxy.row_, proxy.column_ ) );
243 if( proxy.row_ != proxy.column_ ) {
244 reset( proxy.matrix_( proxy.column_, proxy.row_ ) );
245 }
246 }
248 //**********************************************************************************************
249
250 //**********************************************************************************************
261 friend inline void clear( const ScalarProxy& proxy )
262 {
263 using blaze::clear;
264
265 clear( proxy.matrix_( proxy.row_, proxy.column_ ) );
266 if( proxy.row_ != proxy.column_ ) {
267 clear( proxy.matrix_( proxy.column_, proxy.row_ ) );
268 }
269 }
271 //**********************************************************************************************
272};
273//*************************************************************************************************
274
275
276
277
278//=================================================================================================
279//
280// CONSTRUCTORS
281//
282//=================================================================================================
283
284//*************************************************************************************************
291template< typename MT > // Type of the adapted matrix
292inline ScalarProxy<MT>::ScalarProxy( MT& matrix, size_t row, size_t column )
293 : matrix_( matrix ) // Reference to the adapted matrix
294 , row_ ( row ) // Row index of the accessed matrix element
295 , column_( column ) // Column index of the accessed matrix element
296{}
297//*************************************************************************************************
298
299
300
301
302//=================================================================================================
303//
304// OPERATORS
305//
306//=================================================================================================
307
308//*************************************************************************************************
314template< typename MT > // Type of the adapted matrix
316{
317 matrix_(row_,column_) = sp.matrix_(sp.row_,sp.column_);
318 matrix_(column_,row_) = sp.matrix_(sp.row_,sp.column_);
319
320 return *this;
321}
322//*************************************************************************************************
323
324
325//*************************************************************************************************
331template< typename MT > // Type of the adapted matrix
332template< typename T > // Type of the right-hand side value
334{
335 matrix_(row_,column_) = value;
336 if( row_ != column_ )
337 matrix_(column_,row_) = value;
338
339 return *this;
340}
341//*************************************************************************************************
342
343
344//*************************************************************************************************
350template< typename MT > // Type of the adapted matrix
351template< typename T > // Type of the right-hand side value
353{
354 matrix_(row_,column_) += value;
355 if( row_ != column_ )
356 matrix_(column_,row_) += value;
357
358 return *this;
359}
360//*************************************************************************************************
361
362
363//*************************************************************************************************
369template< typename MT > // Type of the adapted matrix
370template< typename T > // Type of the right-hand side value
372{
373 matrix_(row_,column_) -= value;
374 if( row_ != column_ )
375 matrix_(column_,row_) -= value;
376
377 return *this;
378}
379//*************************************************************************************************
380
381
382//*************************************************************************************************
388template< typename MT > // Type of the adapted matrix
389template< typename T > // Type of the right-hand side value
391{
392 matrix_(row_,column_) *= value;
393 if( row_ != column_ )
394 matrix_(column_,row_) *= value;
395
396 return *this;
397}
398//*************************************************************************************************
399
400
401//*************************************************************************************************
407template< typename MT > // Type of the adapted matrix
408template< typename T > // Type of the right-hand side value
410{
411 matrix_(row_,column_) /= value;
412 if( row_ != column_ )
413 matrix_(column_,row_) /= value;
414
415 return *this;
416}
417//*************************************************************************************************
418
419
420//*************************************************************************************************
426template< typename MT > // Type of the adapted matrix
427template< typename T > // Type of the right-hand side value
429{
430 matrix_(row_,column_) %= value;
431 if( row_ != column_ )
432 matrix_(column_,row_) %= value;
433
434 return *this;
435}
436//*************************************************************************************************
437
438
439
440
441//=================================================================================================
442//
443// ACCESS OPERATORS
444//
445//=================================================================================================
446
447//*************************************************************************************************
452template< typename MT > // Type of the adapted matrix
454{
455 return this;
456}
457//*************************************************************************************************
458
459
460//*************************************************************************************************
465template< typename MT > // Type of the adapted matrix
467{
468 return this;
469}
470//*************************************************************************************************
471
472
473
474
475//=================================================================================================
476//
477// UTILITY FUNCTIONS
478//
479//=================================================================================================
480
481//*************************************************************************************************
486template< typename MT > // Type of the adapted matrix
487inline void ScalarProxy<MT>::invert() const
488{
489 using blaze::invert;
490
491 invert( matrix_(row_,column_) );
492 if( row_ != column_ )
493 matrix_(column_,row_) = matrix_(row_,column_);
494}
495//*************************************************************************************************
496
497
498//*************************************************************************************************
503template< typename MT > // Type of the adapted matrix
505{
506 return const_cast<const MT&>( matrix_ )(row_,column_);
507}
508//*************************************************************************************************
509
510
511
512
513//=================================================================================================
514//
515// CONVERSION OPERATOR
516//
517//=================================================================================================
518
519//*************************************************************************************************
524template< typename MT > // Type of the adapted matrix
526{
527 return get();
528}
529//*************************************************************************************************
530
531
532
533
534//=================================================================================================
535//
536// COMPLEX DATA ACCESS FUNCTIONS
537//
538//=================================================================================================
539
540//*************************************************************************************************
548template< typename MT > // Type of the adapted matrix
550{
551 return matrix_(row_,column_).real();
552}
553//*************************************************************************************************
554
555
556//*************************************************************************************************
564template< typename MT > // Type of the adapted matrix
565inline void ScalarProxy<MT>::real( ValueType value ) const
566{
567 matrix_(row_,column_).real( value );
568 if( row_ != column_ )
569 matrix_(column_,row_).real( value );
570}
571//*************************************************************************************************
572
573
574//*************************************************************************************************
582template< typename MT > // Type of the adapted matrix
584{
585 return matrix_(row_,column_).imag();
586}
587//*************************************************************************************************
588
589
590//*************************************************************************************************
599template< typename MT > // Type of the adapted matrix
600inline void ScalarProxy<MT>::imag( ValueType value ) const
601{
602 matrix_(row_,column_).imag( value );
603 if( row_ != column_ )
604 matrix_(column_,row_).imag( value );
605}
606//*************************************************************************************************
607
608
609
610
611//=================================================================================================
612//
613// GLOBAL FUNCTIONS
614//
615//=================================================================================================
616
617//*************************************************************************************************
620template< typename MT >
621void invert( const ScalarProxy<MT>& proxy );
623//*************************************************************************************************
624
625
626//*************************************************************************************************
633template< typename MT >
634inline void invert( const ScalarProxy<MT>& proxy )
635{
636 proxy.invert();
637}
638//*************************************************************************************************
639
640} // namespace blaze
641
642#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
Constraint on the data type.
Constraint on the data type.
Header file for the If class template.
Utility type for generic codes.
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.
Constraint on the data type.
Constraint on the data type.
Proxy base class.
Definition: Proxy.h:169
Access proxy for symmetric, square matrices with scalar element types.
Definition: ScalarProxy.h:102
size_t row_
Row index of the accessed matrix element.
Definition: ScalarProxy.h:204
ScalarProxy(MT &matrix, size_t row, size_t column)
Initialization constructor for a ScalarProxy.
Definition: ScalarProxy.h:292
Pointer operator->()
Direct access to the represented matrix element.
Definition: ScalarProxy.h:453
size_t column_
Column index of the accessed matrix element.
Definition: ScalarProxy.h:205
ValueType imag() const
Returns the imaginary part of the represented complex number.
Definition: ScalarProxy.h:583
ValueType real() const
Returns the real part of the represented complex number.
Definition: ScalarProxy.h:549
typename If_t< IsComplex_v< RepresentedType >, ComplexType< RepresentedType >, BuiltinType< RepresentedType > >::Type ValueType
Value type of the represented complex element.
Definition: ScalarProxy.h:133
MT & matrix_
Reference to the adapted matrix.
Definition: ScalarProxy.h:203
ScalarProxy & operator=(const ScalarProxy &sp)
Copy assignment operator for ScalarProxy.
Definition: ScalarProxy.h:315
ElementType_t< MT > RepresentedType
Type of the represented matrix element.
Definition: ScalarProxy.h:124
Reference_t< MT > Reference
Reference to the represented element.
Definition: ScalarProxy.h:125
ConstReference get() const noexcept
Returning the value of the accessed matrix element.
Definition: ScalarProxy.h:504
void invert() const
In-place inversion of the represented element.
Definition: ScalarProxy.h:487
ConstReference_t< MT > ConstReference
Reference-to-const to the represented element.
Definition: ScalarProxy.h:126
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
#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
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
void invert(const ScalarProxy< MT > &proxy)
In-place inversion of the represented element.
Definition: ScalarProxy.h:634
typename If< Condition >::template Type< T1, T2 > If_t
Auxiliary alias template for the If class template.
Definition: If.h:108
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.