Blaze 3.9
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>
60#include <blaze/util/Assert.h>
65#include <blaze/util/Types.h>
67
68
69namespace blaze {
70
71//=================================================================================================
72//
73// CLASS DEFINITION
74//
75//=================================================================================================
76
77//*************************************************************************************************
111template< typename MT > // Type of the adapted matrix
113 : private SparseElement
114{
115 private:
116 //**Type definitions****************************************************************************
119 //**********************************************************************************************
120
121 public:
122 //**Type definitions****************************************************************************
124 using IndexType = size_t;
128 //**********************************************************************************************
129
130 //**Constructor*********************************************************************************
133 inline HermitianElement( IteratorType pos, MT* matrix, size_t idx );
135 //**********************************************************************************************
136
137 //**Assignment operators************************************************************************
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 );
143 template< typename T > inline HermitianElement& operator*=( const T& v );
144 template< typename T > inline HermitianElement& operator/=( const T& v );
146 //**********************************************************************************************
147
148 //**Access operators****************************************************************************
151 inline Pointer operator->() noexcept;
153 //**********************************************************************************************
154
155 //**Utility functions***************************************************************************
158 inline Reference value() const;
159 inline IndexType index() const;
161 //**********************************************************************************************
162
163 private:
164 //**Utility functions***************************************************************************
167 inline void sync();
168 inline bool isSynced() const;
170 //**********************************************************************************************
171
172 //**Member variables****************************************************************************
175 size_t index_;
176 //**********************************************************************************************
177
178 //**Compile time checks*************************************************************************
194 //**********************************************************************************************
195};
196//*************************************************************************************************
197
198
199
200
201//=================================================================================================
202//
203// CONSTRUCTORS
204//
205//=================================================================================================
206
207//*************************************************************************************************
214template< typename MT > // Type of the adapted matrix
215inline HermitianElement<MT>::HermitianElement( IteratorType pos, MT* matrix, size_t idx )
216 : pos_ ( pos ) // Iterator to the current sparse Hermitian matrix element
217 , matrix_( matrix ) // The sparse matrix containing the iterator
218 , index_ ( idx ) // The row/column index of the iterator
219{
220 BLAZE_INTERNAL_ASSERT( isSynced(), "Missing matrix element detected" );
221}
222//*************************************************************************************************
223
224
225
226
227//=================================================================================================
228//
229// OPERATORS
230//
231//=================================================================================================
232
233//*************************************************************************************************
240template< typename MT > // Type of the adapted matrix
241template< typename T > // Type of the right-hand side value
243{
244 if( IsComplex_v<ElementType> && pos_->index() == index_ && !isReal( v ) ) {
245 BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to diagonal matrix element" );
246 }
247
248 *pos_ = v;
249 sync();
250
251 return *this;
252}
253//*************************************************************************************************
254
255
256//*************************************************************************************************
263template< typename MT > // Type of the adapted matrix
264template< typename T > // Type of the right-hand side value
266{
267 if( IsComplex_v<ElementType> && pos_->index() == index_ && !isReal( v ) ) {
268 BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to diagonal matrix element" );
269 }
270
271 *pos_ += v;
272 sync();
273 return *this;
274}
275//*************************************************************************************************
276
277
278//*************************************************************************************************
285template< typename MT > // Type of the adapted matrix
286template< typename T > // Type of the right-hand side value
288{
289 if( IsComplex_v<ElementType> && pos_->index() == index_ && !isReal( v ) ) {
290 BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to diagonal matrix element" );
291 }
292
293 *pos_ -= v;
294 sync();
295 return *this;
296}
297//*************************************************************************************************
298
299
300//*************************************************************************************************
307template< typename MT > // Type of the adapted matrix
308template< typename T > // Type of the right-hand side value
310{
311 if( IsComplex_v<ElementType> && pos_->index() == index_ && !isReal( v ) ) {
312 BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to diagonal matrix element" );
313 }
314
315 *pos_ *= v;
316 sync();
317 return *this;
318}
319//*************************************************************************************************
320
321
322//*************************************************************************************************
329template< typename MT > // Type of the adapted matrix
330template< typename T > // Type of the right-hand side value
332{
333 if( IsComplex_v<ElementType> && pos_->index() == index_ && !isReal( v ) ) {
334 BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to diagonal matrix element" );
335 }
336
337 *pos_ /= v;
338 sync();
339 return *this;
340}
341//*************************************************************************************************
342
343
344
345
346//=================================================================================================
347//
348// ACCESS OPERATORS
349//
350//=================================================================================================
351
352//*************************************************************************************************
357template< typename MT > // Type of the adapted matrix
359{
360 return this;
361}
362//*************************************************************************************************
363
364
365
366
367//=================================================================================================
368//
369// UTILITY FUNCTIONS
370//
371//=================================================================================================
372
373//*************************************************************************************************
378template< typename MT > // Type of the adapted matrix
380{
381 return Reference( pos_, matrix_, index_ );
382}
383//*************************************************************************************************
384
385
386//*************************************************************************************************
391template< typename MT > // Type of the adapted matrix
393{
394 return pos_->index();
395}
396//*************************************************************************************************
397
398
399//*************************************************************************************************
404template< typename MT > // Type of the adapted matrix
406{
407 if( pos_->index() == index_ || isDefault( pos_->value() ) )
408 return;
409
410 const size_t row ( ( IsRowMajorMatrix_v<MT> )?( pos_->index() ):( index_ ) );
411 const size_t column( ( IsRowMajorMatrix_v<MT> )?( index_ ):( pos_->index() ) );
412
413 matrix_->set( row, column, conj( pos_->value() ) );
414}
415//*************************************************************************************************
416
417
418//*************************************************************************************************
423template< typename MT > // Type of the adapted matrix
425{
426 const size_t row ( ( IsRowMajorMatrix_v<MT> )?( pos_->index() ):( index_ ) );
427 const size_t column( ( IsRowMajorMatrix_v<MT> )?( index_ ):( pos_->index() ) );
428
429 const IteratorType pos2( matrix_->find( row, column ) );
430 const IteratorType end( matrix_->end( pos_->index() ) );
431
432 return ( isDefault( pos_->value() ) && ( pos2 == end || isDefault( pos2->value() ) ) ) ||
433 ( pos2 != end && pos_->value() == conj( pos2->value() ) );
434}
435//*************************************************************************************************
436
437} // namespace blaze
438
439#endif
Header file for auxiliary alias declarations.
typename T::ElementType ElementType_t
Alias declaration for nested ElementType type definitions.
Definition: Aliases.h:190
typename T::Iterator Iterator_t
Alias declaration for nested Iterator type definitions.
Definition: Aliases.h:210
Header file for run time assertion macros.
Header file for the conjugate shim.
Constraint on the data type.
Header file for the HermitianValue class.
Constraint on the data type.
Header file for the IsComplex type trait.
Header file for the isDefault shim.
Header file for the isReal shim.
Header file for the IsRowMajorMatrix type trait.
Constraint on the data type.
Constraint on the data type.
Constraint on the data type.
Constraint on the data type.
Constraint on the data type.
Constraint on the data type.
Constraint on the data type.
Representation of two synchronized elements within the sparse Hermitian matrix.
Definition: HermitianElement.h:114
Pointer operator->() noexcept
Direct access to the Hermitian element.
Definition: HermitianElement.h:358
MT * matrix_
The sparse matrix containing the iterator.
Definition: HermitianElement.h:174
size_t index_
The row/column index of the iterator.
Definition: HermitianElement.h:175
size_t IndexType
The index type of the value-index-pair.
Definition: HermitianElement.h:124
bool isSynced() const
Checking if the current sparse element is in sync.
Definition: HermitianElement.h:424
Iterator_t< MT > IteratorType
Type of the underlying sparse matrix iterators.
Definition: HermitianElement.h:118
void sync()
Synchronization of the current sparse element to the according paired element.
Definition: HermitianElement.h:405
IndexType index() const
Access to the current index of the Hermitian element.
Definition: HermitianElement.h:392
ElementType_t< MT > ElementType
Type of the represented matrix element.
Definition: HermitianElement.h:117
Reference value() const
Access to the current value of the Hermitian element.
Definition: HermitianElement.h:379
HermitianValue< MT > Reference
Reference return type.
Definition: HermitianElement.h:125
HermitianElement(IteratorType pos, MT *matrix, size_t idx)
Constructor for the HermitianElement class.
Definition: HermitianElement.h:215
IteratorType pos_
Iterator to the current sparse Hermitian matrix element.
Definition: HermitianElement.h:173
Representation of two synchronized values within a sparse Hermitian matrix.
Definition: HermitianValue.h:120
Constraint on the data type.
Constraint on the data type.
Constraint on the data type.
Constraint on the data type.
decltype(auto) column(Matrix< MT, SO > &matrix, RCAs... args)
Creating a view on a specific column of the given matrix.
Definition: Column.h:137
#define BLAZE_CONSTRAINT_MUST_NOT_BE_VOLATILE(T)
Constraint on the data type.
Definition: Volatile.h:79
#define BLAZE_CONSTRAINT_MUST_NOT_BE_POINTER_TYPE(T)
Constraint on the data type.
Definition: Pointer.h:79
#define BLAZE_CONSTRAINT_MUST_NOT_BE_CONST(T)
Constraint on the data type.
Definition: Const.h:79
#define BLAZE_CONSTRAINT_MUST_NOT_BE_REFERENCE_TYPE(T)
Constraint on the data type.
Definition: Reference.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:1464
bool isDefault(const DiagonalMatrix< MT, SO, DF > &m)
Returns whether the given diagonal matrix is in default state.
Definition: DiagonalMatrix.h:169
#define BLAZE_CONSTRAINT_MUST_NOT_BE_SYMMETRIC_MATRIX_TYPE(T)
Constraint on the data type.
Definition: Symmetric.h:79
#define BLAZE_CONSTRAINT_MUST_NOT_BE_VIEW_TYPE(T)
Constraint on the data type.
Definition: View.h:81
#define BLAZE_CONSTRAINT_MUST_NOT_BE_HERMITIAN_MATRIX_TYPE(T)
Constraint on the data type.
Definition: Hermitian.h:79
#define BLAZE_CONSTRAINT_MUST_NOT_BE_UPPER_MATRIX_TYPE(T)
Constraint on the data type.
Definition: Upper.h:81
#define BLAZE_CONSTRAINT_MUST_NOT_BE_COMPUTATION_TYPE(T)
Constraint on the data type.
Definition: Computation.h:81
#define BLAZE_CONSTRAINT_MUST_BE_SPARSE_MATRIX_TYPE(T)
Constraint on the data type.
Definition: SparseMatrix.h:61
#define BLAZE_CONSTRAINT_MUST_NOT_BE_LOWER_MATRIX_TYPE(T)
Constraint on the data type.
Definition: Lower.h:81
#define BLAZE_CONSTRAINT_MUST_BE_SCALAR_TYPE(T)
Constraint on the data type.
Definition: Scalar.h:61
#define BLAZE_CONSTRAINT_MUST_NOT_BE_TRANSFORMATION_TYPE(T)
Constraint on the data type.
Definition: Transformation.h:81
bool isReal(const Proxy< PT, RT > &proxy)
Returns whether the element represents a real number.
Definition: Proxy.h:2297
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:584
decltype(auto) row(Matrix< MT, SO > &, RRAs...)
Creating a view on a specific row of the given matrix.
Definition: Row.h:137
#define BLAZE_INTERNAL_ASSERT(expr, msg)
Run time assertion macro for internal checks.
Definition: Assert.h:101
#define BLAZE_THROW_INVALID_ARGUMENT(MESSAGE)
Macro for the emission of a std::invalid_argument exception.
Definition: Exception.h:235
Header file for the exception macros of the math module.
Header file for the SparseElement base class.
Base class for all sparse element types.
Definition: SparseElement.h:58
Header file for basic type definitions.