SymmetricValue.h
Go to the documentation of this file.
1 //=================================================================================================
33 //=================================================================================================
34 
35 #ifndef _BLAZE_MATH_ADAPTORS_SYMMETRICMATRIX_SYMMETRICVALUE_H_
36 #define _BLAZE_MATH_ADAPTORS_SYMMETRICMATRIX_SYMMETRICVALUE_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>
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 //*************************************************************************************************
113 template< typename MT > // Type of the adapted matrix
114 class SymmetricValue : public Proxy< SymmetricValue<MT> >
115 {
116  private:
117  //**Type definitions****************************************************************************
118  typedef typename MT::Iterator IteratorType;
119  //**********************************************************************************************
120 
121  //**struct BuiltinType**************************************************************************
125  template< typename T >
126  struct BuiltinType { typedef INVALID_TYPE Type; };
128  //**********************************************************************************************
129 
130  //**struct ComplexType**************************************************************************
134  template< typename T >
135  struct ComplexType { typedef typename T::value_type Type; };
137  //**********************************************************************************************
138 
139  public:
140  //**Type definitions****************************************************************************
141  typedef typename MT::ElementType RepresentedType;
142 
144  typedef typename If< IsComplex<RepresentedType>
145  , ComplexType<RepresentedType>
146  , BuiltinType<RepresentedType> >::Type::Type ValueType;
147 
148  typedef ValueType value_type;
149  //**********************************************************************************************
150 
151  //**Constructors********************************************************************************
154  inline SymmetricValue( IteratorType pos, MT* matrix, size_t index );
156  //**********************************************************************************************
157 
158  //**Assignment operators************************************************************************
161  inline SymmetricValue& operator= ( const SymmetricValue& sv );
162  template< typename T > inline SymmetricValue& operator= ( const T& value );
163  template< typename T > inline SymmetricValue& operator+=( const T& value );
164  template< typename T > inline SymmetricValue& operator-=( const T& value );
165  template< typename T > inline SymmetricValue& operator*=( const T& value );
166  template< typename T > inline SymmetricValue& operator/=( const T& value );
168  //**********************************************************************************************
169 
170  //**Utility functions***************************************************************************
173  inline void reset () const;
174  inline void clear () const;
175  inline void invert() const;
176 
177  inline RepresentedType get() const;
179  //**********************************************************************************************
180 
181  //**Conversion operator*************************************************************************
184  inline operator RepresentedType() const;
186  //**********************************************************************************************
187 
188  //**Complex data access functions***************************************************************
191  inline ValueType real() const;
192  inline void real( ValueType value ) const;
193  inline ValueType imag() const;
194  inline void imag( ValueType value ) const;
196  //**********************************************************************************************
197 
198  private:
199  //**Utility functions***************************************************************************
202  inline void sync() const;
204  //**********************************************************************************************
205 
206  //**Member variables****************************************************************************
207  IteratorType pos_;
208  MT* matrix_;
209  size_t index_;
210  //**********************************************************************************************
211 
212  //**Compile time checks*************************************************************************
224  BLAZE_CONSTRAINT_MUST_BE_NUMERIC_TYPE( RepresentedType );
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 SymmetricValue<MT>::SymmetricValue( IteratorType pos, MT* matrix, size_t index )
248  : pos_ ( pos ) // Iterator to the current sparse symmetric matrix element
249  , matrix_( matrix ) // The sparse matrix containing the iterator
250  , index_ ( index ) // The row/column index of the iterator
251 {}
252 //*************************************************************************************************
253 
254 
255 
256 
257 //=================================================================================================
258 //
259 // OPERATORS
260 //
261 //=================================================================================================
262 
263 //*************************************************************************************************
269 template< typename MT > // Type of the adapted matrix
271 {
272  pos_->value() = sv.pos_->value();
273  sync();
274  return *this;
275 }
276 //*************************************************************************************************
277 
278 
279 //*************************************************************************************************
285 template< typename MT > // Type of the adapted matrix
286 template< typename T > // Type of the right-hand side value
288 {
289  pos_->value() = value;
290  sync();
291  return *this;
292 }
293 //*************************************************************************************************
294 
295 
296 //*************************************************************************************************
303 template< typename MT > // Type of the adapted matrix
304 template< typename T > // Type of the right-hand side value
306 {
307  pos_->value() += value;
308  sync();
309  return *this;
310 }
311 //*************************************************************************************************
312 
313 
314 //*************************************************************************************************
320 template< typename MT > // Type of the adapted matrix
321 template< typename T > // Type of the right-hand side value
323 {
324  pos_->value() -= value;
325  sync();
326  return *this;
327 }
328 //*************************************************************************************************
329 
330 
331 //*************************************************************************************************
337 template< typename MT > // Type of the adapted matrix
338 template< typename T > // Type of the right-hand side value
340 {
341  pos_->value() *= value;
342  sync();
343  return *this;
344 }
345 //*************************************************************************************************
346 
347 
348 //*************************************************************************************************
354 template< typename MT > // Type of the adapted matrix
355 template< typename T > // Type of the right-hand side value
357 {
358  pos_->value() /= value;
359  sync();
360  return *this;
361 }
362 //*************************************************************************************************
363 
364 
365 
366 
367 //=================================================================================================
368 //
369 // UTILITY FUNCTIONS
370 //
371 //=================================================================================================
372 
373 //*************************************************************************************************
380 template< typename MT > // Type of the adapted matrix
381 inline void SymmetricValue<MT>::reset() const
382 {
383  using blaze::reset;
384 
385  reset( pos_->value() );
386 
387  if( pos_->index() != index_ )
388  {
389  const size_t row ( ( IsRowMajorMatrix<MT>::value )?( pos_->index() ):( index_ ) );
390  const size_t column( ( IsRowMajorMatrix<MT>::value )?( index_ ):( pos_->index() ) );
391  const IteratorType pos2( matrix_->find( row, column ) );
392 
393  reset( pos2->value() );
394  }
395 }
396 //*************************************************************************************************
397 
398 
399 //*************************************************************************************************
406 template< typename MT > // Type of the adapted matrix
407 inline void SymmetricValue<MT>::clear() const
408 {
409  using blaze::clear;
410 
411  clear( pos_->value() );
412 
413  if( pos_->index() != index_ )
414  {
415  const size_t row ( ( IsRowMajorMatrix<MT>::value )?( pos_->index() ):( index_ ) );
416  const size_t column( ( IsRowMajorMatrix<MT>::value )?( index_ ):( pos_->index() ) );
417  const IteratorType pos2( matrix_->find( row, column ) );
418 
419  clear( pos2->value() );
420  }
421 }
422 //*************************************************************************************************
423 
424 
425 //*************************************************************************************************
430 template< typename MT > // Type of the adapted matrix
431 inline void SymmetricValue<MT>::invert() const
432 {
433  using blaze::invert;
434 
435  invert( pos_->value() );
436 
437  if( pos_->index() != index_ )
438  {
439  const size_t row ( ( IsRowMajorMatrix<MT>::value )?( pos_->index() ):( index_ ) );
440  const size_t column( ( IsRowMajorMatrix<MT>::value )?( index_ ):( pos_->index() ) );
441  const IteratorType pos2( matrix_->find( row, column ) );
442 
443  pos2->value() = pos_->value();
444  }
445 }
446 //*************************************************************************************************
447 
448 
449 //*************************************************************************************************
454 template< typename MT > // Type of the adapted matrix
456 {
457  return pos_->value();
458 }
459 //*************************************************************************************************
460 
461 
462 //*************************************************************************************************
467 template< typename MT > // Type of the adapted matrix
468 inline void SymmetricValue<MT>::sync() const
469 {
470  if( pos_->index() == index_ || isDefault( pos_->value() ) )
471  return;
472 
473  const size_t row ( ( IsRowMajorMatrix<MT>::value )?( pos_->index() ):( index_ ) );
474  const size_t column( ( IsRowMajorMatrix<MT>::value )?( index_ ):( pos_->index() ) );
475 
476  matrix_->set( row, column, pos_->value() );
477 }
478 //*************************************************************************************************
479 
480 
481 
482 
483 //=================================================================================================
484 //
485 // CONVERSION OPERATOR
486 //
487 //=================================================================================================
488 
489 //*************************************************************************************************
494 template< typename MT > // Type of the adapted matrix
496 {
497  return pos_->value();
498 }
499 //*************************************************************************************************
500 
501 
502 
503 
504 //=================================================================================================
505 //
506 // COMPLEX DATA ACCESS FUNCTIONS
507 //
508 //=================================================================================================
509 
510 //*************************************************************************************************
518 template< typename MT > // Type of the adapted matrix
520 {
521  return pos_->value().real();
522 }
523 //*************************************************************************************************
524 
525 
526 //*************************************************************************************************
535 template< typename MT > // Type of the adapted matrix
536 inline void SymmetricValue<MT>::real( ValueType value ) const
537 {
538  pos_->value().real() = value;
539  sync();
540 }
541 //*************************************************************************************************
542 
543 
544 //*************************************************************************************************
552 template< typename MT > // Type of the adapted matrix
554 {
555  return pos_->value.imag();
556 }
557 //*************************************************************************************************
558 
559 
560 //*************************************************************************************************
569 template< typename MT > // Type of the adapted matrix
570 inline void SymmetricValue<MT>::imag( ValueType value ) const
571 {
572  pos_->value().imag( value );
573  sync();
574 }
575 //*************************************************************************************************
576 
577 
578 
579 
580 //=================================================================================================
581 //
582 // GLOBAL FUNCTIONS
583 //
584 //=================================================================================================
585 
586 //*************************************************************************************************
589 template< typename MT >
591  conj( const SymmetricValue<MT>& value );
592 
593 template< typename MT >
594 inline void reset( const SymmetricValue<MT>& value );
595 
596 template< typename MT >
597 inline void clear( const SymmetricValue<MT>& value );
598 
599 template< typename MT >
600 inline void invert( const SymmetricValue<MT>& value );
601 
602 template< typename MT >
603 inline bool isDefault( const SymmetricValue<MT>& value );
604 
605 template< typename MT >
606 inline bool isReal( const SymmetricValue<MT>& value );
607 
608 template< typename MT >
609 inline bool isZero( const SymmetricValue<MT>& value );
610 
611 template< typename MT >
612 inline bool isOne( const SymmetricValue<MT>& value );
613 
614 template< typename MT >
615 inline bool isnan( const SymmetricValue<MT>& value );
617 //*************************************************************************************************
618 
619 
620 //*************************************************************************************************
631 template< typename MT >
633  conj( const SymmetricValue<MT>& value )
634 {
635  using blaze::conj;
636 
637  return conj( (~value).get() );
638 }
639 //*************************************************************************************************
640 
641 
642 //*************************************************************************************************
651 template< typename MT >
652 inline void reset( const SymmetricValue<MT>& value )
653 {
654  value.reset();
655 }
656 //*************************************************************************************************
657 
658 
659 //*************************************************************************************************
668 template< typename MT >
669 inline void clear( const SymmetricValue<MT>& value )
670 {
671  value.clear();
672 }
673 //*************************************************************************************************
674 
675 
676 //*************************************************************************************************
683 template< typename MT >
684 inline void invert( const SymmetricValue<MT>& value )
685 {
686  value.invert();
687 }
688 //*************************************************************************************************
689 
690 
691 //*************************************************************************************************
701 template< typename MT >
702 inline bool isDefault( const SymmetricValue<MT>& value )
703 {
704  using blaze::isDefault;
705 
706  return isDefault( value.get() );
707 }
708 //*************************************************************************************************
709 
710 
711 //*************************************************************************************************
723 template< typename MT >
724 inline bool isReal( const SymmetricValue<MT>& value )
725 {
726  using blaze::isReal;
727 
728  return isReal( value.get() );
729 }
730 //*************************************************************************************************
731 
732 
733 //*************************************************************************************************
743 template< typename MT >
744 inline bool isZero( const SymmetricValue<MT>& value )
745 {
746  using blaze::isZero;
747 
748  return isZero( value.get() );
749 }
750 //*************************************************************************************************
751 
752 
753 //*************************************************************************************************
763 template< typename MT >
764 inline bool isOne( const SymmetricValue<MT>& value )
765 {
766  using blaze::isOne;
767 
768  return isOne( value.get() );
769 }
770 //*************************************************************************************************
771 
772 
773 //*************************************************************************************************
783 template< typename MT >
784 inline bool isnan( const SymmetricValue<MT>& value )
785 {
786  using blaze::isnan;
787 
788  return isnan( value.get() );
789 }
790 //*************************************************************************************************
791 
792 } // namespace blaze
793 
794 #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:116
bool isOne(const DiagonalProxy< MT > &proxy)
Returns whether the represented element is 1.
Definition: DiagonalProxy.h:609
Constraint on the data type.
void invert() const
In-place inversion of the symmetric value.
Definition: SymmetricValue.h:431
void clear() const
Clearing the symmetric value.
Definition: SymmetricValue.h:407
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
SymmetricValue & operator=(const SymmetricValue &sv)
Copy assignment operator for SymmetricValue.
Definition: SymmetricValue.h:270
MT * matrix_
The sparse matrix containing the iterator.
Definition: SymmetricValue.h:208
Constraint on the data type.
void reset(const DiagonalProxy< MT > &proxy)
Resetting the represented element to the default initial values.
Definition: DiagonalProxy.h:507
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: SymmetricValue.h:553
RepresentedType get() const
Access to the represented value.
Definition: SymmetricValue.h:455
Constraint on the data type.
ValueType real() const
Returns the real part of the represented complex number.
Definition: SymmetricValue.h:519
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.
IteratorType pos_
Iterator to the current sparse symmetric matrix element.
Definition: SymmetricValue.h:207
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
Constraint on the data type.
void invert(const HermitianProxy< MT > &proxy)
In-place inversion of the represented element.
Definition: HermitianProxy.h:767
MT::Iterator IteratorType
Type of the underlying sparse matrix iterators.
Definition: SymmetricValue.h:118
If< IsComplex< RepresentedType >, ComplexType< RepresentedType >, BuiltinType< RepresentedType > >::Type::Type ValueType
Value type of the represented complex element.
Definition: SymmetricValue.h:146
Header file for the clear shim.
Namespace of the Blaze C++ math library.
Definition: Blaze.h:57
Header file for the If class template.
Compile time check for row-major matrix types.This type trait tests whether or not the given template...
Definition: IsRowMajorMatrix.h:110
#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
Header file for the isZero shim.
Constraint on the data type.
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
Type ElementType
Type of the sparse matrix elements.
Definition: CompressedMatrix.h:2586
void clear(const DiagonalProxy< MT > &proxy)
Clearing the represented element.
Definition: DiagonalProxy.h:527
Header file for the isOne shim.
size_t index_
The row/column index of the iterator.
Definition: SymmetricValue.h:209
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
ValueType value_type
Value type of the represented complex element.
Definition: SymmetricValue.h:148
void sync() const
Synchronization of the current sparse element to the according paired element.
Definition: SymmetricValue.h:468
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.
MT::ElementType RepresentedType
Type of the represented matrix element.
Definition: SymmetricValue.h:141
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
Representation of two synchronized values within a sparse symmetric matrix.The SymmetricValue class r...
Definition: SymmetricValue.h:114
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
Element * Iterator
Iterator over non-constant elements.
Definition: CompressedMatrix.h:2591
Header file for the isDefault shim.
Constraint on the data type.
Constraint on the data type.
SymmetricValue(IteratorType pos, MT *matrix, size_t index)
Constructor for the SymmetricValue class.
Definition: SymmetricValue.h:247
Header file for the IsRowMajorMatrix type trait.
void reset() const
Reset the symmetric value to its default initial value.
Definition: SymmetricValue.h:381
#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.
#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
Header file for the ConjExprTrait class template.
Header file for the isReal shim.
#define BLAZE_CONSTRAINT_MUST_BE_SPARSE_MATRIX_TYPE(T)
Constraint on the data type.In case the given data type T is not a sparse, N-dimensional matrix type...
Definition: SparseMatrix.h:79