HermitianElement.h
Go to the documentation of this file.
1 //=================================================================================================
33 //=================================================================================================
34 
35 #ifndef _BLAZE_MATH_ADAPTORS_HERMITIANMATRIX_HERMITIANELEMENT_H_
36 #define _BLAZE_MATH_ADAPTORS_HERMITIANMATRIX_HERMITIANELEMENT_H_
37 
38 
39 //*************************************************************************************************
40 // Includes
41 //*************************************************************************************************
42 
43 #include <blaze/math/Aliases.h>
51 #include <blaze/math/Exception.h>
57 #include <blaze/util/Assert.h>
63 #include <blaze/util/Types.h>
65 
66 
67 namespace blaze {
68 
69 //=================================================================================================
70 //
71 // CLASS DEFINITION
72 //
73 //=================================================================================================
74 
75 //*************************************************************************************************
109 template< typename MT > // Type of the adapted matrix
111 {
112  private:
113  //**Type definitions****************************************************************************
116  //**********************************************************************************************
117 
118  public:
119  //**Type definitions****************************************************************************
121  typedef size_t IndexType;
125  //**********************************************************************************************
126 
127  //**Constructor*********************************************************************************
130  inline HermitianElement( IteratorType pos, MT* matrix, size_t idx );
132  //**********************************************************************************************
133 
134  //**Assignment operators************************************************************************
137  template< typename T > inline HermitianElement& operator= ( const T& v );
138  template< typename T > inline HermitianElement& operator+=( const T& v );
139  template< typename T > inline HermitianElement& operator-=( const T& v );
140  template< typename T > inline HermitianElement& operator*=( const T& v );
141  template< typename T > inline HermitianElement& operator/=( const T& v );
143  //**********************************************************************************************
144 
145  //**Access operators****************************************************************************
148  inline Pointer operator->() noexcept;
150  //**********************************************************************************************
151 
152  //**Utility functions***************************************************************************
155  inline Reference value() const;
156  inline IndexType index() const;
158  //**********************************************************************************************
159 
160  private:
161  //**Utility functions***************************************************************************
164  inline void sync();
165  inline bool isSynced() const;
167  //**********************************************************************************************
168 
169  //**Member variables****************************************************************************
170  IteratorType pos_;
171  MT* matrix_;
172  size_t index_;
173  //**********************************************************************************************
174 
175  //**Compile time checks*************************************************************************
189  //**********************************************************************************************
190 };
191 //*************************************************************************************************
192 
193 
194 
195 
196 //=================================================================================================
197 //
198 // CONSTRUCTORS
199 //
200 //=================================================================================================
201 
202 //*************************************************************************************************
209 template< typename MT > // Type of the adapted matrix
210 inline HermitianElement<MT>::HermitianElement( IteratorType pos, MT* matrix, size_t idx )
211  : pos_ ( pos ) // Iterator to the current sparse Hermitian matrix element
212  , matrix_( matrix ) // The sparse matrix containing the iterator
213  , index_ ( idx ) // The row/column index of the iterator
214 {
215  BLAZE_INTERNAL_ASSERT( isSynced(), "Missing matrix element detected" );
216 }
217 //*************************************************************************************************
218 
219 
220 
221 
222 //=================================================================================================
223 //
224 // OPERATORS
225 //
226 //=================================================================================================
227 
228 //*************************************************************************************************
235 template< typename MT > // Type of the adapted matrix
236 template< typename T > // Type of the right-hand side value
238 {
239  if( IsComplex<ElementType>::value && pos_->index() == index_ && !isReal( v ) ) {
240  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to diagonal matrix element" );
241  }
242 
243  *pos_ = v;
244  sync();
245 
246  return *this;
247 }
248 //*************************************************************************************************
249 
250 
251 //*************************************************************************************************
258 template< typename MT > // Type of the adapted matrix
259 template< typename T > // Type of the right-hand side value
261 {
262  if( IsComplex<ElementType>::value && pos_->index() == index_ && !isReal( v ) ) {
263  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to diagonal matrix element" );
264  }
265 
266  *pos_ += v;
267  sync();
268  return *this;
269 }
270 //*************************************************************************************************
271 
272 
273 //*************************************************************************************************
280 template< typename MT > // Type of the adapted matrix
281 template< typename T > // Type of the right-hand side value
283 {
284  if( IsComplex<ElementType>::value && pos_->index() == index_ && !isReal( v ) ) {
285  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to diagonal matrix element" );
286  }
287 
288  *pos_ -= v;
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  if( IsComplex<ElementType>::value && pos_->index() == index_ && !isReal( v ) ) {
307  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to diagonal matrix element" );
308  }
309 
310  *pos_ *= v;
311  sync();
312  return *this;
313 }
314 //*************************************************************************************************
315 
316 
317 //*************************************************************************************************
324 template< typename MT > // Type of the adapted matrix
325 template< typename T > // Type of the right-hand side value
327 {
328  if( IsComplex<ElementType>::value && pos_->index() == index_ && !isReal( v ) ) {
329  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to diagonal matrix element" );
330  }
331 
332  *pos_ /= v;
333  sync();
334  return *this;
335 }
336 //*************************************************************************************************
337 
338 
339 
340 
341 //=================================================================================================
342 //
343 // ACCESS OPERATORS
344 //
345 //=================================================================================================
346 
347 //*************************************************************************************************
352 template< typename MT > // Type of the adapted matrix
354 {
355  return this;
356 }
357 //*************************************************************************************************
358 
359 
360 
361 
362 //=================================================================================================
363 //
364 // UTILITY FUNCTIONS
365 //
366 //=================================================================================================
367 
368 //*************************************************************************************************
373 template< typename MT > // Type of the adapted matrix
375 {
376  return Reference( pos_, matrix_, index_ );
377 }
378 //*************************************************************************************************
379 
380 
381 //*************************************************************************************************
386 template< typename MT > // Type of the adapted matrix
388 {
389  return pos_->index();
390 }
391 //*************************************************************************************************
392 
393 
394 //*************************************************************************************************
399 template< typename MT > // Type of the adapted matrix
401 {
402  if( pos_->index() == index_ || isDefault( pos_->value() ) )
403  return;
404 
405  const size_t row ( ( IsRowMajorMatrix<MT>::value )?( pos_->index() ):( index_ ) );
406  const size_t column( ( IsRowMajorMatrix<MT>::value )?( index_ ):( pos_->index() ) );
407 
408  matrix_->set( row, column, conj( pos_->value() ) );
409 }
410 //*************************************************************************************************
411 
412 
413 //*************************************************************************************************
418 template< typename MT > // Type of the adapted matrix
420 {
421  const size_t row ( ( IsRowMajorMatrix<MT>::value )?( pos_->index() ):( index_ ) );
422  const size_t column( ( IsRowMajorMatrix<MT>::value )?( index_ ):( pos_->index() ) );
423 
424  const IteratorType pos2( matrix_->find( row, column ) );
425  const IteratorType end( matrix_->end( pos_->index() ) );
426 
427  return ( isDefault( pos_->value() ) && ( pos2 == end || isDefault( pos2->value() ) ) ) ||
428  ( pos2 != end && pos_->value() == conj( pos2->value() ) );
429 }
430 //*************************************************************************************************
431 
432 } // namespace blaze
433 
434 #endif
HermitianValue< MT > Reference
Reference return type.
Definition: HermitianElement.h:122
#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
#define BLAZE_THROW_INVALID_ARGUMENT(MESSAGE)
Macro for the emission of a std::invalid_argument exception.This macro encapsulates the default way o...
Definition: Exception.h:235
const DMatForEachExpr< MT, Conj, SO > conj(const DenseMatrix< MT, SO > &dm)
Returns a matrix containing the complex conjugate of each single element of dm.
Definition: DMatForEachExpr.h:1158
Header file for auxiliary alias declarations.
Constraint on the data type.
void sync()
Synchronization of the current sparse element to the according paired element.
Definition: HermitianElement.h:400
Header file for basic type definitions.
const HermitianValue< MT > ConstReference
Reference-to-const return type.
Definition: HermitianElement.h:123
bool isReal(const DiagonalProxy< MT > &proxy)
Returns whether the matrix element represents a real number.
Definition: DiagonalProxy.h:595
Reference value() const
Access to the current value of the Hermitian element.
Definition: HermitianElement.h:374
IteratorType pos_
Iterator to the current sparse Hermitian matrix element.
Definition: HermitianElement.h:170
Constraint on the data type.
bool isSynced() const
Checking if the current sparse element is in sync.
Definition: HermitianElement.h:419
HermitianElement(IteratorType pos, MT *matrix, size_t idx)
Constructor for the HermitianElement class.
Definition: HermitianElement.h:210
#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
size_t index_
The row/column index of the iterator.
Definition: HermitianElement.h:172
Constraint on the data type.
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
bool isDefault(const DiagonalProxy< MT > &proxy)
Returns whether the represented element is in default state.
Definition: DiagonalProxy.h:573
Constraint on the data type.
Constraint on the data type.
Constraint on the data type.
Namespace of the Blaze C++ math library.
Definition: Blaze.h:57
Compile time check for row-major matrix types.This type trait tests whether or not the given template...
Definition: IsRowMajorMatrix.h:83
size_t IndexType
The index type of the value-index-pair.
Definition: HermitianElement.h:121
#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
Iterator_< MT > IteratorType
Type of the underlying sparse matrix iterators.
Definition: HermitianElement.h:115
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.
Header file for the SparseElement base class.
Header file for the exception macros of the math module.
#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
BLAZE_ALWAYS_INLINE MT::Iterator end(Matrix< MT, SO > &matrix, size_t i)
Returns an iterator just past the last element of row/column i.
Definition: Matrix.h:254
Representation of two synchronized values within a sparse Hermitian matrix.The HermitianValue class r...
Definition: HermitianValue.h:116
Header file for the conjugate shim.
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
#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
Header file for run time assertion macros.
ElementType_< MT > ElementType
Type of the represented matrix element.
Definition: HermitianElement.h:114
Pointer operator->() noexcept
Direct access to the Hermitian element.
Definition: HermitianElement.h:353
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:61
#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
Header file for the isDefault shim.
Constraint on the data type.
Constraint on the data type.
Base class for all sparse element types.The SparseElement class is the base class for all sparse elem...
Definition: SparseElement.h:57
typename T::Iterator Iterator_
Alias declaration for nested Iterator type definitions.The Iterator_ alias declaration provides a con...
Definition: Aliases.h:183
Header file for the HermitianValue class.
Representation of two synchronized elements within the sparse Hermitian matrix.The HermitianElement c...
Definition: HermitianElement.h:110
Compile time check for complex types.This type trait tests whether or not the given template paramete...
Definition: IsComplex.h:76
Header file for the IsRowMajorMatrix type trait.
#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
IndexType index() const
Access to the current index of the Hermitian element.
Definition: HermitianElement.h:387
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
HermitianValue< MT > ValueType
The value type of the value-index-pair.
Definition: HermitianElement.h:120
MT * matrix_
The sparse matrix containing the iterator.
Definition: HermitianElement.h:171
Header file for the isReal shim.
Size type of the Blaze library.
#define BLAZE_INTERNAL_ASSERT(expr, msg)
Run time assertion macro for internal checks.In case of an invalid run time expression, the program execution is terminated. The BLAZE_INTERNAL_ASSERT macro can be disabled by setting the BLAZE_USER_ASSERTION flag to zero or by defining NDEBUG during the compilation.
Definition: Assert.h:101
#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
HermitianElement * Pointer
Pointer return type.
Definition: HermitianElement.h:124