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**********************************************************************************
143  // No explicitly declared destructor.
144  //**********************************************************************************************
145 
146  //**Assignment operators************************************************************************
149  inline NumericProxy& operator= ( const NumericProxy& sp );
150  template< typename T > inline NumericProxy& operator= ( const T& value );
151  template< typename T > inline NumericProxy& operator+=( const T& value );
152  template< typename T > inline NumericProxy& operator-=( const T& value );
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 );
157  //**********************************************************************************************
158 
159  //**Access operators****************************************************************************
162  inline Pointer operator->();
163  inline ConstPointer operator->() const;
165  //**********************************************************************************************
166 
167  //**Utility functions***************************************************************************
170  inline void reset () const;
171  inline void clear () const;
172  inline void invert() const;
173 
174  inline ConstReference get() const noexcept;
176  //**********************************************************************************************
177 
178  //**Conversion operator*************************************************************************
181  inline operator ConstReference() const noexcept;
183  //**********************************************************************************************
184 
185  //**Complex data access functions***************************************************************
188  inline ValueType real() const;
189  inline void real( ValueType value ) const;
190  inline ValueType imag() const;
191  inline void imag( ValueType value ) const;
193  //**********************************************************************************************
194 
195  private:
196  //**Member variables****************************************************************************
199  MT& matrix_;
200  size_t row_;
201  size_t column_;
202 
203  //**********************************************************************************************
204 
205  //**Compile time checks*************************************************************************
219  //**********************************************************************************************
220 };
221 //*************************************************************************************************
222 
223 
224 
225 
226 //=================================================================================================
227 //
228 // CONSTRUCTORS
229 //
230 //=================================================================================================
231 
232 //*************************************************************************************************
239 template< typename MT > // Type of the adapted matrix
240 inline NumericProxy<MT>::NumericProxy( MT& matrix, size_t row, size_t column )
241  : matrix_( matrix ) // Reference to the adapted matrix
242  , row_ ( row ) // Row index of the accessed matrix element
243  , column_( column ) // Column index of the accessed matrix element
244 {}
245 //*************************************************************************************************
246 
247 
248 //*************************************************************************************************
253 template< typename MT > // Type of the adapted matrix
255  : matrix_( np.matrix_ ) // Reference to the adapted matrix
256  , row_ ( np.row_ ) // Row index of the accessed matrix element
257  , column_( np.column_ ) // Column index of the accessed matrix element
258 {}
259 //*************************************************************************************************
260 
261 
262 
263 
264 //=================================================================================================
265 //
266 // OPERATORS
267 //
268 //=================================================================================================
269 
270 //*************************************************************************************************
276 template< typename MT > // Type of the adapted matrix
278 {
279  matrix_(row_,column_) = np.matrix_(np.row_,np.column_);
280  matrix_(column_,row_) = np.matrix_(np.row_,np.column_);
281 
282  return *this;
283 }
284 //*************************************************************************************************
285 
286 
287 //*************************************************************************************************
293 template< typename MT > // Type of the adapted matrix
294 template< typename T > // Type of the right-hand side value
296 {
297  matrix_(row_,column_) = value;
298  if( row_ != column_ )
299  matrix_(column_,row_) = value;
300 
301  return *this;
302 }
303 //*************************************************************************************************
304 
305 
306 //*************************************************************************************************
312 template< typename MT > // Type of the adapted matrix
313 template< typename T > // Type of the right-hand side value
315 {
316  matrix_(row_,column_) += value;
317  if( row_ != column_ )
318  matrix_(column_,row_) += value;
319 
320  return *this;
321 }
322 //*************************************************************************************************
323 
324 
325 //*************************************************************************************************
331 template< typename MT > // Type of the adapted matrix
332 template< 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 //*************************************************************************************************
350 template< typename MT > // Type of the adapted matrix
351 template< 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 //*************************************************************************************************
369 template< typename MT > // Type of the adapted matrix
370 template< 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 //*************************************************************************************************
388 template< typename MT > // Type of the adapted matrix
389 template< 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 
402 
403 //=================================================================================================
404 //
405 // ACCESS OPERATORS
406 //
407 //=================================================================================================
408 
409 //*************************************************************************************************
414 template< typename MT > // Type of the adapted matrix
416 {
417  return this;
418 }
419 //*************************************************************************************************
420 
421 
422 //*************************************************************************************************
427 template< typename MT > // Type of the adapted matrix
429 {
430  return this;
431 }
432 //*************************************************************************************************
433 
434 
435 
436 
437 //=================================================================================================
438 //
439 // UTILITY FUNCTIONS
440 //
441 //=================================================================================================
442 
443 //*************************************************************************************************
450 template< typename MT > // Type of the adapted matrix
451 inline void NumericProxy<MT>::reset() const
452 {
453  using blaze::reset;
454 
456  if( row_ != column_ )
458 }
459 //*************************************************************************************************
460 
461 
462 //*************************************************************************************************
469 template< typename MT > // Type of the adapted matrix
470 inline void NumericProxy<MT>::clear() const
471 {
472  using blaze::clear;
473 
475  if( row_ != column_ )
477 }
478 //*************************************************************************************************
479 
480 
481 //*************************************************************************************************
486 template< typename MT > // Type of the adapted matrix
487 inline void NumericProxy<MT>::invert() const
488 {
489  using blaze::invert;
490 
492  if( row_ != column_ )
494 }
495 //*************************************************************************************************
496 
497 
498 //*************************************************************************************************
503 template< 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 //*************************************************************************************************
524 template< 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 //*************************************************************************************************
548 template< typename MT > // Type of the adapted matrix
550 {
551  return matrix_(row_,column_).real();
552 }
553 //*************************************************************************************************
554 
555 
556 //*************************************************************************************************
564 template< typename MT > // Type of the adapted matrix
565 inline void NumericProxy<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 //*************************************************************************************************
582 template< typename MT > // Type of the adapted matrix
584 {
585  return matrix_(row_,column_).imag();
586 }
587 //*************************************************************************************************
588 
589 
590 //*************************************************************************************************
599 template< typename MT > // Type of the adapted matrix
600 inline void NumericProxy<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 //*************************************************************************************************
620 template< typename MT >
621 inline void reset( const NumericProxy<MT>& proxy );
622 
623 template< typename MT >
624 inline void clear( const NumericProxy<MT>& proxy );
625 
626 template< typename MT >
627 inline void invert( const NumericProxy<MT>& proxy );
628 
629 template< bool RF, typename MT >
630 inline bool isDefault( const NumericProxy<MT>& proxy );
631 
632 template< bool RF, typename MT >
633 inline bool isReal( const NumericProxy<MT>& proxy );
634 
635 template< bool RF, typename MT >
636 inline bool isZero( const NumericProxy<MT>& proxy );
637 
638 template< bool RF, typename MT >
639 inline bool isOne( const NumericProxy<MT>& proxy );
640 
641 template< typename MT >
642 inline bool isnan( const NumericProxy<MT>& proxy );
644 //*************************************************************************************************
645 
646 
647 //*************************************************************************************************
657 template< typename MT >
658 inline void reset( const NumericProxy<MT>& proxy )
659 {
660  proxy.reset();
661 }
662 //*************************************************************************************************
663 
664 
665 //*************************************************************************************************
675 template< typename MT >
676 inline void clear( const NumericProxy<MT>& proxy )
677 {
678  proxy.clear();
679 }
680 //*************************************************************************************************
681 
682 
683 //*************************************************************************************************
690 template< typename MT >
691 inline void invert( const NumericProxy<MT>& proxy )
692 {
693  proxy.invert();
694 }
695 //*************************************************************************************************
696 
697 
698 //*************************************************************************************************
708 template< bool RF, typename MT >
709 inline bool isDefault( const NumericProxy<MT>& proxy )
710 {
711  using blaze::isDefault;
712 
713  return isDefault<RF>( proxy.get() );
714 }
715 //*************************************************************************************************
716 
717 
718 //*************************************************************************************************
730 template< bool RF, typename MT >
731 inline bool isReal( const NumericProxy<MT>& proxy )
732 {
733  using blaze::isReal;
734 
735  return isReal<RF>( proxy.get() );
736 }
737 //*************************************************************************************************
738 
739 
740 //*************************************************************************************************
750 template< bool RF, typename MT >
751 inline bool isZero( const NumericProxy<MT>& proxy )
752 {
753  using blaze::isZero;
754 
755  return isZero<RF>( proxy.get() );
756 }
757 //*************************************************************************************************
758 
759 
760 //*************************************************************************************************
770 template< bool RF, typename MT >
771 inline bool isOne( const NumericProxy<MT>& proxy )
772 {
773  using blaze::isOne;
774 
775  return isOne<RF>( proxy.get() );
776 }
777 //*************************************************************************************************
778 
779 
780 //*************************************************************************************************
790 template< typename MT >
791 inline bool isnan( const NumericProxy<MT>& proxy )
792 {
793  using blaze::isnan;
794 
795  return isnan( proxy.get() );
796 }
797 //*************************************************************************************************
798 
799 } // namespace blaze
800 
801 #endif
bool isReal(const DiagonalProxy< MT > &proxy)
Returns whether the matrix element represents a real number.
Definition: DiagonalProxy.h:650
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:131
Constraint on the data type.
ConstReference_< MT > ConstReference
Reference-to-const to the represented element.
Definition: NumericProxy.h:124
size_t row_
Row index of the accessed matrix element.
Definition: NumericProxy.h:200
Header file for basic type definitions.
Proxy base class.The Proxy class is a base class for all proxy classes within the Blaze library that ...
Definition: Forward.h:51
Constraint on the data type.
void reset(const DiagonalProxy< MT > &proxy)
Resetting the represented element to the default initial values.
Definition: DiagonalProxy.h:588
MT & matrix_
Reference to the adapted matrix.
Definition: NumericProxy.h:199
#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.
void invert() const
In-place inversion of the represented element.
Definition: NumericProxy.h:487
ConstReference get() const noexcept
Returning the value of the accessed matrix element.
Definition: NumericProxy.h:504
void clear() const
Clearing the represented element.
Definition: NumericProxy.h:470
Constraint on the data type.
ValueType real() const
Returns the real part of the represented complex number.
Definition: NumericProxy.h:549
Header file for the Proxy class.
typename If_< IsComplex< RepresentedType >, ComplexType< RepresentedType >, BuiltinType< RepresentedType > >::Type ValueType
Value type of the represented complex element.
Definition: NumericProxy.h:131
Constraint on the data type.
Constraint on the data type.
bool isZero(const DiagonalProxy< MT > &proxy)
Returns whether the represented element is 0.
Definition: DiagonalProxy.h:670
void invert(const HermitianProxy< MT > &proxy)
In-place inversion of the represented element.
Definition: HermitianProxy.h:772
ElementType_< MT > RepresentedType
Type of the represented matrix element.
Definition: NumericProxy.h:122
Header file for the clear shim.
Namespace of the Blaze C++ math library.
Definition: Blaze.h:58
Header file for the If class template.
Reference_< MT > Reference
Reference to the represented element.
Definition: NumericProxy.h:123
#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
Header file for the isZero shim.
typename T::ElementType ElementType_
Alias declaration for nested ElementType type definitions.The ElementType_ alias declaration provides...
Definition: Aliases.h:163
Constraint on the data type.
bool isnan(const DiagonalProxy< MT > &proxy)
Returns whether the represented element is not a number.
Definition: DiagonalProxy.h:710
#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:415
typename T::Reference Reference_
Alias declaration for nested Reference type definitions.The Reference_ alias declaration provides a c...
Definition: Aliases.h:303
void clear(const DiagonalProxy< MT > &proxy)
Clearing the represented element.
Definition: DiagonalProxy.h:608
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
BLAZE_ALWAYS_INLINE T1 & operator+=(SIMDPack< T1 > &lhs, const SIMDPack< T2 > &rhs)
Addition assignment operator for the addition of two SIMD packs.
Definition: BasicTypes.h:1357
Utility type for generic codes.
Constraint on the data type.
Constraint on the data type.
typename If< T1, T2, T3 >::Type If_
Auxiliary alias declaration for the If class template.The If_ alias declaration provides a convenient...
Definition: If.h:154
decltype(auto) row(Matrix< MT, SO > &, RRAs...)
Creating a view on a specific row of the given matrix.
Definition: Row.h:131
#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:201
Header file for the reset shim.
#define BLAZE_CONSTRAINT_MUST_NOT_BE_LOWER_MATRIX_TYPE(T)
Constraint on the data type.In case the given data type T is a lower triangular matrix type...
Definition: Lower.h: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:690
Header file for the isDefault shim.
Constraint on the data type.
Constraint on the data type.
NumericProxy & operator=(const NumericProxy &sp)
Copy assignment operator for NumericProxy.
Definition: NumericProxy.h:277
typename T::ConstReference ConstReference_
Alias declaration for nested ConstReference type definitions.The ConstReference_ alias declaration pr...
Definition: Aliases.h:143
EnableIf_< IsNumeric< ST >, MT &> operator/=(DenseMatrix< MT, SO > &mat, ST scalar)
Division assignment operator for the division of a dense matrix by a scalar value ( )...
Definition: DenseMatrix.h:655
void reset() const
Reset the represented element to its default initial value.
Definition: NumericProxy.h:451
#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:628
#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:240
BLAZE_ALWAYS_INLINE T1 & operator-=(SIMDPack< T1 > &lhs, const SIMDPack< T2 > &rhs)
Subtraction assignment operator for the subtraction of two SIMD packs.
Definition: BasicTypes.h:1375
#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:583
EnableIf_< IsNumeric< ST >, MT &> operator*=(DenseMatrix< MT, SO > &mat, ST scalar)
Multiplication assignment operator for the multiplication of a dense matrix and a scalar value ( )...
Definition: DenseMatrix.h:593
Header file for the isReal shim.