DenseMatrixProxy.h
Go to the documentation of this file.
1 //=================================================================================================
33 //=================================================================================================
34 
35 #ifndef _BLAZE_MATH_PROXY_DENSEMATRIXPROXY_H_
36 #define _BLAZE_MATH_PROXY_DENSEMATRIXPROXY_H_
37 
38 
39 //*************************************************************************************************
40 // Includes
41 //*************************************************************************************************
42 
43 #include <stdexcept>
46 #include <blaze/math/shims/Clear.h>
47 #include <blaze/math/shims/Reset.h>
49 #include <blaze/system/Inline.h>
50 #include <blaze/util/Types.h>
51 
52 
53 namespace blaze {
54 
55 //=================================================================================================
56 //
57 // CLASS DEFINITION
58 //
59 //=================================================================================================
60 
61 //*************************************************************************************************
69 template< typename PT // Type of the proxy
70  , typename MT > // Type of the dense matrix
71 class DenseMatrixProxy : public DenseMatrix< PT, IsColumnMajorMatrix<MT>::value >
72 {
73  public:
74  //**Type definitions****************************************************************************
75  typedef typename MT::Reference Reference;
77  typedef typename MT::Pointer Pointer;
78  typedef typename MT::ConstPointer ConstPointer;
79  typedef typename MT::Iterator Iterator;
80  typedef typename MT::ConstIterator ConstIterator;
81  //**********************************************************************************************
82 
83  //**Data access functions***********************************************************************
86  inline Reference operator()( size_t i, size_t j ) const;
87 
88  inline Pointer data () const;
89  inline Pointer data ( size_t i ) const;
90  inline Iterator begin ( size_t i ) const;
91  inline ConstIterator cbegin( size_t i ) const;
92  inline Iterator end ( size_t i ) const;
93  inline ConstIterator cend ( size_t i ) const;
95  //**********************************************************************************************
96 
97  //**Utility functions***************************************************************************
100  inline size_t rows() const;
101  inline size_t columns() const;
102  inline size_t spacing() const;
103  inline size_t capacity() const;
104  inline size_t capacity( size_t i ) const;
105  inline size_t nonZeros() const;
106  inline size_t nonZeros( size_t i ) const;
107  inline void reset() const;
108  inline void reset( size_t i ) const;
109  inline void clear() const;
110  inline void resize( size_t m, size_t n, bool preserve=true ) const;
111  inline void extend( size_t m, size_t n, bool preserve=true ) const;
112  inline void reserve( size_t n ) const;
113  inline void transpose() const;
114 
115  template< typename Other > inline void scale( const Other& scalar ) const;
117  //**********************************************************************************************
118 
119  private:
120  //**Compile time checks*************************************************************************
124  //**********************************************************************************************
125 };
126 //*************************************************************************************************
127 
128 
129 
130 
131 //=================================================================================================
132 //
133 // DATA ACCESS FUNCTIONS
134 //
135 //=================================================================================================
136 
137 //*************************************************************************************************
144 template< typename PT // Type of the proxy
145  , typename MT > // Type of the dense matrix
147  DenseMatrixProxy<PT,MT>::operator()( size_t i, size_t j ) const
148 {
149  if( (~*this).isRestricted() )
150  throw std::invalid_argument( "Invalid access to restricted element" );
151 
152  return (~*this).get()(i,j);
153 }
154 //*************************************************************************************************
155 
156 
157 //*************************************************************************************************
168 template< typename PT // Type of the proxy
169  , typename MT > // Type of the dense matrix
171 {
172  if( (~*this).isRestricted() )
173  throw std::invalid_argument( "Invalid access to restricted element" );
174 
175  return (~*this).get().data();
176 }
177 //*************************************************************************************************
178 
179 
180 //*************************************************************************************************
187 template< typename PT // Type of the proxy
188  , typename MT > // Type of the dense matrix
190 {
191  if( (~*this).isRestricted() )
192  throw std::invalid_argument( "Invalid access to restricted element" );
193 
194  return (~*this).get().data(i);
195 }
196 //*************************************************************************************************
197 
198 
199 //*************************************************************************************************
210 template< typename PT // Type of the proxy
211  , typename MT > // Type of the dense matrix
212 inline typename DenseMatrixProxy<PT,MT>::Iterator
214 {
215  if( (~*this).isRestricted() )
216  throw std::invalid_argument( "Invalid access to restricted element" );
217 
218  return (~*this).get().begin(i);
219 }
220 //*************************************************************************************************
221 
222 
223 //*************************************************************************************************
234 template< typename PT // Type of the proxy
235  , typename MT > // Type of the dense matrix
238 {
239  return (~*this).get().cbegin(i);
240 }
241 //*************************************************************************************************
242 
243 
244 //*************************************************************************************************
255 template< typename PT // Type of the proxy
256  , typename MT > // Type of the dense matrix
257 inline typename DenseMatrixProxy<PT,MT>::Iterator
259 {
260  if( (~*this).isRestricted() )
261  throw std::invalid_argument( "Invalid access to restricted element" );
262 
263  return (~*this).get().end(i);
264 }
265 //*************************************************************************************************
266 
267 
268 //*************************************************************************************************
279 template< typename PT // Type of the proxy
280  , typename MT > // Type of the dense matrix
283 {
284  return (~*this).get().cend(i);
285 }
286 //*************************************************************************************************
287 
288 
289 
290 
291 //=================================================================================================
292 //
293 // UTILITY FUNCTIONS
294 //
295 //=================================================================================================
296 
297 //*************************************************************************************************
302 template< typename PT // Type of the proxy
303  , typename MT > // Type of the dense matrix
304 inline size_t DenseMatrixProxy<PT,MT>::rows() const
305 {
306  return (~*this).get().rows();
307 }
308 //*************************************************************************************************
309 
310 
311 //*************************************************************************************************
316 template< typename PT // Type of the proxy
317  , typename MT > // Type of the dense matrix
318 inline size_t DenseMatrixProxy<PT,MT>::columns() const
319 {
320  return (~*this).get().columns();
321 }
322 //*************************************************************************************************
323 
324 
325 //*************************************************************************************************
335 template< typename PT // Type of the proxy
336  , typename MT > // Type of the dense matrix
337 inline size_t DenseMatrixProxy<PT,MT>::spacing() const
338 {
339  return (~*this).get().spacing();
340 }
341 //*************************************************************************************************
342 
343 
344 //*************************************************************************************************
349 template< typename PT // Type of the proxy
350  , typename MT > // Type of the dense matrix
352 {
353  return (~*this).get().capacity();
354 }
355 //*************************************************************************************************
356 
357 
358 //*************************************************************************************************
369 template< typename PT // Type of the proxy
370  , typename MT > // Type of the dense matrix
371 inline size_t DenseMatrixProxy<PT,MT>::capacity( size_t i ) const
372 {
373  return (~*this).get().capacity(i);
374 }
375 //*************************************************************************************************
376 
377 
378 //*************************************************************************************************
383 template< typename PT // Type of the proxy
384  , typename MT > // Type of the dense matrix
386 {
387  return (~*this).get().nonZeros();
388 }
389 //*************************************************************************************************
390 
391 
392 //*************************************************************************************************
403 template< typename PT // Type of the proxy
404  , typename MT > // Type of the dense matrix
405 inline size_t DenseMatrixProxy<PT,MT>::nonZeros( size_t i ) const
406 {
407  return (~*this).get().nonZeros(i);
408 }
409 //*************************************************************************************************
410 
411 
412 //*************************************************************************************************
419 template< typename PT // Type of the proxy
420  , typename MT > // Type of the dense matrix
422 {
423  using blaze::reset;
424 
425  reset( (~*this).get() );
426 }
427 //*************************************************************************************************
428 
429 
430 //*************************************************************************************************
441 template< typename PT // Type of the proxy
442  , typename MT > // Type of the dense matrix
443 inline void DenseMatrixProxy<PT,MT>::reset( size_t i ) const
444 {
445  using blaze::reset;
446 
447  reset( (~*this).get(), i );
448 }
449 //*************************************************************************************************
450 
451 
452 //*************************************************************************************************
459 template< typename PT // Type of the proxy
460  , typename MT > // Type of the dense matrix
462 {
463  using blaze::clear;
464 
465  clear( (~*this).get() );
466 }
467 //*************************************************************************************************
468 
469 
470 //*************************************************************************************************
486 template< typename PT // Type of the proxy
487  , typename MT > // Type of the dense matrix
488 inline void DenseMatrixProxy<PT,MT>::resize( size_t m, size_t n, bool preserve ) const
489 {
490  if( (~*this).isRestricted() )
491  throw std::invalid_argument( "Invalid access to restricted element" );
492 
493  (~*this).get().resize( m, n, preserve );
494 }
495 //*************************************************************************************************
496 
497 
498 //*************************************************************************************************
513 template< typename PT // Type of the proxy
514  , typename MT > // Type of the dense matrix
515 inline void DenseMatrixProxy<PT,MT>::extend( size_t m, size_t n, bool preserve ) const
516 {
517  if( (~*this).isRestricted() )
518  throw std::invalid_argument( "Invalid access to restricted element" );
519 
520  (~*this).get().extend( m, n, preserve );
521 }
522 //*************************************************************************************************
523 
524 
525 //*************************************************************************************************
534 template< typename PT // Type of the proxy
535  , typename MT > // Type of the dense matrix
536 inline void DenseMatrixProxy<PT,MT>::reserve( size_t n ) const
537 {
538  if( (~*this).isRestricted() )
539  throw std::invalid_argument( "Invalid access to restricted element" );
540 
541  (~*this).get().reserve( n );
542 }
543 //*************************************************************************************************
544 
545 
546 //*************************************************************************************************
551 template< typename PT // Type of the proxy
552  , typename MT > // Type of the dense matrix
554 {
555  if( (~*this).isRestricted() )
556  throw std::invalid_argument( "Invalid access to restricted element" );
557 
558  (~*this).get().transpose();
559 }
560 //*************************************************************************************************
561 
562 
563 //*************************************************************************************************
569 template< typename PT // Type of the proxy
570  , typename MT > // Type of the dense matrix
571 template< typename Other > // Data type of the scalar value
572 inline void DenseMatrixProxy<PT,MT>::scale( const Other& scalar ) const
573 {
574  if( (~*this).isRestricted() )
575  throw std::invalid_argument( "Invalid access to restricted element" );
576 
577  (~*this).get().scale( scalar );
578 }
579 //*************************************************************************************************
580 
581 
582 
583 
584 //=================================================================================================
585 //
586 // GLOBAL FUNCTIONS
587 //
588 //=================================================================================================
589 
590 //*************************************************************************************************
593 template< typename PT, typename MT >
595  begin( const DenseMatrixProxy<PT,MT>& proxy, size_t i );
596 
597 template< typename PT, typename MT >
599  cbegin( const DenseMatrixProxy<PT,MT>& proxy, size_t i );
600 
601 template< typename PT, typename MT >
603  end( const DenseMatrixProxy<PT,MT>& proxy, size_t i );
604 
605 template< typename PT, typename MT >
607  cend( const DenseMatrixProxy<PT,MT>& proxy, size_t i );
608 
609 template< typename PT, typename MT >
610 BLAZE_ALWAYS_INLINE size_t rows( const DenseMatrixProxy<PT,MT>& proxy );
611 
612 template< typename PT, typename MT >
614 
615 template< typename PT, typename MT >
617 
618 template< typename PT, typename MT >
619 BLAZE_ALWAYS_INLINE size_t capacity( const DenseMatrixProxy<PT,MT>& proxy, size_t i );
620 
621 template< typename PT, typename MT >
623 
624 template< typename PT, typename MT >
625 BLAZE_ALWAYS_INLINE size_t nonZeros( const DenseMatrixProxy<PT,MT>& proxy, size_t i );
626 
627 template< typename PT, typename MT >
629 
630 template< typename PT, typename MT >
631 BLAZE_ALWAYS_INLINE void reset( const DenseMatrixProxy<PT,MT>& proxy, size_t i );
632 
633 template< typename PT, typename MT >
636 //*************************************************************************************************
637 
638 
639 //*************************************************************************************************
652 template< typename PT // Type of the proxy
653  , typename MT > // Type of the dense matrix
655  begin( const DenseMatrixProxy<PT,MT>& proxy, size_t i )
656 {
657  return proxy.begin(i);
658 }
659 //*************************************************************************************************
660 
661 
662 //*************************************************************************************************
675 template< typename PT // Type of the proxy
676  , typename MT > // Type of the dense matrix
678  cbegin( const DenseMatrixProxy<PT,MT>& proxy, size_t i )
679 {
680  return proxy.cbegin(i);
681 }
682 //*************************************************************************************************
683 
684 
685 //*************************************************************************************************
699 template< typename PT // Type of the proxy
700  , typename MT > // Type of the dense matrix
702  end( const DenseMatrixProxy<PT,MT>& proxy, size_t i )
703 {
704  return proxy.end(i);
705 }
706 //*************************************************************************************************
707 
708 
709 //*************************************************************************************************
723 template< typename PT // Type of the proxy
724  , typename MT > // Type of the dense matrix
726  cend( const DenseMatrixProxy<PT,MT>& proxy, size_t i )
727 {
728  return proxy.cend(i);
729 }
730 //*************************************************************************************************
731 
732 
733 //*************************************************************************************************
740 template< typename PT // Type of the proxy
741  , typename MT > // Type of the dense matrix
743 {
744  return proxy.rows();
745 }
746 //*************************************************************************************************
747 
748 
749 //*************************************************************************************************
756 template< typename PT // Type of the proxy
757  , typename MT > // Type of the dense matrix
759 {
760  return proxy.columns();
761 }
762 //*************************************************************************************************
763 
764 
765 //*************************************************************************************************
772 template< typename PT // Type of the proxy
773  , typename MT > // Type of the dense matrix
775 {
776  return proxy.capacity();
777 }
778 //*************************************************************************************************
779 
780 
781 //*************************************************************************************************
794 template< typename PT // Type of the proxy
795  , typename MT > // Type of the dense matrix
796 BLAZE_ALWAYS_INLINE size_t capacity( const DenseMatrixProxy<PT,MT>& proxy, size_t i )
797 {
798  return proxy.capacity(i);
799 }
800 //*************************************************************************************************
801 
802 
803 //*************************************************************************************************
810 template< typename PT // Type of the proxy
811  , typename MT > // Type of the dense matrix
813 {
814  return proxy.nonZeros();
815 }
816 //*************************************************************************************************
817 
818 
819 //*************************************************************************************************
832 template< typename PT // Type of the proxy
833  , typename MT > // Type of the dense matrix
834 BLAZE_ALWAYS_INLINE size_t nonZeros( const DenseMatrixProxy<PT,MT>& proxy, size_t i )
835 {
836  return proxy.nonZeros(i);
837 }
838 //*************************************************************************************************
839 
840 
841 //*************************************************************************************************
850 template< typename PT // Type of the proxy
851  , typename MT > // Type of the dense matrix
853 {
854  proxy.reset();
855 }
856 //*************************************************************************************************
857 
858 
859 //*************************************************************************************************
872 template< typename PT // Type of the proxy
873  , typename MT > // Type of the dense matrix
874 BLAZE_ALWAYS_INLINE void reset( const DenseMatrixProxy<PT,MT>& proxy, size_t i )
875 {
876  proxy.reset(i);
877 }
878 //*************************************************************************************************
879 
880 
881 //*************************************************************************************************
890 template< typename PT // Type of the proxy
891  , typename MT > // Type of the dense matrix
893 {
894  proxy.clear();
895 }
896 //*************************************************************************************************
897 
898 } // namespace blaze
899 
900 #endif
MT::ConstIterator ConstIterator
Iterator over constant elements.
Definition: DenseMatrixProxy.h:80
Header file for basic type definitions.
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
size_t rows() const
Returns the current number of rows of the represented matrix.
Definition: DenseMatrixProxy.h:304
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
#define BLAZE_CONSTRAINT_MUST_BE_DENSE_MATRIX_TYPE(T)
Constraint on the data type.In case the given data type T is not a dense, N-dimensional matrix type...
Definition: DenseMatrix.h:79
void extend(size_t m, size_t n, bool preserve=true) const
Extending the size of the represented matrix.
Definition: DenseMatrixProxy.h:515
Header file for the IsColumnMajorMatrix type trait.
void reset(const DiagonalProxy< MT > &proxy)
Resetting the represented element to the default initial values.
Definition: DiagonalProxy.h:821
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
Iterator begin(size_t i) const
Returns an iterator to the first element of row/column i of the represented matrix.
Definition: DenseMatrixProxy.h:213
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 scale(const Other &scalar) const
Scaling of the matrix by the scalar value scalar ( ).
Definition: DenseMatrixProxy.h:572
Proxy backend for dense matrix types.The DenseMatrixProxy class serves as a backend for the Proxy cla...
Definition: DenseMatrixProxy.h:71
Base class for dense matrices.The DenseMatrix class is a base class for all dense matrix classes...
Definition: DenseMatrix.h:70
Iterator end(size_t i) const
Returns an iterator just past the last element of row/column i of the represented matrix...
Definition: DenseMatrixProxy.h:258
size_t columns() const
Returns the current number of columns of the represented matrix.
Definition: DenseMatrixProxy.h:318
ConstIterator cbegin(size_t i) const
Returns an iterator to the first element of row/column i of the represented matrix.
Definition: DenseMatrixProxy.h:237
Constraint on the data type.
MT::Iterator Iterator
Iterator over non-constant elements.
Definition: DenseMatrixProxy.h:79
Reference operator()(size_t i, size_t j) const
Function call operator for the direct access to matrix elements.
Definition: DenseMatrixProxy.h:147
void transpose() const
Transposing the represented matrix.
Definition: DenseMatrixProxy.h:553
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
const Element * ConstIterator
Iterator over constant elements.
Definition: CompressedMatrix.h:2511
Header file for the DenseMatrix base class.
size_t spacing() const
Returns the spacing between the beginning of two rows/columns of the represented matrix.
Definition: DenseMatrixProxy.h:337
size_t capacity() const
Returns the maximum capacity of the represented matrix.
Definition: DenseMatrixProxy.h:351
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
const Type & ConstReference
Reference to a constant matrix value.
Definition: CompressedMatrix.h:2509
void clear(const DiagonalProxy< MT > &proxy)
Clearing the represented element.
Definition: DiagonalProxy.h:841
void clear() const
Clearing the represented matrix.
Definition: DenseMatrixProxy.h:461
MT::Reference Reference
Reference to a non-constant matrix value.
Definition: DenseMatrixProxy.h:75
Header file for the reset shim.
Element * Iterator
Iterator over non-constant elements.
Definition: CompressedMatrix.h:2510
void reserve(size_t n) const
Setting the minimum capacity of the represented matrix.
Definition: DenseMatrixProxy.h:536
Pointer data() const
Low-level data access to matrix elements.
Definition: DenseMatrixProxy.h:170
MT::ConstReference ConstReference
Reference to a constant matrix value.
Definition: DenseMatrixProxy.h:76
MT::Pointer Pointer
Pointer to a non-constant matrix value.
Definition: DenseMatrixProxy.h:77
MT::ConstPointer ConstPointer
Pointer to a constant matrix value.
Definition: DenseMatrixProxy.h:78
void resize(size_t m, size_t n, bool preserve=true) const
Changing the size of the represented matrix.
Definition: DenseMatrixProxy.h:488
size_t nonZeros() const
Returns the number of non-zero elements in the represented matrix.
Definition: DenseMatrixProxy.h:385
void reset() const
Reset to the default initial value.
Definition: DenseMatrixProxy.h:421
BLAZE_ALWAYS_INLINE size_t columns(const Matrix< MT, SO > &matrix)
Returns the current number of columns of the matrix.
Definition: Matrix.h:332
MatrixAccessProxy< This > Reference
Reference to a non-constant matrix value.
Definition: CompressedMatrix.h:2508
ConstIterator cend(size_t i) const
Returns an iterator just past the last element of row/column i of the represented matrix...
Definition: DenseMatrixProxy.h:282
System settings for the inline keywords.