Blaze  3.6
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>
53 #include <blaze/math/proxy/Proxy.h>
54 #include <blaze/math/shims/Clear.h>
56 #include <blaze/math/shims/IsNaN.h>
57 #include <blaze/math/shims/IsOne.h>
60 #include <blaze/math/shims/Reset.h>
62 #include <blaze/util/Assert.h>
68 #include <blaze/util/Types.h>
69 
70 
71 namespace blaze {
72 
73 //=================================================================================================
74 //
75 // CLASS DEFINITION
76 //
77 //=================================================================================================
78 
79 //*************************************************************************************************
104 template< typename MT > // Type of the adapted matrix
106  : public Proxy< NonNumericProxy<MT>, ValueType_t< ElementType_t<MT> > >
107 {
108  private:
109  //**Enumerations********************************************************************************
111  static constexpr bool rmm = IsRowMajorMatrix_v<MT>;
112  //**********************************************************************************************
113 
114  //**Type definitions****************************************************************************
116  using ET = ElementType_t<MT>;
117 
118  //**********************************************************************************************
119 
120  public:
121  //**Type definitions****************************************************************************
124  //**********************************************************************************************
125 
126  //**Constructors********************************************************************************
129  explicit inline NonNumericProxy( MT& sm, size_t i, size_t j );
130  inline NonNumericProxy( const NonNumericProxy& nnp );
132  //**********************************************************************************************
133 
134  //**Destructor**********************************************************************************
137  inline ~NonNumericProxy();
139  //**********************************************************************************************
140 
141  //**Operators***********************************************************************************
144  inline NonNumericProxy& operator= ( const NonNumericProxy& nnp );
145 
146  template< typename T >
148 
149  template< typename T >
151 
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 );
156  template< typename T > inline NonNumericProxy& operator/=( const T& value );
157  template< typename T > inline NonNumericProxy& operator%=( const T& value );
159  //**********************************************************************************************
160 
161  //**Utility functions***************************************************************************
164  inline RawReference get() const noexcept;
166  //**********************************************************************************************
167 
168  //**Conversion operator*************************************************************************
171  inline operator RawReference() const noexcept;
173  //**********************************************************************************************
174 
175  private:
176  //**Member variables****************************************************************************
179  MT& matrix_;
180  size_t i_;
181  size_t j_;
182 
183  //**********************************************************************************************
184 
185  //**Forbidden operations************************************************************************
188  void* operator&() const;
189 
190  //**********************************************************************************************
191 
192  //**Compile time checks*************************************************************************
208  //**********************************************************************************************
209 };
210 //*************************************************************************************************
211 
212 
213 
214 
215 //=================================================================================================
216 //
217 // CONSTRUCTORS
218 //
219 //=================================================================================================
220 
221 //*************************************************************************************************
228 template< typename MT > // Type of the adapted matrix
229 inline NonNumericProxy<MT>::NonNumericProxy( MT& matrix, size_t i, size_t j )
230  : matrix_( matrix ) // Reference to the adapted matrix
231  , i_ ( i ) // Row-index of the accessed matrix element
232  , j_ ( j ) // Column-index of the accessed matrix element
233 {
234  const typename MT::Iterator pos( matrix_.find( i_, j_ ) );
235  const size_t index( rmm ? i_ : j_ );
236 
237  if( pos == matrix_.end(index) )
238  {
239  const ElementType_t<MT> element( ( RepresentedType() ) );
240  matrix_.insert( i_, j_, element );
241  if( i_ != j_ )
242  matrix_.insert( j_, i_, element );
243  }
244 
245  BLAZE_INTERNAL_ASSERT( matrix_.find(i_,j_)->value() == matrix_.find(j_,i_)->value(), "Unbalance detected" );
246 }
247 //*************************************************************************************************
248 
249 
250 //*************************************************************************************************
255 template< typename MT > // Type of the adapted matrix
257  : matrix_( nnp.matrix_ ) // Reference to the adapted matrix
258  , i_ ( nnp.i_ ) // Row-index of the accessed matrix element
259  , j_ ( nnp.j_ ) // Column-index of the accessed matrix element
260 {
261  BLAZE_INTERNAL_ASSERT( matrix_.find(i_,j_) != matrix_.end( rmm ? i_ : j_ ), "Missing matrix element detected" );
262  BLAZE_INTERNAL_ASSERT( matrix_.find(j_,i_) != matrix_.end( rmm ? j_ : i_ ), "Missing matrix element detected" );
263 }
264 //*************************************************************************************************
265 
266 
267 
268 
269 //=================================================================================================
270 //
271 // DESTRUCTORS
272 //
273 //=================================================================================================
274 
275 //*************************************************************************************************
278 template< typename MT > // Type of the adapted matrix
280 {
281  const typename MT::Iterator pos( matrix_.find( i_, j_ ) );
282  const size_t index( rmm ? i_ : j_ );
283 
284  if( pos != matrix_.end( index ) && isDefault( *pos->value() ) )
285  {
286  matrix_.erase( index, pos );
287  if( i_ != j_ )
288  matrix_.erase( ( rmm ? j_ : i_ ), matrix_.find( j_, i_ ) );
289  }
290 }
291 //*************************************************************************************************
292 
293 
294 
295 
296 //=================================================================================================
297 //
298 // OPERATORS
299 //
300 //=================================================================================================
301 
302 //*************************************************************************************************
308 template< typename MT > // Type of the adapted matrix
310 {
311  get() = nnp.get();
312  return *this;
313 }
314 //*************************************************************************************************
315 
316 
317 //*************************************************************************************************
323 template< typename MT > // Type of the adapted matrix
324 template< typename T > // Type of the right-hand side value
326 {
327  get() = list;
328 
329  return *this;
330 }
331 //*************************************************************************************************
332 
333 
334 //*************************************************************************************************
340 template< typename MT > // Type of the adapted matrix
341 template< typename T > // Type of the right-hand side value
343 {
344  get() = list;
345 
346  return *this;
347 }
348 //*************************************************************************************************
349 
350 
351 //*************************************************************************************************
357 template< typename MT > // Type of the adapted matrix
358 template< typename T > // Type of the right-hand side value
360 {
361  get() = value;
362  return *this;
363 }
364 //*************************************************************************************************
365 
366 
367 //*************************************************************************************************
373 template< typename MT > // Type of the adapted matrix
374 template< typename T > // Type of the right-hand side value
376 {
377  get() += value;
378  return *this;
379 }
380 //*************************************************************************************************
381 
382 
383 //*************************************************************************************************
389 template< typename MT > // Type of the adapted matrix
390 template< typename T > // Type of the right-hand side value
392 {
393  get() -= value;
394  return *this;
395 }
396 //*************************************************************************************************
397 
398 
399 //*************************************************************************************************
405 template< typename MT > // Type of the adapted matrix
406 template< typename T > // Type of the right-hand side value
408 {
409  get() *= value;
410  return *this;
411 }
412 //*************************************************************************************************
413 
414 
415 //*************************************************************************************************
421 template< typename MT > // Type of the adapted matrix
422 template< typename T > // Type of the right-hand side value
424 {
425  get() /= value;
426  return *this;
427 }
428 //*************************************************************************************************
429 
430 
431 //*************************************************************************************************
437 template< typename MT > // Type of the adapted matrix
438 template< typename T > // Type of the right-hand side value
440 {
441  get() %= value;
442  return *this;
443 }
444 //*************************************************************************************************
445 
446 
447 
448 
449 //=================================================================================================
450 //
451 // UTILITY FUNCTIONS
452 //
453 //=================================================================================================
454 
455 //*************************************************************************************************
460 template< typename MT > // Type of the sparse matrix
462 {
463  const typename MT::Iterator pos( matrix_.find( i_, j_ ) );
464  BLAZE_INTERNAL_ASSERT( pos != matrix_.end( rmm ? i_ : j_ ), "Missing matrix element detected" );
465  return *pos->value();
466 }
467 //*************************************************************************************************
468 
469 
470 
471 
472 //=================================================================================================
473 //
474 // CONVERSION OPERATOR
475 //
476 //=================================================================================================
477 
478 //*************************************************************************************************
483 template< typename MT > // Type of the adapted matrix
485 {
486  return get();
487 }
488 //*************************************************************************************************
489 
490 
491 
492 
493 //=================================================================================================
494 //
495 // GLOBAL FUNCTIONS
496 //
497 //=================================================================================================
498 
499 //*************************************************************************************************
502 template< typename MT >
503 void reset( const NonNumericProxy<MT>& proxy );
504 
505 template< typename MT >
506 void clear( const NonNumericProxy<MT>& proxy );
507 
508 template< bool RF, typename MT >
509 bool isDefault( const NonNumericProxy<MT>& proxy );
510 
511 template< bool RF, typename MT >
512 bool isReal( const NonNumericProxy<MT>& proxy );
513 
514 template< bool RF, typename MT >
515 bool isZero( const NonNumericProxy<MT>& proxy );
516 
517 template< bool RF, typename MT >
518 bool isOne( const NonNumericProxy<MT>& proxy );
519 
520 template< typename MT >
521 bool isnan( const NonNumericProxy<MT>& proxy );
523 //*************************************************************************************************
524 
525 
526 //*************************************************************************************************
538 template< typename MT >
539 inline void reset( const NonNumericProxy<MT>& proxy )
540 {
541  using blaze::reset;
542 
543  reset( proxy.get() );
544 }
545 //*************************************************************************************************
546 
547 
548 //*************************************************************************************************
559 template< typename MT >
560 inline void clear( const NonNumericProxy<MT>& proxy )
561 {
562  using blaze::clear;
563 
564  clear( proxy.get() );
565 }
566 //*************************************************************************************************
567 
568 
569 //*************************************************************************************************
579 template< bool RF, typename MT >
580 inline bool isDefault( const NonNumericProxy<MT>& proxy )
581 {
582  using blaze::isDefault;
583 
584  return isDefault<RF>( proxy.get() );
585 }
586 //*************************************************************************************************
587 
588 
589 //*************************************************************************************************
601 template< bool RF, typename MT >
602 inline bool isReal( const NonNumericProxy<MT>& proxy )
603 {
604  using blaze::isReal;
605 
606  return isReal<RF>( proxy.get() );
607 }
608 //*************************************************************************************************
609 
610 
611 //*************************************************************************************************
621 template< bool RF, typename MT >
622 inline bool isZero( const NonNumericProxy<MT>& proxy )
623 {
624  using blaze::isZero;
625 
626  return isZero<RF>( proxy.get() );
627 }
628 //*************************************************************************************************
629 
630 
631 //*************************************************************************************************
641 template< bool RF, typename MT >
642 inline bool isOne( const NonNumericProxy<MT>& proxy )
643 {
644  using blaze::isOne;
645 
646  return isOne<RF>( proxy.get() );
647 }
648 //*************************************************************************************************
649 
650 
651 //*************************************************************************************************
661 template< typename MT >
662 inline bool isnan( const NonNumericProxy<MT>& proxy )
663 {
664  using blaze::isnan;
665 
666  return isnan( proxy.get() );
667 }
668 //*************************************************************************************************
669 
670 } // namespace blaze
671 
672 #endif
bool isReal(const DiagonalProxy< MT > &proxy)
Returns whether the matrix element represents a real number.
Definition: DiagonalProxy.h:657
#define BLAZE_CONSTRAINT_MUST_NOT_BE_TRANSFORMATION_TYPE(T)
Constraint on the data type.In case the given data type T is a transformation expression (i....
Definition: Transformation.h:81
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,...
Definition: Const.h:79
Constraint on the data type.
Header file for auxiliary alias declarations.
Constraint on the data type.
Constraint on the data type.
Header file for basic type definitions.
NonNumericProxy & operator=(const NonNumericProxy &nnp)
Copy assignment operator for NonNumericProxy.
Definition: NonNumericProxy.h:309
Proxy base class.The Proxy class is a base class for all proxy classes within the Blaze library that ...
Definition: Forward.h:51
typename T::Reference Reference_t
Alias declaration for nested Reference type definitions.The Reference_t alias declaration provides a ...
Definition: Aliases.h:330
typename T::ValueType ValueType_t
Alias declaration for nested ValueType type definitions.The ValueType_t alias declaration provides a ...
Definition: Aliases.h:490
Header file for the isZero shim.
Access proxy for symmetric, square matrices with non-numeric element types.The NonNumericProxy provid...
Definition: NonNumericProxy.h:105
#define BLAZE_CONSTRAINT_MUST_NOT_BE_COMPUTATION_TYPE(T)
Constraint on the data type.In case the given data type T is a computational expression (i....
Definition: Computation.h:81
void reset(const DiagonalProxy< MT > &proxy)
Resetting the represented element to the default initial values.
Definition: DiagonalProxy.h:595
#define BLAZE_CONSTRAINT_MUST_NOT_BE_VOLATILE(T)
Constraint on the data type.In case the given data type is a volatile-qualified type,...
Definition: Volatile.h:79
Header file for the reset shim.
Header file for the extended initializer_list functionality.
Constraint on the data type.
Header file for the Proxy class.
typename T::ElementType ElementType_t
Alias declaration for nested ElementType type definitions.The ElementType_t alias declaration provide...
Definition: Aliases.h:170
size_t i_
Row-index of the accessed matrix element.
Definition: NonNumericProxy.h:180
Constraint on the data type.
ValueType_t< ET > RepresentedType
Type of the represented matrix element.
Definition: NonNumericProxy.h:122
Constraint on the data type.
Constraint on the data type.
bool isZero(const DiagonalProxy< MT > &proxy)
Returns whether the represented element is 0.
Definition: DiagonalProxy.h:677
size_t j_
Column-index of the accessed matrix element.
Definition: NonNumericProxy.h:181
Namespace of the Blaze C++ math library.
Definition: Blaze.h:58
#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
Constraint on the data type.
RawReference get() const noexcept
Returning a reference to the accessed matrix element.
Definition: NonNumericProxy.h:461
bool isnan(const DiagonalProxy< MT > &proxy)
Returns whether the represented element is not a number.
Definition: DiagonalProxy.h:717
#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
Reference_t< ET > RawReference
Raw reference to the represented element.
Definition: NonNumericProxy.h:123
void clear(const DiagonalProxy< MT > &proxy)
Clearing the represented element.
Definition: DiagonalProxy.h:615
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,...
Definition: Symmetric.h:79
Header file for run time assertion macros.
Constraint on the data type.
Constraint on the data type.
#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,...
Definition: Reference.h:79
bool isOne(const DiagonalProxy< MT > &proxy)
Returns whether the represented element is 1.
Definition: DiagonalProxy.h:697
Header file for the isDefault shim.
Constraint on the data type.
Constraint on the data type.
#define BLAZE_CONSTRAINT_MUST_NOT_BE_VIEW_TYPE(T)
Constraint on the data type.In case the given data type T is a view type (i.e. a subvector,...
Definition: View.h:81
MT & matrix_
Reference to the adapted matrix.
Definition: NonNumericProxy.h:179
static constexpr bool rmm
Compile time flag indicating whether the given matrix type is a row-major matrix.
Definition: NonNumericProxy.h:111
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:229
bool isDefault(const DiagonalProxy< MT > &proxy)
Returns whether the represented element is in default state.
Definition: DiagonalProxy.h:635
#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,...
Definition: Hermitian.h:79
~NonNumericProxy()
The destructor for NonNumericProxy.
Definition: NonNumericProxy.h:279
Constraint on the data type.
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,...
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
Header file for the clear shim.
constexpr Type & get(StaticVector< Type, N, TF > &v) noexcept
Tuple-like index-based access the contents of a static vector.
Definition: StaticVector.h:2704