NumericProxy.h
Go to the documentation of this file.
1 //=================================================================================================
33 //=================================================================================================
34 
35 #ifndef _BLAZE_MATH_ADAPTORS_SYMMETRICMATRIX_NUMERICPROXY_H_
36 #define _BLAZE_MATH_ADAPTORS_SYMMETRICMATRIX_NUMERICPROXY_H_
37 
38 
39 //*************************************************************************************************
40 // Includes
41 //*************************************************************************************************
42 
43 #include <blaze/math/Aliases.h>
50 #include <blaze/math/proxy/Proxy.h>
51 #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>
64 #include <blaze/util/InvalidType.h>
65 #include <blaze/util/mpl/If.h>
66 #include <blaze/util/Types.h>
68 
69 
70 namespace blaze {
71 
72 //=================================================================================================
73 //
74 // CLASS DEFINITION
75 //
76 //=================================================================================================
77 
78 //*************************************************************************************************
97 template< typename MT > // Type of the adapted matrix
99  : public Proxy< NumericProxy<MT> >
100 {
101  private:
102  //**struct BuiltinType**************************************************************************
106  template< typename T >
107  struct BuiltinType { using Type = INVALID_TYPE; };
109  //**********************************************************************************************
110 
111  //**struct ComplexType**************************************************************************
115  template< typename T >
116  struct ComplexType { using Type = typename T::value_type; };
118  //**********************************************************************************************
119 
120  public:
121  //**Type definitions****************************************************************************
126  using ConstPointer = const NumericProxy*;
127 
130  , ComplexType<RepresentedType>
131  , BuiltinType<RepresentedType> >::Type;
132  //**********************************************************************************************
133 
134  //**Constructors********************************************************************************
137  explicit inline NumericProxy( MT& matrix, size_t row, size_t column );
138  inline NumericProxy( const NumericProxy& np );
140  //**********************************************************************************************
141 
142  //**Destructor**********************************************************************************
145  ~NumericProxy() = default;
147  //**********************************************************************************************
148 
149  //**Assignment operators************************************************************************
152  inline NumericProxy& operator= ( const NumericProxy& sp );
153  template< typename T > inline NumericProxy& operator= ( const T& value );
154  template< typename T > inline NumericProxy& operator+=( const T& value );
155  template< typename T > inline NumericProxy& operator-=( const T& value );
156  template< typename T > inline NumericProxy& operator*=( const T& value );
157  template< typename T > inline NumericProxy& operator/=( const T& value );
158  template< typename T > inline NumericProxy& operator%=( const T& value );
160  //**********************************************************************************************
161 
162  //**Access operators****************************************************************************
165  inline Pointer operator->();
166  inline ConstPointer operator->() const;
168  //**********************************************************************************************
169 
170  //**Utility functions***************************************************************************
173  inline void reset () const;
174  inline void clear () const;
175  inline void invert() const;
176 
177  inline ConstReference get() const noexcept;
179  //**********************************************************************************************
180 
181  //**Conversion operator*************************************************************************
184  inline operator ConstReference() const noexcept;
186  //**********************************************************************************************
187 
188  //**Complex data access functions***************************************************************
191  inline ValueType real() const;
192  inline void real( ValueType value ) const;
193  inline ValueType imag() const;
194  inline void imag( ValueType value ) const;
196  //**********************************************************************************************
197 
198  private:
199  //**Member variables****************************************************************************
202  MT& matrix_;
203  size_t row_;
204  size_t column_;
205 
206  //**********************************************************************************************
207 
208  //**Compile time checks*************************************************************************
222  //**********************************************************************************************
223 };
224 //*************************************************************************************************
225 
226 
227 
228 
229 //=================================================================================================
230 //
231 // CONSTRUCTORS
232 //
233 //=================================================================================================
234 
235 //*************************************************************************************************
242 template< typename MT > // Type of the adapted matrix
243 inline NumericProxy<MT>::NumericProxy( MT& matrix, size_t row, size_t column )
244  : matrix_( matrix ) // Reference to the adapted matrix
245  , row_ ( row ) // Row index of the accessed matrix element
246  , column_( column ) // Column index of the accessed matrix element
247 {}
248 //*************************************************************************************************
249 
250 
251 //*************************************************************************************************
256 template< typename MT > // Type of the adapted matrix
258  : matrix_( np.matrix_ ) // Reference to the adapted matrix
259  , row_ ( np.row_ ) // Row index of the accessed matrix element
260  , column_( np.column_ ) // Column index of the accessed matrix element
261 {}
262 //*************************************************************************************************
263 
264 
265 
266 
267 //=================================================================================================
268 //
269 // OPERATORS
270 //
271 //=================================================================================================
272 
273 //*************************************************************************************************
279 template< typename MT > // Type of the adapted matrix
281 {
282  matrix_(row_,column_) = np.matrix_(np.row_,np.column_);
283  matrix_(column_,row_) = np.matrix_(np.row_,np.column_);
284 
285  return *this;
286 }
287 //*************************************************************************************************
288 
289 
290 //*************************************************************************************************
296 template< typename MT > // Type of the adapted matrix
297 template< typename T > // Type of the right-hand side value
299 {
300  matrix_(row_,column_) = value;
301  if( row_ != column_ )
302  matrix_(column_,row_) = value;
303 
304  return *this;
305 }
306 //*************************************************************************************************
307 
308 
309 //*************************************************************************************************
315 template< typename MT > // Type of the adapted matrix
316 template< typename T > // Type of the right-hand side value
318 {
319  matrix_(row_,column_) += value;
320  if( row_ != column_ )
321  matrix_(column_,row_) += value;
322 
323  return *this;
324 }
325 //*************************************************************************************************
326 
327 
328 //*************************************************************************************************
334 template< typename MT > // Type of the adapted matrix
335 template< typename T > // Type of the right-hand side value
337 {
338  matrix_(row_,column_) -= value;
339  if( row_ != column_ )
340  matrix_(column_,row_) -= value;
341 
342  return *this;
343 }
344 //*************************************************************************************************
345 
346 
347 //*************************************************************************************************
353 template< typename MT > // Type of the adapted matrix
354 template< typename T > // Type of the right-hand side value
356 {
357  matrix_(row_,column_) *= value;
358  if( row_ != column_ )
359  matrix_(column_,row_) *= value;
360 
361  return *this;
362 }
363 //*************************************************************************************************
364 
365 
366 //*************************************************************************************************
372 template< typename MT > // Type of the adapted matrix
373 template< typename T > // Type of the right-hand side value
375 {
376  matrix_(row_,column_) /= value;
377  if( row_ != column_ )
378  matrix_(column_,row_) /= value;
379 
380  return *this;
381 }
382 //*************************************************************************************************
383 
384 
385 //*************************************************************************************************
391 template< typename MT > // Type of the adapted matrix
392 template< typename T > // Type of the right-hand side value
394 {
395  matrix_(row_,column_) %= value;
396  if( row_ != column_ )
397  matrix_(column_,row_) %= value;
398 
399  return *this;
400 }
401 //*************************************************************************************************
402 
403 
404 
405 
406 //=================================================================================================
407 //
408 // ACCESS OPERATORS
409 //
410 //=================================================================================================
411 
412 //*************************************************************************************************
417 template< typename MT > // Type of the adapted matrix
419 {
420  return this;
421 }
422 //*************************************************************************************************
423 
424 
425 //*************************************************************************************************
430 template< typename MT > // Type of the adapted matrix
432 {
433  return this;
434 }
435 //*************************************************************************************************
436 
437 
438 
439 
440 //=================================================================================================
441 //
442 // UTILITY FUNCTIONS
443 //
444 //=================================================================================================
445 
446 //*************************************************************************************************
453 template< typename MT > // Type of the adapted matrix
454 inline void NumericProxy<MT>::reset() const
455 {
456  using blaze::reset;
457 
458  reset( matrix_(row_,column_) );
459  if( row_ != column_ )
460  reset( matrix_(column_,row_) );
461 }
462 //*************************************************************************************************
463 
464 
465 //*************************************************************************************************
472 template< typename MT > // Type of the adapted matrix
473 inline void NumericProxy<MT>::clear() const
474 {
475  using blaze::clear;
476 
477  clear( matrix_(row_,column_) );
478  if( row_ != column_ )
479  clear( matrix_(column_,row_) );
480 }
481 //*************************************************************************************************
482 
483 
484 //*************************************************************************************************
489 template< typename MT > // Type of the adapted matrix
490 inline void NumericProxy<MT>::invert() const
491 {
492  using blaze::invert;
493 
494  invert( matrix_(row_,column_) );
495  if( row_ != column_ )
496  matrix_(column_,row_) = matrix_(row_,column_);
497 }
498 //*************************************************************************************************
499 
500 
501 //*************************************************************************************************
506 template< typename MT > // Type of the adapted matrix
508 {
509  return const_cast<const MT&>( matrix_ )(row_,column_);
510 }
511 //*************************************************************************************************
512 
513 
514 
515 
516 //=================================================================================================
517 //
518 // CONVERSION OPERATOR
519 //
520 //=================================================================================================
521 
522 //*************************************************************************************************
527 template< typename MT > // Type of the adapted matrix
529 {
530  return get();
531 }
532 //*************************************************************************************************
533 
534 
535 
536 
537 //=================================================================================================
538 //
539 // COMPLEX DATA ACCESS FUNCTIONS
540 //
541 //=================================================================================================
542 
543 //*************************************************************************************************
551 template< typename MT > // Type of the adapted matrix
553 {
554  return matrix_(row_,column_).real();
555 }
556 //*************************************************************************************************
557 
558 
559 //*************************************************************************************************
567 template< typename MT > // Type of the adapted matrix
568 inline void NumericProxy<MT>::real( ValueType value ) const
569 {
570  matrix_(row_,column_).real( value );
571  if( row_ != column_ )
572  matrix_(column_,row_).real( value );
573 }
574 //*************************************************************************************************
575 
576 
577 //*************************************************************************************************
585 template< typename MT > // Type of the adapted matrix
587 {
588  return matrix_(row_,column_).imag();
589 }
590 //*************************************************************************************************
591 
592 
593 //*************************************************************************************************
602 template< typename MT > // Type of the adapted matrix
603 inline void NumericProxy<MT>::imag( ValueType value ) const
604 {
605  matrix_(row_,column_).imag( value );
606  if( row_ != column_ )
607  matrix_(column_,row_).imag( value );
608 }
609 //*************************************************************************************************
610 
611 
612 
613 
614 //=================================================================================================
615 //
616 // GLOBAL FUNCTIONS
617 //
618 //=================================================================================================
619 
620 //*************************************************************************************************
623 template< typename MT >
624 void reset( const NumericProxy<MT>& proxy );
625 
626 template< typename MT >
627 void clear( const NumericProxy<MT>& proxy );
628 
629 template< typename MT >
630 void invert( const NumericProxy<MT>& proxy );
631 
632 template< bool RF, typename MT >
633 bool isDefault( const NumericProxy<MT>& proxy );
634 
635 template< bool RF, typename MT >
636 bool isReal( const NumericProxy<MT>& proxy );
637 
638 template< bool RF, typename MT >
639 bool isZero( const NumericProxy<MT>& proxy );
640 
641 template< bool RF, typename MT >
642 bool isOne( const NumericProxy<MT>& proxy );
643 
644 template< typename MT >
645 bool isnan( const NumericProxy<MT>& proxy );
647 //*************************************************************************************************
648 
649 
650 //*************************************************************************************************
660 template< typename MT >
661 inline void reset( const NumericProxy<MT>& proxy )
662 {
663  proxy.reset();
664 }
665 //*************************************************************************************************
666 
667 
668 //*************************************************************************************************
678 template< typename MT >
679 inline void clear( const NumericProxy<MT>& proxy )
680 {
681  proxy.clear();
682 }
683 //*************************************************************************************************
684 
685 
686 //*************************************************************************************************
693 template< typename MT >
694 inline void invert( const NumericProxy<MT>& proxy )
695 {
696  proxy.invert();
697 }
698 //*************************************************************************************************
699 
700 
701 //*************************************************************************************************
711 template< bool RF, typename MT >
712 inline bool isDefault( const NumericProxy<MT>& proxy )
713 {
714  using blaze::isDefault;
715 
716  return isDefault<RF>( proxy.get() );
717 }
718 //*************************************************************************************************
719 
720 
721 //*************************************************************************************************
733 template< bool RF, typename MT >
734 inline bool isReal( const NumericProxy<MT>& proxy )
735 {
736  using blaze::isReal;
737 
738  return isReal<RF>( proxy.get() );
739 }
740 //*************************************************************************************************
741 
742 
743 //*************************************************************************************************
753 template< bool RF, typename MT >
754 inline bool isZero( const NumericProxy<MT>& proxy )
755 {
756  using blaze::isZero;
757 
758  return isZero<RF>( proxy.get() );
759 }
760 //*************************************************************************************************
761 
762 
763 //*************************************************************************************************
773 template< bool RF, typename MT >
774 inline bool isOne( const NumericProxy<MT>& proxy )
775 {
776  using blaze::isOne;
777 
778  return isOne<RF>( proxy.get() );
779 }
780 //*************************************************************************************************
781 
782 
783 //*************************************************************************************************
793 template< typename MT >
794 inline bool isnan( const NumericProxy<MT>& proxy )
795 {
796  using blaze::isnan;
797 
798  return isnan( proxy.get() );
799 }
800 //*************************************************************************************************
801 
802 } // namespace blaze
803 
804 #endif
bool isReal(const DiagonalProxy< MT > &proxy)
Returns whether the matrix element represents a real number.
Definition: DiagonalProxy.h:653
Header file for the isnan shim.
#define BLAZE_CONSTRAINT_MUST_NOT_BE_CONST(T)
Constraint on the data type.In case the given data type is a const-qualified type, a compilation error is created.
Definition: Const.h:79
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.
size_t row_
Row index of the accessed matrix element.
Definition: NumericProxy.h:203
Header file for basic type definitions.
typename If< Condition, T1, T2 >::Type If_t
Auxiliary alias declaration for the If class template.The If_t alias declaration provides a convenien...
Definition: If.h:109
Proxy base class.The Proxy class is a base class for all proxy classes within the Blaze library that ...
Definition: Forward.h:51
typename T::Reference Reference_t
Alias declaration for nested Reference type definitions.The Reference_t alias declaration provides a ...
Definition: Aliases.h:330
Header file for the isZero shim.
Constraint on the data type.
void reset(const DiagonalProxy< MT > &proxy)
Resetting the represented element to the default initial values.
Definition: DiagonalProxy.h:591
ElementType_t< MT > RepresentedType
Type of the represented matrix element.
Definition: NumericProxy.h:122
MT & matrix_
Reference to the adapted matrix.
Definition: NumericProxy.h:202
const Type & ConstReference
Reference to a constant matrix value.
Definition: CompressedMatrix.h:3084
#define BLAZE_CONSTRAINT_MUST_NOT_BE_VOLATILE(T)
Constraint on the data type.In case the given data type is a volatile-qualified type, a compilation error is created.
Definition: Volatile.h:79
Header file for the invert shim.
Header file for the reset shim.
void invert() const
In-place inversion of the represented element.
Definition: NumericProxy.h:490
ConstReference get() const noexcept
Returning the value of the accessed matrix element.
Definition: NumericProxy.h:507
void clear() const
Clearing the represented element.
Definition: NumericProxy.h:473
Constraint on the data type.
ValueType real() const
Returns the real part of the represented complex number.
Definition: NumericProxy.h:552
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.
typename If_t< IsComplex_v< RepresentedType >, ComplexType< RepresentedType >, BuiltinType< RepresentedType > >::Type ValueType
Value type of the represented complex element.
Definition: NumericProxy.h:131
bool isZero(const DiagonalProxy< MT > &proxy)
Returns whether the represented element is 0.
Definition: DiagonalProxy.h:673
void invert(const HermitianProxy< MT > &proxy)
In-place inversion of the represented element.
Definition: HermitianProxy.h:775
Namespace of the Blaze C++ math library.
Definition: Blaze.h:58
Reference_t< MT > Reference
Reference to the represented element.
Definition: NumericProxy.h:123
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.
Access proxy for symmetric, square matrices with numeric element types.The NumericProxy provides cont...
Definition: NumericProxy.h:98
Constraint on the data type.
bool isnan(const DiagonalProxy< MT > &proxy)
Returns whether the represented element is not a number.
Definition: DiagonalProxy.h:713
#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
Pointer operator->()
Direct access to the represented matrix element.
Definition: NumericProxy.h:418
void clear(const DiagonalProxy< MT > &proxy)
Clearing the represented element.
Definition: DiagonalProxy.h:611
Header file for the isOne shim.
#define BLAZE_CONSTRAINT_MUST_NOT_BE_SYMMETRIC_MATRIX_TYPE(T)
Constraint on the data type.In case the given data type T is a symmetric matrix type, a compilation error is created.
Definition: Symmetric.h:79
Utility type for generic codes.
Constraint on the data type.
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
size_t column_
Column index of the accessed matrix element.
Definition: NumericProxy.h:204
#define BLAZE_CONSTRAINT_MUST_NOT_BE_LOWER_MATRIX_TYPE(T)
Constraint on the data type.In case the given data type T is a lower triangular matrix type...
Definition: Lower.h:81
#define BLAZE_CONSTRAINT_MUST_NOT_BE_REFERENCE_TYPE(T)
Constraint on the data type.In case the given data type T is not a reference type, a compilation error is created.
Definition: Reference.h:79
bool isOne(const DiagonalProxy< MT > &proxy)
Returns whether the represented element is 1.
Definition: DiagonalProxy.h:693
Header file for the isDefault shim.
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.
NumericProxy & operator=(const NumericProxy &sp)
Copy assignment operator for NumericProxy.
Definition: NumericProxy.h:280
void reset() const
Reset the represented element to its default initial value.
Definition: NumericProxy.h:454
#define BLAZE_CONSTRAINT_MUST_NOT_BE_EXPRESSION_TYPE(T)
Constraint on the data type.In case the given data type T is an expression (i.e. a type derived from ...
Definition: Expression.h:81
Header file for the IsComplex type trait.
bool isDefault(const DiagonalProxy< MT > &proxy)
Returns whether the represented element is in default state.
Definition: DiagonalProxy.h:631
#define BLAZE_CONSTRAINT_MUST_NOT_BE_HERMITIAN_MATRIX_TYPE(T)
Constraint on the data type.In case the given data type T is an Hermitian matrix type, a compilation error is created.
Definition: Hermitian.h:79
NumericProxy(MT &matrix, size_t row, size_t column)
Initialization constructor for a NumericProxy.
Definition: NumericProxy.h:243
#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
ValueType imag() const
Returns the imaginary part of the represented complex number.
Definition: NumericProxy.h:586
Header file for the isReal shim.
Header file for the clear shim.
ConstReference_t< MT > ConstReference
Reference-to-const to the represented element.
Definition: NumericProxy.h:124