Blaze 3.9
NonScalarProxy.h
Go to the documentation of this file.
1//=================================================================================================
33//=================================================================================================
34
35#ifndef _BLAZE_MATH_ADAPTORS_SYMMETRICMATRIX_NONSCALARPROXY_H_
36#define _BLAZE_MATH_ADAPTORS_SYMMETRICMATRIX_NONSCALARPROXY_H_
37
38
39//*************************************************************************************************
40// Includes
41//*************************************************************************************************
42
43#include <blaze/math/Aliases.h>
61#include <blaze/util/Assert.h>
66#include <blaze/util/Types.h>
67
68
69namespace blaze {
70
71//=================================================================================================
72//
73// CLASS DEFINITION
74//
75//=================================================================================================
76
77//*************************************************************************************************
102template< typename MT > // Type of the adapted matrix
104 : public Proxy< NonScalarProxy<MT>, ValueType_t< ElementType_t<MT> > >
105{
106 private:
107 //**Enumerations********************************************************************************
109 static constexpr bool rmm = IsRowMajorMatrix_v<MT>;
110 //**********************************************************************************************
111
112 //**Type definitions****************************************************************************
114 using ET = ElementType_t<MT>;
116 //**********************************************************************************************
117
118 public:
119 //**Type definitions****************************************************************************
122 //**********************************************************************************************
123
124 //**Constructors********************************************************************************
127 inline NonScalarProxy( MT& sm, size_t i, size_t j );
128
129 NonScalarProxy( const NonScalarProxy& ) = default;
131 //**********************************************************************************************
132
133 //**Destructor**********************************************************************************
136 inline ~NonScalarProxy();
138 //**********************************************************************************************
139
140 //**Operators***********************************************************************************
143 inline NonScalarProxy& operator= ( const NonScalarProxy& nsp );
144
145 template< typename T >
146 inline NonScalarProxy& operator=( initializer_list<T> list );
147
148 template< typename T >
149 inline NonScalarProxy& operator=( initializer_list< initializer_list<T> > list );
150
151 template< typename T > inline NonScalarProxy& operator= ( const T& value );
152 template< typename T > inline NonScalarProxy& operator+=( const T& value );
153 template< typename T > inline NonScalarProxy& operator-=( const T& value );
154 template< typename T > inline NonScalarProxy& operator*=( const T& value );
155 template< typename T > inline NonScalarProxy& operator/=( const T& value );
156 template< typename T > inline NonScalarProxy& operator%=( const T& value );
158 //**********************************************************************************************
159
160 //**Utility functions***************************************************************************
163 inline RawReference get() const noexcept;
165 //**********************************************************************************************
166
167 //**Conversion operator*************************************************************************
170 inline operator RawReference() const noexcept;
172 //**********************************************************************************************
173
174 private:
175 //**Member variables****************************************************************************
179 size_t i_;
180 size_t j_;
182 //**********************************************************************************************
183
184 //**Forbidden operations************************************************************************
187 void* operator&() const;
189 //**********************************************************************************************
190
191 //**Compile time checks*************************************************************************
207 //**********************************************************************************************
208};
209//*************************************************************************************************
210
211
212
213
214//=================================================================================================
215//
216// CONSTRUCTORS
217//
218//=================================================================================================
219
220//*************************************************************************************************
227template< typename MT > // Type of the adapted matrix
228inline NonScalarProxy<MT>::NonScalarProxy( MT& matrix, size_t i, size_t j )
229 : matrix_( matrix ) // Reference to the adapted matrix
230 , i_ ( i ) // Row-index of the accessed matrix element
231 , j_ ( j ) // Column-index of the accessed matrix element
232{
233 const typename MT::Iterator pos( matrix_.find( i_, j_ ) );
234 const size_t index( rmm ? i_ : j_ );
235
236 if( pos == matrix_.end(index) )
237 {
238 const ElementType_t<MT> element( ( RepresentedType() ) );
239 matrix_.insert( i_, j_, element );
240 if( i_ != j_ )
241 matrix_.insert( j_, i_, element );
242 }
243
244 BLAZE_INTERNAL_ASSERT( matrix_.find(i_,j_)->value() == matrix_.find(j_,i_)->value(), "Unbalance detected" );
245}
246//*************************************************************************************************
247
248
249
250
251//=================================================================================================
252//
253// DESTRUCTORS
254//
255//=================================================================================================
256
257//*************************************************************************************************
260template< typename MT > // Type of the adapted matrix
262{
263 const typename MT::Iterator pos( matrix_.find( i_, j_ ) );
264 const size_t index( rmm ? i_ : j_ );
265
266 if( pos != matrix_.end( index ) && isDefault( *pos->value() ) )
267 {
268 matrix_.erase( index, pos );
269 if( i_ != j_ )
270 matrix_.erase( ( rmm ? j_ : i_ ), matrix_.find( j_, i_ ) );
271 }
272}
273//*************************************************************************************************
274
275
276
277
278//=================================================================================================
279//
280// OPERATORS
281//
282//=================================================================================================
283
284//*************************************************************************************************
290template< typename MT > // Type of the adapted matrix
292{
293 get() = nsp.get();
294 return *this;
295}
296//*************************************************************************************************
297
298
299//*************************************************************************************************
305template< typename MT > // Type of the adapted matrix
306template< typename T > // Type of the right-hand side value
307inline NonScalarProxy<MT>& NonScalarProxy<MT>::operator=( initializer_list<T> list )
308{
309 get() = list;
310
311 return *this;
312}
313//*************************************************************************************************
314
315
316//*************************************************************************************************
322template< typename MT > // Type of the adapted matrix
323template< typename T > // Type of the right-hand side value
324inline NonScalarProxy<MT>& NonScalarProxy<MT>::operator=( initializer_list< initializer_list<T> > list )
325{
326 get() = list;
327
328 return *this;
329}
330//*************************************************************************************************
331
332
333//*************************************************************************************************
339template< typename MT > // Type of the adapted matrix
340template< typename T > // Type of the right-hand side value
342{
343 get() = value;
344 return *this;
345}
346//*************************************************************************************************
347
348
349//*************************************************************************************************
355template< typename MT > // Type of the adapted matrix
356template< typename T > // Type of the right-hand side value
358{
359 get() += value;
360 return *this;
361}
362//*************************************************************************************************
363
364
365//*************************************************************************************************
371template< typename MT > // Type of the adapted matrix
372template< typename T > // Type of the right-hand side value
374{
375 get() -= value;
376 return *this;
377}
378//*************************************************************************************************
379
380
381//*************************************************************************************************
387template< typename MT > // Type of the adapted matrix
388template< typename T > // Type of the right-hand side value
390{
391 get() *= value;
392 return *this;
393}
394//*************************************************************************************************
395
396
397//*************************************************************************************************
403template< typename MT > // Type of the adapted matrix
404template< typename T > // Type of the right-hand side value
406{
407 get() /= value;
408 return *this;
409}
410//*************************************************************************************************
411
412
413//*************************************************************************************************
419template< typename MT > // Type of the adapted matrix
420template< typename T > // Type of the right-hand side value
422{
423 get() %= value;
424 return *this;
425}
426//*************************************************************************************************
427
428
429
430
431//=================================================================================================
432//
433// UTILITY FUNCTIONS
434//
435//=================================================================================================
436
437//*************************************************************************************************
442template< typename MT > // Type of the sparse matrix
444{
445 const typename MT::Iterator pos( matrix_.find( i_, j_ ) );
446 BLAZE_INTERNAL_ASSERT( pos != matrix_.end( rmm ? i_ : j_ ), "Missing matrix element detected" );
447 return *pos->value();
448}
449//*************************************************************************************************
450
451
452
453
454//=================================================================================================
455//
456// CONVERSION OPERATOR
457//
458//=================================================================================================
459
460//*************************************************************************************************
465template< typename MT > // Type of the adapted matrix
467{
468 return get();
469}
470//*************************************************************************************************
471
472} // namespace blaze
473
474#endif
Header file for auxiliary alias declarations.
typename T::ValueType ValueType_t
Alias declaration for nested ValueType type definitions.
Definition: Aliases.h:570
typename T::ElementType ElementType_t
Alias declaration for nested ElementType type definitions.
Definition: Aliases.h:190
typename T::Reference Reference_t
Alias declaration for nested Reference type definitions.
Definition: Aliases.h:390
Header file for run time assertion macros.
Constraint on the data type.
Constraint on the data type.
Header file for the isDefault shim.
Header file for the isOne 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.
Header file for the relaxation flag enumeration.
Constraint on the data type.
Constraint on the data type.
Constraint on the data type.
Constraint on the data type.
Access proxy for symmetric, square matrices with non-scalar element types.
Definition: NonScalarProxy.h:105
static constexpr bool rmm
Compile time flag indicating whether the given matrix type is a row-major matrix.
Definition: NonScalarProxy.h:109
NonScalarProxy & operator=(const NonScalarProxy &nsp)
Copy assignment operator for NonScalarProxy.
Definition: NonScalarProxy.h:291
~NonScalarProxy()
The destructor for NonScalarProxy.
Definition: NonScalarProxy.h:261
Reference_t< ET > RawReference
Raw reference to the represented element.
Definition: NonScalarProxy.h:121
size_t i_
Row-index of the accessed matrix element.
Definition: NonScalarProxy.h:179
RawReference get() const noexcept
Returning a reference to the accessed matrix element.
Definition: NonScalarProxy.h:443
ValueType_t< ET > RepresentedType
Type of the represented matrix element.
Definition: NonScalarProxy.h:120
size_t j_
Column-index of the accessed matrix element.
Definition: NonScalarProxy.h:180
NonScalarProxy(MT &sm, size_t i, size_t j)
Initialization constructor for a NonScalarProxy.
Definition: NonScalarProxy.h:228
MT & matrix_
Reference to the adapted matrix.
Definition: NonScalarProxy.h:178
Proxy base class.
Definition: Proxy.h:169
Constraint on the data type.
Constraint on the data type.
Constraint on the data type.
Constraint on the data type.
#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
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_NOT_BE_SCALAR_TYPE(T)
Constraint on the data type.
Definition: Scalar.h:81
#define BLAZE_CONSTRAINT_MUST_NOT_BE_TRANSFORMATION_TYPE(T)
Constraint on the data type.
Definition: Transformation.h:81
#define BLAZE_INTERNAL_ASSERT(expr, msg)
Run time assertion macro for internal checks.
Definition: Assert.h:101
Header file for the extended initializer_list functionality.
Header file for the Proxy class.
Header file for the isZero shim.
Header file for basic type definitions.