All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MatrixAccessProxy.h
Go to the documentation of this file.
1 //=================================================================================================
33 //=================================================================================================
34 
35 #ifndef _BLAZE_MATH_SPARSE_MATRIXACCESSPROXY_H_
36 #define _BLAZE_MATH_SPARSE_MATRIXACCESSPROXY_H_
37 
38 
39 //*************************************************************************************************
40 // Includes
41 //*************************************************************************************************
42 
43 #include <algorithm>
44 #include <ostream>
46 #include <blaze/math/proxy/Proxy.h>
47 #include <blaze/math/shims/Clear.h>
49 #include <blaze/math/shims/Reset.h>
51 #include <blaze/util/Assert.h>
52 #include <blaze/util/Types.h>
53 
54 
55 namespace blaze {
56 
57 //=================================================================================================
58 //
59 // CLASS DEFINITION
60 //
61 //=================================================================================================
62 
63 //*************************************************************************************************
94 template< typename MT > // Type of the sparse matrix
95 class MatrixAccessProxy : public Proxy< MatrixAccessProxy<MT>, typename MT::ElementType >
96 {
97  private:
98  //**Enumerations********************************************************************************
100  enum { rmm = IsRowMajorMatrix<MT>::value };
101  //**********************************************************************************************
102 
103  public:
104  //**Type definitions****************************************************************************
105  typedef typename MT::ElementType RepresentedType;
107  //**********************************************************************************************
108 
109  //**Constructors********************************************************************************
112  explicit inline MatrixAccessProxy( MT& sm, size_t i, size_t j );
113  inline MatrixAccessProxy( const MatrixAccessProxy& map );
115  //**********************************************************************************************
116 
117  //**Destructor**********************************************************************************
120  inline ~MatrixAccessProxy();
122  //**********************************************************************************************
123 
124  //**Operators***********************************************************************************
127  inline MatrixAccessProxy& operator= ( const MatrixAccessProxy& map );
128  template< typename T > inline MatrixAccessProxy& operator= ( const T& value );
129  template< typename T > inline MatrixAccessProxy& operator+=( const T& value );
130  template< typename T > inline MatrixAccessProxy& operator-=( const T& value );
131  template< typename T > inline MatrixAccessProxy& operator*=( const T& value );
132  template< typename T > inline MatrixAccessProxy& operator/=( const T& value );
134  //**********************************************************************************************
135 
136  //**Utility functions***************************************************************************
139  inline RawReference get() const;
141  //**********************************************************************************************
142 
143  //**Conversion operator*************************************************************************
146  inline operator RawReference() const;
148  //**********************************************************************************************
149 
150  private:
151  //**Member variables****************************************************************************
154  MT& sm_;
155  size_t i_;
156  size_t j_;
157 
158  //**********************************************************************************************
159 
160  //**Forbidden operations************************************************************************
163  void* operator&() const;
164 
165  //**********************************************************************************************
166 
167  //**Compile time checks*************************************************************************
171  //**********************************************************************************************
172 };
173 //*************************************************************************************************
174 
175 
176 
177 
178 //=================================================================================================
179 //
180 // CONSTRUCTORS
181 //
182 //=================================================================================================
183 
184 //*************************************************************************************************
191 template< typename MT > // Type of the sparse matrix
192 inline MatrixAccessProxy<MT>::MatrixAccessProxy( MT& sm, size_t i, size_t j )
193  : sm_( sm ) // Reference to the accessed sparse matrix
194  , i_ ( i ) // Row-index of the accessed sparse matrix element
195  , j_ ( j ) // Column-index of the accessed sparse matrix element
196 {
197  const typename MT::Iterator element( sm_.find( i_, j_ ) );
198  const size_t index( rmm ? i_ : j_ );
199  if( element == sm_.end(index) )
200  sm_.insert( i_, j_, RepresentedType() );
201 }
202 //*************************************************************************************************
203 
204 
205 //*************************************************************************************************
210 template< typename MT > // Type of the sparse matrix
212  : sm_( map.sm_ ) // Reference to the accessed sparse matrix
213  , i_ ( map.i_ ) // Row-index of the accessed sparse matrix element
214  , j_ ( map.j_ ) // Column-index of the accessed sparse matrix element
215 {
216  BLAZE_INTERNAL_ASSERT( sm_.find(i_,j_) != sm_.end( rmm ? i_ : j_ ), "Missing matrix element detected" );
217 }
218 //*************************************************************************************************
219 
220 
221 
222 
223 //=================================================================================================
224 //
225 // DESTRUCTORS
226 //
227 //=================================================================================================
228 
229 //*************************************************************************************************
232 template< typename MT > // Type of the sparse matrix
234 {
235  const typename MT::Iterator element( sm_.find( i_, j_ ) );
236  const size_t index( rmm ? i_ : j_ );
237  if( element != sm_.end( index ) && isDefault( element->value() ) )
238  sm_.erase( index, element );
239 }
240 //*************************************************************************************************
241 
242 
243 
244 
245 //=================================================================================================
246 //
247 // OPERATORS
248 //
249 //=================================================================================================
250 
251 //*************************************************************************************************
257 template< typename MT > // Type of the sparse matrix
259 {
260  get() = map.get();
261  return *this;
262 }
263 //*************************************************************************************************
264 
265 
266 //*************************************************************************************************
272 template< typename MT > // Type of the sparse matrix
273 template< typename T > // Type of the right-hand side value
275 {
276  get() = value;
277  return *this;
278 }
279 //*************************************************************************************************
280 
281 
282 //*************************************************************************************************
288 template< typename MT > // Type of the sparse matrix
289 template< typename T > // Type of the right-hand side value
291 {
292  get() += value;
293  return *this;
294 }
295 //*************************************************************************************************
296 
297 
298 //*************************************************************************************************
304 template< typename MT > // Type of the sparse 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 sparse 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 sparse matrix
337 template< typename T > // Type of the right-hand side value
339 {
340  get() /= value;
341  return *this;
342 }
343 //*************************************************************************************************
344 
345 
346 
347 
348 //=================================================================================================
349 //
350 // UTILITY FUNCTIONS
351 //
352 //=================================================================================================
353 
354 //*************************************************************************************************
359 template< typename MT > // Type of the sparse matrix
361 {
362  const typename MT::Iterator element( sm_.find( i_, j_ ) );
363  BLAZE_INTERNAL_ASSERT( element != sm_.end( rmm ? i_ : j_ ), "Missing matrix element detected" );
364  return element->value();
365 }
366 //*************************************************************************************************
367 
368 
369 
370 
371 //=================================================================================================
372 //
373 // CONVERSION OPERATOR
374 //
375 //=================================================================================================
376 
377 //*************************************************************************************************
382 template< typename MT > // Type of the sparse matrix
384 {
385  return get();
386 }
387 //*************************************************************************************************
388 
389 
390 
391 
392 //=================================================================================================
393 //
394 // GLOBAL OPERATORS
395 //
396 //=================================================================================================
397 
398 //*************************************************************************************************
401 template< typename MT1, typename MT2 >
402 inline bool operator==( const MatrixAccessProxy<MT1>& lhs, const MatrixAccessProxy<MT2>& rhs );
403 
404 template< typename MT, typename T >
405 inline bool operator==( const MatrixAccessProxy<MT>& lhs, const T& rhs );
406 
407 template< typename T, typename MT >
408 inline bool operator==( const T& lhs, const MatrixAccessProxy<MT>& rhs );
409 
410 template< typename MT1, typename MT2 >
411 inline bool operator!=( const MatrixAccessProxy<MT1>& lhs, const MatrixAccessProxy<MT2>& rhs );
412 
413 template< typename MT, typename T >
414 inline bool operator!=( const MatrixAccessProxy<MT>& lhs, const T& rhs );
415 
416 template< typename T, typename MT >
417 inline bool operator!=( const T& lhs, const MatrixAccessProxy<MT>& rhs );
418 
419 template< typename MT1, typename MT2 >
420 inline bool operator<( const MatrixAccessProxy<MT1>& lhs, const MatrixAccessProxy<MT2>& rhs );
421 
422 template< typename MT, typename T >
423 inline bool operator<( const MatrixAccessProxy<MT>& lhs, const T& rhs );
424 
425 template< typename T, typename MT >
426 inline bool operator<( const T& lhs, const MatrixAccessProxy<MT>& rhs );
427 
428 template< typename MT1, typename MT2 >
429 inline bool operator>( const MatrixAccessProxy<MT1>& lhs, const MatrixAccessProxy<MT2>& rhs );
430 
431 template< typename MT, typename T >
432 inline bool operator>( const MatrixAccessProxy<MT>& lhs, const T& rhs );
433 
434 template< typename T, typename MT >
435 inline bool operator>( const T& lhs, const MatrixAccessProxy<MT>& rhs );
436 
437 template< typename MT1, typename MT2 >
438 inline bool operator<=( const MatrixAccessProxy<MT1>& lhs, const MatrixAccessProxy<MT2>& rhs );
439 
440 template< typename MT, typename T >
441 inline bool operator<=( const MatrixAccessProxy<MT>& lhs, const T& rhs );
442 
443 template< typename T, typename MT >
444 inline bool operator<=( const T& lhs, const MatrixAccessProxy<MT>& rhs );
445 
446 template< typename MT1, typename MT2 >
447 inline bool operator>=( const MatrixAccessProxy<MT1>& lhs, const MatrixAccessProxy<MT2>& rhs );
448 
449 template< typename MT, typename T >
450 inline bool operator>=( const MatrixAccessProxy<MT>& lhs, const T& rhs );
451 
452 template< typename T, typename MT >
453 inline bool operator>=( const T& lhs, const MatrixAccessProxy<MT>& rhs );
454 
455 template< typename MT >
456 inline std::ostream& operator<<( std::ostream& os, const MatrixAccessProxy<MT>& proxy );
458 //*************************************************************************************************
459 
460 
461 //*************************************************************************************************
469 template< typename MT1, typename MT2 >
470 inline bool operator==( const MatrixAccessProxy<MT1>& lhs, const MatrixAccessProxy<MT2>& rhs )
471 {
472  return ( lhs.get() == rhs.get() );
473 }
474 //*************************************************************************************************
475 
476 
477 //*************************************************************************************************
485 template< typename MT, typename T >
486 inline bool operator==( const MatrixAccessProxy<MT>& lhs, const T& rhs )
487 {
488  return ( lhs.get() == rhs );
489 }
490 //*************************************************************************************************
491 
492 
493 //*************************************************************************************************
501 template< typename T, typename MT >
502 inline bool operator==( const T& lhs, const MatrixAccessProxy<MT>& rhs )
503 {
504  return ( lhs == rhs.get() );
505 }
506 //*************************************************************************************************
507 
508 
509 //*************************************************************************************************
517 template< typename MT1, typename MT2 >
518 inline bool operator!=( const MatrixAccessProxy<MT1>& lhs, const MatrixAccessProxy<MT2>& rhs )
519 {
520  return ( lhs.get() != rhs.get() );
521 }
522 //*************************************************************************************************
523 
524 
525 //*************************************************************************************************
533 template< typename MT, typename T >
534 inline bool operator!=( const MatrixAccessProxy<MT>& lhs, const T& rhs )
535 {
536  return ( lhs.get() != rhs );
537 }
538 //*************************************************************************************************
539 
540 
541 //*************************************************************************************************
549 template< typename T, typename MT >
550 inline bool operator!=( const T& lhs, const MatrixAccessProxy<MT>& rhs )
551 {
552  return ( lhs != rhs.get() );
553 }
554 //*************************************************************************************************
555 
556 
557 //*************************************************************************************************
565 template< typename MT1, typename MT2 >
566 inline bool operator<( const MatrixAccessProxy<MT1>& lhs, const MatrixAccessProxy<MT2>& rhs )
567 {
568  return ( lhs.get() < rhs.get() );
569 }
570 //*************************************************************************************************
571 
572 
573 //*************************************************************************************************
581 template< typename MT, typename T >
582 inline bool operator<( const MatrixAccessProxy<MT>& lhs, const T& rhs )
583 {
584  return ( lhs.get() < rhs );
585 }
586 //*************************************************************************************************
587 
588 
589 //*************************************************************************************************
597 template< typename T, typename MT >
598 inline bool operator<( const T& lhs, const MatrixAccessProxy<MT>& rhs )
599 {
600  return ( lhs < rhs.get() );
601 }
602 //*************************************************************************************************
603 
604 
605 //*************************************************************************************************
613 template< typename MT1, typename MT2 >
614 inline bool operator>( const MatrixAccessProxy<MT1>& lhs, const MatrixAccessProxy<MT2>& rhs )
615 {
616  return ( lhs.get() > rhs.get() );
617 }
618 //*************************************************************************************************
619 
620 
621 //*************************************************************************************************
629 template< typename MT, typename T >
630 inline bool operator>( const MatrixAccessProxy<MT>& lhs, const T& rhs )
631 {
632  return ( lhs.get() > rhs );
633 }
634 //*************************************************************************************************
635 
636 
637 //*************************************************************************************************
645 template< typename T, typename MT >
646 inline bool operator>( const T& lhs, const MatrixAccessProxy<MT>& rhs )
647 {
648  return ( lhs > rhs.get() );
649 }
650 //*************************************************************************************************
651 
652 
653 //*************************************************************************************************
661 template< typename MT1, typename MT2 >
662 inline bool operator<=( const MatrixAccessProxy<MT1>& lhs, const MatrixAccessProxy<MT2>& rhs )
663 {
664  return ( lhs.get() <= rhs.get() );
665 }
666 //*************************************************************************************************
667 
668 
669 //*************************************************************************************************
677 template< typename MT, typename T >
678 inline bool operator<=( const MatrixAccessProxy<MT>& lhs, const T& rhs )
679 {
680  return ( lhs.get() <= rhs );
681 }
682 //*************************************************************************************************
683 
684 
685 //*************************************************************************************************
693 template< typename T, typename MT >
694 inline bool operator<=( const T& lhs, const MatrixAccessProxy<MT>& rhs )
695 {
696  return ( lhs <= rhs.get() );
697 }
698 //*************************************************************************************************
699 
700 
701 //*************************************************************************************************
709 template< typename MT1, typename MT2 >
710 inline bool operator>=( const MatrixAccessProxy<MT1>& lhs, const MatrixAccessProxy<MT2>& rhs )
711 {
712  return ( lhs.get() >= rhs.get() );
713 }
714 //*************************************************************************************************
715 
716 
717 //*************************************************************************************************
725 template< typename MT, typename T >
726 inline bool operator>=( const MatrixAccessProxy<MT>& lhs, const T& rhs )
727 {
728  return ( lhs.get() >= rhs );
729 }
730 //*************************************************************************************************
731 
732 
733 //*************************************************************************************************
741 template< typename T, typename MT >
742 inline bool operator>=( const T& lhs, const MatrixAccessProxy<MT>& rhs )
743 {
744  return ( lhs >= rhs.get() );
745 }
746 //*************************************************************************************************
747 
748 
749 //*************************************************************************************************
757 template< typename MT >
758 inline std::ostream& operator<<( std::ostream& os, const MatrixAccessProxy<MT>& proxy )
759 {
760  return os << proxy.get();
761 }
762 //*************************************************************************************************
763 
764 
765 
766 
767 //=================================================================================================
768 //
769 // GLOBAL FUNCTIONS
770 //
771 //=================================================================================================
772 
773 //*************************************************************************************************
776 template< typename MT >
777 inline void reset( const MatrixAccessProxy<MT>& proxy );
778 
779 template< typename MT >
780 inline void clear( const MatrixAccessProxy<MT>& proxy );
781 
782 template< typename MT >
783 inline bool isDefault( const MatrixAccessProxy<MT>& proxy );
784 
785 template< typename MT >
786 inline void swap( const MatrixAccessProxy<MT>& a, const MatrixAccessProxy<MT>& b ) /* throw() */;
787 
788 template< typename MT, typename T >
789 inline void swap( const MatrixAccessProxy<MT>& a, T& b ) /* throw() */;
790 
791 template< typename T, typename MT >
792 inline void swap( T& a, const MatrixAccessProxy<MT>& v ) /* throw() */;
794 //*************************************************************************************************
795 
796 
797 //*************************************************************************************************
809 template< typename MT >
810 inline void reset( const MatrixAccessProxy<MT>& proxy )
811 {
812  using blaze::reset;
813 
814  reset( proxy.get() );
815 }
816 //*************************************************************************************************
817 
818 
819 //*************************************************************************************************
830 template< typename MT >
831 inline void clear( const MatrixAccessProxy<MT>& proxy )
832 {
833  using blaze::clear;
834 
835  clear( proxy.get() );
836 }
837 //*************************************************************************************************
838 
839 
840 //*************************************************************************************************
850 template< typename MT >
851 inline bool isDefault( const MatrixAccessProxy<MT>& proxy )
852 {
853  using blaze::isDefault;
854 
855  return isDefault( proxy.get() );
856 }
857 //*************************************************************************************************
858 
859 
860 //*************************************************************************************************
869 template< typename MT >
870 inline void swap( const MatrixAccessProxy<MT>& a, const MatrixAccessProxy<MT>& b ) /* throw() */
871 {
872  using std::swap;
873 
874  swap( a.get(), b.get() );
875 }
876 //*************************************************************************************************
877 
878 
879 //*************************************************************************************************
888 template< typename MT, typename T >
889 inline void swap( const MatrixAccessProxy<MT>& a, T& b ) /* throw() */
890 {
891  using std::swap;
892 
893  swap( a.get(), b );
894 }
895 //*************************************************************************************************
896 
897 
898 //*************************************************************************************************
907 template< typename T, typename MT >
908 inline void swap( T& a, const MatrixAccessProxy<MT>& b ) /* throw() */
909 {
910  using std::swap;
911 
912  swap( a, b.get() );
913 }
914 //*************************************************************************************************
915 
916 } // namespace blaze
917 
918 #endif
size_t i_
Row-index of the accessed sparse matrix element.
Definition: MatrixAccessProxy.h:155
void swap(SymmetricMatrix< MT, SO, DF, NF > &a, SymmetricMatrix< MT, SO, DF, NF > &b)
Swapping the contents of two matrices.
Definition: SymmetricMatrix.h:195
Proxy base class.The Proxy class is a base class for all proxy classes within the Blaze library that ...
Definition: Proxy.h:99
void * operator&() const
Address operator (private & undefined)
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
Access proxy for sparse, matrices.The MatrixAccessProxy provides safe access to the elements of a no...
Definition: MatrixAccessProxy.h:95
MT::ElementType RepresentedType
Type of the represented sparse matrix element.
Definition: MatrixAccessProxy.h:105
Constraint on the data type.
Header file for the clear shim.
Compile time check for row-major matrix types.This type trait tests whether or not the given template...
Definition: IsRowMajorMatrix.h:104
void swap(CompressedMatrix< Type, SO > &a, CompressedMatrix< Type, SO > &b)
Swapping the contents of two compressed matrices.
Definition: CompressedMatrix.h:4754
BLAZE_ALWAYS_INLINE void clear(const NonNumericProxy< MT > &proxy)
Clearing the represented element.
Definition: NonNumericProxy.h:854
MatrixAccessProxy(MT &sm, size_t i, size_t j)
Initialization constructor for a MatrixAccessProxy.
Definition: MatrixAccessProxy.h:192
RawReference get() const
Returning the value of the accessed sparse matrix element.
Definition: MatrixAccessProxy.h:360
Type ElementType
Type of the sparse matrix elements.
Definition: CompressedMatrix.h:2476
MatrixAccessProxy & operator=(const MatrixAccessProxy &map)
Copy assignment operator for MatrixAccessProxy.
Definition: MatrixAccessProxy.h:258
~MatrixAccessProxy()
The destructor for MatrixAccessProxy.
Definition: MatrixAccessProxy.h:233
Header file for run time assertion macros.
Header file for the Proxy class.
MT & sm_
Reference to the accessed sparse matrix.
Definition: MatrixAccessProxy.h:154
Header file for the reset shim.
Element * Iterator
Iterator over non-constant elements.
Definition: CompressedMatrix.h:2481
Header file for the isDefault shim.
BLAZE_ALWAYS_INLINE bool isDefault(const NonNumericProxy< MT > &proxy)
Returns whether the represented element is in default state.
Definition: NonNumericProxy.h:874
BLAZE_ALWAYS_INLINE void reset(const NonNumericProxy< MT > &proxy)
Resetting the represented element to the default initial values.
Definition: NonNumericProxy.h:833
size_t j_
Column-index of the accessed sparse matrix element.
Definition: MatrixAccessProxy.h:156
Header file for the IsRowMajorMatrix type trait.
RepresentedType & RawReference
Raw reference to the represented element.
Definition: MatrixAccessProxy.h:106
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
Header file for basic type definitions.
#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