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 
49 #include <blaze/math/proxy/Proxy.h>
50 #include <blaze/math/shims/Clear.h>
53 #include <blaze/math/shims/IsNaN.h>
54 #include <blaze/math/shims/IsOne.h>
57 #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>, typename MT::ElementType::ValueType >
104 {
105  private:
106  //**Enumerations********************************************************************************
108  enum { rmm = IsRowMajorMatrix<MT>::value };
109  //**********************************************************************************************
110 
111  //**Type definitions****************************************************************************
113  typedef typename MT::ElementType ET;
114 
115  //**********************************************************************************************
116 
117  public:
118  //**Type definitions****************************************************************************
119  typedef typename ET::ValueType RepresentedType;
120  typedef typename ET::Reference RawReference;
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  template< typename T > inline NonNumericProxy& operator= ( const T& value );
143  template< typename T > inline NonNumericProxy& operator+=( const T& value );
144  template< typename T > inline NonNumericProxy& operator-=( const T& value );
145  template< typename T > inline NonNumericProxy& operator*=( const T& value );
146  template< typename T > inline NonNumericProxy& operator/=( const T& value );
148  //**********************************************************************************************
149 
150  //**Utility functions***************************************************************************
153  inline RawReference get() const;
155  //**********************************************************************************************
156 
157  //**Conversion operator*************************************************************************
160  inline operator RawReference() const;
162  //**********************************************************************************************
163 
164  private:
165  //**Member variables****************************************************************************
168  MT& matrix_;
169  size_t i_;
170  size_t j_;
171 
172  //**********************************************************************************************
173 
174  //**Forbidden operations************************************************************************
177  void* operator&() const;
178 
179  //**********************************************************************************************
180 
181  //**Compile time checks*************************************************************************
193  BLAZE_CONSTRAINT_MUST_NOT_BE_NUMERIC_TYPE ( RepresentedType );
195  //**********************************************************************************************
196 };
197 //*************************************************************************************************
198 
199 
200 
201 
202 //=================================================================================================
203 //
204 // CONSTRUCTORS
205 //
206 //=================================================================================================
207 
208 //*************************************************************************************************
215 template< typename MT > // Type of the adapted matrix
216 inline NonNumericProxy<MT>::NonNumericProxy( MT& matrix, size_t i, size_t j )
217  : matrix_( matrix ) // Reference to the adapted matrix
218  , i_ ( i ) // Row-index of the accessed matrix element
219  , j_ ( j ) // Column-index of the accessed matrix element
220 {
221  const typename MT::Iterator pos( matrix_.find( i_, j_ ) );
222  const size_t index( rmm ? i_ : j_ );
223 
224  if( pos == matrix_.end(index) )
225  {
226  const typename MT::ElementType element( ( RepresentedType() ) );
227  matrix_.insert( i_, j_, element );
228  if( i_ != j_ )
229  matrix_.insert( j_, i_, element );
230  }
231 
232  BLAZE_INTERNAL_ASSERT( matrix_.find(i_,j_)->value() == matrix_.find(j_,i_)->value(), "Unbalance detected" );
233 }
234 //*************************************************************************************************
235 
236 
237 //*************************************************************************************************
242 template< typename MT > // Type of the adapted matrix
244  : matrix_( nnp.matrix_ ) // Reference to the adapted matrix
245  , i_ ( nnp.i_ ) // Row-index of the accessed matrix element
246  , j_ ( nnp.j_ ) // Column-index of the accessed matrix element
247 {
248  BLAZE_INTERNAL_ASSERT( matrix_.find(i_,j_) != matrix_.end( rmm ? i_ : j_ ), "Missing matrix element detected" );
249  BLAZE_INTERNAL_ASSERT( matrix_.find(j_,i_) != matrix_.end( rmm ? j_ : i_ ), "Missing matrix element detected" );
250 }
251 //*************************************************************************************************
252 
253 
254 
255 
256 //=================================================================================================
257 //
258 // DESTRUCTORS
259 //
260 //=================================================================================================
261 
262 //*************************************************************************************************
265 template< typename MT > // Type of the adapted matrix
267 {
268  const typename MT::Iterator pos( matrix_.find( i_, j_ ) );
269  const size_t index( rmm ? i_ : j_ );
270 
271  if( pos != matrix_.end( index ) && isDefault( *pos->value() ) )
272  {
273  matrix_.erase( index, pos );
274  if( i_ != j_ )
275  matrix_.erase( ( rmm ? j_ : i_ ), matrix_.find( j_, i_ ) );
276  }
277 }
278 //*************************************************************************************************
279 
280 
281 
282 
283 //=================================================================================================
284 //
285 // OPERATORS
286 //
287 //=================================================================================================
288 
289 //*************************************************************************************************
295 template< typename MT > // Type of the adapted matrix
297 {
298  get() = nnp.get();
299  return *this;
300 }
301 //*************************************************************************************************
302 
303 
304 //*************************************************************************************************
310 template< typename MT > // Type of the adapted matrix
311 template< typename T > // Type of the right-hand side value
313 {
314  get() = value;
315  return *this;
316 }
317 //*************************************************************************************************
318 
319 
320 //*************************************************************************************************
326 template< typename MT > // Type of the adapted matrix
327 template< typename T > // Type of the right-hand side value
329 {
330  get() += value;
331  return *this;
332 }
333 //*************************************************************************************************
334 
335 
336 //*************************************************************************************************
342 template< typename MT > // Type of the adapted matrix
343 template< typename T > // Type of the right-hand side value
345 {
346  get() -= value;
347  return *this;
348 }
349 //*************************************************************************************************
350 
351 
352 //*************************************************************************************************
358 template< typename MT > // Type of the adapted matrix
359 template< typename T > // Type of the right-hand side value
361 {
362  get() *= value;
363  return *this;
364 }
365 //*************************************************************************************************
366 
367 
368 //*************************************************************************************************
374 template< typename MT > // Type of the adapted matrix
375 template< typename T > // Type of the right-hand side value
377 {
378  get() /= value;
379  return *this;
380 }
381 //*************************************************************************************************
382 
383 
384 
385 
386 //=================================================================================================
387 //
388 // UTILITY FUNCTIONS
389 //
390 //=================================================================================================
391 
392 //*************************************************************************************************
397 template< typename MT > // Type of the sparse matrix
399 {
400  const typename MT::Iterator pos( matrix_.find( i_, j_ ) );
401  BLAZE_INTERNAL_ASSERT( pos != matrix_.end( rmm ? i_ : j_ ), "Missing matrix element detected" );
402  return *pos->value();
403 }
404 //*************************************************************************************************
405 
406 
407 
408 
409 //=================================================================================================
410 //
411 // CONVERSION OPERATOR
412 //
413 //=================================================================================================
414 
415 //*************************************************************************************************
420 template< typename MT > // Type of the adapted matrix
422 {
423  return get();
424 }
425 //*************************************************************************************************
426 
427 
428 
429 
430 //=================================================================================================
431 //
432 // GLOBAL FUNCTIONS
433 //
434 //=================================================================================================
435 
436 //*************************************************************************************************
439 template< typename MT >
441  conj( const NonNumericProxy<MT>& proxy );
442 
443 template< typename MT >
444 inline void reset( const NonNumericProxy<MT>& proxy );
445 
446 template< typename MT >
447 inline void clear( const NonNumericProxy<MT>& proxy );
448 
449 template< typename MT >
450 inline bool isDefault( const NonNumericProxy<MT>& proxy );
451 
452 template< typename MT >
453 inline bool isReal( const NonNumericProxy<MT>& proxy );
454 
455 template< typename MT >
456 inline bool isZero( const NonNumericProxy<MT>& proxy );
457 
458 template< typename MT >
459 inline bool isOne( const NonNumericProxy<MT>& proxy );
460 
461 template< typename MT >
462 inline bool isnan( const NonNumericProxy<MT>& proxy );
464 //*************************************************************************************************
465 
466 
467 //*************************************************************************************************
478 template< typename MT >
480  conj( const NonNumericProxy<MT>& proxy )
481 {
482  using blaze::conj;
483 
484  return conj( (~proxy).get() );
485 }
486 //*************************************************************************************************
487 
488 
489 //*************************************************************************************************
501 template< typename MT >
502 inline void reset( const NonNumericProxy<MT>& proxy )
503 {
504  using blaze::reset;
505 
506  reset( proxy.get() );
507 }
508 //*************************************************************************************************
509 
510 
511 //*************************************************************************************************
522 template< typename MT >
523 inline void clear( const NonNumericProxy<MT>& proxy )
524 {
525  using blaze::clear;
526 
527  clear( proxy.get() );
528 }
529 //*************************************************************************************************
530 
531 
532 //*************************************************************************************************
542 template< typename MT >
543 inline bool isDefault( const NonNumericProxy<MT>& proxy )
544 {
545  using blaze::isDefault;
546 
547  return isDefault( proxy.get() );
548 }
549 //*************************************************************************************************
550 
551 
552 //*************************************************************************************************
564 template< typename MT >
565 inline bool isReal( const NonNumericProxy<MT>& proxy )
566 {
567  using blaze::isReal;
568 
569  return isReal( proxy.get() );
570 }
571 //*************************************************************************************************
572 
573 
574 //*************************************************************************************************
584 template< typename MT >
585 inline bool isZero( const NonNumericProxy<MT>& proxy )
586 {
587  using blaze::isZero;
588 
589  return isZero( proxy.get() );
590 }
591 //*************************************************************************************************
592 
593 
594 //*************************************************************************************************
604 template< typename MT >
605 inline bool isOne( const NonNumericProxy<MT>& proxy )
606 {
607  using blaze::isOne;
608 
609  return isOne( proxy.get() );
610 }
611 //*************************************************************************************************
612 
613 
614 //*************************************************************************************************
624 template< typename MT >
625 inline bool isnan( const NonNumericProxy<MT>& proxy )
626 {
627  using blaze::isnan;
628 
629  return isnan( proxy.get() );
630 }
631 //*************************************************************************************************
632 
633 } // namespace blaze
634 
635 #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:116
bool isOne(const DiagonalProxy< MT > &proxy)
Returns whether the represented element is 1.
Definition: DiagonalProxy.h:609
Constraint on the data type.
Header file for basic type definitions.
NonNumericProxy & operator=(const NonNumericProxy &nnp)
Copy assignment operator for NonNumericProxy.
Definition: NonNumericProxy.h:296
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:569
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:507
void * operator&() const
Address operator (private & undefined)
#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:116
Constraint on the data type.
Header file for the Proxy class.
size_t i_
Row-index of the accessed matrix element.
Definition: NonNumericProxy.h:169
bool isDefault(const DiagonalProxy< MT > &proxy)
Returns whether the represented element is in default state.
Definition: DiagonalProxy.h:547
Constraint on the data type.
Constraint on the data type.
ConjExprTrait< typename DiagonalProxy< MT >::RepresentedType >::Type conj(const DiagonalProxy< MT > &proxy)
Computing the complex conjugate of the represented element.
Definition: DiagonalProxy.h:487
Constraint on the data type.
ET::ValueType RepresentedType
Type of the represented matrix element.
Definition: NonNumericProxy.h:119
size_t j_
Column-index of the accessed matrix element.
Definition: NonNumericProxy.h:170
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:116
Header file for the isZero shim.
Constraint on the data type.
bool isnan(const DiagonalProxy< MT > &proxy)
Returns whether the represented element is not a number.
Definition: DiagonalProxy.h:629
#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:118
#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:118
Type ElementType
Type of the sparse matrix elements.
Definition: CompressedMatrix.h:2586
void clear(const DiagonalProxy< MT > &proxy)
Clearing the represented element.
Definition: DiagonalProxy.h:527
RawReference get() const
Returning a reference to the accessed matrix element.
Definition: NonNumericProxy.h:398
Header file for the isOne shim.
Header file for the conjugate shim.
Evaluation of the return type of a complex conjugate expression.Via this type trait it is possible to...
Definition: ConjExprTrait.h:87
#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:116
Header file for run time assertion macros.
Constraint on the data type.
Constraint on the data type.
ET::Reference RawReference
Raw reference to the represented element.
Definition: NonNumericProxy.h:120
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:118
#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:116
Element * Iterator
Iterator over non-constant elements.
Definition: CompressedMatrix.h:2591
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:168
Header file for the IsRowMajorMatrix type trait.
NonNumericProxy(MT &sm, size_t i, size_t j)
Initialization constructor for a NonNumericProxy.
Definition: NonNumericProxy.h:216
#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:118
bool isZero(const DiagonalProxy< MT > &proxy)
Returns whether the represented element is 0.
Definition: DiagonalProxy.h:589
MatrixAccessProxy< This > Reference
Reference to a non-constant matrix value.
Definition: CompressedMatrix.h:2589
#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:116
~NonNumericProxy()
The destructor for NonNumericProxy.
Definition: NonNumericProxy.h:266
Header file for the ConjExprTrait class template.
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:79