Blaze  3.6
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>
52 #include <blaze/math/proxy/Proxy.h>
53 #include <blaze/math/shims/Clear.h>
56 #include <blaze/math/shims/IsNaN.h>
57 #include <blaze/math/shims/IsOne.h>
60 #include <blaze/math/shims/Reset.h>
67 #include <blaze/util/InvalidType.h>
68 #include <blaze/util/mpl/If.h>
69 #include <blaze/util/Types.h>
71 
72 
73 namespace blaze {
74 
75 //=================================================================================================
76 //
77 // CLASS DEFINITION
78 //
79 //=================================================================================================
80 
81 //*************************************************************************************************
114 template< typename MT > // Type of the adapted matrix
116  : public Proxy< SymmetricValue<MT> >
117 {
118  private:
119  //**Type definitions****************************************************************************
120  using IteratorType = typename MT::Iterator;
121  //**********************************************************************************************
122 
123  //**struct BuiltinType**************************************************************************
127  template< typename T >
128  struct BuiltinType { using Type = INVALID_TYPE; };
130  //**********************************************************************************************
131 
132  //**struct ComplexType**************************************************************************
136  template< typename T >
137  struct ComplexType { using Type = typename T::value_type; };
139  //**********************************************************************************************
140 
141  public:
142  //**Type definitions****************************************************************************
144 
147  , ComplexType<RepresentedType>
148  , BuiltinType<RepresentedType> >::Type;
149 
151  //**********************************************************************************************
152 
153  //**Constructors********************************************************************************
156  inline SymmetricValue( IteratorType pos, MT* matrix, size_t index );
158  //**********************************************************************************************
159 
160  //**Assignment operators************************************************************************
163  inline SymmetricValue& operator= ( const SymmetricValue& sv );
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 );
167  template< typename T > inline SymmetricValue& operator*=( const T& value );
168  template< typename T > inline SymmetricValue& operator/=( const T& value );
170  //**********************************************************************************************
171 
172  //**Utility functions***************************************************************************
175  inline void reset () const;
176  inline void clear () const;
177  inline void invert() const;
178 
179  inline RepresentedType get() const noexcept;
181  //**********************************************************************************************
182 
183  //**Conversion operator*************************************************************************
186  inline operator RepresentedType() const noexcept;
188  //**********************************************************************************************
189 
190  //**Complex data access functions***************************************************************
193  inline ValueType real() const;
194  inline void real( ValueType value ) const;
195  inline ValueType imag() const;
196  inline void imag( ValueType value ) const;
198  //**********************************************************************************************
199 
200  private:
201  //**Utility functions***************************************************************************
204  inline void sync() const;
206  //**********************************************************************************************
207 
208  //**Member variables****************************************************************************
210  MT* matrix_;
211  size_t index_;
212  //**********************************************************************************************
213 
214  //**Compile time checks*************************************************************************
230  //**********************************************************************************************
231 };
232 //*************************************************************************************************
233 
234 
235 
236 
237 //=================================================================================================
238 //
239 // CONSTRUCTORS
240 //
241 //=================================================================================================
242 
243 //*************************************************************************************************
250 template< typename MT > // Type of the adapted matrix
251 inline SymmetricValue<MT>::SymmetricValue( IteratorType pos, MT* matrix, size_t index )
252  : pos_ ( pos ) // Iterator to the current sparse symmetric matrix element
253  , matrix_( matrix ) // The sparse matrix containing the iterator
254  , index_ ( index ) // The row/column index of the iterator
255 {}
256 //*************************************************************************************************
257 
258 
259 
260 
261 //=================================================================================================
262 //
263 // OPERATORS
264 //
265 //=================================================================================================
266 
267 //*************************************************************************************************
273 template< typename MT > // Type of the adapted matrix
275 {
276  pos_->value() = sv.pos_->value();
277  sync();
278  return *this;
279 }
280 //*************************************************************************************************
281 
282 
283 //*************************************************************************************************
289 template< typename MT > // Type of the adapted matrix
290 template< typename T > // Type of the right-hand side value
292 {
293  pos_->value() = value;
294  sync();
295  return *this;
296 }
297 //*************************************************************************************************
298 
299 
300 //*************************************************************************************************
307 template< typename MT > // Type of the adapted matrix
308 template< typename T > // Type of the right-hand side value
310 {
311  pos_->value() += value;
312  sync();
313  return *this;
314 }
315 //*************************************************************************************************
316 
317 
318 //*************************************************************************************************
324 template< typename MT > // Type of the adapted matrix
325 template< typename T > // Type of the right-hand side value
327 {
328  pos_->value() -= value;
329  sync();
330  return *this;
331 }
332 //*************************************************************************************************
333 
334 
335 //*************************************************************************************************
341 template< typename MT > // Type of the adapted matrix
342 template< typename T > // Type of the right-hand side value
344 {
345  pos_->value() *= value;
346  sync();
347  return *this;
348 }
349 //*************************************************************************************************
350 
351 
352 //*************************************************************************************************
358 template< typename MT > // Type of the adapted matrix
359 template< typename T > // Type of the right-hand side value
361 {
362  pos_->value() /= value;
363  sync();
364  return *this;
365 }
366 //*************************************************************************************************
367 
368 
369 
370 
371 //=================================================================================================
372 //
373 // UTILITY FUNCTIONS
374 //
375 //=================================================================================================
376 
377 //*************************************************************************************************
384 template< typename MT > // Type of the adapted matrix
385 inline void SymmetricValue<MT>::reset() const
386 {
387  using blaze::reset;
388 
389  reset( pos_->value() );
390 
391  if( pos_->index() != index_ )
392  {
393  const size_t row ( ( IsRowMajorMatrix_v<MT> )?( pos_->index() ):( index_ ) );
394  const size_t column( ( IsRowMajorMatrix_v<MT> )?( index_ ):( pos_->index() ) );
395  const IteratorType pos2( matrix_->find( row, column ) );
396 
397  reset( pos2->value() );
398  }
399 }
400 //*************************************************************************************************
401 
402 
403 //*************************************************************************************************
410 template< typename MT > // Type of the adapted matrix
411 inline void SymmetricValue<MT>::clear() const
412 {
413  using blaze::clear;
414 
415  clear( pos_->value() );
416 
417  if( pos_->index() != index_ )
418  {
419  const size_t row ( ( IsRowMajorMatrix_v<MT> )?( pos_->index() ):( index_ ) );
420  const size_t column( ( IsRowMajorMatrix_v<MT> )?( index_ ):( pos_->index() ) );
421  const IteratorType pos2( matrix_->find( row, column ) );
422 
423  clear( pos2->value() );
424  }
425 }
426 //*************************************************************************************************
427 
428 
429 //*************************************************************************************************
434 template< typename MT > // Type of the adapted matrix
435 inline void SymmetricValue<MT>::invert() const
436 {
437  using blaze::invert;
438 
439  invert( pos_->value() );
440 
441  if( pos_->index() != index_ )
442  {
443  const size_t row ( ( IsRowMajorMatrix_v<MT> )?( pos_->index() ):( index_ ) );
444  const size_t column( ( IsRowMajorMatrix_v<MT> )?( index_ ):( pos_->index() ) );
445  const IteratorType pos2( matrix_->find( row, column ) );
446 
447  pos2->value() = pos_->value();
448  }
449 }
450 //*************************************************************************************************
451 
452 
453 //*************************************************************************************************
458 template< typename MT > // Type of the adapted matrix
460 {
461  return pos_->value();
462 }
463 //*************************************************************************************************
464 
465 
466 //*************************************************************************************************
471 template< typename MT > // Type of the adapted matrix
472 inline void SymmetricValue<MT>::sync() const
473 {
474  if( pos_->index() == index_ || isDefault( pos_->value() ) )
475  return;
476 
477  const size_t row ( ( IsRowMajorMatrix_v<MT> )?( pos_->index() ):( index_ ) );
478  const size_t column( ( IsRowMajorMatrix_v<MT> )?( index_ ):( pos_->index() ) );
479 
480  matrix_->set( row, column, pos_->value() );
481 }
482 //*************************************************************************************************
483 
484 
485 
486 
487 //=================================================================================================
488 //
489 // CONVERSION OPERATOR
490 //
491 //=================================================================================================
492 
493 //*************************************************************************************************
498 template< typename MT > // Type of the adapted matrix
500 {
501  return pos_->value();
502 }
503 //*************************************************************************************************
504 
505 
506 
507 
508 //=================================================================================================
509 //
510 // COMPLEX DATA ACCESS FUNCTIONS
511 //
512 //=================================================================================================
513 
514 //*************************************************************************************************
522 template< typename MT > // Type of the adapted matrix
524 {
525  return pos_->value().real();
526 }
527 //*************************************************************************************************
528 
529 
530 //*************************************************************************************************
539 template< typename MT > // Type of the adapted matrix
540 inline void SymmetricValue<MT>::real( ValueType value ) const
541 {
542  pos_->value().real() = value;
543  sync();
544 }
545 //*************************************************************************************************
546 
547 
548 //*************************************************************************************************
556 template< typename MT > // Type of the adapted matrix
558 {
559  return pos_->value.imag();
560 }
561 //*************************************************************************************************
562 
563 
564 //*************************************************************************************************
573 template< typename MT > // Type of the adapted matrix
574 inline void SymmetricValue<MT>::imag( ValueType value ) const
575 {
576  pos_->value().imag( value );
577  sync();
578 }
579 //*************************************************************************************************
580 
581 
582 
583 
584 //=================================================================================================
585 //
586 // GLOBAL FUNCTIONS
587 //
588 //=================================================================================================
589 
590 //*************************************************************************************************
593 template< typename MT >
594 void reset( const SymmetricValue<MT>& value );
595 
596 template< typename MT >
597 void clear( const SymmetricValue<MT>& value );
598 
599 template< typename MT >
600 void invert( const SymmetricValue<MT>& value );
601 
602 template< bool RF, typename MT >
603 bool isDefault( const SymmetricValue<MT>& value );
604 
605 template< bool RF, typename MT >
606 bool isReal( const SymmetricValue<MT>& value );
607 
608 template< bool RF, typename MT >
609 bool isZero( const SymmetricValue<MT>& value );
610 
611 template< bool RF, typename MT >
612 bool isOne( const SymmetricValue<MT>& value );
613 
614 template< typename MT >
615 bool isnan( const SymmetricValue<MT>& value );
617 //*************************************************************************************************
618 
619 
620 //*************************************************************************************************
629 template< typename MT >
630 inline void reset( const SymmetricValue<MT>& value )
631 {
632  value.reset();
633 }
634 //*************************************************************************************************
635 
636 
637 //*************************************************************************************************
646 template< typename MT >
647 inline void clear( const SymmetricValue<MT>& value )
648 {
649  value.clear();
650 }
651 //*************************************************************************************************
652 
653 
654 //*************************************************************************************************
661 template< typename MT >
662 inline void invert( const SymmetricValue<MT>& value )
663 {
664  value.invert();
665 }
666 //*************************************************************************************************
667 
668 
669 //*************************************************************************************************
679 template< bool RF, typename MT >
680 inline bool isDefault( const SymmetricValue<MT>& value )
681 {
682  using blaze::isDefault;
683 
684  return isDefault<RF>( value.get() );
685 }
686 //*************************************************************************************************
687 
688 
689 //*************************************************************************************************
701 template< bool RF, typename MT >
702 inline bool isReal( const SymmetricValue<MT>& value )
703 {
704  using blaze::isReal;
705 
706  return isReal<RF>( value.get() );
707 }
708 //*************************************************************************************************
709 
710 
711 //*************************************************************************************************
721 template< bool RF, typename MT >
722 inline bool isZero( const SymmetricValue<MT>& value )
723 {
724  using blaze::isZero;
725 
726  return isZero<RF>( value.get() );
727 }
728 //*************************************************************************************************
729 
730 
731 //*************************************************************************************************
741 template< bool RF, typename MT >
742 inline bool isOne( const SymmetricValue<MT>& value )
743 {
744  using blaze::isOne;
745 
746  return isOne<RF>( value.get() );
747 }
748 //*************************************************************************************************
749 
750 
751 //*************************************************************************************************
761 template< typename MT >
762 inline bool isnan( const SymmetricValue<MT>& value )
763 {
764  using blaze::isnan;
765 
766  return isnan( value.get() );
767 }
768 //*************************************************************************************************
769 
770 } // namespace blaze
771 
772 #endif
bool isReal(const DiagonalProxy< MT > &proxy)
Returns whether the matrix element represents a real number.
Definition: DiagonalProxy.h:657
#define BLAZE_CONSTRAINT_MUST_NOT_BE_TRANSFORMATION_TYPE(T)
Constraint on the data type.In case the given data type T is a transformation expression (i....
Definition: Transformation.h:81
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,...
Definition: Const.h:79
Constraint on the data type.
Header file for auxiliary alias declarations.
typename MT::Iterator IteratorType
Type of the underlying sparse matrix iterators.
Definition: SymmetricValue.h:120
decltype(auto) column(Matrix< MT, SO > &matrix, RCAs... args)
Creating a view on a specific column of the given matrix.
Definition: Column.h:133
Constraint on the data type.
Constraint on the data type.
void sync() const
Synchronization of the current sparse element to the according paired element.
Definition: SymmetricValue.h:472
Header file for basic type definitions.
typename If_t< IsComplex_v< RepresentedType >, ComplexType< RepresentedType >, BuiltinType< RepresentedType > >::Type ValueType
Value type of the represented complex element.
Definition: SymmetricValue.h:148
typename If< Condition, T1, T2 >::Type If_t
Auxiliary alias template for the If class template.The If_t alias template provides a convenient shor...
Definition: If.h:109
Proxy base class.The Proxy class is a base class for all proxy classes within the Blaze library that ...
Definition: Forward.h:51
Header file for the isZero shim.
SymmetricValue & operator=(const SymmetricValue &sv)
Copy assignment operator for SymmetricValue.
Definition: SymmetricValue.h:274
#define BLAZE_CONSTRAINT_MUST_NOT_BE_COMPUTATION_TYPE(T)
Constraint on the data type.In case the given data type T is a computational expression (i....
Definition: Computation.h:81
MT * matrix_
The sparse matrix containing the iterator.
Definition: SymmetricValue.h:210
void reset(const DiagonalProxy< MT > &proxy)
Resetting the represented element to the default initial values.
Definition: DiagonalProxy.h:595
#define BLAZE_CONSTRAINT_MUST_NOT_BE_VOLATILE(T)
Constraint on the data type.In case the given data type is a volatile-qualified type,...
Definition: Volatile.h:79
Header file for the invert shim.
Header file for the reset shim.
Constraint on the data type.
Header file for the Proxy class.
typename T::ElementType ElementType_t
Alias declaration for nested ElementType type definitions.The ElementType_t alias declaration provide...
Definition: Aliases.h:170
Constraint on the data type.
IteratorType pos_
Iterator to the current sparse symmetric matrix element.
Definition: SymmetricValue.h:209
Constraint on the data type.
Constraint on the data type.
bool isZero(const DiagonalProxy< MT > &proxy)
Returns whether the represented element is 0.
Definition: DiagonalProxy.h:677
void invert(const HermitianProxy< MT > &proxy)
In-place inversion of the represented element.
Definition: HermitianProxy.h:779
Namespace of the Blaze C++ math library.
Definition: Blaze.h:58
Header file for the If class template.
#define BLAZE_CONSTRAINT_MUST_NOT_BE_POINTER_TYPE(T)
Constraint on the data type.In case the given data type T is not a pointer type, a compilation error ...
Definition: Pointer.h:79
Constraint on the data type.
bool isnan(const DiagonalProxy< MT > &proxy)
Returns whether the represented element is not a number.
Definition: DiagonalProxy.h:717
#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:459
void clear(const DiagonalProxy< MT > &proxy)
Clearing the represented element.
Definition: DiagonalProxy.h:615
Header file for the isOne shim.
size_t index_
The row/column index of the iterator.
Definition: SymmetricValue.h:211
ElementType_t< MT > RepresentedType
Type of the represented matrix element.
Definition: SymmetricValue.h:143
ValueType value_type
Value type of the represented complex element.
Definition: SymmetricValue.h:150
#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,...
Definition: Symmetric.h:79
Utility type for generic codes.
Constraint on the data type.
Constraint on the data type.
decltype(auto) row(Matrix< MT, SO > &, RRAs...)
Creating a view on a specific row of the given matrix.
Definition: Row.h:133
#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:115
#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,...
Definition: Reference.h:79
bool isOne(const DiagonalProxy< MT > &proxy)
Returns whether the represented element is 1.
Definition: DiagonalProxy.h:697
Header file for the isDefault shim.
Constraint on the data type.
Constraint on the data type.
#define BLAZE_CONSTRAINT_MUST_NOT_BE_VIEW_TYPE(T)
Constraint on the data type.In case the given data type T is a view type (i.e. a subvector,...
Definition: View.h:81
void clear() const
Clearing the symmetric value.
Definition: SymmetricValue.h:411
void reset() const
Reset the symmetric value to its default initial value.
Definition: SymmetricValue.h:385
void invert() const
In-place inversion of the symmetric value.
Definition: SymmetricValue.h:435
SymmetricValue(IteratorType pos, MT *matrix, size_t index)
Constructor for the SymmetricValue class.
Definition: SymmetricValue.h:251
Header file for the IsRowMajorMatrix type trait.
ValueType real() const
Returns the real part of the represented complex number.
Definition: SymmetricValue.h:523
ValueType imag() const
Returns the imaginary part of the represented complex number.
Definition: SymmetricValue.h:557
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:635
#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,...
Definition: Hermitian.h:79
Constraint on the data type.
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
Header file for the clear shim.