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 <ostream>
49 #include <blaze/math/proxy/Proxy.h>
50 #include <blaze/math/shims/Clear.h>
52 #include <blaze/math/shims/Reset.h>
54 #include <blaze/system/Inline.h>
55 #include <blaze/util/Assert.h>
61 #include <blaze/util/Types.h>
62 
63 
64 namespace blaze {
65 
66 //=================================================================================================
67 //
68 // CLASS DEFINITION
69 //
70 //=================================================================================================
71 
72 //*************************************************************************************************
97 template< typename MT > // Type of the adapted matrix
98 class NonNumericProxy : public Proxy< NonNumericProxy<MT>, typename MT::ElementType::ValueType >
99 {
100  private:
101  //**Enumerations********************************************************************************
103  enum { rmm = IsRowMajorMatrix<MT>::value };
104  //**********************************************************************************************
105 
106  //**Type definitions****************************************************************************
108  typedef typename MT::ElementType ET;
109 
110  //**********************************************************************************************
111 
112  public:
113  //**Type definitions****************************************************************************
114  typedef typename ET::ValueType RepresentedType;
115  typedef typename ET::Reference RawReference;
116  //**********************************************************************************************
117 
118  //**Constructors********************************************************************************
121  explicit inline NonNumericProxy( MT& sm, size_t i, size_t j );
122  inline NonNumericProxy( const NonNumericProxy& nnp );
124  //**********************************************************************************************
125 
126  //**Destructor**********************************************************************************
129  inline ~NonNumericProxy();
131  //**********************************************************************************************
132 
133  //**Operators***********************************************************************************
136  inline NonNumericProxy& operator= ( const NonNumericProxy& nnp );
137  template< typename T > inline NonNumericProxy& operator= ( const T& value );
138  template< typename T > inline NonNumericProxy& operator+=( const T& value );
139  template< typename T > inline NonNumericProxy& operator-=( const T& value );
140  template< typename T > inline NonNumericProxy& operator*=( const T& value );
141  template< typename T > inline NonNumericProxy& operator/=( const T& value );
143  //**********************************************************************************************
144 
145  //**Utility functions***************************************************************************
148  inline RawReference get() const;
150  //**********************************************************************************************
151 
152  //**Conversion operator*************************************************************************
155  inline operator RawReference() const;
157  //**********************************************************************************************
158 
159  private:
160  //**Member variables****************************************************************************
163  MT& matrix_;
164  size_t i_;
165  size_t j_;
166 
167  //**********************************************************************************************
168 
169  //**Forbidden operations************************************************************************
172  void* operator&() const;
173 
174  //**********************************************************************************************
175 
176  //**Compile time checks*************************************************************************
187  BLAZE_CONSTRAINT_MUST_NOT_BE_NUMERIC_TYPE ( RepresentedType );
189  //**********************************************************************************************
190 };
191 //*************************************************************************************************
192 
193 
194 
195 
196 //=================================================================================================
197 //
198 // CONSTRUCTORS
199 //
200 //=================================================================================================
201 
202 //*************************************************************************************************
209 template< typename MT > // Type of the adapted matrix
210 inline NonNumericProxy<MT>::NonNumericProxy( MT& matrix, size_t i, size_t j )
211  : matrix_( matrix ) // Reference to the adapted matrix
212  , i_ ( i ) // Row-index of the accessed matrix element
213  , j_ ( j ) // Column-index of the accessed matrix element
214 {
215  const typename MT::Iterator pos( matrix_.find( i_, j_ ) );
216  const size_t index( rmm ? i_ : j_ );
217 
218  if( pos == matrix_.end(index) )
219  {
220  const typename MT::ElementType element( ( RepresentedType() ) );
221  matrix_.insert( i_, j_, element );
222  if( i_ != j_ )
223  matrix_.insert( j_, i_, element );
224  }
225 
226  BLAZE_INTERNAL_ASSERT( matrix_.find(i_,j_)->value() == matrix_.find(j_,i_)->value(), "Unbalance detected" );
227 }
228 //*************************************************************************************************
229 
230 
231 //*************************************************************************************************
236 template< typename MT > // Type of the adapted matrix
238  : matrix_( nnp.matrix_ ) // Reference to the adapted matrix
239  , i_ ( nnp.i_ ) // Row-index of the accessed matrix element
240  , j_ ( nnp.j_ ) // Column-index of the accessed matrix element
241 {
242  BLAZE_INTERNAL_ASSERT( matrix_.find(i_,j_) != matrix_.end( rmm ? i_ : j_ ), "Missing matrix element detected" );
243  BLAZE_INTERNAL_ASSERT( matrix_.find(j_,i_) != matrix_.end( rmm ? j_ : i_ ), "Missing matrix element detected" );
244 }
245 //*************************************************************************************************
246 
247 
248 
249 
250 //=================================================================================================
251 //
252 // DESTRUCTORS
253 //
254 //=================================================================================================
255 
256 //*************************************************************************************************
259 template< typename MT > // Type of the adapted matrix
261 {
262  const typename MT::Iterator pos( matrix_.find( i_, j_ ) );
263  const size_t index( rmm ? i_ : j_ );
264 
265  if( pos != matrix_.end( index ) && isDefault( *pos->value() ) )
266  {
267  matrix_.erase( index, pos );
268  if( i_ != j_ )
269  matrix_.erase( ( rmm ? j_ : i_ ), matrix_.find( j_, i_ ) );
270  }
271 }
272 //*************************************************************************************************
273 
274 
275 
276 
277 //=================================================================================================
278 //
279 // OPERATORS
280 //
281 //=================================================================================================
282 
283 //*************************************************************************************************
289 template< typename MT > // Type of the adapted matrix
291 {
292  get() = nnp.get();
293  return *this;
294 }
295 //*************************************************************************************************
296 
297 
298 //*************************************************************************************************
304 template< typename MT > // Type of the adapted matrix
305 template< typename T > // Type of the right-hand side value
307 {
308  get() = value;
309  return *this;
310 }
311 //*************************************************************************************************
312 
313 
314 //*************************************************************************************************
320 template< typename MT > // Type of the adapted matrix
321 template< typename T > // Type of the right-hand side value
323 {
324  get() += value;
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() -= value;
341  return *this;
342 }
343 //*************************************************************************************************
344 
345 
346 //*************************************************************************************************
352 template< typename MT > // Type of the adapted matrix
353 template< typename T > // Type of the right-hand side value
355 {
356  get() *= value;
357  return *this;
358 }
359 //*************************************************************************************************
360 
361 
362 //*************************************************************************************************
368 template< typename MT > // Type of the adapted matrix
369 template< typename T > // Type of the right-hand side value
371 {
372  get() /= value;
373  return *this;
374 }
375 //*************************************************************************************************
376 
377 
378 
379 
380 //=================================================================================================
381 //
382 // UTILITY FUNCTIONS
383 //
384 //=================================================================================================
385 
386 //*************************************************************************************************
391 template< typename MT > // Type of the sparse matrix
393 {
394  const typename MT::Iterator pos( matrix_.find( i_, j_ ) );
395  BLAZE_INTERNAL_ASSERT( pos != matrix_.end( rmm ? i_ : j_ ), "Missing matrix element detected" );
396  return *pos->value();
397 }
398 //*************************************************************************************************
399 
400 
401 
402 
403 //=================================================================================================
404 //
405 // CONVERSION OPERATOR
406 //
407 //=================================================================================================
408 
409 //*************************************************************************************************
414 template< typename MT > // Type of the adapted matrix
416 {
417  return get();
418 }
419 //*************************************************************************************************
420 
421 
422 
423 
424 //=================================================================================================
425 //
426 // GLOBAL OPERATORS
427 //
428 //=================================================================================================
429 
430 //*************************************************************************************************
433 template< typename MT1, typename MT2 >
434 inline bool operator==( const NonNumericProxy<MT1>& lhs, const NonNumericProxy<MT2>& rhs );
435 
436 template< typename MT, typename T >
437 inline bool operator==( const NonNumericProxy<MT>& lhs, const T& rhs );
438 
439 template< typename T, typename MT >
440 inline bool operator==( const T& lhs, const NonNumericProxy<MT>& rhs );
441 
442 template< typename MT1, typename MT2 >
443 inline bool operator!=( const NonNumericProxy<MT1>& lhs, const NonNumericProxy<MT2>& rhs );
444 
445 template< typename MT, typename T >
446 inline bool operator!=( const NonNumericProxy<MT>& lhs, const T& rhs );
447 
448 template< typename T, typename MT >
449 inline bool operator!=( const T& lhs, const NonNumericProxy<MT>& rhs );
450 
451 template< typename MT1, typename MT2 >
452 inline bool operator<( const NonNumericProxy<MT1>& lhs, const NonNumericProxy<MT2>& rhs );
453 
454 template< typename MT, typename T >
455 inline bool operator<( const NonNumericProxy<MT>& lhs, const T& rhs );
456 
457 template< typename T, typename MT >
458 inline bool operator<( const T& lhs, const NonNumericProxy<MT>& rhs );
459 
460 template< typename MT1, typename MT2 >
461 inline bool operator>( const NonNumericProxy<MT1>& lhs, const NonNumericProxy<MT2>& rhs );
462 
463 template< typename MT, typename T >
464 inline bool operator>( const NonNumericProxy<MT>& lhs, const T& rhs );
465 
466 template< typename T, typename MT >
467 inline bool operator>( const T& lhs, const NonNumericProxy<MT>& rhs );
468 
469 template< typename MT1, typename MT2 >
470 inline bool operator<=( const NonNumericProxy<MT1>& lhs, const NonNumericProxy<MT2>& rhs );
471 
472 template< typename MT, typename T >
473 inline bool operator<=( const NonNumericProxy<MT>& lhs, const T& rhs );
474 
475 template< typename T, typename MT >
476 inline bool operator<=( const T& lhs, const NonNumericProxy<MT>& rhs );
477 
478 template< typename MT1, typename MT2 >
479 inline bool operator>=( const NonNumericProxy<MT1>& lhs, const NonNumericProxy<MT2>& rhs );
480 
481 template< typename MT, typename T >
482 inline bool operator>=( const NonNumericProxy<MT>& lhs, const T& rhs );
483 
484 template< typename T, typename MT >
485 inline bool operator>=( const T& lhs, const NonNumericProxy<MT>& rhs );
486 
487 template< typename MT >
488 inline std::ostream& operator<<( std::ostream& os, const NonNumericProxy<MT>& proxy );
490 //*************************************************************************************************
491 
492 
493 //*************************************************************************************************
501 template< typename MT1, typename MT2 >
502 inline bool operator==( const NonNumericProxy<MT1>& lhs, const NonNumericProxy<MT2>& rhs )
503 {
504  return ( lhs.get() == rhs.get() );
505 }
506 //*************************************************************************************************
507 
508 
509 //*************************************************************************************************
517 template< typename MT, typename T >
518 inline bool operator==( const NonNumericProxy<MT>& lhs, const T& rhs )
519 {
520  return ( lhs.get() == rhs );
521 }
522 //*************************************************************************************************
523 
524 
525 //*************************************************************************************************
533 template< typename T, typename MT >
534 inline bool operator==( const T& lhs, const NonNumericProxy<MT>& rhs )
535 {
536  return ( lhs == rhs.get() );
537 }
538 //*************************************************************************************************
539 
540 
541 //*************************************************************************************************
549 template< typename MT1, typename MT2 >
550 inline bool operator!=( const NonNumericProxy<MT1>& lhs, const NonNumericProxy<MT2>& rhs )
551 {
552  return ( lhs.get() != rhs.get() );
553 }
554 //*************************************************************************************************
555 
556 
557 //*************************************************************************************************
565 template< typename MT, typename T >
566 inline bool operator!=( const NonNumericProxy<MT>& lhs, const T& rhs )
567 {
568  return ( lhs.get() != rhs );
569 }
570 //*************************************************************************************************
571 
572 
573 //*************************************************************************************************
581 template< typename T, typename MT >
582 inline bool operator!=( const T& lhs, const NonNumericProxy<MT>& rhs )
583 {
584  return ( lhs != rhs.get() );
585 }
586 //*************************************************************************************************
587 
588 
589 //*************************************************************************************************
597 template< typename MT1, typename MT2 >
598 inline bool operator<( const NonNumericProxy<MT1>& lhs, const NonNumericProxy<MT2>& rhs )
599 {
600  return ( lhs.get() < rhs.get() );
601 }
602 //*************************************************************************************************
603 
604 
605 //*************************************************************************************************
613 template< typename MT, typename T >
614 inline bool operator<( const NonNumericProxy<MT>& lhs, const T& rhs )
615 {
616  return ( lhs.get() < rhs );
617 }
618 //*************************************************************************************************
619 
620 
621 //*************************************************************************************************
629 template< typename T, typename MT >
630 inline bool operator<( const T& lhs, const NonNumericProxy<MT>& rhs )
631 {
632  return ( lhs < rhs.get() );
633 }
634 //*************************************************************************************************
635 
636 
637 //*************************************************************************************************
645 template< typename MT1, typename MT2 >
646 inline bool operator>( const NonNumericProxy<MT1>& lhs, const NonNumericProxy<MT2>& rhs )
647 {
648  return ( lhs.get() > rhs.get() );
649 }
650 //*************************************************************************************************
651 
652 
653 //*************************************************************************************************
661 template< typename MT, typename T >
662 inline bool operator>( const NonNumericProxy<MT>& lhs, const T& rhs )
663 {
664  return ( lhs.get() > rhs );
665 }
666 //*************************************************************************************************
667 
668 
669 //*************************************************************************************************
677 template< typename T, typename MT >
678 inline bool operator>( const T& lhs, const NonNumericProxy<MT>& rhs )
679 {
680  return ( lhs > rhs.get() );
681 }
682 //*************************************************************************************************
683 
684 
685 //*************************************************************************************************
693 template< typename MT1, typename MT2 >
694 inline bool operator<=( const NonNumericProxy<MT1>& lhs, const NonNumericProxy<MT2>& rhs )
695 {
696  return ( lhs.get() <= rhs.get() );
697 }
698 //*************************************************************************************************
699 
700 
701 //*************************************************************************************************
709 template< typename MT, typename T >
710 inline bool operator<=( const NonNumericProxy<MT>& lhs, const T& rhs )
711 {
712  return ( lhs.get() <= rhs );
713 }
714 //*************************************************************************************************
715 
716 
717 //*************************************************************************************************
725 template< typename T, typename MT >
726 inline bool operator<=( const T& lhs, const NonNumericProxy<MT>& rhs )
727 {
728  return ( lhs <= rhs.get() );
729 }
730 //*************************************************************************************************
731 
732 
733 //*************************************************************************************************
741 template< typename MT1, typename MT2 >
742 inline bool operator>=( const NonNumericProxy<MT1>& lhs, const NonNumericProxy<MT2>& rhs )
743 {
744  return ( lhs.get() >= rhs.get() );
745 }
746 //*************************************************************************************************
747 
748 
749 //*************************************************************************************************
757 template< typename MT, typename T >
758 inline bool operator>=( const NonNumericProxy<MT>& lhs, const T& rhs )
759 {
760  return ( lhs.get() >= rhs );
761 }
762 //*************************************************************************************************
763 
764 
765 //*************************************************************************************************
773 template< typename T, typename MT >
774 inline bool operator>=( const T& lhs, const NonNumericProxy<MT>& rhs )
775 {
776  return ( lhs >= rhs.get() );
777 }
778 //*************************************************************************************************
779 
780 
781 //*************************************************************************************************
789 template< typename MT >
790 inline std::ostream& operator<<( std::ostream& os, const NonNumericProxy<MT>& proxy )
791 {
792  return os << proxy.get();
793 }
794 //*************************************************************************************************
795 
796 
797 
798 
799 //=================================================================================================
800 //
801 // GLOBAL FUNCTIONS
802 //
803 //=================================================================================================
804 
805 //*************************************************************************************************
808 template< typename MT >
809 BLAZE_ALWAYS_INLINE void reset( const NonNumericProxy<MT>& proxy );
810 
811 template< typename MT >
812 BLAZE_ALWAYS_INLINE void clear( const NonNumericProxy<MT>& proxy );
813 
814 template< typename MT >
815 BLAZE_ALWAYS_INLINE bool isDefault( const NonNumericProxy<MT>& proxy );
817 //*************************************************************************************************
818 
819 
820 //*************************************************************************************************
832 template< typename MT >
834 {
835  using blaze::reset;
836 
837  reset( proxy.get() );
838 }
839 //*************************************************************************************************
840 
841 
842 //*************************************************************************************************
853 template< typename MT >
855 {
856  using blaze::clear;
857 
858  clear( proxy.get() );
859 }
860 //*************************************************************************************************
861 
862 
863 //*************************************************************************************************
873 template< typename MT >
875 {
876  using blaze::isDefault;
877 
878  return isDefault( proxy.get() );
879 }
880 //*************************************************************************************************
881 
882 } // namespace blaze
883 
884 #endif
#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
Constraint on the data type.
Header file for basic type definitions.
NonNumericProxy & operator=(const NonNumericProxy &nnp)
Copy assignment operator for NonNumericProxy.
Definition: NonNumericProxy.h:290
Proxy base class.The Proxy class is a base class for all proxy classes within the Blaze library that ...
Definition: Proxy.h:99
Access proxy for symmetric, square matrices with non-numeric element types.The NonNumericProxy provid...
Definition: NonNumericProxy.h:98
Constraint on the data type.
void reset(const DiagonalProxy< MT > &proxy)
Resetting the represented element to the default initial values.
Definition: DiagonalProxy.h:821
bool operator>(const NegativeAccuracy< A > &lhs, const T &rhs)
Greater-than comparison between a NegativeAccuracy object and a floating point value.
Definition: Accuracy.h:366
bool operator>=(const NegativeAccuracy< A > &, const T &rhs)
Greater-or-equal-than comparison between a NegativeAccuracy object and a floating point value...
Definition: Accuracy.h:442
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.
size_t i_
Row-index of the accessed matrix element.
Definition: NonNumericProxy.h:164
bool isDefault(const DiagonalProxy< MT > &proxy)
Returns whether the represented element is in default state.
Definition: DiagonalProxy.h:861
Constraint on the data type.
Constraint on the data type.
ET::ValueType RepresentedType
Type of the represented matrix element.
Definition: NonNumericProxy.h:114
size_t j_
Column-index of the accessed matrix element.
Definition: NonNumericProxy.h:165
Header file for the clear shim.
Namespace of the Blaze C++ math library.
Definition: Blaze.h:57
#define BLAZE_ALWAYS_INLINE
Platform dependent setup of an enforced inline keyword.
Definition: Inline.h:85
Compile time check for row-major matrix types.This type trait tests whether or not the given template...
Definition: IsRowMajorMatrix.h:104
#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
Constraint on the data type.
#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:2505
void clear(const DiagonalProxy< MT > &proxy)
Clearing the represented element.
Definition: DiagonalProxy.h:841
RawReference get() const
Returning a reference to the accessed matrix element.
Definition: NonNumericProxy.h:392
#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.
Header file for the Proxy class.
Constraint on the data type.
Constraint on the data type.
ET::Reference RawReference
Raw reference to the represented element.
Definition: NonNumericProxy.h:115
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:2510
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:163
Header file for the IsRowMajorMatrix type trait.
NonNumericProxy(MT &sm, size_t i, size_t j)
Initialization constructor for a NonNumericProxy.
Definition: NonNumericProxy.h:210
#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 operator==(const NegativeAccuracy< A > &lhs, const T &rhs)
Equality comparison between a NegativeAccuracy object and a floating point value. ...
Definition: Accuracy.h:249
bool operator!=(const NegativeAccuracy< A > &lhs, const T &rhs)
Inequality comparison between a NegativeAccuracy object and a floating point value.
Definition: Accuracy.h:289
MatrixAccessProxy< This > Reference
Reference to a non-constant matrix value.
Definition: CompressedMatrix.h:2508
~NonNumericProxy()
The destructor for NonNumericProxy.
Definition: NonNumericProxy.h:260
System settings for the inline keywords.
#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