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
98 class NumericProxy : public Proxy< NumericProxy<MT> >
99 {
100  private:
101  //**struct BuiltinType**************************************************************************
105  template< typename T >
106  struct BuiltinType { typedef INVALID_TYPE Type; };
108  //**********************************************************************************************
109 
110  //**struct ComplexType**************************************************************************
114  template< typename T >
115  struct ComplexType { typedef typename T::value_type Type; };
117  //**********************************************************************************************
118 
119  public:
120  //**Type definitions****************************************************************************
125  typedef const NumericProxy* ConstPointer;
126 
128  typedef typename If_< IsComplex<RepresentedType>
129  , ComplexType<RepresentedType>
130  , BuiltinType<RepresentedType> >::Type ValueType;
131  //**********************************************************************************************
132 
133  //**Constructors********************************************************************************
136  explicit inline NumericProxy( MT& matrix, size_t row, size_t column );
137  inline NumericProxy( const NumericProxy& np );
139  //**********************************************************************************************
140 
141  //**Destructor**********************************************************************************
142  // No explicitly declared destructor.
143  //**********************************************************************************************
144 
145  //**Assignment operators************************************************************************
148  inline NumericProxy& operator= ( const NumericProxy& sp );
149  template< typename T > inline NumericProxy& operator= ( const T& value );
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 );
155  //**********************************************************************************************
156 
157  //**Access operators****************************************************************************
160  inline Pointer operator->();
161  inline ConstPointer operator->() const;
163  //**********************************************************************************************
164 
165  //**Utility functions***************************************************************************
168  inline void reset () const;
169  inline void clear () const;
170  inline void invert() const;
171 
172  inline ConstReference get() const noexcept;
174  //**********************************************************************************************
175 
176  //**Conversion operator*************************************************************************
179  inline operator ConstReference() const noexcept;
181  //**********************************************************************************************
182 
183  //**Complex data access functions***************************************************************
186  inline ValueType real() const;
187  inline void real( ValueType value ) const;
188  inline ValueType imag() const;
189  inline void imag( ValueType value ) const;
191  //**********************************************************************************************
192 
193  private:
194  //**Member variables****************************************************************************
197  MT& matrix_;
198  size_t row_;
199  size_t column_;
200 
201  //**********************************************************************************************
202 
203  //**Compile time checks*************************************************************************
215  BLAZE_CONSTRAINT_MUST_BE_NUMERIC_TYPE ( RepresentedType );
217  //**********************************************************************************************
218 };
219 //*************************************************************************************************
220 
221 
222 
223 
224 //=================================================================================================
225 //
226 // CONSTRUCTORS
227 //
228 //=================================================================================================
229 
230 //*************************************************************************************************
237 template< typename MT > // Type of the adapted matrix
238 inline NumericProxy<MT>::NumericProxy( MT& matrix, size_t row, size_t column )
239  : matrix_( matrix ) // Reference to the adapted matrix
240  , row_ ( row ) // Row index of the accessed matrix element
241  , column_( column ) // Column index of the accessed matrix element
242 {}
243 //*************************************************************************************************
244 
245 
246 //*************************************************************************************************
251 template< typename MT > // Type of the adapted matrix
253  : matrix_( np.matrix_ ) // Reference to the adapted matrix
254  , row_ ( np.row_ ) // Row index of the accessed matrix element
255  , column_( np.column_ ) // Column index of the accessed matrix element
256 {}
257 //*************************************************************************************************
258 
259 
260 
261 
262 //=================================================================================================
263 //
264 // OPERATORS
265 //
266 //=================================================================================================
267 
268 //*************************************************************************************************
274 template< typename MT > // Type of the adapted matrix
276 {
277  matrix_(row_,column_) = np.matrix_(np.row_,np.column_);
278  matrix_(column_,row_) = np.matrix_(np.row_,np.column_);
279 
280  return *this;
281 }
282 //*************************************************************************************************
283 
284 
285 //*************************************************************************************************
291 template< typename MT > // Type of the adapted matrix
292 template< typename T > // Type of the right-hand side value
294 {
295  matrix_(row_,column_) = value;
296  if( row_ != column_ )
297  matrix_(column_,row_) = value;
298 
299  return *this;
300 }
301 //*************************************************************************************************
302 
303 
304 //*************************************************************************************************
310 template< typename MT > // Type of the adapted matrix
311 template< typename T > // Type of the right-hand side value
313 {
314  matrix_(row_,column_) += value;
315  if( row_ != column_ )
316  matrix_(column_,row_) += value;
317 
318  return *this;
319 }
320 //*************************************************************************************************
321 
322 
323 //*************************************************************************************************
329 template< typename MT > // Type of the adapted matrix
330 template< typename T > // Type of the right-hand side value
332 {
333  matrix_(row_,column_) -= value;
334  if( row_ != column_ )
335  matrix_(column_,row_) -= value;
336 
337  return *this;
338 }
339 //*************************************************************************************************
340 
341 
342 //*************************************************************************************************
348 template< typename MT > // Type of the adapted matrix
349 template< typename T > // Type of the right-hand side value
351 {
352  matrix_(row_,column_) *= value;
353  if( row_ != column_ )
354  matrix_(column_,row_) *= value;
355 
356  return *this;
357 }
358 //*************************************************************************************************
359 
360 
361 //*************************************************************************************************
367 template< typename MT > // Type of the adapted matrix
368 template< typename T > // Type of the right-hand side value
370 {
371  matrix_(row_,column_) /= value;
372  if( row_ != column_ )
373  matrix_(column_,row_) /= value;
374 
375  return *this;
376 }
377 //*************************************************************************************************
378 
379 
380 
381 
382 //=================================================================================================
383 //
384 // ACCESS OPERATORS
385 //
386 //=================================================================================================
387 
388 //*************************************************************************************************
393 template< typename MT > // Type of the adapted matrix
395 {
396  return this;
397 }
398 //*************************************************************************************************
399 
400 
401 //*************************************************************************************************
406 template< typename MT > // Type of the adapted matrix
408 {
409  return this;
410 }
411 //*************************************************************************************************
412 
413 
414 
415 
416 //=================================================================================================
417 //
418 // UTILITY FUNCTIONS
419 //
420 //=================================================================================================
421 
422 //*************************************************************************************************
429 template< typename MT > // Type of the adapted matrix
430 inline void NumericProxy<MT>::reset() const
431 {
432  using blaze::reset;
433 
434  reset( matrix_(row_,column_) );
435  if( row_ != column_ )
436  reset( matrix_(column_,row_) );
437 }
438 //*************************************************************************************************
439 
440 
441 //*************************************************************************************************
448 template< typename MT > // Type of the adapted matrix
449 inline void NumericProxy<MT>::clear() const
450 {
451  using blaze::clear;
452 
453  clear( matrix_(row_,column_) );
454  if( row_ != column_ )
455  clear( matrix_(column_,row_) );
456 }
457 //*************************************************************************************************
458 
459 
460 //*************************************************************************************************
465 template< typename MT > // Type of the adapted matrix
466 inline void NumericProxy<MT>::invert() const
467 {
468  using blaze::invert;
469 
470  invert( matrix_(row_,column_) );
471  if( row_ != column_ )
472  matrix_(column_,row_) = matrix_(row_,column_);
473 }
474 //*************************************************************************************************
475 
476 
477 //*************************************************************************************************
482 template< typename MT > // Type of the adapted matrix
484 {
485  return const_cast<const MT&>( matrix_ )(row_,column_);
486 }
487 //*************************************************************************************************
488 
489 
490 
491 
492 //=================================================================================================
493 //
494 // CONVERSION OPERATOR
495 //
496 //=================================================================================================
497 
498 //*************************************************************************************************
503 template< typename MT > // Type of the adapted matrix
505 {
506  return get();
507 }
508 //*************************************************************************************************
509 
510 
511 
512 
513 //=================================================================================================
514 //
515 // COMPLEX DATA ACCESS FUNCTIONS
516 //
517 //=================================================================================================
518 
519 //*************************************************************************************************
527 template< typename MT > // Type of the adapted matrix
529 {
530  return matrix_(row_,column_).real();
531 }
532 //*************************************************************************************************
533 
534 
535 //*************************************************************************************************
543 template< typename MT > // Type of the adapted matrix
544 inline void NumericProxy<MT>::real( ValueType value ) const
545 {
546  matrix_(row_,column_).real( value );
547  if( row_ != column_ )
548  matrix_(column_,row_).real( value );
549 }
550 //*************************************************************************************************
551 
552 
553 //*************************************************************************************************
561 template< typename MT > // Type of the adapted matrix
563 {
564  return matrix_(row_,column_).imag();
565 }
566 //*************************************************************************************************
567 
568 
569 //*************************************************************************************************
578 template< typename MT > // Type of the adapted matrix
579 inline void NumericProxy<MT>::imag( ValueType value ) const
580 {
581  matrix_(row_,column_).imag( value );
582  if( row_ != column_ )
583  matrix_(column_,row_).imag( value );
584 }
585 //*************************************************************************************************
586 
587 
588 
589 
590 //=================================================================================================
591 //
592 // GLOBAL FUNCTIONS
593 //
594 //=================================================================================================
595 
596 //*************************************************************************************************
599 template< typename MT >
600 inline void reset( const NumericProxy<MT>& proxy );
601 
602 template< typename MT >
603 inline void clear( const NumericProxy<MT>& proxy );
604 
605 template< typename MT >
606 inline void invert( const NumericProxy<MT>& proxy );
607 
608 template< typename MT >
609 inline bool isDefault( const NumericProxy<MT>& proxy );
610 
611 template< typename MT >
612 inline bool isReal( const NumericProxy<MT>& proxy );
613 
614 template< typename MT >
615 inline bool isZero( const NumericProxy<MT>& proxy );
616 
617 template< typename MT >
618 inline bool isOne( const NumericProxy<MT>& proxy );
619 
620 template< typename MT >
621 inline bool isnan( const NumericProxy<MT>& proxy );
623 //*************************************************************************************************
624 
625 
626 //*************************************************************************************************
636 template< typename MT >
637 inline void reset( const NumericProxy<MT>& proxy )
638 {
639  proxy.reset();
640 }
641 //*************************************************************************************************
642 
643 
644 //*************************************************************************************************
654 template< typename MT >
655 inline void clear( const NumericProxy<MT>& proxy )
656 {
657  proxy.clear();
658 }
659 //*************************************************************************************************
660 
661 
662 //*************************************************************************************************
669 template< typename MT >
670 inline void invert( const NumericProxy<MT>& proxy )
671 {
672  proxy.invert();
673 }
674 //*************************************************************************************************
675 
676 
677 //*************************************************************************************************
687 template< typename MT >
688 inline bool isDefault( const NumericProxy<MT>& proxy )
689 {
690  using blaze::isDefault;
691 
692  return isDefault( proxy.get() );
693 }
694 //*************************************************************************************************
695 
696 
697 //*************************************************************************************************
709 template< typename MT >
710 inline bool isReal( const NumericProxy<MT>& proxy )
711 {
712  using blaze::isReal;
713 
714  return isReal( proxy.get() );
715 }
716 //*************************************************************************************************
717 
718 
719 //*************************************************************************************************
729 template< typename MT >
730 inline bool isZero( const NumericProxy<MT>& proxy )
731 {
732  using blaze::isZero;
733 
734  return isZero( proxy.get() );
735 }
736 //*************************************************************************************************
737 
738 
739 //*************************************************************************************************
749 template< typename MT >
750 inline bool isOne( const NumericProxy<MT>& proxy )
751 {
752  using blaze::isOne;
753 
754  return isOne( proxy.get() );
755 }
756 //*************************************************************************************************
757 
758 
759 //*************************************************************************************************
769 template< typename MT >
770 inline bool isnan( const NumericProxy<MT>& proxy )
771 {
772  using blaze::isnan;
773 
774  return isnan( proxy.get() );
775 }
776 //*************************************************************************************************
777 
778 } // namespace blaze
779 
780 #endif
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
bool isOne(const DiagonalProxy< MT > &proxy)
Returns whether the represented element is 1.
Definition: DiagonalProxy.h:635
Header file for auxiliary alias declarations.
Constraint on the data type.
size_t row_
Row index of the accessed matrix element.
Definition: NumericProxy.h:198
Header file for basic type definitions.
ElementType_< MT > RepresentedType
Type of the represented matrix element.
Definition: NumericProxy.h:121
Proxy base class.The Proxy class is a base class for all proxy classes within the Blaze library that ...
Definition: Forward.h:51
bool isReal(const DiagonalProxy< MT > &proxy)
Returns whether the matrix element represents a real number.
Definition: DiagonalProxy.h:595
NumericProxy * Pointer
Pointer to the represented element.
Definition: NumericProxy.h:124
Constraint on the data type.
If_< IsComplex< RepresentedType >, ComplexType< RepresentedType >, BuiltinType< RepresentedType > >::Type ValueType
Value type of the represented complex element.
Definition: NumericProxy.h:130
void reset(const DiagonalProxy< MT > &proxy)
Resetting the represented element to the default initial values.
Definition: DiagonalProxy.h:533
MT & matrix_
Reference to the adapted matrix.
Definition: NumericProxy.h:197
#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.
ValueType imag() const
Returns the imaginary part of the represented complex number.
Definition: NumericProxy.h:562
Constraint on the data type.
void reset() const
Reset the represented element to its default initial value.
Definition: NumericProxy.h:430
DisableIf_< Or< IsComputation< MT >, IsTransExpr< MT > >, ColumnExprTrait_< MT > > column(Matrix< MT, SO > &matrix, size_t index)
Creating a view on a specific column of the given matrix.
Definition: Column.h:126
Header file for the Proxy class.
bool isDefault(const DiagonalProxy< MT > &proxy)
Returns whether the represented element is in default state.
Definition: DiagonalProxy.h:573
Constraint on the data type.
Constraint on the data type.
void invert(const HermitianProxy< MT > &proxy)
In-place inversion of the represented element.
Definition: HermitianProxy.h:741
Header file for the clear shim.
Namespace of the Blaze C++ math library.
Definition: Blaze.h:57
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
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
ValueType real() const
Returns the real part of the represented complex number.
Definition: NumericProxy.h:528
Constraint on the data type.
void invert() const
In-place inversion of the represented element.
Definition: NumericProxy.h:466
bool isnan(const DiagonalProxy< MT > &proxy)
Returns whether the represented element is not a number.
Definition: DiagonalProxy.h:655
#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:394
const Type & ConstReference
Reference to a constant matrix value.
Definition: CompressedMatrix.h:2645
ConstReference get() const noexcept
Returning the value of the accessed matrix element.
Definition: NumericProxy.h:483
typename T::Reference Reference_
Alias declaration for nested Reference type definitions.The Reference_ alias declaration provides a c...
Definition: Aliases.h:283
void clear(const DiagonalProxy< MT > &proxy)
Clearing the represented element.
Definition: DiagonalProxy.h:553
Header file for the isOne shim.
DisableIf_< Or< IsComputation< MT >, IsTransExpr< MT > >, RowExprTrait_< MT > > row(Matrix< MT, SO > &matrix, size_t index)
Creating a view on a specific row of the given matrix.
Definition: Row.h:126
#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.
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:160
#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:199
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
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:275
typename T::ConstReference ConstReference_
Alias declaration for nested ConstReference type definitions.The ConstReference_ alias declaration pr...
Definition: Aliases.h:143
const NumericProxy * ConstPointer
Pointer-to-const to the represented element.
Definition: NumericProxy.h:125
#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
bool isZero(const DiagonalProxy< MT > &proxy)
Returns whether the represented element is 0.
Definition: DiagonalProxy.h:615
Header file for the IsComplex type trait.
#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:238
ConstReference_< MT > ConstReference
Reference-to-const to the represented element.
Definition: NumericProxy.h:123
#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
void clear() const
Clearing the represented element.
Definition: NumericProxy.h:449
Header file for the isReal shim.
Reference_< MT > Reference
Reference to the represented element.
Definition: NumericProxy.h:122