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 
55 #include <blaze/util/Assert.h>
61 #include <blaze/util/Exception.h>
62 #include <blaze/util/Types.h>
64 
65 
66 namespace blaze {
67 
68 //=================================================================================================
69 //
70 // CLASS DEFINITION
71 //
72 //=================================================================================================
73 
74 //*************************************************************************************************
108 template< typename MT > // Type of the adapted matrix
110 {
111  private:
112  //**Type definitions****************************************************************************
113  typedef typename MT::ElementType ElementType;
114  typedef typename MT::Iterator IteratorType;
115  //**********************************************************************************************
116 
117  public:
118  //**Type definitions****************************************************************************
120  typedef size_t IndexType;
124  //**********************************************************************************************
125 
126  //**Constructor*********************************************************************************
129  inline HermitianElement( IteratorType pos, MT* matrix, size_t idx );
131  //**********************************************************************************************
132 
133  //**Assignment operators************************************************************************
136  template< typename T > inline HermitianElement& operator= ( const T& v );
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 );
142  //**********************************************************************************************
143 
144  //**Access operators****************************************************************************
147  inline Pointer operator->();
149  //**********************************************************************************************
150 
151  //**Utility functions***************************************************************************
154  inline Reference value() const;
155  inline IndexType index() const;
157  //**********************************************************************************************
158 
159  private:
160  //**Utility functions***************************************************************************
163  inline void sync();
164  inline bool isSynced() const;
166  //**********************************************************************************************
167 
168  //**Member variables****************************************************************************
169  IteratorType pos_;
170  MT* matrix_;
171  size_t index_;
172  //**********************************************************************************************
173 
174  //**Compile time checks*************************************************************************
188  //**********************************************************************************************
189 };
190 //*************************************************************************************************
191 
192 
193 
194 
195 //=================================================================================================
196 //
197 // CONSTRUCTORS
198 //
199 //=================================================================================================
200 
201 //*************************************************************************************************
208 template< typename MT > // Type of the adapted matrix
209 inline HermitianElement<MT>::HermitianElement( IteratorType pos, MT* matrix, size_t idx )
210  : pos_ ( pos ) // Iterator to the current sparse Hermitian matrix element
211  , matrix_( matrix ) // The sparse matrix containing the iterator
212  , index_ ( idx ) // The row/column index of the iterator
213 {
214  BLAZE_INTERNAL_ASSERT( isSynced(), "Missing matrix element detected" );
215 }
216 //*************************************************************************************************
217 
218 
219 
220 
221 //=================================================================================================
222 //
223 // OPERATORS
224 //
225 //=================================================================================================
226 
227 //*************************************************************************************************
234 template< typename MT > // Type of the adapted matrix
235 template< typename T > // Type of the right-hand side value
237 {
238  if( IsComplex<ElementType>::value && pos_->index() == index_ && !isReal( v ) ) {
239  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to diagonal matrix element" );
240  }
241 
242  *pos_ = v;
243  sync();
244 
245  return *this;
246 }
247 //*************************************************************************************************
248 
249 
250 //*************************************************************************************************
257 template< typename MT > // Type of the adapted matrix
258 template< typename T > // Type of the right-hand side value
260 {
261  if( IsComplex<ElementType>::value && pos_->index() == index_ && !isReal( v ) ) {
262  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to diagonal matrix element" );
263  }
264 
265  *pos_ += v;
266  sync();
267  return *this;
268 }
269 //*************************************************************************************************
270 
271 
272 //*************************************************************************************************
279 template< typename MT > // Type of the adapted matrix
280 template< typename T > // Type of the right-hand side value
282 {
283  if( IsComplex<ElementType>::value && pos_->index() == index_ && !isReal( v ) ) {
284  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to diagonal matrix element" );
285  }
286 
287  *pos_ -= v;
288  sync();
289  return *this;
290 }
291 //*************************************************************************************************
292 
293 
294 //*************************************************************************************************
301 template< typename MT > // Type of the adapted matrix
302 template< typename T > // Type of the right-hand side value
304 {
305  if( IsComplex<ElementType>::value && pos_->index() == index_ && !isReal( v ) ) {
306  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to diagonal matrix element" );
307  }
308 
309  *pos_ *= v;
310  sync();
311  return *this;
312 }
313 //*************************************************************************************************
314 
315 
316 //*************************************************************************************************
323 template< typename MT > // Type of the adapted matrix
324 template< typename T > // Type of the right-hand side value
326 {
327  if( IsComplex<ElementType>::value && pos_->index() == index_ && !isReal( v ) ) {
328  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to diagonal matrix element" );
329  }
330 
331  *pos_ /= v;
332  sync();
333  return *this;
334 }
335 //*************************************************************************************************
336 
337 
338 
339 
340 //=================================================================================================
341 //
342 // ACCESS OPERATORS
343 //
344 //=================================================================================================
345 
346 //*************************************************************************************************
351 template< typename MT > // Type of the adapted matrix
353 {
354  return this;
355 }
356 //*************************************************************************************************
357 
358 
359 
360 
361 //=================================================================================================
362 //
363 // UTILITY FUNCTIONS
364 //
365 //=================================================================================================
366 
367 //*************************************************************************************************
372 template< typename MT > // Type of the adapted matrix
374 {
375  return Reference( pos_, matrix_, index_ );
376 }
377 //*************************************************************************************************
378 
379 
380 //*************************************************************************************************
385 template< typename MT > // Type of the adapted matrix
387 {
388  return pos_->index();
389 }
390 //*************************************************************************************************
391 
392 
393 //*************************************************************************************************
398 template< typename MT > // Type of the adapted matrix
400 {
401  if( pos_->index() == index_ || isDefault( pos_->value() ) )
402  return;
403 
404  const size_t row ( ( IsRowMajorMatrix<MT>::value )?( pos_->index() ):( index_ ) );
405  const size_t column( ( IsRowMajorMatrix<MT>::value )?( index_ ):( pos_->index() ) );
406 
407  matrix_->set( row, column, conj( pos_->value() ) );
408 }
409 //*************************************************************************************************
410 
411 
412 //*************************************************************************************************
417 template< typename MT > // Type of the adapted matrix
419 {
420  const size_t row ( ( IsRowMajorMatrix<MT>::value )?( pos_->index() ):( index_ ) );
421  const size_t column( ( IsRowMajorMatrix<MT>::value )?( index_ ):( pos_->index() ) );
422 
423  const IteratorType pos2( matrix_->find( row, column ) );
424  const IteratorType end( matrix_->end( pos_->index() ) );
425 
426  return ( isDefault( pos_->value() ) && ( pos2 == end || isDefault( pos2->value() ) ) ) ||
427  ( pos2 != end && pos_->value() == conj( pos2->value() ) );
428 }
429 //*************************************************************************************************
430 
431 } // namespace blaze
432 
433 #endif
HermitianValue< MT > Reference
Reference return type.
Definition: HermitianElement.h:121
#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:116
#define BLAZE_THROW_INVALID_ARGUMENT(MESSAGE)
Macro for the emission of a std::invalid_argument exceptionThis macro encapsulates the default way of...
Definition: Exception.h:187
Constraint on the data type.
Pointer operator->()
Direct access to the Hermitian element.
Definition: HermitianElement.h:352
void sync()
Synchronization of the current sparse element to the according paired element.
Definition: HermitianElement.h:399
Header file for basic type definitions.
const HermitianValue< MT > ConstReference
Reference-to-const return type.
Definition: HermitianElement.h:122
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:250
bool isReal(const DiagonalProxy< MT > &proxy)
Returns whether the matrix element represents a real number.
Definition: DiagonalProxy.h:569
Reference value() const
Access to the current value of the Hermitian element.
Definition: HermitianElement.h:373
IteratorType pos_
Iterator to the current sparse Hermitian matrix element.
Definition: HermitianElement.h:169
Constraint on the data type.
bool isSynced() const
Checking if the current sparse element is in sync.
Definition: HermitianElement.h:418
HermitianElement(IteratorType pos, MT *matrix, size_t idx)
Constructor for the HermitianElement class.
Definition: HermitianElement.h:209
DisableIf< Or< IsComputation< MT >, IsTransExpr< MT > >, typename ColumnExprTrait< MT >::Type >::Type column(Matrix< MT, SO > &matrix, size_t index)
Creating a view on a specific column of the given matrix.
Definition: Column.h:107
#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:116
size_t index_
The row/column index of the iterator.
Definition: HermitianElement.h:171
Constraint on the data type.
bool isDefault(const DiagonalProxy< MT > &proxy)
Returns whether the represented element is in default state.
Definition: DiagonalProxy.h:547
Constraint on the data type.
Constraint on the data type.
ConjExprTrait< typename DiagonalProxy< MT >::RepresentedType >::Type conj(const DiagonalProxy< MT > &proxy)
Computing the complex conjugate of the represented element.
Definition: DiagonalProxy.h:487
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:110
size_t IndexType
The index type of the value-index-pair.
Definition: HermitianElement.h:120
#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:116
MT::Iterator IteratorType
Type of the underlying sparse matrix iterators.
Definition: HermitianElement.h:114
Constraint on the data type.
Header file for the SparseElement base class.
#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:118
Type ElementType
Type of the sparse matrix elements.
Definition: CompressedMatrix.h:2586
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 > >, typename RowExprTrait< MT >::Type >::Type row(Matrix< MT, SO > &matrix, size_t index)
Creating a view on a specific row of the given matrix.
Definition: Row.h:107
#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:116
Header file for run time assertion macros.
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:79
#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:118
#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:116
Element * Iterator
Iterator over non-constant elements.
Definition: CompressedMatrix.h:2591
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
Header file for the HermitianValue class.
Representation of two synchronized elements within the sparse Hermitian matrix.The HermitianElement c...
Definition: HermitianElement.h:109
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:118
IndexType index() const
Access to the current index of the Hermitian element.
Definition: HermitianElement.h:386
Header file for the IsComplex type trait.
MatrixAccessProxy< This > Reference
Reference to a non-constant matrix value.
Definition: CompressedMatrix.h:2589
#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:116
HermitianValue< MT > ValueType
The value type of the value-index-pair.
Definition: HermitianElement.h:119
Header file for exception macros.
MT::ElementType ElementType
Type of the represented matrix element.
Definition: HermitianElement.h:113
MT * matrix_
The sparse matrix containing the iterator.
Definition: HermitianElement.h:170
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:79
HermitianElement * Pointer
Pointer return type.
Definition: HermitianElement.h:123