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  : private SparseElement
112 {
113  private:
114  //**Type definitions****************************************************************************
117  //**********************************************************************************************
118 
119  public:
120  //**Type definitions****************************************************************************
122  using IndexType = size_t;
126  //**********************************************************************************************
127 
128  //**Constructor*********************************************************************************
131  inline HermitianElement( IteratorType pos, MT* matrix, size_t idx );
133  //**********************************************************************************************
134 
135  //**Assignment operators************************************************************************
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 );
142  template< typename T > inline HermitianElement& operator/=( const T& v );
144  //**********************************************************************************************
145 
146  //**Access operators****************************************************************************
149  inline Pointer operator->() noexcept;
151  //**********************************************************************************************
152 
153  //**Utility functions***************************************************************************
156  inline Reference value() const;
157  inline IndexType index() const;
159  //**********************************************************************************************
160 
161  private:
162  //**Utility functions***************************************************************************
165  inline void sync();
166  inline bool isSynced() const;
168  //**********************************************************************************************
169 
170  //**Member variables****************************************************************************
172  MT* matrix_;
173  size_t index_;
174  //**********************************************************************************************
175 
176  //**Compile time checks*************************************************************************
190  //**********************************************************************************************
191 };
192 //*************************************************************************************************
193 
194 
195 
196 
197 //=================================================================================================
198 //
199 // CONSTRUCTORS
200 //
201 //=================================================================================================
202 
203 //*************************************************************************************************
210 template< typename MT > // Type of the adapted matrix
211 inline HermitianElement<MT>::HermitianElement( IteratorType pos, MT* matrix, size_t idx )
212  : pos_ ( pos ) // Iterator to the current sparse Hermitian matrix element
213  , matrix_( matrix ) // The sparse matrix containing the iterator
214  , index_ ( idx ) // The row/column index of the iterator
215 {
216  BLAZE_INTERNAL_ASSERT( isSynced(), "Missing matrix element detected" );
217 }
218 //*************************************************************************************************
219 
220 
221 
222 
223 //=================================================================================================
224 //
225 // OPERATORS
226 //
227 //=================================================================================================
228 
229 //*************************************************************************************************
236 template< typename MT > // Type of the adapted matrix
237 template< typename T > // Type of the right-hand side value
239 {
240  if( IsComplex_v<ElementType> && pos_->index() == index_ && !isReal( v ) ) {
241  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to diagonal matrix element" );
242  }
243 
244  *pos_ = v;
245  sync();
246 
247  return *this;
248 }
249 //*************************************************************************************************
250 
251 
252 //*************************************************************************************************
259 template< typename MT > // Type of the adapted matrix
260 template< typename T > // Type of the right-hand side value
262 {
263  if( IsComplex_v<ElementType> && pos_->index() == index_ && !isReal( v ) ) {
264  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to diagonal matrix element" );
265  }
266 
267  *pos_ += v;
268  sync();
269  return *this;
270 }
271 //*************************************************************************************************
272 
273 
274 //*************************************************************************************************
281 template< typename MT > // Type of the adapted matrix
282 template< typename T > // Type of the right-hand side value
284 {
285  if( IsComplex_v<ElementType> && pos_->index() == index_ && !isReal( v ) ) {
286  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to diagonal matrix element" );
287  }
288 
289  *pos_ -= v;
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  if( IsComplex_v<ElementType> && pos_->index() == index_ && !isReal( v ) ) {
308  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to diagonal matrix element" );
309  }
310 
311  *pos_ *= v;
312  sync();
313  return *this;
314 }
315 //*************************************************************************************************
316 
317 
318 //*************************************************************************************************
325 template< typename MT > // Type of the adapted matrix
326 template< typename T > // Type of the right-hand side value
328 {
329  if( IsComplex_v<ElementType> && pos_->index() == index_ && !isReal( v ) ) {
330  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to diagonal matrix element" );
331  }
332 
333  *pos_ /= v;
334  sync();
335  return *this;
336 }
337 //*************************************************************************************************
338 
339 
340 
341 
342 //=================================================================================================
343 //
344 // ACCESS OPERATORS
345 //
346 //=================================================================================================
347 
348 //*************************************************************************************************
353 template< typename MT > // Type of the adapted matrix
355 {
356  return this;
357 }
358 //*************************************************************************************************
359 
360 
361 
362 
363 //=================================================================================================
364 //
365 // UTILITY FUNCTIONS
366 //
367 //=================================================================================================
368 
369 //*************************************************************************************************
374 template< typename MT > // Type of the adapted matrix
376 {
377  return Reference( pos_, matrix_, index_ );
378 }
379 //*************************************************************************************************
380 
381 
382 //*************************************************************************************************
387 template< typename MT > // Type of the adapted matrix
389 {
390  return pos_->index();
391 }
392 //*************************************************************************************************
393 
394 
395 //*************************************************************************************************
400 template< typename MT > // Type of the adapted matrix
402 {
403  if( pos_->index() == index_ || isDefault( pos_->value() ) )
404  return;
405 
406  const size_t row ( ( IsRowMajorMatrix_v<MT> )?( pos_->index() ):( index_ ) );
407  const size_t column( ( IsRowMajorMatrix_v<MT> )?( index_ ):( pos_->index() ) );
408 
409  matrix_->set( row, column, conj( pos_->value() ) );
410 }
411 //*************************************************************************************************
412 
413 
414 //*************************************************************************************************
419 template< typename MT > // Type of the adapted matrix
421 {
422  const size_t row ( ( IsRowMajorMatrix_v<MT> )?( pos_->index() ):( index_ ) );
423  const size_t column( ( IsRowMajorMatrix_v<MT> )?( index_ ):( pos_->index() ) );
424 
425  const IteratorType pos2( matrix_->find( row, column ) );
426  const IteratorType end( matrix_->end( pos_->index() ) );
427 
428  return ( isDefault( pos_->value() ) && ( pos2 == end || isDefault( pos2->value() ) ) ) ||
429  ( pos2 != end && pos_->value() == conj( pos2->value() ) );
430 }
431 //*************************************************************************************************
432 
433 } // namespace blaze
434 
435 #endif
bool isReal(const DiagonalProxy< MT > &proxy)
Returns whether the matrix element represents a real number.
Definition: DiagonalProxy.h:653
#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
Header file for auxiliary alias declarations.
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.
void sync()
Synchronization of the current sparse element to the according paired element.
Definition: HermitianElement.h:401
Header file for basic type definitions.
HermitianValue< MT > Reference
Reference return type.
Definition: HermitianElement.h:123
IteratorType pos_
Iterator to the current sparse Hermitian matrix element.
Definition: HermitianElement.h:171
Iterator_t< MT > IteratorType
Type of the underlying sparse matrix iterators.
Definition: HermitianElement.h:116
Constraint on the data type.
HermitianElement(IteratorType pos, MT *matrix, size_t idx)
Constructor for the HermitianElement class.
Definition: HermitianElement.h:211
#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
Reference value() const
Access to the current value of the Hermitian element.
Definition: HermitianElement.h:375
size_t index_
The row/column index of the iterator.
Definition: HermitianElement.h:173
Constraint on the data type.
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.
Constraint on the data type.
Constraint on the data type.
bool isSynced() const
Checking if the current sparse element is in sync.
Definition: HermitianElement.h:420
Namespace of the Blaze C++ math library.
Definition: Blaze.h:58
#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.
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
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:438
Representation of two synchronized values within a sparse Hermitian matrix.The HermitianValue class r...
Definition: HermitianValue.h:116
Header file for the conjugate shim.
#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
typename T::Iterator Iterator_t
Alias declaration for nested Iterator type definitions.The Iterator_t alias declaration provides a co...
Definition: Aliases.h:190
Header file for run time assertion macros.
Pointer operator->() noexcept
Direct access to the Hermitian element.
Definition: HermitianElement.h:354
ElementType_t< MT > ElementType
Type of the represented matrix element.
Definition: HermitianElement.h:115
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
#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
IndexType index() const
Access to the current index of the Hermitian element.
Definition: HermitianElement.h:388
Header file for the HermitianValue class.
Representation of two synchronized elements within the sparse Hermitian matrix.The HermitianElement c...
Definition: HermitianElement.h:110
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
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:631
#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
decltype(auto) conj(const DenseMatrix< MT, SO > &dm)
Returns a matrix containing the complex conjugate of each single element of dm.
Definition: DMatMapExpr.h:1326
MT * matrix_
The sparse matrix containing the iterator.
Definition: HermitianElement.h:172
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