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
104  : public Proxy< NonNumericProxy<MT>, ValueType_< ElementType_<MT> > >
105 {
106  private:
107  //**Enumerations********************************************************************************
109  enum : bool { rmm = IsRowMajorMatrix<MT>::value };
110  //**********************************************************************************************
111 
112  //**Type definitions****************************************************************************
114  using ET = ElementType_<MT>;
115 
116  //**********************************************************************************************
117 
118  public:
119  //**Type definitions****************************************************************************
122  //**********************************************************************************************
123 
124  //**Constructors********************************************************************************
127  explicit inline NonNumericProxy( MT& sm, size_t i, size_t j );
128  inline NonNumericProxy( const NonNumericProxy& nnp );
130  //**********************************************************************************************
131 
132  //**Destructor**********************************************************************************
135  inline ~NonNumericProxy();
137  //**********************************************************************************************
138 
139  //**Operators***********************************************************************************
142  inline NonNumericProxy& operator= ( const NonNumericProxy& nnp );
143 
144  template< typename T >
146 
147  template< typename T >
149 
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 );
154  template< typename T > inline NonNumericProxy& operator/=( const T& value );
155  template< typename T > inline NonNumericProxy& operator%=( const T& value );
157  //**********************************************************************************************
158 
159  //**Utility functions***************************************************************************
162  inline RawReference get() const noexcept;
164  //**********************************************************************************************
165 
166  //**Conversion operator*************************************************************************
169  inline operator RawReference() const noexcept;
171  //**********************************************************************************************
172 
173  private:
174  //**Member variables****************************************************************************
177  MT& matrix_;
178  size_t i_;
179  size_t j_;
180 
181  //**********************************************************************************************
182 
183  //**Forbidden operations************************************************************************
186  void* operator&() const;
187 
188  //**********************************************************************************************
189 
190  //**Compile time checks*************************************************************************
204  //**********************************************************************************************
205 };
206 //*************************************************************************************************
207 
208 
209 
210 
211 //=================================================================================================
212 //
213 // CONSTRUCTORS
214 //
215 //=================================================================================================
216 
217 //*************************************************************************************************
224 template< typename MT > // Type of the adapted matrix
225 inline NonNumericProxy<MT>::NonNumericProxy( MT& matrix, size_t i, size_t j )
226  : matrix_( matrix ) // Reference to the adapted matrix
227  , i_ ( i ) // Row-index of the accessed matrix element
228  , j_ ( j ) // Column-index of the accessed matrix element
229 {
230  const typename MT::Iterator pos( matrix_.find( i_, j_ ) );
231  const size_t index( rmm ? i_ : j_ );
232 
233  if( pos == matrix_.end(index) )
234  {
235  const ElementType_<MT> element( ( RepresentedType() ) );
236  matrix_.insert( i_, j_, element );
237  if( i_ != j_ )
238  matrix_.insert( j_, i_, element );
239  }
240 
241  BLAZE_INTERNAL_ASSERT( matrix_.find(i_,j_)->value() == matrix_.find(j_,i_)->value(), "Unbalance detected" );
242 }
243 //*************************************************************************************************
244 
245 
246 //*************************************************************************************************
251 template< typename MT > // Type of the adapted matrix
253  : matrix_( nnp.matrix_ ) // Reference to the adapted matrix
254  , i_ ( nnp.i_ ) // Row-index of the accessed matrix element
255  , j_ ( nnp.j_ ) // Column-index of the accessed matrix element
256 {
257  BLAZE_INTERNAL_ASSERT( matrix_.find(i_,j_) != matrix_.end( rmm ? i_ : j_ ), "Missing matrix element detected" );
258  BLAZE_INTERNAL_ASSERT( matrix_.find(j_,i_) != matrix_.end( rmm ? j_ : i_ ), "Missing matrix element detected" );
259 }
260 //*************************************************************************************************
261 
262 
263 
264 
265 //=================================================================================================
266 //
267 // DESTRUCTORS
268 //
269 //=================================================================================================
270 
271 //*************************************************************************************************
274 template< typename MT > // Type of the adapted matrix
276 {
277  const typename MT::Iterator pos( matrix_.find( i_, j_ ) );
278  const size_t index( rmm ? i_ : j_ );
279 
280  if( pos != matrix_.end( index ) && isDefault( *pos->value() ) )
281  {
282  matrix_.erase( index, pos );
283  if( i_ != j_ )
284  matrix_.erase( ( rmm ? j_ : i_ ), matrix_.find( j_, i_ ) );
285  }
286 }
287 //*************************************************************************************************
288 
289 
290 
291 
292 //=================================================================================================
293 //
294 // OPERATORS
295 //
296 //=================================================================================================
297 
298 //*************************************************************************************************
304 template< typename MT > // Type of the adapted matrix
306 {
307  get() = nnp.get();
308  return *this;
309 }
310 //*************************************************************************************************
311 
312 
313 //*************************************************************************************************
319 template< typename MT > // Type of the adapted matrix
320 template< typename T > // Type of the right-hand side value
322 {
323  get() = list;
324 
325  return *this;
326 }
327 //*************************************************************************************************
328 
329 
330 //*************************************************************************************************
336 template< typename MT > // Type of the adapted matrix
337 template< typename T > // Type of the right-hand side value
339 {
340  get() = list;
341 
342  return *this;
343 }
344 //*************************************************************************************************
345 
346 
347 //*************************************************************************************************
353 template< typename MT > // Type of the adapted matrix
354 template< typename T > // Type of the right-hand side value
356 {
357  get() = value;
358  return *this;
359 }
360 //*************************************************************************************************
361 
362 
363 //*************************************************************************************************
369 template< typename MT > // Type of the adapted matrix
370 template< typename T > // Type of the right-hand side value
372 {
373  get() += value;
374  return *this;
375 }
376 //*************************************************************************************************
377 
378 
379 //*************************************************************************************************
385 template< typename MT > // Type of the adapted matrix
386 template< typename T > // Type of the right-hand side value
388 {
389  get() -= value;
390  return *this;
391 }
392 //*************************************************************************************************
393 
394 
395 //*************************************************************************************************
401 template< typename MT > // Type of the adapted matrix
402 template< typename T > // Type of the right-hand side value
404 {
405  get() *= value;
406  return *this;
407 }
408 //*************************************************************************************************
409 
410 
411 //*************************************************************************************************
417 template< typename MT > // Type of the adapted matrix
418 template< typename T > // Type of the right-hand side value
420 {
421  get() /= value;
422  return *this;
423 }
424 //*************************************************************************************************
425 
426 
427 //*************************************************************************************************
433 template< typename MT > // Type of the adapted matrix
434 template< typename T > // Type of the right-hand side value
436 {
437  get() %= value;
438  return *this;
439 }
440 //*************************************************************************************************
441 
442 
443 
444 
445 //=================================================================================================
446 //
447 // UTILITY FUNCTIONS
448 //
449 //=================================================================================================
450 
451 //*************************************************************************************************
456 template< typename MT > // Type of the sparse matrix
458 {
459  const typename MT::Iterator pos( matrix_.find( i_, j_ ) );
460  BLAZE_INTERNAL_ASSERT( pos != matrix_.end( rmm ? i_ : j_ ), "Missing matrix element detected" );
461  return *pos->value();
462 }
463 //*************************************************************************************************
464 
465 
466 
467 
468 //=================================================================================================
469 //
470 // CONVERSION OPERATOR
471 //
472 //=================================================================================================
473 
474 //*************************************************************************************************
479 template< typename MT > // Type of the adapted matrix
481 {
482  return get();
483 }
484 //*************************************************************************************************
485 
486 
487 
488 
489 //=================================================================================================
490 //
491 // GLOBAL FUNCTIONS
492 //
493 //=================================================================================================
494 
495 //*************************************************************************************************
498 template< typename MT >
499 inline void reset( const NonNumericProxy<MT>& proxy );
500 
501 template< typename MT >
502 inline void clear( const NonNumericProxy<MT>& proxy );
503 
504 template< bool RF, typename MT >
505 inline bool isDefault( const NonNumericProxy<MT>& proxy );
506 
507 template< bool RF, typename MT >
508 inline bool isReal( const NonNumericProxy<MT>& proxy );
509 
510 template< bool RF, typename MT >
511 inline bool isZero( const NonNumericProxy<MT>& proxy );
512 
513 template< bool RF, typename MT >
514 inline bool isOne( const NonNumericProxy<MT>& proxy );
515 
516 template< typename MT >
517 inline bool isnan( const NonNumericProxy<MT>& proxy );
519 //*************************************************************************************************
520 
521 
522 //*************************************************************************************************
534 template< typename MT >
535 inline void reset( const NonNumericProxy<MT>& proxy )
536 {
537  using blaze::reset;
538 
539  reset( proxy.get() );
540 }
541 //*************************************************************************************************
542 
543 
544 //*************************************************************************************************
555 template< typename MT >
556 inline void clear( const NonNumericProxy<MT>& proxy )
557 {
558  using blaze::clear;
559 
560  clear( proxy.get() );
561 }
562 //*************************************************************************************************
563 
564 
565 //*************************************************************************************************
575 template< bool RF, typename MT >
576 inline bool isDefault( const NonNumericProxy<MT>& proxy )
577 {
578  using blaze::isDefault;
579 
580  return isDefault<RF>( proxy.get() );
581 }
582 //*************************************************************************************************
583 
584 
585 //*************************************************************************************************
597 template< bool RF, typename MT >
598 inline bool isReal( const NonNumericProxy<MT>& proxy )
599 {
600  using blaze::isReal;
601 
602  return isReal<RF>( proxy.get() );
603 }
604 //*************************************************************************************************
605 
606 
607 //*************************************************************************************************
617 template< bool RF, typename MT >
618 inline bool isZero( const NonNumericProxy<MT>& proxy )
619 {
620  using blaze::isZero;
621 
622  return isZero<RF>( proxy.get() );
623 }
624 //*************************************************************************************************
625 
626 
627 //*************************************************************************************************
637 template< bool RF, typename MT >
638 inline bool isOne( const NonNumericProxy<MT>& proxy )
639 {
640  using blaze::isOne;
641 
642  return isOne<RF>( proxy.get() );
643 }
644 //*************************************************************************************************
645 
646 
647 //*************************************************************************************************
657 template< typename MT >
658 inline bool isnan( const NonNumericProxy<MT>& proxy )
659 {
660  using blaze::isnan;
661 
662  return isnan( proxy.get() );
663 }
664 //*************************************************************************************************
665 
666 } // namespace blaze
667 
668 #endif
bool isReal(const DiagonalProxy< MT > &proxy)
Returns whether the matrix element represents a real number.
Definition: DiagonalProxy.h:622
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
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:305
Proxy base class.The Proxy class is a base class for all proxy classes within the Blaze library that ...
Definition: Forward.h:51
Access proxy for symmetric, square matrices with non-numeric element types.The NonNumericProxy provid...
Definition: NonNumericProxy.h:103
Constraint on the data type.
void reset(const DiagonalProxy< MT > &proxy)
Resetting the represented element to the default initial values.
Definition: DiagonalProxy.h:560
#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
Element * Iterator
Iterator over non-constant elements.
Definition: CompressedMatrix.h:3086
Constraint on the data type.
Header file for the Proxy class.
size_t i_
Row-index of the accessed matrix element.
Definition: NonNumericProxy.h:178
Constraint on the data type.
Constraint on the data type.
Header file for the std::initializer_list aliases.
Constraint on the data type.
bool isZero(const DiagonalProxy< MT > &proxy)
Returns whether the represented element is 0.
Definition: DiagonalProxy.h:642
size_t j_
Column-index of the accessed matrix element.
Definition: NonNumericProxy.h:179
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:110
#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:443
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.
RawReference get() const noexcept
Returning a reference to the accessed matrix element.
Definition: NonNumericProxy.h:457
bool isnan(const DiagonalProxy< MT > &proxy)
Returns whether the represented element is not a number.
Definition: DiagonalProxy.h:682
#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:303
void clear(const DiagonalProxy< MT > &proxy)
Clearing the represented element.
Definition: DiagonalProxy.h:580
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
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
bool isOne(const DiagonalProxy< MT > &proxy)
Returns whether the represented element is 1.
Definition: DiagonalProxy.h:662
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:177
Reference_< ET > RawReference
Raw reference to the represented element.
Definition: NonNumericProxy.h:121
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:225
#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 isDefault(const DiagonalProxy< MT > &proxy)
Returns whether the represented element is in default state.
Definition: DiagonalProxy.h:600
#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
ValueType_< ET > RepresentedType
Type of the represented matrix element.
Definition: NonNumericProxy.h:120
~NonNumericProxy()
The destructor for NonNumericProxy.
Definition: NonNumericProxy.h:275
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