NonNumericProxy.h
Go to the documentation of this file.
1 //=================================================================================================
33 //=================================================================================================
34 
35 #ifndef _BLAZE_MATH_ADAPTORS_SYMMETRICMATRIX_NONNUMERICPROXY_H_
36 #define _BLAZE_MATH_ADAPTORS_SYMMETRICMATRIX_NONNUMERICPROXY_H_
37 
38 
39 //*************************************************************************************************
40 // Includes
41 //*************************************************************************************************
42 
43 #include <blaze/math/Aliases.h>
51 #include <blaze/math/proxy/Proxy.h>
52 #include <blaze/math/shims/Clear.h>
54 #include <blaze/math/shims/IsNaN.h>
55 #include <blaze/math/shims/IsOne.h>
58 #include <blaze/math/shims/Reset.h>
60 #include <blaze/util/Assert.h>
66 #include <blaze/util/Types.h>
67 
68 
69 namespace blaze {
70 
71 //=================================================================================================
72 //
73 // CLASS DEFINITION
74 //
75 //=================================================================================================
76 
77 //*************************************************************************************************
102 template< typename MT > // Type of the adapted matrix
103 class NonNumericProxy : public Proxy< NonNumericProxy<MT>, ValueType_< ElementType_<MT> > >
104 {
105  private:
106  //**Enumerations********************************************************************************
108  enum : bool { rmm = IsRowMajorMatrix<MT>::value };
109  //**********************************************************************************************
110 
111  //**Type definitions****************************************************************************
113  typedef ElementType_<MT> ET;
114 
115  //**********************************************************************************************
116 
117  public:
118  //**Type definitions****************************************************************************
121  //**********************************************************************************************
122 
123  //**Constructors********************************************************************************
126  explicit inline NonNumericProxy( MT& sm, size_t i, size_t j );
127  inline NonNumericProxy( const NonNumericProxy& nnp );
129  //**********************************************************************************************
130 
131  //**Destructor**********************************************************************************
134  inline ~NonNumericProxy();
136  //**********************************************************************************************
137 
138  //**Operators***********************************************************************************
141  inline NonNumericProxy& operator= ( const NonNumericProxy& nnp );
142 
143  template< typename T >
145 
146  template< typename T >
148 
149  template< typename T > inline NonNumericProxy& operator= ( const T& value );
150  template< typename T > inline NonNumericProxy& operator+=( const T& value );
151  template< typename T > inline NonNumericProxy& operator-=( const T& value );
152  template< typename T > inline NonNumericProxy& operator*=( const T& value );
153  template< typename T > inline NonNumericProxy& operator/=( const T& value );
155  //**********************************************************************************************
156 
157  //**Utility functions***************************************************************************
160  inline RawReference get() const noexcept;
162  //**********************************************************************************************
163 
164  //**Conversion operator*************************************************************************
167  inline operator RawReference() const noexcept;
169  //**********************************************************************************************
170 
171  private:
172  //**Member variables****************************************************************************
175  MT& matrix_;
176  size_t i_;
177  size_t j_;
178 
179  //**********************************************************************************************
180 
181  //**Forbidden operations************************************************************************
184  void* operator&() const;
185 
186  //**********************************************************************************************
187 
188  //**Compile time checks*************************************************************************
200  BLAZE_CONSTRAINT_MUST_NOT_BE_NUMERIC_TYPE ( RepresentedType );
202  //**********************************************************************************************
203 };
204 //*************************************************************************************************
205 
206 
207 
208 
209 //=================================================================================================
210 //
211 // CONSTRUCTORS
212 //
213 //=================================================================================================
214 
215 //*************************************************************************************************
222 template< typename MT > // Type of the adapted matrix
223 inline NonNumericProxy<MT>::NonNumericProxy( MT& matrix, size_t i, size_t j )
224  : matrix_( matrix ) // Reference to the adapted matrix
225  , i_ ( i ) // Row-index of the accessed matrix element
226  , j_ ( j ) // Column-index of the accessed matrix element
227 {
228  const typename MT::Iterator pos( matrix_.find( i_, j_ ) );
229  const size_t index( rmm ? i_ : j_ );
230 
231  if( pos == matrix_.end(index) )
232  {
233  const ElementType_<MT> element( ( RepresentedType() ) );
234  matrix_.insert( i_, j_, element );
235  if( i_ != j_ )
236  matrix_.insert( j_, i_, element );
237  }
238 
239  BLAZE_INTERNAL_ASSERT( matrix_.find(i_,j_)->value() == matrix_.find(j_,i_)->value(), "Unbalance detected" );
240 }
241 //*************************************************************************************************
242 
243 
244 //*************************************************************************************************
249 template< typename MT > // Type of the adapted matrix
251  : matrix_( nnp.matrix_ ) // Reference to the adapted matrix
252  , i_ ( nnp.i_ ) // Row-index of the accessed matrix element
253  , j_ ( nnp.j_ ) // Column-index of the accessed matrix element
254 {
255  BLAZE_INTERNAL_ASSERT( matrix_.find(i_,j_) != matrix_.end( rmm ? i_ : j_ ), "Missing matrix element detected" );
256  BLAZE_INTERNAL_ASSERT( matrix_.find(j_,i_) != matrix_.end( rmm ? j_ : i_ ), "Missing matrix element detected" );
257 }
258 //*************************************************************************************************
259 
260 
261 
262 
263 //=================================================================================================
264 //
265 // DESTRUCTORS
266 //
267 //=================================================================================================
268 
269 //*************************************************************************************************
272 template< typename MT > // Type of the adapted matrix
274 {
275  const typename MT::Iterator pos( matrix_.find( i_, j_ ) );
276  const size_t index( rmm ? i_ : j_ );
277 
278  if( pos != matrix_.end( index ) && isDefault( *pos->value() ) )
279  {
280  matrix_.erase( index, pos );
281  if( i_ != j_ )
282  matrix_.erase( ( rmm ? j_ : i_ ), matrix_.find( j_, i_ ) );
283  }
284 }
285 //*************************************************************************************************
286 
287 
288 
289 
290 //=================================================================================================
291 //
292 // OPERATORS
293 //
294 //=================================================================================================
295 
296 //*************************************************************************************************
302 template< typename MT > // Type of the adapted matrix
304 {
305  get() = nnp.get();
306  return *this;
307 }
308 //*************************************************************************************************
309 
310 
311 //*************************************************************************************************
317 template< typename MT > // Type of the adapted matrix
318 template< typename T > // Type of the right-hand side value
320 {
321  get() = list;
322 
323  return *this;
324 }
325 //*************************************************************************************************
326 
327 
328 //*************************************************************************************************
334 template< typename MT > // Type of the adapted matrix
335 template< typename T > // Type of the right-hand side value
337 {
338  get() = list;
339 
340  return *this;
341 }
342 //*************************************************************************************************
343 
344 
345 //*************************************************************************************************
351 template< typename MT > // Type of the adapted matrix
352 template< typename T > // Type of the right-hand side value
354 {
355  get() = value;
356  return *this;
357 }
358 //*************************************************************************************************
359 
360 
361 //*************************************************************************************************
367 template< typename MT > // Type of the adapted matrix
368 template< typename T > // Type of the right-hand side value
370 {
371  get() += value;
372  return *this;
373 }
374 //*************************************************************************************************
375 
376 
377 //*************************************************************************************************
383 template< typename MT > // Type of the adapted matrix
384 template< typename T > // Type of the right-hand side value
386 {
387  get() -= value;
388  return *this;
389 }
390 //*************************************************************************************************
391 
392 
393 //*************************************************************************************************
399 template< typename MT > // Type of the adapted matrix
400 template< typename T > // Type of the right-hand side value
402 {
403  get() *= value;
404  return *this;
405 }
406 //*************************************************************************************************
407 
408 
409 //*************************************************************************************************
415 template< typename MT > // Type of the adapted matrix
416 template< typename T > // Type of the right-hand side value
418 {
419  get() /= value;
420  return *this;
421 }
422 //*************************************************************************************************
423 
424 
425 
426 
427 //=================================================================================================
428 //
429 // UTILITY FUNCTIONS
430 //
431 //=================================================================================================
432 
433 //*************************************************************************************************
438 template< typename MT > // Type of the sparse matrix
440 {
441  const typename MT::Iterator pos( matrix_.find( i_, j_ ) );
442  BLAZE_INTERNAL_ASSERT( pos != matrix_.end( rmm ? i_ : j_ ), "Missing matrix element detected" );
443  return *pos->value();
444 }
445 //*************************************************************************************************
446 
447 
448 
449 
450 //=================================================================================================
451 //
452 // CONVERSION OPERATOR
453 //
454 //=================================================================================================
455 
456 //*************************************************************************************************
461 template< typename MT > // Type of the adapted matrix
462 inline NonNumericProxy<MT>::operator RawReference() const noexcept
463 {
464  return get();
465 }
466 //*************************************************************************************************
467 
468 
469 
470 
471 //=================================================================================================
472 //
473 // GLOBAL FUNCTIONS
474 //
475 //=================================================================================================
476 
477 //*************************************************************************************************
480 template< typename MT >
481 inline void reset( const NonNumericProxy<MT>& proxy );
482 
483 template< typename MT >
484 inline void clear( const NonNumericProxy<MT>& proxy );
485 
486 template< typename MT >
487 inline bool isDefault( const NonNumericProxy<MT>& proxy );
488 
489 template< typename MT >
490 inline bool isReal( const NonNumericProxy<MT>& proxy );
491 
492 template< typename MT >
493 inline bool isZero( const NonNumericProxy<MT>& proxy );
494 
495 template< typename MT >
496 inline bool isOne( const NonNumericProxy<MT>& proxy );
497 
498 template< typename MT >
499 inline bool isnan( const NonNumericProxy<MT>& proxy );
501 //*************************************************************************************************
502 
503 
504 //*************************************************************************************************
516 template< typename MT >
517 inline void reset( const NonNumericProxy<MT>& proxy )
518 {
519  using blaze::reset;
520 
521  reset( proxy.get() );
522 }
523 //*************************************************************************************************
524 
525 
526 //*************************************************************************************************
537 template< typename MT >
538 inline void clear( const NonNumericProxy<MT>& proxy )
539 {
540  using blaze::clear;
541 
542  clear( proxy.get() );
543 }
544 //*************************************************************************************************
545 
546 
547 //*************************************************************************************************
557 template< typename MT >
558 inline bool isDefault( const NonNumericProxy<MT>& proxy )
559 {
560  using blaze::isDefault;
561 
562  return isDefault( proxy.get() );
563 }
564 //*************************************************************************************************
565 
566 
567 //*************************************************************************************************
579 template< typename MT >
580 inline bool isReal( const NonNumericProxy<MT>& proxy )
581 {
582  using blaze::isReal;
583 
584  return isReal( proxy.get() );
585 }
586 //*************************************************************************************************
587 
588 
589 //*************************************************************************************************
599 template< typename MT >
600 inline bool isZero( const NonNumericProxy<MT>& proxy )
601 {
602  using blaze::isZero;
603 
604  return isZero( proxy.get() );
605 }
606 //*************************************************************************************************
607 
608 
609 //*************************************************************************************************
619 template< typename MT >
620 inline bool isOne( const NonNumericProxy<MT>& proxy )
621 {
622  using blaze::isOne;
623 
624  return isOne( proxy.get() );
625 }
626 //*************************************************************************************************
627 
628 
629 //*************************************************************************************************
639 template< typename MT >
640 inline bool isnan( const NonNumericProxy<MT>& proxy )
641 {
642  using blaze::isnan;
643 
644  return isnan( proxy.get() );
645 }
646 //*************************************************************************************************
647 
648 } // namespace blaze
649 
650 #endif
Header file for the isnan shim.
#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
bool isOne(const DiagonalProxy< MT > &proxy)
Returns whether the represented element is 1.
Definition: DiagonalProxy.h:635
Header file for auxiliary alias declarations.
Constraint on the data type.
Header file for basic type definitions.
NonNumericProxy & operator=(const NonNumericProxy &nnp)
Copy assignment operator for NonNumericProxy.
Definition: NonNumericProxy.h:303
Proxy base class.The Proxy class is a base class for all proxy classes within the Blaze library that ...
Definition: Forward.h:51
bool isReal(const DiagonalProxy< MT > &proxy)
Returns whether the matrix element represents a real number.
Definition: DiagonalProxy.h:595
Access proxy for symmetric, square matrices with non-numeric element types.The NonNumericProxy provid...
Definition: NonNumericProxy.h:103
ValueType_< ET > RepresentedType
Type of the represented matrix element.
Definition: NonNumericProxy.h:119
Constraint on the data type.
void reset(const DiagonalProxy< MT > &proxy)
Resetting the represented element to the default initial values.
Definition: DiagonalProxy.h:533
#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
Constraint on the data type.
Header file for the Proxy class.
size_t i_
Row-index of the accessed matrix element.
Definition: NonNumericProxy.h:176
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.
Header file for the std::initializer_list aliases.
Constraint on the data type.
size_t j_
Column-index of the accessed matrix element.
Definition: NonNumericProxy.h:177
Header file for the clear shim.
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
#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
typename T::ValueType ValueType_
Alias declaration for nested ValueType type definitions.The ValueType_ alias declaration provides a c...
Definition: Aliases.h:423
Header file for the isZero shim.
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.
bool isnan(const DiagonalProxy< MT > &proxy)
Returns whether the represented element is not a number.
Definition: DiagonalProxy.h:655
#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
#define BLAZE_CONSTRAINT_MUST_NOT_BE_NUMERIC_TYPE(T)
Constraint on the data type.In case the given data type T is a numeric (integral or floating point) d...
Definition: Numeric.h:81
typename T::Reference Reference_
Alias declaration for nested Reference type definitions.The Reference_ alias declaration provides a c...
Definition: Aliases.h:283
void clear(const DiagonalProxy< MT > &proxy)
Clearing the represented element.
Definition: DiagonalProxy.h:553
Header file for the isOne 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
Reference_< ET > RawReference
Raw reference to the represented element.
Definition: NonNumericProxy.h:120
Header file for run time assertion macros.
Constraint on the data type.
Constraint on the data type.
Header file for the reset shim.
#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
Element * Iterator
Iterator over non-constant elements.
Definition: CompressedMatrix.h:2646
Header file for the isDefault shim.
Constraint on the data type.
Constraint on the data type.
MT & matrix_
Reference to the adapted matrix.
Definition: NonNumericProxy.h:175
RawReference get() const noexcept
Returning a reference to the accessed matrix element.
Definition: NonNumericProxy.h:439
Header file for the IsRowMajorMatrix type trait.
Initializer list type of the Blaze library.
NonNumericProxy(MT &sm, size_t i, size_t j)
Initialization constructor for a NonNumericProxy.
Definition: NonNumericProxy.h:223
#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
bool isZero(const DiagonalProxy< MT > &proxy)
Returns whether the represented element is 0.
Definition: DiagonalProxy.h:615
#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
~NonNumericProxy()
The destructor for NonNumericProxy.
Definition: NonNumericProxy.h:273
Header file for the isReal shim.
#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