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 
49 #include <blaze/math/proxy/Proxy.h>
50 #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>
65 #include <blaze/util/InvalidType.h>
66 #include <blaze/util/mpl/If.h>
67 #include <blaze/util/Types.h>
69 
70 
71 namespace blaze {
72 
73 //=================================================================================================
74 //
75 // CLASS DEFINITION
76 //
77 //=================================================================================================
78 
79 //*************************************************************************************************
98 template< typename MT > // Type of the adapted matrix
99 class NumericProxy : public Proxy< NumericProxy<MT> >
100 {
101  private:
102  //**struct BuiltinType**************************************************************************
106  template< typename T >
107  struct BuiltinType { typedef INVALID_TYPE Type; };
109  //**********************************************************************************************
110 
111  //**struct ComplexType**************************************************************************
115  template< typename T >
116  struct ComplexType { typedef typename T::value_type Type; };
118  //**********************************************************************************************
119 
120  public:
121  //**Type definitions****************************************************************************
122  typedef typename MT::ElementType RepresentedType;
123  typedef typename MT::Reference Reference;
126  typedef const NumericProxy* ConstPointer;
127 
129  typedef typename If< IsComplex<RepresentedType>
130  , ComplexType<RepresentedType>
131  , BuiltinType<RepresentedType> >::Type::Type ValueType;
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 );
156  //**********************************************************************************************
157 
158  //**Access operators****************************************************************************
161  inline Pointer operator->();
162  inline ConstPointer operator->() const;
164  //**********************************************************************************************
165 
166  //**Utility functions***************************************************************************
169  inline void reset () const;
170  inline void clear () const;
171  inline void invert() const;
172 
173  inline ConstReference get() const;
175  //**********************************************************************************************
176 
177  //**Conversion operator*************************************************************************
180  inline operator ConstReference() const;
182  //**********************************************************************************************
183 
184  //**Complex data access functions***************************************************************
187  inline ValueType real() const;
188  inline void real( ValueType value ) const;
189  inline ValueType imag() const;
190  inline void imag( ValueType value ) const;
192  //**********************************************************************************************
193 
194  private:
195  //**Member variables****************************************************************************
198  MT& matrix_;
199  size_t row_;
200  size_t column_;
201 
202  //**********************************************************************************************
203 
204  //**Compile time checks*************************************************************************
216  BLAZE_CONSTRAINT_MUST_BE_NUMERIC_TYPE ( RepresentedType );
218  //**********************************************************************************************
219 };
220 //*************************************************************************************************
221 
222 
223 
224 
225 //=================================================================================================
226 //
227 // CONSTRUCTORS
228 //
229 //=================================================================================================
230 
231 //*************************************************************************************************
238 template< typename MT > // Type of the adapted matrix
239 inline NumericProxy<MT>::NumericProxy( MT& matrix, size_t row, size_t column )
240  : matrix_( matrix ) // Reference to the adapted matrix
241  , row_ ( row ) // Row index of the accessed matrix element
242  , column_( column ) // Column index of the accessed matrix element
243 {}
244 //*************************************************************************************************
245 
246 
247 //*************************************************************************************************
252 template< typename MT > // Type of the adapted matrix
254  : matrix_( np.matrix_ ) // Reference to the adapted matrix
255  , row_ ( np.row_ ) // Row index of the accessed matrix element
256  , column_( np.column_ ) // Column index of the accessed matrix element
257 {}
258 //*************************************************************************************************
259 
260 
261 
262 
263 //=================================================================================================
264 //
265 // OPERATORS
266 //
267 //=================================================================================================
268 
269 //*************************************************************************************************
275 template< typename MT > // Type of the adapted matrix
277 {
278  matrix_(row_,column_) = np.matrix_(np.row_,np.column_);
279  matrix_(column_,row_) = np.matrix_(np.row_,np.column_);
280 
281  return *this;
282 }
283 //*************************************************************************************************
284 
285 
286 //*************************************************************************************************
292 template< typename MT > // Type of the adapted matrix
293 template< typename T > // Type of the right-hand side value
295 {
296  matrix_(row_,column_) = value;
297  if( row_ != column_ )
298  matrix_(column_,row_) = value;
299 
300  return *this;
301 }
302 //*************************************************************************************************
303 
304 
305 //*************************************************************************************************
311 template< typename MT > // Type of the adapted matrix
312 template< typename T > // Type of the right-hand side value
314 {
315  matrix_(row_,column_) += value;
316  if( row_ != column_ )
317  matrix_(column_,row_) += value;
318 
319  return *this;
320 }
321 //*************************************************************************************************
322 
323 
324 //*************************************************************************************************
330 template< typename MT > // Type of the adapted matrix
331 template< typename T > // Type of the right-hand side value
333 {
334  matrix_(row_,column_) -= value;
335  if( row_ != column_ )
336  matrix_(column_,row_) -= value;
337 
338  return *this;
339 }
340 //*************************************************************************************************
341 
342 
343 //*************************************************************************************************
349 template< typename MT > // Type of the adapted matrix
350 template< typename T > // Type of the right-hand side value
352 {
353  matrix_(row_,column_) *= value;
354  if( row_ != column_ )
355  matrix_(column_,row_) *= value;
356 
357  return *this;
358 }
359 //*************************************************************************************************
360 
361 
362 //*************************************************************************************************
368 template< typename MT > // Type of the adapted matrix
369 template< typename T > // Type of the right-hand side value
371 {
372  matrix_(row_,column_) /= value;
373  if( row_ != column_ )
374  matrix_(column_,row_) /= value;
375 
376  return *this;
377 }
378 //*************************************************************************************************
379 
380 
381 
382 
383 //=================================================================================================
384 //
385 // ACCESS OPERATORS
386 //
387 //=================================================================================================
388 
389 //*************************************************************************************************
394 template< typename MT > // Type of the adapted matrix
396 {
397  return this;
398 }
399 //*************************************************************************************************
400 
401 
402 //*************************************************************************************************
407 template< typename MT > // Type of the adapted matrix
409 {
410  return this;
411 }
412 //*************************************************************************************************
413 
414 
415 
416 
417 //=================================================================================================
418 //
419 // UTILITY FUNCTIONS
420 //
421 //=================================================================================================
422 
423 //*************************************************************************************************
430 template< typename MT > // Type of the adapted matrix
431 inline void NumericProxy<MT>::reset() const
432 {
433  using blaze::reset;
434 
435  reset( matrix_(row_,column_) );
436  if( row_ != column_ )
437  reset( matrix_(column_,row_) );
438 }
439 //*************************************************************************************************
440 
441 
442 //*************************************************************************************************
449 template< typename MT > // Type of the adapted matrix
450 inline void NumericProxy<MT>::clear() const
451 {
452  using blaze::clear;
453 
454  clear( matrix_(row_,column_) );
455  if( row_ != column_ )
456  clear( matrix_(column_,row_) );
457 }
458 //*************************************************************************************************
459 
460 
461 //*************************************************************************************************
466 template< typename MT > // Type of the adapted matrix
467 inline void NumericProxy<MT>::invert() const
468 {
469  using blaze::invert;
470 
471  invert( matrix_(row_,column_) );
472  if( row_ != column_ )
473  matrix_(column_,row_) = matrix_(row_,column_);
474 }
475 //*************************************************************************************************
476 
477 
478 //*************************************************************************************************
483 template< typename MT > // Type of the adapted matrix
485 {
486  return const_cast<const MT&>( matrix_ )(row_,column_);
487 }
488 //*************************************************************************************************
489 
490 
491 
492 
493 //=================================================================================================
494 //
495 // CONVERSION OPERATOR
496 //
497 //=================================================================================================
498 
499 //*************************************************************************************************
504 template< typename MT > // Type of the adapted matrix
506 {
507  return get();
508 }
509 //*************************************************************************************************
510 
511 
512 
513 
514 //=================================================================================================
515 //
516 // COMPLEX DATA ACCESS FUNCTIONS
517 //
518 //=================================================================================================
519 
520 //*************************************************************************************************
528 template< typename MT > // Type of the adapted matrix
530 {
531  return matrix_(row_,column_).real();
532 }
533 //*************************************************************************************************
534 
535 
536 //*************************************************************************************************
544 template< typename MT > // Type of the adapted matrix
545 inline void NumericProxy<MT>::real( ValueType value ) const
546 {
547  matrix_(row_,column_).real( value );
548  if( row_ != column_ )
549  matrix_(column_,row_).real( value );
550 }
551 //*************************************************************************************************
552 
553 
554 //*************************************************************************************************
562 template< typename MT > // Type of the adapted matrix
564 {
565  return matrix_(row_,column_).imag();
566 }
567 //*************************************************************************************************
568 
569 
570 //*************************************************************************************************
579 template< typename MT > // Type of the adapted matrix
580 inline void NumericProxy<MT>::imag( ValueType value ) const
581 {
582  matrix_(row_,column_).imag( value );
583  if( row_ != column_ )
584  matrix_(column_,row_).imag( value );
585 }
586 //*************************************************************************************************
587 
588 
589 
590 
591 //=================================================================================================
592 //
593 // GLOBAL FUNCTIONS
594 //
595 //=================================================================================================
596 
597 //*************************************************************************************************
600 template< typename MT >
602  conj( const NumericProxy<MT>& proxy );
603 
604 template< typename MT >
605 inline void reset( const NumericProxy<MT>& proxy );
606 
607 template< typename MT >
608 inline void clear( const NumericProxy<MT>& proxy );
609 
610 template< typename MT >
611 inline void invert( const NumericProxy<MT>& proxy );
612 
613 template< typename MT >
614 inline bool isDefault( const NumericProxy<MT>& proxy );
615 
616 template< typename MT >
617 inline bool isReal( const NumericProxy<MT>& proxy );
618 
619 template< typename MT >
620 inline bool isZero( const NumericProxy<MT>& proxy );
621 
622 template< typename MT >
623 inline bool isOne( const NumericProxy<MT>& proxy );
624 
625 template< typename MT >
626 inline bool isnan( const NumericProxy<MT>& proxy );
628 //*************************************************************************************************
629 
630 
631 //*************************************************************************************************
642 template< typename MT >
644  conj( const NumericProxy<MT>& proxy )
645 {
646  using blaze::conj;
647 
648  return conj( (~proxy).get() );
649 }
650 //*************************************************************************************************
651 
652 
653 //*************************************************************************************************
663 template< typename MT >
664 inline void reset( const NumericProxy<MT>& proxy )
665 {
666  proxy.reset();
667 }
668 //*************************************************************************************************
669 
670 
671 //*************************************************************************************************
681 template< typename MT >
682 inline void clear( const NumericProxy<MT>& proxy )
683 {
684  proxy.clear();
685 }
686 //*************************************************************************************************
687 
688 
689 //*************************************************************************************************
696 template< typename MT >
697 inline void invert( const NumericProxy<MT>& proxy )
698 {
699  proxy.invert();
700 }
701 //*************************************************************************************************
702 
703 
704 //*************************************************************************************************
714 template< typename MT >
715 inline bool isDefault( const NumericProxy<MT>& proxy )
716 {
717  using blaze::isDefault;
718 
719  return isDefault( proxy.get() );
720 }
721 //*************************************************************************************************
722 
723 
724 //*************************************************************************************************
736 template< typename MT >
737 inline bool isReal( const NumericProxy<MT>& proxy )
738 {
739  using blaze::isReal;
740 
741  return isReal( proxy.get() );
742 }
743 //*************************************************************************************************
744 
745 
746 //*************************************************************************************************
756 template< typename MT >
757 inline bool isZero( const NumericProxy<MT>& proxy )
758 {
759  using blaze::isZero;
760 
761  return isZero( proxy.get() );
762 }
763 //*************************************************************************************************
764 
765 
766 //*************************************************************************************************
776 template< typename MT >
777 inline bool isOne( const NumericProxy<MT>& proxy )
778 {
779  using blaze::isOne;
780 
781  return isOne( proxy.get() );
782 }
783 //*************************************************************************************************
784 
785 
786 //*************************************************************************************************
796 template< typename MT >
797 inline bool isnan( const NumericProxy<MT>& proxy )
798 {
799  using blaze::isnan;
800 
801  return isnan( proxy.get() );
802 }
803 //*************************************************************************************************
804 
805 } // namespace blaze
806 
807 #endif
MT::ElementType RepresentedType
Type of the represented matrix element.
Definition: NumericProxy.h:122
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:116
bool isOne(const DiagonalProxy< MT > &proxy)
Returns whether the represented element is 1.
Definition: DiagonalProxy.h:609
Constraint on the data type.
size_t row_
Row index of the accessed matrix element.
Definition: NumericProxy.h:199
Compile time type selection.The If class template selects one of the two given types T2 and T3 depend...
Definition: If.h:112
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
bool isReal(const DiagonalProxy< MT > &proxy)
Returns whether the matrix element represents a real number.
Definition: DiagonalProxy.h:569
NumericProxy * Pointer
Pointer to the represented element.
Definition: NumericProxy.h:125
Constraint on the data type.
void reset(const DiagonalProxy< MT > &proxy)
Resetting the represented element to the default initial values.
Definition: DiagonalProxy.h:507
MT & matrix_
Reference to the adapted matrix.
Definition: NumericProxy.h:198
DisableIf< Or< IsComputation< MT >, IsTransExpr< MT > >, typename ColumnExprTrait< MT >::Type >::Type column(Matrix< MT, SO > &matrix, size_t index)
Creating a view on a specific column of the given matrix.
Definition: Column.h:107
#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:116
Header file for the invert shim.
ValueType imag() const
Returns the imaginary part of the represented complex number.
Definition: NumericProxy.h:563
Constraint on the data type.
ConstReference get() const
Returning the value of the accessed matrix element.
Definition: NumericProxy.h:484
void reset() const
Reset the represented element to its default initial value.
Definition: NumericProxy.h:431
Header file for the Proxy class.
bool isDefault(const DiagonalProxy< MT > &proxy)
Returns whether the represented element is in default state.
Definition: DiagonalProxy.h:547
Constraint on the data type.
Constraint on the data type.
ConjExprTrait< typename DiagonalProxy< MT >::RepresentedType >::Type conj(const DiagonalProxy< MT > &proxy)
Computing the complex conjugate of the represented element.
Definition: DiagonalProxy.h:487
void invert(const HermitianProxy< MT > &proxy)
In-place inversion of the represented element.
Definition: HermitianProxy.h:767
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:116
Constraint on the data type.
Access proxy for symmetric, square matrices with numeric element types.The NumericProxy provides cont...
Definition: NumericProxy.h:99
Header file for the isZero shim.
ValueType real() const
Returns the real part of the represented complex number.
Definition: NumericProxy.h:529
Constraint on the data type.
void invert() const
In-place inversion of the represented element.
Definition: NumericProxy.h:467
bool isnan(const DiagonalProxy< MT > &proxy)
Returns whether the represented element is not a number.
Definition: DiagonalProxy.h:629
#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:118
Pointer operator->()
Direct access to the represented matrix element.
Definition: NumericProxy.h:395
Type ElementType
Type of the sparse matrix elements.
Definition: CompressedMatrix.h:2586
const Type & ConstReference
Reference to a constant matrix value.
Definition: CompressedMatrix.h:2590
MT::Reference Reference
Reference to the represented element.
Definition: NumericProxy.h:123
void clear(const DiagonalProxy< MT > &proxy)
Clearing the represented element.
Definition: DiagonalProxy.h:527
Header file for the isOne shim.
Header file for the conjugate shim.
DisableIf< Or< IsComputation< MT >, IsTransExpr< MT > >, typename RowExprTrait< MT >::Type >::Type row(Matrix< MT, SO > &matrix, size_t index)
Creating a view on a specific row of the given matrix.
Definition: Row.h:107
Evaluation of the return type of a complex conjugate expression.Via this type trait it is possible to...
Definition: ConjExprTrait.h:87
#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:116
Utility type for generic codes.
Constraint on the data type.
Constraint on the data type.
#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:79
size_t column_
Column index of the accessed matrix element.
Definition: NumericProxy.h:200
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:118
#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:116
Header file for the isDefault shim.
If< IsComplex< RepresentedType >, ComplexType< RepresentedType >, BuiltinType< RepresentedType > >::Type::Type ValueType
Value type of the represented complex element.
Definition: NumericProxy.h:131
Constraint on the data type.
Constraint on the data type.
NumericProxy & operator=(const NumericProxy &sp)
Copy assignment operator for NumericProxy.
Definition: NumericProxy.h:276
MT::ConstReference ConstReference
Reference-to-const to the represented element.
Definition: NumericProxy.h:124
const NumericProxy * ConstPointer
Pointer-to-const to the represented element.
Definition: NumericProxy.h:126
#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:118
bool isZero(const DiagonalProxy< MT > &proxy)
Returns whether the represented element is 0.
Definition: DiagonalProxy.h:589
Header file for the IsComplex type trait.
MatrixAccessProxy< This > Reference
Reference to a non-constant matrix value.
Definition: CompressedMatrix.h:2589
#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:116
NumericProxy(MT &matrix, size_t row, size_t column)
Initialization constructor for a NumericProxy.
Definition: NumericProxy.h:239
#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:79
void clear() const
Clearing the represented element.
Definition: NumericProxy.h:450
Header file for the ConjExprTrait class template.
Header file for the isReal shim.