All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SparseMatrixProxy.h
Go to the documentation of this file.
1 //=================================================================================================
33 //=================================================================================================
34 
35 #ifndef _BLAZE_MATH_PROXY_SPARSEMATRIXPROXY_H_
36 #define _BLAZE_MATH_PROXY_SPARSEMATRIXPROXY_H_
37 
38 
39 //*************************************************************************************************
40 // Includes
41 //*************************************************************************************************
42 
45 #include <blaze/math/shims/Clear.h>
46 #include <blaze/math/shims/Reset.h>
48 #include <blaze/system/Inline.h>
49 #include <blaze/util/Types.h>
50 
51 
52 namespace blaze {
53 
54 //=================================================================================================
55 //
56 // CLASS DEFINITION
57 //
58 //=================================================================================================
59 
60 //*************************************************************************************************
68 template< typename PT // Type of the proxy
69  , typename MT > // Type of the sparse matrix
70 class SparseMatrixProxy : public SparseMatrix< PT, IsColumnMajorMatrix<MT>::value >
71 {
72  public:
73  //**Type definitions****************************************************************************
74  typedef typename MT::ElementType ElementType;
75  typedef typename MT::Reference Reference;
77  typedef typename MT::Iterator Iterator;
78  typedef typename MT::ConstIterator ConstIterator;
79  //**********************************************************************************************
80 
81  //**Data access functions***********************************************************************
84  inline Reference operator()( size_t i, size_t j ) const;
85 
86  inline Iterator begin ( size_t i ) const;
87  inline ConstIterator cbegin( size_t i ) const;
88  inline Iterator end ( size_t i ) const;
89  inline ConstIterator cend ( size_t i ) const;
91  //**********************************************************************************************
92 
93  //**Utility functions***************************************************************************
96  inline size_t rows() const;
97  inline size_t columns() const;
98  inline size_t capacity() const;
99  inline size_t capacity( size_t i ) const;
100  inline size_t nonZeros() const;
101  inline size_t nonZeros( size_t i ) const;
102  inline void reset() const;
103  inline void reset( size_t i ) const;
104  inline void clear() const;
105  inline Iterator set( size_t i, size_t j, const ElementType& value ) const;
106  inline Iterator insert( size_t i, size_t j, const ElementType& value ) const;
107  inline void append( size_t i, size_t j, const ElementType& value, bool check=false ) const;
108  inline void finalize( size_t i ) const;
109  inline void erase( size_t i, size_t j ) const;
110  inline Iterator erase( size_t i, Iterator pos ) const;
111  inline Iterator erase( size_t i, Iterator first, Iterator last ) const;
112  inline void resize( size_t m, size_t n, bool preserve=true ) const;
113  inline void reserve( size_t n ) const;
114  inline void reserve( size_t i, size_t n ) const;
115  inline void trim() const;
116  inline void trim( size_t i ) const;
117  inline void transpose() const;
118 
119  template< typename Other > inline void scale( const Other& scalar ) const;
121  //**********************************************************************************************
122 
123  //**Lookup functions****************************************************************************
126  inline Iterator find ( size_t i, size_t j ) const;
127  inline Iterator lowerBound( size_t i, size_t j ) const;
128  inline Iterator upperBound( size_t i, size_t j ) const;
130  //**********************************************************************************************
131 
132  private:
133  //**Compile time checks*************************************************************************
137  //**********************************************************************************************
138 };
139 //*************************************************************************************************
140 
141 
142 
143 
144 //=================================================================================================
145 //
146 // DATA ACCESS FUNCTIONS
147 //
148 //=================================================================================================
149 
150 //*************************************************************************************************
157 template< typename PT // Type of the proxy
158  , typename MT > // Type of the sparse matrix
160  SparseMatrixProxy<PT,MT>::operator()( size_t i, size_t j ) const
161 {
162  return (~*this).get()(i,j);
163 }
164 //*************************************************************************************************
165 
166 
167 //*************************************************************************************************
178 template< typename PT // Type of the proxy
179  , typename MT > // Type of the sparse matrix
182 {
183  return (~*this).get().begin(i);
184 }
185 //*************************************************************************************************
186 
187 
188 //*************************************************************************************************
199 template< typename PT // Type of the proxy
200  , typename MT > // Type of the sparse matrix
203 {
204  return (~*this).get().cbegin(i);
205 }
206 //*************************************************************************************************
207 
208 
209 //*************************************************************************************************
220 template< typename PT // Type of the proxy
221  , typename MT > // Type of the sparse matrix
224 {
225  return (~*this).get().end(i);
226 }
227 //*************************************************************************************************
228 
229 
230 //*************************************************************************************************
241 template< typename PT // Type of the proxy
242  , typename MT > // Type of the sparse matrix
245 {
246  return (~*this).get().cend(i);
247 }
248 //*************************************************************************************************
249 
250 
251 
252 
253 //=================================================================================================
254 //
255 // UTILITY FUNCTIONS
256 //
257 //=================================================================================================
258 
259 //*************************************************************************************************
264 template< typename PT // Type of the proxy
265  , typename MT > // Type of the sparse matrix
266 inline size_t SparseMatrixProxy<PT,MT>::rows() const
267 {
268  return (~*this).get().rows();
269 }
270 //*************************************************************************************************
271 
272 
273 //*************************************************************************************************
278 template< typename PT // Type of the proxy
279  , typename MT > // Type of the sparse matrix
281 {
282  return (~*this).get().columns();
283 }
284 //*************************************************************************************************
285 
286 
287 //*************************************************************************************************
292 template< typename PT // Type of the proxy
293  , typename MT > // Type of the sparse matrix
295 {
296  return (~*this).get().capacity();
297 }
298 //*************************************************************************************************
299 
300 
301 //*************************************************************************************************
312 template< typename PT // Type of the proxy
313  , typename MT > // Type of the sparse matrix
314 inline size_t SparseMatrixProxy<PT,MT>::capacity( size_t i ) const
315 {
316  return (~*this).get().capacity(i);
317 }
318 //*************************************************************************************************
319 
320 
321 //*************************************************************************************************
326 template< typename PT // Type of the proxy
327  , typename MT > // Type of the sparse matrix
329 {
330  return (~*this).get().nonZeros();
331 }
332 //*************************************************************************************************
333 
334 
335 //*************************************************************************************************
346 template< typename PT // Type of the proxy
347  , typename MT > // Type of the sparse matrix
348 inline size_t SparseMatrixProxy<PT,MT>::nonZeros( size_t i ) const
349 {
350  return (~*this).get().nonZeros(i);
351 }
352 //*************************************************************************************************
353 
354 
355 //*************************************************************************************************
362 template< typename PT // Type of the proxy
363  , typename MT > // Type of the sparse matrix
365 {
366  using blaze::reset;
367 
368  reset( (~*this).get() );
369 }
370 //*************************************************************************************************
371 
372 
373 //*************************************************************************************************
384 template< typename PT // Type of the proxy
385  , typename MT > // Type of the sparse matrix
386 inline void SparseMatrixProxy<PT,MT>::reset( size_t i ) const
387 {
388  using blaze::reset;
389 
390  reset( (~*this).get(), i );
391 }
392 //*************************************************************************************************
393 
394 
395 //*************************************************************************************************
402 template< typename PT // Type of the proxy
403  , typename MT > // Type of the sparse matrix
405 {
406  using blaze::clear;
407 
408  clear( (~*this).get() );
409 }
410 //*************************************************************************************************
411 
412 
413 //*************************************************************************************************
426 template< typename PT // Type of the proxy
427  , typename MT > // Type of the sparse matrix
429  SparseMatrixProxy<PT,MT>::set( size_t i, size_t j, const ElementType& value ) const
430 {
431  return (~*this).get().set( i, j, value );
432 }
433 //*************************************************************************************************
434 
435 
436 //*************************************************************************************************
449 template< typename PT // Type of the proxy
450  , typename MT > // Type of the sparse matrix
452  SparseMatrixProxy<PT,MT>::insert( size_t i, size_t j, const ElementType& value ) const
453 {
454  return (~*this).get().insert( i, j, value );
455 }
456 //*************************************************************************************************
457 
458 
459 //*************************************************************************************************
485 template< typename PT // Type of the proxy
486  , typename MT > // Type of the sparse matrix
487 inline void SparseMatrixProxy<PT,MT>::append( size_t i, size_t j, const ElementType& value, bool check ) const
488 {
489  (~*this).get().append( i, j, value, check );
490 }
491 //*************************************************************************************************
492 
493 
494 //*************************************************************************************************
507 template< typename PT // Type of the proxy
508  , typename MT > // Type of the sparse matrix
509 inline void SparseMatrixProxy<PT,MT>::finalize( size_t i ) const
510 {
511  (~*this).get().finalize( i );
512 }
513 //*************************************************************************************************
514 
515 
516 //*************************************************************************************************
525 template< typename PT // Type of the proxy
526  , typename MT > // Type of the sparse matrix
527 inline void SparseMatrixProxy<PT,MT>::erase( size_t i, size_t j ) const
528 {
529  (~*this).get().erase( i, j );
530 }
531 //*************************************************************************************************
532 
533 
534 //*************************************************************************************************
545 template< typename PT // Type of the proxy
546  , typename MT > // Type of the sparse matrix
549 {
550  return (~*this).get().erase( i, pos );
551 }
552 //*************************************************************************************************
553 
554 
555 //*************************************************************************************************
567 template< typename PT // Type of the proxy
568  , typename MT > // Type of the sparse matrix
570  SparseMatrixProxy<PT,MT>::erase( size_t i, Iterator first, Iterator last ) const
571 {
572  return (~*this).get().erase( i, first, last );
573 }
574 //*************************************************************************************************
575 
576 
577 //*************************************************************************************************
592 template< typename PT // Type of the proxy
593  , typename MT > // Type of the sparse matrix
594 inline void SparseMatrixProxy<PT,MT>::resize( size_t m, size_t n, bool preserve ) const
595 {
596  (~*this).get().resize( m, n, preserve );
597 }
598 //*************************************************************************************************
599 
600 
601 //*************************************************************************************************
611 template< typename PT // Type of the proxy
612  , typename MT > // Type of the sparse matrix
613 inline void SparseMatrixProxy<PT,MT>::reserve( size_t n ) const
614 {
615  (~*this).get().reserve( n );
616 }
617 //*************************************************************************************************
618 
619 
620 //*************************************************************************************************
634 template< typename PT // Type of the proxy
635  , typename MT > // Type of the sparse matrix
636 inline void SparseMatrixProxy<PT,MT>::reserve( size_t i, size_t n ) const
637 {
638  (~*this).get().reserve( i, n );
639 }
640 //*************************************************************************************************
641 
642 
643 //*************************************************************************************************
653 template< typename PT // Type of the proxy
654  , typename MT > // Type of the sparse matrix
656 {
657  (~*this).get().trim();
658 }
659 //*************************************************************************************************
660 
661 
662 //*************************************************************************************************
673 template< typename PT // Type of the proxy
674  , typename MT > // Type of the sparse matrix
675 inline void SparseMatrixProxy<PT,MT>::trim( size_t i ) const
676 {
677  (~*this).get().trim( i );
678 }
679 //*************************************************************************************************
680 
681 
682 //*************************************************************************************************
687 template< typename PT // Type of the proxy
688  , typename MT > // Type of the sparse matrix
690 {
691  (~*this).get().transpose();
692 }
693 //*************************************************************************************************
694 
695 
696 //*************************************************************************************************
702 template< typename PT // Type of the proxy
703  , typename MT > // Type of the sparse matrix
704 template< typename Other > // Data type of the scalar value
705 inline void SparseMatrixProxy<PT,MT>::scale( const Other& scalar ) const
706 {
707  (~*this).get().scale( scalar );
708 }
709 //*************************************************************************************************
710 
711 
712 
713 
714 //=================================================================================================
715 //
716 // LOOKUP FUNCTIONS
717 //
718 //=================================================================================================
719 
720 //*************************************************************************************************
735 template< typename PT // Type of the proxy
736  , typename MT > // Type of the sparse matrix
738  SparseMatrixProxy<PT,MT>::find( size_t i, size_t j ) const
739 {
740  return (~*this).get().find( i, j );
741 }
742 //*************************************************************************************************
743 
744 
745 //*************************************************************************************************
760 template< typename PT // Type of the proxy
761  , typename MT > // Type of the sparse matrix
763  SparseMatrixProxy<PT,MT>::lowerBound( size_t i, size_t j ) const
764 {
765  return (~*this).get().lowerBound( i, j );
766 }
767 //*************************************************************************************************
768 
769 
770 //*************************************************************************************************
785 template< typename PT // Type of the proxy
786  , typename MT > // Type of the sparse matrix
788  SparseMatrixProxy<PT,MT>::upperBound( size_t i, size_t j ) const
789 {
790  return (~*this).get().upperBound( i, j );
791 }
792 //*************************************************************************************************
793 
794 
795 
796 
797 //=================================================================================================
798 //
799 // GLOBAL FUNCTIONS
800 //
801 //=================================================================================================
802 
803 //*************************************************************************************************
806 template< typename PT, typename MT >
808  begin( const SparseMatrixProxy<PT,MT>& proxy, size_t i );
809 
810 template< typename PT, typename MT >
812  cbegin( const SparseMatrixProxy<PT,MT>& proxy, size_t i );
813 
814 template< typename PT, typename MT >
816  end( const SparseMatrixProxy<PT,MT>& proxy, size_t i );
817 
818 template< typename PT, typename MT >
820  cend( const SparseMatrixProxy<PT,MT>& proxy, size_t i );
821 
822 template< typename PT, typename MT >
823 BLAZE_ALWAYS_INLINE size_t rows( const SparseMatrixProxy<PT,MT>& proxy );
824 
825 template< typename PT, typename MT >
827 
828 template< typename PT, typename MT >
830 
831 template< typename PT, typename MT >
832 BLAZE_ALWAYS_INLINE size_t capacity( const SparseMatrixProxy<PT,MT>& proxy, size_t i );
833 
834 template< typename PT, typename MT >
836 
837 template< typename PT, typename MT >
838 BLAZE_ALWAYS_INLINE size_t nonZeros( const SparseMatrixProxy<PT,MT>& proxy, size_t i );
839 
840 template< typename PT, typename MT >
842 
843 template< typename PT, typename MT >
844 BLAZE_ALWAYS_INLINE void reset( const SparseMatrixProxy<PT,MT>& proxy, size_t i );
845 
846 template< typename PT, typename MT >
849 //*************************************************************************************************
850 
851 
852 //*************************************************************************************************
865 template< typename PT // Type of the proxy
866  , typename MT > // Type of the sparse matrix
868  begin( const SparseMatrixProxy<PT,MT>& proxy, size_t i )
869 {
870  return proxy.begin(i);
871 }
872 //*************************************************************************************************
873 
874 
875 //*************************************************************************************************
888 template< typename PT // Type of the proxy
889  , typename MT > // Type of the sparse matrix
891  cbegin( const SparseMatrixProxy<PT,MT>& proxy, size_t i )
892 {
893  return proxy.cbegin(i);
894 }
895 //*************************************************************************************************
896 
897 
898 //*************************************************************************************************
912 template< typename PT // Type of the proxy
913  , typename MT > // Type of the sparse matrix
915  end( const SparseMatrixProxy<PT,MT>& proxy, size_t i )
916 {
917  return proxy.end(i);
918 }
919 //*************************************************************************************************
920 
921 
922 //*************************************************************************************************
936 template< typename PT // Type of the proxy
937  , typename MT > // Type of the sparse matrix
939  cend( const SparseMatrixProxy<PT,MT>& proxy, size_t i )
940 {
941  return proxy.cend(i);
942 }
943 //*************************************************************************************************
944 
945 
946 //*************************************************************************************************
953 template< typename PT // Type of the proxy
954  , typename MT > // Type of the sparse matrix
956 {
957  return proxy.rows();
958 }
959 //*************************************************************************************************
960 
961 
962 //*************************************************************************************************
969 template< typename PT // Type of the proxy
970  , typename MT > // Type of the sparse matrix
972 {
973  return proxy.columns();
974 }
975 //*************************************************************************************************
976 
977 
978 //*************************************************************************************************
985 template< typename PT // Type of the proxy
986  , typename MT > // Type of the sparse matrix
988 {
989  return proxy.capacity();
990 }
991 //*************************************************************************************************
992 
993 
994 //*************************************************************************************************
1007 template< typename PT // Type of the proxy
1008  , typename MT > // Type of the sparse matrix
1010 {
1011  return proxy.capacity(i);
1012 }
1013 //*************************************************************************************************
1014 
1015 
1016 //*************************************************************************************************
1023 template< typename PT // Type of the proxy
1024  , typename MT > // Type of the sparse matrix
1026 {
1027  return proxy.nonZeros();
1028 }
1029 //*************************************************************************************************
1030 
1031 
1032 //*************************************************************************************************
1045 template< typename PT // Type of the proxy
1046  , typename MT > // Type of the sparse matrix
1048 {
1049  return proxy.nonZeros(i);
1050 }
1051 //*************************************************************************************************
1052 
1053 
1054 //*************************************************************************************************
1063 template< typename PT // Type of the proxy
1064  , typename MT > // Type of the sparse matrix
1066 {
1067  proxy.reset();
1068 }
1069 //*************************************************************************************************
1070 
1071 
1072 //*************************************************************************************************
1085 template< typename PT // Type of the proxy
1086  , typename MT > // Type of the sparse matrix
1088 {
1089  proxy.reset(i);
1090 }
1091 //*************************************************************************************************
1092 
1093 
1094 //*************************************************************************************************
1103 template< typename PT // Type of the proxy
1104  , typename MT > // Type of the sparse matrix
1106 {
1107  proxy.clear();
1108 }
1109 //*************************************************************************************************
1110 
1111 } // namespace blaze
1112 
1113 #endif
Iterator set(size_t i, size_t j, const ElementType &value) const
Setting an element of the represented sparse matrix.
Definition: SparseMatrixProxy.h:429
void append(size_t i, size_t j, const ElementType &value, bool check=false) const
Appending an element to the specified row/column of the sparse matrix.
Definition: SparseMatrixProxy.h:487
Iterator insert(size_t i, size_t j, const ElementType &value) const
Inserting an element into the represented sparse matrix.
Definition: SparseMatrixProxy.h:452
size_t nonZeros() const
Returns the number of non-zero elements in the represented matrix.
Definition: SparseMatrixProxy.h:328
BLAZE_ALWAYS_INLINE MT::ConstIterator cbegin(const Matrix< MT, SO > &matrix, size_t i)
Returns an iterator to the first element of row/column i.
Definition: Matrix.h:237
BLAZE_ALWAYS_INLINE MT::ConstIterator cend(const Matrix< MT, SO > &matrix, size_t i)
Returns an iterator just past the last element of row/column i.
Definition: Matrix.h:300
BLAZE_ALWAYS_INLINE MT::Iterator end(Matrix< MT, SO > &matrix, size_t i)
Returns an iterator just past the last element of row/column i.
Definition: Matrix.h:258
MT::Iterator Iterator
Iterator over non-constant elements.
Definition: SparseMatrixProxy.h:77
void reset() const
Reset to the default initial value.
Definition: SparseMatrixProxy.h:364
void erase(size_t i, size_t j) const
Erasing an element from the sparse matrix.
Definition: SparseMatrixProxy.h:527
Header file for the IsColumnMajorMatrix type trait.
Iterator upperBound(size_t i, size_t j) const
Returns an iterator to the first index greater then the given index.
Definition: SparseMatrixProxy.h:788
size_t capacity() const
Returns the maximum capacity of the represented matrix.
Definition: SparseMatrixProxy.h:294
void transpose() const
Transposing the represented matrix.
Definition: SparseMatrixProxy.h:689
BLAZE_ALWAYS_INLINE size_t capacity(const Matrix< MT, SO > &matrix)
Returns the maximum capacity of the matrix.
Definition: Matrix.h:348
BLAZE_ALWAYS_INLINE size_t rows(const Matrix< MT, SO > &matrix)
Returns the current number of rows of the matrix.
Definition: Matrix.h:316
ConstIterator cend(size_t i) const
Returns an iterator just past the last element of row/column i of the represented matrix...
Definition: SparseMatrixProxy.h:244
BLAZE_ALWAYS_INLINE size_t nonZeros(const Matrix< MT, SO > &matrix)
Returns the total number of non-zero elements in the matrix.
Definition: Matrix.h:386
void finalize(size_t i) const
Finalizing the element insertion of a row/column.
Definition: SparseMatrixProxy.h:509
Iterator lowerBound(size_t i, size_t j) const
Returns an iterator to the first index not less then the given index.
Definition: SparseMatrixProxy.h:763
MT::Reference Reference
Reference to a non-constant matrix value.
Definition: SparseMatrixProxy.h:75
Iterator find(size_t i, size_t j) const
Searches for a specific matrix element.
Definition: SparseMatrixProxy.h:738
Base class for sparse matrices.The SparseMatrix class is a base class for all sparse matrix classes...
Definition: Forward.h:107
Header file for the SparseMatrix base class.
Constraint on the data type.
void trim() const
Removing all excessive capacity from all rows/columns.
Definition: SparseMatrixProxy.h:655
Iterator begin(size_t i) const
Returns an iterator to the first element of row/column i of the represented matrix.
Definition: SparseMatrixProxy.h:181
void reserve(size_t n) const
Setting the minimum capacity of the represented matrix.
Definition: SparseMatrixProxy.h:613
Header file for the clear shim.
#define BLAZE_ALWAYS_INLINE
Platform dependent setup of an enforced inline keyword.
Definition: Inline.h:85
const Element * ConstIterator
Iterator over constant elements.
Definition: CompressedMatrix.h:2482
MT::ConstReference ConstReference
Reference to a constant matrix value.
Definition: SparseMatrixProxy.h:76
MT::ElementType ElementType
Type of the sparse matrix elements.
Definition: SparseMatrixProxy.h:74
BLAZE_ALWAYS_INLINE void clear(const NonNumericProxy< MT > &proxy)
Clearing the represented element.
Definition: NonNumericProxy.h:854
void scale(const Other &scalar) const
Scaling of the sparse matrix by the scalar value scalar ( ).
Definition: SparseMatrixProxy.h:705
RawReference get() const
Returning the value of the accessed sparse matrix element.
Definition: MatrixAccessProxy.h:360
BLAZE_ALWAYS_INLINE MT::Iterator begin(Matrix< MT, SO > &matrix, size_t i)
Returns an iterator to the first element of row/column i.
Definition: Matrix.h:195
Proxy backend for sparse matrix types.The SparseMatrixProxy class serves as a backend for the Proxy c...
Definition: SparseMatrixProxy.h:70
Type ElementType
Type of the sparse matrix elements.
Definition: CompressedMatrix.h:2476
ConstIterator cbegin(size_t i) const
Returns an iterator to the first element of row/column i of the represented matrix.
Definition: SparseMatrixProxy.h:202
const Type & ConstReference
Reference to a constant matrix value.
Definition: CompressedMatrix.h:2480
void clear() const
Clearing the represented vector.
Definition: SparseMatrixProxy.h:404
size_t columns() const
Returns the current number of columns of the represented matrix.
Definition: SparseMatrixProxy.h:280
Header file for the reset shim.
Element * Iterator
Iterator over non-constant elements.
Definition: CompressedMatrix.h:2481
MT::ConstIterator ConstIterator
Iterator over constant elements.
Definition: SparseMatrixProxy.h:78
Reference operator()(size_t i, size_t j) const
Function call operator for the direct access to matrix elements.
Definition: SparseMatrixProxy.h:160
BLAZE_ALWAYS_INLINE void reset(const NonNumericProxy< MT > &proxy)
Resetting the represented element to the default initial values.
Definition: NonNumericProxy.h:833
Iterator end(size_t i) const
Returns an iterator just past the last element of row/column i of the represented matrix...
Definition: SparseMatrixProxy.h:223
BLAZE_ALWAYS_INLINE size_t columns(const Matrix< MT, SO > &matrix)
Returns the current number of columns of the matrix.
Definition: Matrix.h:332
Header file for basic type definitions.
size_t rows() const
Returns the current number of rows of the represented matrix.
Definition: SparseMatrixProxy.h:266
MatrixAccessProxy< This > Reference
Reference to a non-constant matrix value.
Definition: CompressedMatrix.h:2479
System settings for the inline keywords.
#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
void resize(size_t m, size_t n, bool preserve=true) const
Changing the size of the represented matrix.
Definition: SparseMatrixProxy.h:594