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 
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>
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 //*************************************************************************************************
112 template< typename MT > // Type of the adapted matrix
113 class SymmetricValue : public Proxy< SymmetricValue<MT> >
114 {
115  private:
116  //**Type definitions****************************************************************************
117  typedef typename MT::Iterator IteratorType;
118  //**********************************************************************************************
119 
120  //**struct BuiltinType**************************************************************************
124  template< typename T >
125  struct BuiltinType { typedef INVALID_TYPE Type; };
127  //**********************************************************************************************
128 
129  //**struct ComplexType**************************************************************************
133  template< typename T >
134  struct ComplexType { typedef typename T::value_type Type; };
136  //**********************************************************************************************
137 
138  public:
139  //**Type definitions****************************************************************************
141 
143  typedef typename If_< IsComplex<RepresentedType>
144  , ComplexType<RepresentedType>
145  , BuiltinType<RepresentedType> >::Type ValueType;
146 
147  typedef ValueType value_type;
148  //**********************************************************************************************
149 
150  //**Constructors********************************************************************************
153  inline SymmetricValue( IteratorType pos, MT* matrix, size_t index );
155  //**********************************************************************************************
156 
157  //**Assignment operators************************************************************************
160  inline SymmetricValue& operator= ( const SymmetricValue& sv );
161  template< typename T > inline SymmetricValue& operator= ( const T& value );
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 );
167  //**********************************************************************************************
168 
169  //**Utility functions***************************************************************************
172  inline void reset () const;
173  inline void clear () const;
174  inline void invert() const;
175 
176  inline RepresentedType get() const noexcept;
178  //**********************************************************************************************
179 
180  //**Conversion operator*************************************************************************
183  inline operator RepresentedType() const noexcept;
185  //**********************************************************************************************
186 
187  //**Complex data access functions***************************************************************
190  inline ValueType real() const;
191  inline void real( ValueType value ) const;
192  inline ValueType imag() const;
193  inline void imag( ValueType value ) const;
195  //**********************************************************************************************
196 
197  private:
198  //**Utility functions***************************************************************************
201  inline void sync() const;
203  //**********************************************************************************************
204 
205  //**Member variables****************************************************************************
206  IteratorType pos_;
207  MT* matrix_;
208  size_t index_;
209  //**********************************************************************************************
210 
211  //**Compile time checks*************************************************************************
223  BLAZE_CONSTRAINT_MUST_BE_NUMERIC_TYPE( RepresentedType );
225  //**********************************************************************************************
226 };
227 //*************************************************************************************************
228 
229 
230 
231 
232 //=================================================================================================
233 //
234 // CONSTRUCTORS
235 //
236 //=================================================================================================
237 
238 //*************************************************************************************************
245 template< typename MT > // Type of the adapted matrix
246 inline SymmetricValue<MT>::SymmetricValue( IteratorType pos, MT* matrix, size_t index )
247  : pos_ ( pos ) // Iterator to the current sparse symmetric matrix element
248  , matrix_( matrix ) // The sparse matrix containing the iterator
249  , index_ ( index ) // The row/column index of the iterator
250 {}
251 //*************************************************************************************************
252 
253 
254 
255 
256 //=================================================================================================
257 //
258 // OPERATORS
259 //
260 //=================================================================================================
261 
262 //*************************************************************************************************
268 template< typename MT > // Type of the adapted matrix
270 {
271  pos_->value() = sv.pos_->value();
272  sync();
273  return *this;
274 }
275 //*************************************************************************************************
276 
277 
278 //*************************************************************************************************
284 template< typename MT > // Type of the adapted matrix
285 template< typename T > // Type of the right-hand side value
287 {
288  pos_->value() = value;
289  sync();
290  return *this;
291 }
292 //*************************************************************************************************
293 
294 
295 //*************************************************************************************************
302 template< typename MT > // Type of the adapted matrix
303 template< typename T > // Type of the right-hand side value
305 {
306  pos_->value() += value;
307  sync();
308  return *this;
309 }
310 //*************************************************************************************************
311 
312 
313 //*************************************************************************************************
319 template< typename MT > // Type of the adapted matrix
320 template< typename T > // Type of the right-hand side value
322 {
323  pos_->value() -= value;
324  sync();
325  return *this;
326 }
327 //*************************************************************************************************
328 
329 
330 //*************************************************************************************************
336 template< typename MT > // Type of the adapted matrix
337 template< typename T > // Type of the right-hand side value
339 {
340  pos_->value() *= value;
341  sync();
342  return *this;
343 }
344 //*************************************************************************************************
345 
346 
347 //*************************************************************************************************
353 template< typename MT > // Type of the adapted matrix
354 template< typename T > // Type of the right-hand side value
356 {
357  pos_->value() /= value;
358  sync();
359  return *this;
360 }
361 //*************************************************************************************************
362 
363 
364 
365 
366 //=================================================================================================
367 //
368 // UTILITY FUNCTIONS
369 //
370 //=================================================================================================
371 
372 //*************************************************************************************************
379 template< typename MT > // Type of the adapted matrix
380 inline void SymmetricValue<MT>::reset() const
381 {
382  using blaze::reset;
383 
384  reset( pos_->value() );
385 
386  if( pos_->index() != index_ )
387  {
388  const size_t row ( ( IsRowMajorMatrix<MT>::value )?( pos_->index() ):( index_ ) );
389  const size_t column( ( IsRowMajorMatrix<MT>::value )?( index_ ):( pos_->index() ) );
390  const IteratorType pos2( matrix_->find( row, column ) );
391 
392  reset( pos2->value() );
393  }
394 }
395 //*************************************************************************************************
396 
397 
398 //*************************************************************************************************
405 template< typename MT > // Type of the adapted matrix
406 inline void SymmetricValue<MT>::clear() const
407 {
408  using blaze::clear;
409 
410  clear( pos_->value() );
411 
412  if( pos_->index() != index_ )
413  {
414  const size_t row ( ( IsRowMajorMatrix<MT>::value )?( pos_->index() ):( index_ ) );
415  const size_t column( ( IsRowMajorMatrix<MT>::value )?( index_ ):( pos_->index() ) );
416  const IteratorType pos2( matrix_->find( row, column ) );
417 
418  clear( pos2->value() );
419  }
420 }
421 //*************************************************************************************************
422 
423 
424 //*************************************************************************************************
429 template< typename MT > // Type of the adapted matrix
430 inline void SymmetricValue<MT>::invert() const
431 {
432  using blaze::invert;
433 
434  invert( pos_->value() );
435 
436  if( pos_->index() != index_ )
437  {
438  const size_t row ( ( IsRowMajorMatrix<MT>::value )?( pos_->index() ):( index_ ) );
439  const size_t column( ( IsRowMajorMatrix<MT>::value )?( index_ ):( pos_->index() ) );
440  const IteratorType pos2( matrix_->find( row, column ) );
441 
442  pos2->value() = pos_->value();
443  }
444 }
445 //*************************************************************************************************
446 
447 
448 //*************************************************************************************************
453 template< typename MT > // Type of the adapted matrix
455 {
456  return pos_->value();
457 }
458 //*************************************************************************************************
459 
460 
461 //*************************************************************************************************
466 template< typename MT > // Type of the adapted matrix
467 inline void SymmetricValue<MT>::sync() const
468 {
469  if( pos_->index() == index_ || isDefault( pos_->value() ) )
470  return;
471 
472  const size_t row ( ( IsRowMajorMatrix<MT>::value )?( pos_->index() ):( index_ ) );
473  const size_t column( ( IsRowMajorMatrix<MT>::value )?( index_ ):( pos_->index() ) );
474 
475  matrix_->set( row, column, pos_->value() );
476 }
477 //*************************************************************************************************
478 
479 
480 
481 
482 //=================================================================================================
483 //
484 // CONVERSION OPERATOR
485 //
486 //=================================================================================================
487 
488 //*************************************************************************************************
493 template< typename MT > // Type of the adapted matrix
495 {
496  return pos_->value();
497 }
498 //*************************************************************************************************
499 
500 
501 
502 
503 //=================================================================================================
504 //
505 // COMPLEX DATA ACCESS FUNCTIONS
506 //
507 //=================================================================================================
508 
509 //*************************************************************************************************
517 template< typename MT > // Type of the adapted matrix
519 {
520  return pos_->value().real();
521 }
522 //*************************************************************************************************
523 
524 
525 //*************************************************************************************************
534 template< typename MT > // Type of the adapted matrix
535 inline void SymmetricValue<MT>::real( ValueType value ) const
536 {
537  pos_->value().real() = value;
538  sync();
539 }
540 //*************************************************************************************************
541 
542 
543 //*************************************************************************************************
551 template< typename MT > // Type of the adapted matrix
553 {
554  return pos_->value.imag();
555 }
556 //*************************************************************************************************
557 
558 
559 //*************************************************************************************************
568 template< typename MT > // Type of the adapted matrix
569 inline void SymmetricValue<MT>::imag( ValueType value ) const
570 {
571  pos_->value().imag( value );
572  sync();
573 }
574 //*************************************************************************************************
575 
576 
577 
578 
579 //=================================================================================================
580 //
581 // GLOBAL FUNCTIONS
582 //
583 //=================================================================================================
584 
585 //*************************************************************************************************
588 template< typename MT >
589 inline void reset( const SymmetricValue<MT>& value );
590 
591 template< typename MT >
592 inline void clear( const SymmetricValue<MT>& value );
593 
594 template< typename MT >
595 inline void invert( const SymmetricValue<MT>& value );
596 
597 template< typename MT >
598 inline bool isDefault( const SymmetricValue<MT>& value );
599 
600 template< typename MT >
601 inline bool isReal( const SymmetricValue<MT>& value );
602 
603 template< typename MT >
604 inline bool isZero( const SymmetricValue<MT>& value );
605 
606 template< typename MT >
607 inline bool isOne( const SymmetricValue<MT>& value );
608 
609 template< typename MT >
610 inline bool isnan( const SymmetricValue<MT>& value );
612 //*************************************************************************************************
613 
614 
615 //*************************************************************************************************
624 template< typename MT >
625 inline void reset( const SymmetricValue<MT>& value )
626 {
627  value.reset();
628 }
629 //*************************************************************************************************
630 
631 
632 //*************************************************************************************************
641 template< typename MT >
642 inline void clear( const SymmetricValue<MT>& value )
643 {
644  value.clear();
645 }
646 //*************************************************************************************************
647 
648 
649 //*************************************************************************************************
656 template< typename MT >
657 inline void invert( const SymmetricValue<MT>& value )
658 {
659  value.invert();
660 }
661 //*************************************************************************************************
662 
663 
664 //*************************************************************************************************
674 template< typename MT >
675 inline bool isDefault( const SymmetricValue<MT>& value )
676 {
677  using blaze::isDefault;
678 
679  return isDefault( value.get() );
680 }
681 //*************************************************************************************************
682 
683 
684 //*************************************************************************************************
696 template< typename MT >
697 inline bool isReal( const SymmetricValue<MT>& value )
698 {
699  using blaze::isReal;
700 
701  return isReal( value.get() );
702 }
703 //*************************************************************************************************
704 
705 
706 //*************************************************************************************************
716 template< typename MT >
717 inline bool isZero( const SymmetricValue<MT>& value )
718 {
719  using blaze::isZero;
720 
721  return isZero( value.get() );
722 }
723 //*************************************************************************************************
724 
725 
726 //*************************************************************************************************
736 template< typename MT >
737 inline bool isOne( const SymmetricValue<MT>& value )
738 {
739  using blaze::isOne;
740 
741  return isOne( value.get() );
742 }
743 //*************************************************************************************************
744 
745 
746 //*************************************************************************************************
756 template< typename MT >
757 inline bool isnan( const SymmetricValue<MT>& value )
758 {
759  using blaze::isnan;
760 
761  return isnan( value.get() );
762 }
763 //*************************************************************************************************
764 
765 } // namespace blaze
766 
767 #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.
void invert() const
In-place inversion of the symmetric value.
Definition: SymmetricValue.h:430
void clear() const
Clearing the symmetric value.
Definition: SymmetricValue.h:406
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:595
SymmetricValue & operator=(const SymmetricValue &sv)
Copy assignment operator for SymmetricValue.
Definition: SymmetricValue.h:269
MT * matrix_
The sparse matrix containing the iterator.
Definition: SymmetricValue.h:207
Constraint on the data type.
void reset(const DiagonalProxy< MT > &proxy)
Resetting the represented element to the default initial values.
Definition: DiagonalProxy.h:533
#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: SymmetricValue.h:552
Constraint on the data type.
ValueType real() const
Returns the real part of the represented complex number.
Definition: SymmetricValue.h:518
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.
RepresentedType get() const noexcept
Access to the represented value.
Definition: SymmetricValue.h:454
bool isDefault(const DiagonalProxy< MT > &proxy)
Returns whether the represented element is in default state.
Definition: DiagonalProxy.h:573
Constraint on the data type.
IteratorType pos_
Iterator to the current sparse symmetric matrix element.
Definition: SymmetricValue.h:206
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
MT::Iterator IteratorType
Type of the underlying sparse matrix iterators.
Definition: SymmetricValue.h:117
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:83
#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
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: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
If_< IsComplex< RepresentedType >, ComplexType< RepresentedType >, BuiltinType< RepresentedType > >::Type ValueType
Value type of the represented complex element.
Definition: SymmetricValue.h:145
void clear(const DiagonalProxy< MT > &proxy)
Clearing the represented element.
Definition: DiagonalProxy.h:553
Header file for the isOne shim.
size_t index_
The row/column index of the iterator.
Definition: SymmetricValue.h:208
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
ValueType value_type
Value type of the represented complex element.
Definition: SymmetricValue.h:147
void sync() const
Synchronization of the current sparse element to the according paired element.
Definition: SymmetricValue.h:467
#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.
ElementType_< MT > RepresentedType
Type of the represented matrix element.
Definition: SymmetricValue.h:140
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
Representation of two synchronized values within a sparse symmetric matrix.The SymmetricValue class r...
Definition: SymmetricValue.h:113
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
Element * Iterator
Iterator over non-constant elements.
Definition: CompressedMatrix.h:2646
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:246
Header file for the IsRowMajorMatrix type trait.
void reset() const
Reset the symmetric value to its default initial value.
Definition: SymmetricValue.h:380
#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
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:61