Blaze  3.6
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>
52 #include <blaze/math/proxy/Proxy.h>
53 #include <blaze/math/shims/Clear.h>
56 #include <blaze/math/shims/IsNaN.h>
57 #include <blaze/math/shims/IsOne.h>
60 #include <blaze/math/shims/Reset.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 //*************************************************************************************************
99 template< typename MT > // Type of the adapted matrix
101  : public Proxy< NumericProxy<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 NumericProxy*;
129 
132  , ComplexType<RepresentedType>
133  , BuiltinType<RepresentedType> >::Type;
134  //**********************************************************************************************
135 
136  //**Constructors********************************************************************************
139  explicit inline NumericProxy( MT& matrix, size_t row, size_t column );
140  inline NumericProxy( const NumericProxy& np );
142  //**********************************************************************************************
143 
144  //**Destructor**********************************************************************************
147  ~NumericProxy() = default;
149  //**********************************************************************************************
150 
151  //**Assignment operators************************************************************************
154  inline NumericProxy& operator= ( const NumericProxy& sp );
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 );
159  template< typename T > inline NumericProxy& operator/=( const T& value );
160  template< typename T > inline NumericProxy& operator%=( const T& value );
162  //**********************************************************************************************
163 
164  //**Access operators****************************************************************************
167  inline Pointer operator->();
168  inline ConstPointer operator->() const;
170  //**********************************************************************************************
171 
172  //**Utility functions***************************************************************************
175  inline void reset () const;
176  inline void clear () const;
177  inline void invert() const;
178 
179  inline ConstReference get() const noexcept;
181  //**********************************************************************************************
182 
183  //**Conversion operator*************************************************************************
186  inline operator ConstReference() const noexcept;
188  //**********************************************************************************************
189 
190  //**Complex data access functions***************************************************************
193  inline ValueType real() const;
194  inline void real( ValueType value ) const;
195  inline ValueType imag() const;
196  inline void imag( ValueType value ) const;
198  //**********************************************************************************************
199 
200  private:
201  //**Member variables****************************************************************************
204  MT& matrix_;
205  size_t row_;
206  size_t column_;
207 
208  //**********************************************************************************************
209 
210  //**Compile time checks*************************************************************************
226  //**********************************************************************************************
227 };
228 //*************************************************************************************************
229 
230 
231 
232 
233 //=================================================================================================
234 //
235 // CONSTRUCTORS
236 //
237 //=================================================================================================
238 
239 //*************************************************************************************************
246 template< typename MT > // Type of the adapted matrix
247 inline NumericProxy<MT>::NumericProxy( MT& matrix, size_t row, size_t column )
248  : matrix_( matrix ) // Reference to the adapted matrix
249  , row_ ( row ) // Row index of the accessed matrix element
250  , column_( column ) // Column index of the accessed matrix element
251 {}
252 //*************************************************************************************************
253 
254 
255 //*************************************************************************************************
260 template< typename MT > // Type of the adapted matrix
262  : matrix_( np.matrix_ ) // Reference to the adapted matrix
263  , row_ ( np.row_ ) // Row index of the accessed matrix element
264  , column_( np.column_ ) // Column index of the accessed matrix element
265 {}
266 //*************************************************************************************************
267 
268 
269 
270 
271 //=================================================================================================
272 //
273 // OPERATORS
274 //
275 //=================================================================================================
276 
277 //*************************************************************************************************
283 template< typename MT > // Type of the adapted matrix
285 {
286  matrix_(row_,column_) = np.matrix_(np.row_,np.column_);
287  matrix_(column_,row_) = np.matrix_(np.row_,np.column_);
288 
289  return *this;
290 }
291 //*************************************************************************************************
292 
293 
294 //*************************************************************************************************
300 template< typename MT > // Type of the adapted matrix
301 template< typename T > // Type of the right-hand side value
303 {
304  matrix_(row_,column_) = value;
305  if( row_ != column_ )
306  matrix_(column_,row_) = value;
307 
308  return *this;
309 }
310 //*************************************************************************************************
311 
312 
313 //*************************************************************************************************
319 template< typename MT > // Type of the adapted matrix
320 template< typename T > // Type of the right-hand side value
322 {
323  matrix_(row_,column_) += value;
324  if( row_ != column_ )
325  matrix_(column_,row_) += value;
326 
327  return *this;
328 }
329 //*************************************************************************************************
330 
331 
332 //*************************************************************************************************
338 template< typename MT > // Type of the adapted matrix
339 template< typename T > // Type of the right-hand side value
341 {
342  matrix_(row_,column_) -= value;
343  if( row_ != column_ )
344  matrix_(column_,row_) -= value;
345 
346  return *this;
347 }
348 //*************************************************************************************************
349 
350 
351 //*************************************************************************************************
357 template< typename MT > // Type of the adapted matrix
358 template< typename T > // Type of the right-hand side value
360 {
361  matrix_(row_,column_) *= value;
362  if( row_ != column_ )
363  matrix_(column_,row_) *= value;
364 
365  return *this;
366 }
367 //*************************************************************************************************
368 
369 
370 //*************************************************************************************************
376 template< typename MT > // Type of the adapted matrix
377 template< typename T > // Type of the right-hand side value
379 {
380  matrix_(row_,column_) /= value;
381  if( row_ != column_ )
382  matrix_(column_,row_) /= value;
383 
384  return *this;
385 }
386 //*************************************************************************************************
387 
388 
389 //*************************************************************************************************
395 template< typename MT > // Type of the adapted matrix
396 template< typename T > // Type of the right-hand side value
398 {
399  matrix_(row_,column_) %= value;
400  if( row_ != column_ )
401  matrix_(column_,row_) %= value;
402 
403  return *this;
404 }
405 //*************************************************************************************************
406 
407 
408 
409 
410 //=================================================================================================
411 //
412 // ACCESS OPERATORS
413 //
414 //=================================================================================================
415 
416 //*************************************************************************************************
421 template< typename MT > // Type of the adapted matrix
423 {
424  return this;
425 }
426 //*************************************************************************************************
427 
428 
429 //*************************************************************************************************
434 template< typename MT > // Type of the adapted matrix
436 {
437  return this;
438 }
439 //*************************************************************************************************
440 
441 
442 
443 
444 //=================================================================================================
445 //
446 // UTILITY FUNCTIONS
447 //
448 //=================================================================================================
449 
450 //*************************************************************************************************
457 template< typename MT > // Type of the adapted matrix
458 inline void NumericProxy<MT>::reset() const
459 {
460  using blaze::reset;
461 
462  reset( matrix_(row_,column_) );
463  if( row_ != column_ )
464  reset( matrix_(column_,row_) );
465 }
466 //*************************************************************************************************
467 
468 
469 //*************************************************************************************************
476 template< typename MT > // Type of the adapted matrix
477 inline void NumericProxy<MT>::clear() const
478 {
479  using blaze::clear;
480 
481  clear( matrix_(row_,column_) );
482  if( row_ != column_ )
483  clear( matrix_(column_,row_) );
484 }
485 //*************************************************************************************************
486 
487 
488 //*************************************************************************************************
493 template< typename MT > // Type of the adapted matrix
494 inline void NumericProxy<MT>::invert() const
495 {
496  using blaze::invert;
497 
498  invert( matrix_(row_,column_) );
499  if( row_ != column_ )
500  matrix_(column_,row_) = matrix_(row_,column_);
501 }
502 //*************************************************************************************************
503 
504 
505 //*************************************************************************************************
510 template< typename MT > // Type of the adapted matrix
512 {
513  return const_cast<const MT&>( matrix_ )(row_,column_);
514 }
515 //*************************************************************************************************
516 
517 
518 
519 
520 //=================================================================================================
521 //
522 // CONVERSION OPERATOR
523 //
524 //=================================================================================================
525 
526 //*************************************************************************************************
531 template< typename MT > // Type of the adapted matrix
533 {
534  return get();
535 }
536 //*************************************************************************************************
537 
538 
539 
540 
541 //=================================================================================================
542 //
543 // COMPLEX DATA ACCESS FUNCTIONS
544 //
545 //=================================================================================================
546 
547 //*************************************************************************************************
555 template< typename MT > // Type of the adapted matrix
557 {
558  return matrix_(row_,column_).real();
559 }
560 //*************************************************************************************************
561 
562 
563 //*************************************************************************************************
571 template< typename MT > // Type of the adapted matrix
572 inline void NumericProxy<MT>::real( ValueType value ) const
573 {
574  matrix_(row_,column_).real( value );
575  if( row_ != column_ )
576  matrix_(column_,row_).real( value );
577 }
578 //*************************************************************************************************
579 
580 
581 //*************************************************************************************************
589 template< typename MT > // Type of the adapted matrix
591 {
592  return matrix_(row_,column_).imag();
593 }
594 //*************************************************************************************************
595 
596 
597 //*************************************************************************************************
606 template< typename MT > // Type of the adapted matrix
607 inline void NumericProxy<MT>::imag( ValueType value ) const
608 {
609  matrix_(row_,column_).imag( value );
610  if( row_ != column_ )
611  matrix_(column_,row_).imag( value );
612 }
613 //*************************************************************************************************
614 
615 
616 
617 
618 //=================================================================================================
619 //
620 // GLOBAL FUNCTIONS
621 //
622 //=================================================================================================
623 
624 //*************************************************************************************************
627 template< typename MT >
628 void reset( const NumericProxy<MT>& proxy );
629 
630 template< typename MT >
631 void clear( const NumericProxy<MT>& proxy );
632 
633 template< typename MT >
634 void invert( const NumericProxy<MT>& proxy );
635 
636 template< bool RF, typename MT >
637 bool isDefault( const NumericProxy<MT>& proxy );
638 
639 template< bool RF, typename MT >
640 bool isReal( const NumericProxy<MT>& proxy );
641 
642 template< bool RF, typename MT >
643 bool isZero( const NumericProxy<MT>& proxy );
644 
645 template< bool RF, typename MT >
646 bool isOne( const NumericProxy<MT>& proxy );
647 
648 template< typename MT >
649 bool isnan( const NumericProxy<MT>& proxy );
651 //*************************************************************************************************
652 
653 
654 //*************************************************************************************************
664 template< typename MT >
665 inline void reset( const NumericProxy<MT>& proxy )
666 {
667  proxy.reset();
668 }
669 //*************************************************************************************************
670 
671 
672 //*************************************************************************************************
682 template< typename MT >
683 inline void clear( const NumericProxy<MT>& proxy )
684 {
685  proxy.clear();
686 }
687 //*************************************************************************************************
688 
689 
690 //*************************************************************************************************
697 template< typename MT >
698 inline void invert( const NumericProxy<MT>& proxy )
699 {
700  proxy.invert();
701 }
702 //*************************************************************************************************
703 
704 
705 //*************************************************************************************************
715 template< bool RF, typename MT >
716 inline bool isDefault( const NumericProxy<MT>& proxy )
717 {
718  using blaze::isDefault;
719 
720  return isDefault<RF>( proxy.get() );
721 }
722 //*************************************************************************************************
723 
724 
725 //*************************************************************************************************
737 template< bool RF, typename MT >
738 inline bool isReal( const NumericProxy<MT>& proxy )
739 {
740  using blaze::isReal;
741 
742  return isReal<RF>( proxy.get() );
743 }
744 //*************************************************************************************************
745 
746 
747 //*************************************************************************************************
757 template< bool RF, typename MT >
758 inline bool isZero( const NumericProxy<MT>& proxy )
759 {
760  using blaze::isZero;
761 
762  return isZero<RF>( proxy.get() );
763 }
764 //*************************************************************************************************
765 
766 
767 //*************************************************************************************************
777 template< bool RF, typename MT >
778 inline bool isOne( const NumericProxy<MT>& proxy )
779 {
780  using blaze::isOne;
781 
782  return isOne<RF>( proxy.get() );
783 }
784 //*************************************************************************************************
785 
786 
787 //*************************************************************************************************
797 template< typename MT >
798 inline bool isnan( const NumericProxy<MT>& proxy )
799 {
800  using blaze::isnan;
801 
802  return isnan( proxy.get() );
803 }
804 //*************************************************************************************************
805 
806 } // namespace blaze
807 
808 #endif
bool isReal(const DiagonalProxy< MT > &proxy)
Returns whether the matrix element represents a real number.
Definition: DiagonalProxy.h:657
#define BLAZE_CONSTRAINT_MUST_NOT_BE_TRANSFORMATION_TYPE(T)
Constraint on the data type.In case the given data type T is a transformation expression (i....
Definition: Transformation.h:81
Header file for the isnan shim.
#define BLAZE_CONSTRAINT_MUST_NOT_BE_CONST(T)
Constraint on the data type.In case the given data type is a const-qualified type,...
Definition: Const.h:79
Constraint on the data type.
Header file for auxiliary alias declarations.
decltype(auto) column(Matrix< MT, SO > &matrix, RCAs... args)
Creating a view on a specific column of the given matrix.
Definition: Column.h:133
Constraint on the data type.
Constraint on the data type.
size_t row_
Row index of the accessed matrix element.
Definition: NumericProxy.h:205
Header file for basic type definitions.
typename If< Condition, T1, T2 >::Type If_t
Auxiliary alias template for the If class template.The If_t alias template provides a convenient shor...
Definition: If.h:109
Proxy base class.The Proxy class is a base class for all proxy classes within the Blaze library that ...
Definition: Forward.h:51
typename T::Reference Reference_t
Alias declaration for nested Reference type definitions.The Reference_t alias declaration provides a ...
Definition: Aliases.h:330
Header file for the isZero shim.
#define BLAZE_CONSTRAINT_MUST_NOT_BE_COMPUTATION_TYPE(T)
Constraint on the data type.In case the given data type T is a computational expression (i....
Definition: Computation.h:81
void reset(const DiagonalProxy< MT > &proxy)
Resetting the represented element to the default initial values.
Definition: DiagonalProxy.h:595
ElementType_t< MT > RepresentedType
Type of the represented matrix element.
Definition: NumericProxy.h:124
MT & matrix_
Reference to the adapted matrix.
Definition: NumericProxy.h:204
#define BLAZE_CONSTRAINT_MUST_NOT_BE_VOLATILE(T)
Constraint on the data type.In case the given data type is a volatile-qualified type,...
Definition: Volatile.h:79
Header file for the invert shim.
Header file for the reset shim.
void invert() const
In-place inversion of the represented element.
Definition: NumericProxy.h:494
ConstReference get() const noexcept
Returning the value of the accessed matrix element.
Definition: NumericProxy.h:511
void clear() const
Clearing the represented element.
Definition: NumericProxy.h:477
Constraint on the data type.
ValueType real() const
Returns the real part of the represented complex number.
Definition: NumericProxy.h:556
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:133
bool isZero(const DiagonalProxy< MT > &proxy)
Returns whether the represented element is 0.
Definition: DiagonalProxy.h:677
void invert(const HermitianProxy< MT > &proxy)
In-place inversion of the represented element.
Definition: HermitianProxy.h:779
Namespace of the Blaze C++ math library.
Definition: Blaze.h:58
Reference_t< MT > Reference
Reference to the represented element.
Definition: NumericProxy.h:125
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:100
Constraint on the data type.
bool isnan(const DiagonalProxy< MT > &proxy)
Returns whether the represented element is not a number.
Definition: DiagonalProxy.h:717
#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:422
void clear(const DiagonalProxy< MT > &proxy)
Clearing the represented element.
Definition: DiagonalProxy.h:615
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,...
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:206
#define BLAZE_CONSTRAINT_MUST_NOT_BE_LOWER_MATRIX_TYPE(T)
Constraint on the data type.In case the given data type T is a lower triangular matrix type,...
Definition: Lower.h:81
#define BLAZE_CONSTRAINT_MUST_NOT_BE_REFERENCE_TYPE(T)
Constraint on the data type.In case the given data type T is not a reference type,...
Definition: Reference.h:79
bool isOne(const DiagonalProxy< MT > &proxy)
Returns whether the represented element is 1.
Definition: DiagonalProxy.h:697
Header file for the isDefault shim.
Constraint on the data type.
typename T::ConstReference ConstReference_t
Alias declaration for nested ConstReference type definitions.The ConstReference_t alias declaration p...
Definition: Aliases.h:150
Constraint on the data type.
#define BLAZE_CONSTRAINT_MUST_NOT_BE_VIEW_TYPE(T)
Constraint on the data type.In case the given data type T is a view type (i.e. a subvector,...
Definition: View.h:81
NumericProxy & operator=(const NumericProxy &sp)
Copy assignment operator for NumericProxy.
Definition: NumericProxy.h:284
void reset() const
Reset the represented element to its default initial value.
Definition: NumericProxy.h:458
Header file for the IsComplex type trait.
bool isDefault(const DiagonalProxy< MT > &proxy)
Returns whether the represented element is in default state.
Definition: DiagonalProxy.h:635
#define BLAZE_CONSTRAINT_MUST_NOT_BE_HERMITIAN_MATRIX_TYPE(T)
Constraint on the data type.In case the given data type T is an Hermitian matrix type,...
Definition: Hermitian.h:79
NumericProxy(MT &matrix, size_t row, size_t column)
Initialization constructor for a NumericProxy.
Definition: NumericProxy.h:247
#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:590
Constraint on the data type.
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:126
constexpr Type & get(StaticVector< Type, N, TF > &v) noexcept
Tuple-like index-based access the contents of a static vector.
Definition: StaticVector.h:2704