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
114  : public Proxy< SymmetricValue<MT> >
115 {
116  private:
117  //**Type definitions****************************************************************************
118  using IteratorType = typename MT::Iterator;
119  //**********************************************************************************************
120 
121  //**struct BuiltinType**************************************************************************
125  template< typename T >
126  struct BuiltinType { using Type = INVALID_TYPE; };
128  //**********************************************************************************************
129 
130  //**struct ComplexType**************************************************************************
134  template< typename T >
135  struct ComplexType { using Type = typename T::value_type; };
137  //**********************************************************************************************
138 
139  public:
140  //**Type definitions****************************************************************************
142 
145  , ComplexType<RepresentedType>
146  , BuiltinType<RepresentedType> >::Type;
147 
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 noexcept;
179  //**********************************************************************************************
180 
181  //**Conversion operator*************************************************************************
184  inline operator RepresentedType() const noexcept;
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****************************************************************************
208  MT* matrix_;
209  size_t index_;
210  //**********************************************************************************************
211 
212  //**Compile time checks*************************************************************************
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 >
590 inline void reset( const SymmetricValue<MT>& value );
591 
592 template< typename MT >
593 inline void clear( const SymmetricValue<MT>& value );
594 
595 template< typename MT >
596 inline void invert( const SymmetricValue<MT>& value );
597 
598 template< bool RF, typename MT >
599 inline bool isDefault( const SymmetricValue<MT>& value );
600 
601 template< bool RF, typename MT >
602 inline bool isReal( const SymmetricValue<MT>& value );
603 
604 template< bool RF, typename MT >
605 inline bool isZero( const SymmetricValue<MT>& value );
606 
607 template< bool RF, typename MT >
608 inline bool isOne( const SymmetricValue<MT>& value );
609 
610 template< typename MT >
611 inline bool isnan( const SymmetricValue<MT>& value );
613 //*************************************************************************************************
614 
615 
616 //*************************************************************************************************
625 template< typename MT >
626 inline void reset( const SymmetricValue<MT>& value )
627 {
628  value.reset();
629 }
630 //*************************************************************************************************
631 
632 
633 //*************************************************************************************************
642 template< typename MT >
643 inline void clear( const SymmetricValue<MT>& value )
644 {
645  value.clear();
646 }
647 //*************************************************************************************************
648 
649 
650 //*************************************************************************************************
657 template< typename MT >
658 inline void invert( const SymmetricValue<MT>& value )
659 {
660  value.invert();
661 }
662 //*************************************************************************************************
663 
664 
665 //*************************************************************************************************
675 template< bool RF, typename MT >
676 inline bool isDefault( const SymmetricValue<MT>& value )
677 {
678  using blaze::isDefault;
679 
680  return isDefault<RF>( value.get() );
681 }
682 //*************************************************************************************************
683 
684 
685 //*************************************************************************************************
697 template< bool RF, typename MT >
698 inline bool isReal( const SymmetricValue<MT>& value )
699 {
700  using blaze::isReal;
701 
702  return isReal<RF>( value.get() );
703 }
704 //*************************************************************************************************
705 
706 
707 //*************************************************************************************************
717 template< bool RF, typename MT >
718 inline bool isZero( const SymmetricValue<MT>& value )
719 {
720  using blaze::isZero;
721 
722  return isZero<RF>( value.get() );
723 }
724 //*************************************************************************************************
725 
726 
727 //*************************************************************************************************
737 template< bool RF, typename MT >
738 inline bool isOne( const SymmetricValue<MT>& value )
739 {
740  using blaze::isOne;
741 
742  return isOne<RF>( value.get() );
743 }
744 //*************************************************************************************************
745 
746 
747 //*************************************************************************************************
757 template< typename MT >
758 inline bool isnan( const SymmetricValue<MT>& value )
759 {
760  using blaze::isnan;
761 
762  return isnan( value.get() );
763 }
764 //*************************************************************************************************
765 
766 } // namespace blaze
767 
768 #endif
bool isReal(const DiagonalProxy< MT > &proxy)
Returns whether the matrix element represents a real number.
Definition: DiagonalProxy.h:622
Header file for the isnan shim.
#define BLAZE_CONSTRAINT_MUST_NOT_BE_CONST(T)
Constraint on the data type.In case the given data type is a const-qualified type, a compilation error is created.
Definition: Const.h:79
Header file for auxiliary alias declarations.
typename MT::Iterator IteratorType
Type of the underlying sparse matrix iterators.
Definition: SymmetricValue.h:118
Constraint on the data type.
void sync() const
Synchronization of the current sparse element to the according paired element.
Definition: SymmetricValue.h:468
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
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
BLAZE_ALWAYS_INLINE T1 & operator/=(SIMDPack< T1 > &lhs, const SIMDPack< T2 > &rhs)
Division assignment operator for the division of two SIMD packs.
Definition: BasicTypes.h:1411
Constraint on the data type.
void reset(const DiagonalProxy< MT > &proxy)
Resetting the represented element to the default initial values.
Definition: DiagonalProxy.h:560
#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.
Column< MT > column(Matrix< MT, SO > &matrix, size_t index)
Creating a view on a specific column of the given matrix.
Definition: Column.h:124
Element * Iterator
Iterator over non-constant elements.
Definition: CompressedMatrix.h:3086
BLAZE_ALWAYS_INLINE T1 & operator*=(SIMDPack< T1 > &lhs, const SIMDPack< T2 > &rhs)
Multiplication assignment operator for the multiplication of two SIMD packs.
Definition: BasicTypes.h:1393
Constraint on the data type.
Header file for the Proxy class.
Constraint on the data type.
IteratorType pos_
Iterator to the current sparse symmetric matrix element.
Definition: SymmetricValue.h:207
Constraint on the data type.
Row< MT > row(Matrix< MT, SO > &matrix, size_t index)
Creating a view on a specific row of the given matrix.
Definition: Row.h:124
Constraint on the data type.
bool isZero(const DiagonalProxy< MT > &proxy)
Returns whether the represented element is 0.
Definition: DiagonalProxy.h:642
void invert(const HermitianProxy< MT > &proxy)
In-place inversion of the represented element.
Definition: HermitianProxy.h:772
typename If_< IsComplex< RepresentedType >, ComplexType< RepresentedType >, BuiltinType< RepresentedType > >::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: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:682
#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
RepresentedType get() const noexcept
Access to the represented value.
Definition: SymmetricValue.h:455
void clear(const DiagonalProxy< MT > &proxy)
Clearing the represented element.
Definition: DiagonalProxy.h:580
Header file for the isOne shim.
ElementType_< MT > RepresentedType
Type of the represented matrix element.
Definition: SymmetricValue.h:141
size_t index_
The row/column index of the iterator.
Definition: SymmetricValue.h:209
ValueType value_type
Value type of the represented complex element.
Definition: SymmetricValue.h:148
#define BLAZE_CONSTRAINT_MUST_NOT_BE_SYMMETRIC_MATRIX_TYPE(T)
Constraint on the data type.In case the given data type T is a symmetric matrix type, a compilation error is created.
Definition: Symmetric.h:79
BLAZE_ALWAYS_INLINE T1 & operator+=(SIMDPack< T1 > &lhs, const SIMDPack< T2 > &rhs)
Addition assignment operator for the addition of two SIMD packs.
Definition: BasicTypes.h:1357
Utility type for generic codes.
Constraint on the data type.
Constraint on the data type.
typename If< T1, T2, T3 >::Type If_
Auxiliary alias declaration for the If class template.The If_ alias declaration provides a convenient...
Definition: If.h:154
#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
bool isOne(const DiagonalProxy< MT > &proxy)
Returns whether the represented element is 1.
Definition: DiagonalProxy.h:662
Header file for the isDefault shim.
Constraint on the data type.
Constraint on the data type.
void clear() const
Clearing the symmetric value.
Definition: SymmetricValue.h:407
void reset() const
Reset the symmetric value to its default initial value.
Definition: SymmetricValue.h:381
void invert() const
In-place inversion of the symmetric value.
Definition: SymmetricValue.h:431
SymmetricValue(IteratorType pos, MT *matrix, size_t index)
Constructor for the SymmetricValue class.
Definition: SymmetricValue.h:247
Header file for the IsRowMajorMatrix type trait.
ValueType real() const
Returns the real part of the represented complex number.
Definition: SymmetricValue.h:519
#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
ValueType imag() const
Returns the imaginary part of the represented complex number.
Definition: SymmetricValue.h:553
Header file for the IsComplex type trait.
bool isDefault(const DiagonalProxy< MT > &proxy)
Returns whether the represented element is in default state.
Definition: DiagonalProxy.h:600
#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
BLAZE_ALWAYS_INLINE T1 & operator-=(SIMDPack< T1 > &lhs, const SIMDPack< T2 > &rhs)
Subtraction assignment operator for the subtraction of two SIMD packs.
Definition: BasicTypes.h:1375
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