All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DynamicMatrix.h
Go to the documentation of this file.
1 //=================================================================================================
33 //=================================================================================================
34 
35 #ifndef _BLAZE_MATH_DENSE_DYNAMICMATRIX_H_
36 #define _BLAZE_MATH_DENSE_DYNAMICMATRIX_H_
37 
38 
39 //*************************************************************************************************
40 // Includes
41 //*************************************************************************************************
42 
43 #include <algorithm>
44 #include <stdexcept>
48 #include <blaze/math/Forward.h>
49 #include <blaze/math/Functions.h>
50 #include <blaze/math/Intrinsics.h>
51 #include <blaze/math/shims/Equal.h>
53 #include <blaze/math/shims/Reset.h>
64 #include <blaze/system/CacheSize.h>
65 #include <blaze/system/Restrict.h>
67 #include <blaze/system/Streaming.h>
68 #include <blaze/util/Assert.h>
75 #include <blaze/util/DisableIf.h>
76 #include <blaze/util/EnableIf.h>
77 #include <blaze/util/Memory.h>
78 #include <blaze/util/Null.h>
79 #include <blaze/util/Template.h>
80 #include <blaze/util/Types.h>
84 #include <blaze/util/Unused.h>
85 
86 
87 namespace blaze {
88 
89 //=================================================================================================
90 //
91 // CLASS DEFINITION
92 //
93 //=================================================================================================
94 
95 //*************************************************************************************************
174 template< typename Type // Data type of the matrix
175  , bool SO = defaultStorageOrder > // Storage order
176 class DynamicMatrix : public DenseMatrix< DynamicMatrix<Type,SO>, SO >
177 {
178  private:
179  //**Type definitions****************************************************************************
181  //**********************************************************************************************
182 
183  public:
184  //**Type definitions****************************************************************************
186  typedef This ResultType;
189  typedef Type ElementType;
190  typedef typename IT::Type IntrinsicType;
191  typedef const Type& ReturnType;
192  typedef const This& CompositeType;
193  typedef Type& Reference;
194  typedef const Type& ConstReference;
197  //**********************************************************************************************
198 
199  //**Compilation flags***************************************************************************
201 
205  enum { vectorizable = IsVectorizable<Type>::value };
206  //**********************************************************************************************
207 
208  //**Constructors********************************************************************************
211  explicit inline DynamicMatrix();
212  explicit inline DynamicMatrix( size_t m, size_t n );
213  explicit inline DynamicMatrix( size_t m, size_t n, const Type& init );
214  template< typename Other > explicit inline DynamicMatrix( size_t m, size_t n, const Other* array );
215 
216  template< typename Other, size_t M, size_t N >
217  explicit inline DynamicMatrix( const Other (&array)[M][N] );
218 
219  inline DynamicMatrix( const DynamicMatrix& m );
220  template< typename MT, bool SO2 > inline DynamicMatrix( const Matrix<MT,SO2>& m );
222  //**********************************************************************************************
223 
224  //**Destructor**********************************************************************************
227  inline ~DynamicMatrix();
229  //**********************************************************************************************
230 
231  //**Data access functions***********************************************************************
234  inline Reference operator()( size_t i, size_t j );
235  inline ConstReference operator()( size_t i, size_t j ) const;
236  inline Type* data ();
237  inline const Type* data () const;
238  inline Type* data ( size_t i );
239  inline const Type* data ( size_t i ) const;
240  inline Iterator begin ( size_t i );
241  inline ConstIterator begin ( size_t i ) const;
242  inline ConstIterator cbegin( size_t i ) const;
243  inline Iterator end ( size_t i );
244  inline ConstIterator end ( size_t i ) const;
245  inline ConstIterator cend ( size_t i ) const;
247  //**********************************************************************************************
248 
249  //**Assignment operators************************************************************************
252  template< typename Other, size_t M, size_t N >
253  inline DynamicMatrix& operator=( const Other (&array)[M][N] );
254 
255  inline DynamicMatrix& operator= ( Type set );
256  inline DynamicMatrix& operator= ( const DynamicMatrix& set );
257  template< typename MT, bool SO2 > inline DynamicMatrix& operator= ( const Matrix<MT,SO2>& rhs );
258  template< typename MT, bool SO2 > inline DynamicMatrix& operator+=( const Matrix<MT,SO2>& rhs );
259  template< typename MT, bool SO2 > inline DynamicMatrix& operator-=( const Matrix<MT,SO2>& rhs );
260  template< typename MT, bool SO2 > inline DynamicMatrix& operator*=( const Matrix<MT,SO2>& rhs );
261 
262  template< typename Other >
263  inline typename EnableIf< IsNumeric<Other>, DynamicMatrix >::Type&
264  operator*=( Other rhs );
265 
266  template< typename Other >
267  inline typename EnableIf< IsNumeric<Other>, DynamicMatrix >::Type&
268  operator/=( Other rhs );
270  //**********************************************************************************************
271 
272  //**Utility functions***************************************************************************
275  inline size_t rows() const;
276  inline size_t columns() const;
277  inline size_t spacing() const;
278  inline size_t capacity() const;
279  inline size_t capacity( size_t i ) const;
280  inline size_t nonZeros() const;
281  inline size_t nonZeros( size_t i ) const;
282  inline void reset();
283  inline void reset( size_t i );
284  inline void clear();
285  void resize ( size_t m, size_t n, bool preserve=true );
286  inline void extend ( size_t m, size_t n, bool preserve=true );
287  inline void reserve( size_t elements );
288  inline DynamicMatrix& transpose();
289  template< typename Other > inline DynamicMatrix& scale( Other scalar );
290  inline void swap( DynamicMatrix& m ) /* throw() */;
292  //**********************************************************************************************
293 
294  private:
295  //**********************************************************************************************
297  template< typename MT >
299  struct VectorizedAssign {
300  enum { value = vectorizable && MT::vectorizable &&
302  };
304  //**********************************************************************************************
305 
306  //**********************************************************************************************
308  template< typename MT >
310  struct VectorizedAddAssign {
311  enum { value = vectorizable && MT::vectorizable &&
312  IsSame<Type,typename MT::ElementType>::value &&
313  IntrinsicTrait<Type>::addition };
314  };
316  //**********************************************************************************************
317 
318  //**********************************************************************************************
320  template< typename MT >
322  struct VectorizedSubAssign {
323  enum { value = vectorizable && MT::vectorizable &&
324  IsSame<Type,typename MT::ElementType>::value &&
325  IntrinsicTrait<Type>::subtraction };
326  };
328  //**********************************************************************************************
329 
330  public:
331  //**Expression template evaluation functions****************************************************
334  template< typename Other > inline bool canAlias ( const Other* alias ) const;
335  template< typename Other > inline bool isAliased( const Other* alias ) const;
336 
337  inline IntrinsicType load ( size_t i, size_t j ) const;
338  inline IntrinsicType loadu ( size_t i, size_t j ) const;
339  inline void store ( size_t i, size_t j, const IntrinsicType& value );
340  inline void storeu( size_t i, size_t j, const IntrinsicType& value );
341  inline void stream( size_t i, size_t j, const IntrinsicType& value );
342 
343  template< typename MT >
344  inline typename DisableIf< VectorizedAssign<MT> >::Type
345  assign( const DenseMatrix<MT,SO>& rhs );
346 
347  template< typename MT >
348  inline typename EnableIf< VectorizedAssign<MT> >::Type
349  assign( const DenseMatrix<MT,SO>& rhs );
350 
351  template< typename MT > inline void assign( const DenseMatrix<MT,!SO>& rhs );
352  template< typename MT > inline void assign( const SparseMatrix<MT,SO>& rhs );
353  template< typename MT > inline void assign( const SparseMatrix<MT,!SO>& rhs );
354 
355  template< typename MT >
356  inline typename DisableIf< VectorizedAddAssign<MT> >::Type
357  addAssign( const DenseMatrix<MT,SO>& rhs );
358 
359  template< typename MT >
360  inline typename EnableIf< VectorizedAddAssign<MT> >::Type
361  addAssign( const DenseMatrix<MT,SO>& rhs );
362 
363  template< typename MT > inline void addAssign( const DenseMatrix<MT,!SO>& rhs );
364  template< typename MT > inline void addAssign( const SparseMatrix<MT,SO>& rhs );
365  template< typename MT > inline void addAssign( const SparseMatrix<MT,!SO>& rhs );
366 
367  template< typename MT >
368  inline typename DisableIf< VectorizedSubAssign<MT> >::Type
369  subAssign( const DenseMatrix<MT,SO>& rhs );
370 
371  template< typename MT >
372  inline typename EnableIf< VectorizedSubAssign<MT> >::Type
373  subAssign( const DenseMatrix<MT,SO>& rhs );
374 
375  template< typename MT > inline void subAssign( const DenseMatrix<MT,!SO>& rhs );
376  template< typename MT > inline void subAssign( const SparseMatrix<MT,SO>& rhs );
377  template< typename MT > inline void subAssign( const SparseMatrix<MT,!SO>& rhs );
379  //**********************************************************************************************
380 
381  private:
382  //**Utility functions***************************************************************************
385  inline size_t adjustColumns( size_t minColumns ) const;
387  //**********************************************************************************************
388 
389  //**Member variables****************************************************************************
392  size_t m_;
393  size_t n_;
394  size_t nn_;
395  size_t capacity_;
397 
407  //**********************************************************************************************
408 
409  //**Compile time checks*************************************************************************
416  //**********************************************************************************************
417 };
418 //*************************************************************************************************
419 
420 
421 
422 
423 //=================================================================================================
424 //
425 // CONSTRUCTORS
426 //
427 //=================================================================================================
428 
429 //*************************************************************************************************
432 template< typename Type // Data type of the matrix
433  , bool SO > // Storage order
435  : m_ ( 0UL ) // The current number of rows of the matrix
436  , n_ ( 0UL ) // The current number of columns of the matrix
437  , nn_ ( 0UL ) // The alignment adjusted number of columns
438  , capacity_( 0UL ) // The maximum capacity of the matrix
439  , v_ ( NULL ) // The matrix elements
440 {}
441 //*************************************************************************************************
442 
443 
444 //*************************************************************************************************
453 template< typename Type // Data type of the matrix
454  , bool SO > // Storage order
455 inline DynamicMatrix<Type,SO>::DynamicMatrix( size_t m, size_t n )
456  : m_ ( m ) // The current number of rows of the matrix
457  , n_ ( n ) // The current number of columns of the matrix
458  , nn_ ( adjustColumns( n ) ) // The alignment adjusted number of columns
459  , capacity_( m_*nn_ ) // The maximum capacity of the matrix
460  , v_ ( allocate<Type>( capacity_ ) ) // The matrix elements
461 {
462  if( IsNumeric<Type>::value ) {
463  for( size_t i=0UL; i<m_; ++i ) {
464  for( size_t j=n_; j<nn_; ++j )
465  v_[i*nn_+j] = Type();
466  }
467  }
468 }
469 //*************************************************************************************************
470 
471 
472 //*************************************************************************************************
481 template< typename Type // Data type of the matrix
482  , bool SO > // Storage order
483 inline DynamicMatrix<Type,SO>::DynamicMatrix( size_t m, size_t n, const Type& init )
484  : m_ ( m ) // The current number of rows of the matrix
485  , n_ ( n ) // The current number of columns of the matrix
486  , nn_ ( adjustColumns( n ) ) // The alignment adjusted number of columns
487  , capacity_( m_*nn_ ) // The maximum capacity of the matrix
488  , v_ ( allocate<Type>( capacity_ ) ) // The matrix elements
489 {
490  for( size_t i=0UL; i<m; ++i ) {
491  for( size_t j=0UL; j<n_; ++j )
492  v_[i*nn_+j] = init;
493 
494  if( IsNumeric<Type>::value ) {
495  for( size_t j=n_; j<nn_; ++j )
496  v_[i*nn_+j] = Type();
497  }
498  }
499 }
500 //*************************************************************************************************
501 
502 
503 //*************************************************************************************************
526 template< typename Type // Data type of the matrix
527  , bool SO > // Storage order
528 template< typename Other > // Data type of the initialization array
529 inline DynamicMatrix<Type,SO>::DynamicMatrix( size_t m, size_t n, const Other* array )
530  : m_ ( m ) // The current number of rows of the matrix
531  , n_ ( n ) // The current number of columns of the matrix
532  , nn_ ( adjustColumns( n ) ) // The alignment adjusted number of columns
533  , capacity_( m_*nn_ ) // The maximum capacity of the matrix
534  , v_ ( allocate<Type>( capacity_ ) ) // The matrix elements
535 {
536  for( size_t i=0UL; i<m; ++i ) {
537  for( size_t j=0UL; j<n; ++j )
538  v_[i*nn_+j] = array[i*n+j];
539 
540  if( IsNumeric<Type>::value ) {
541  for( size_t j=n; j<nn_; ++j )
542  v_[i*nn_+j] = Type();
543  }
544  }
545 }
546 //*************************************************************************************************
547 
548 
549 //*************************************************************************************************
570 template< typename Type // Data type of the matrix
571  , bool SO > // Storage order
572 template< typename Other // Data type of the initialization array
573  , size_t M // Number of rows of the initialization array
574  , size_t N > // Number of columns of the initialization array
575 inline DynamicMatrix<Type,SO>::DynamicMatrix( const Other (&array)[M][N] )
576  : m_ ( M ) // The current number of rows of the matrix
577  , n_ ( N ) // The current number of columns of the matrix
578  , nn_ ( adjustColumns( N ) ) // The alignment adjusted number of columns
579  , capacity_( m_*nn_ ) // The maximum capacity of the matrix
580  , v_ ( allocate<Type>( capacity_ ) ) // The matrix elements
581 {
582  for( size_t i=0UL; i<M; ++i ) {
583  for( size_t j=0UL; j<N; ++j )
584  v_[i*nn_+j] = array[i][j];
585 
586  if( IsNumeric<Type>::value ) {
587  for( size_t j=N; j<nn_; ++j )
588  v_[i*nn_+j] = Type();
589  }
590  }
591 }
592 //*************************************************************************************************
593 
594 
595 //*************************************************************************************************
603 template< typename Type // Data type of the matrix
604  , bool SO > // Storage order
606  : m_ ( m.m_ ) // The current number of rows of the matrix
607  , n_ ( m.n_ ) // The current number of columns of the matrix
608  , nn_ ( m.nn_ ) // The alignment adjusted number of columns
609  , capacity_( m_*nn_ ) // The maximum capacity of the matrix
610  , v_ ( allocate<Type>( capacity_ ) ) // The matrix elements
611 {
612  BLAZE_INTERNAL_ASSERT( capacity_ <= m.capacity_, "Invalid capacity estimation" );
613 
614  for( size_t i=0UL; i<capacity_; ++i )
615  v_[i] = m.v_[i];
616 }
617 //*************************************************************************************************
618 
619 
620 //*************************************************************************************************
625 template< typename Type // Data type of the matrix
626  , bool SO > // Storage order
627 template< typename MT // Type of the foreign matrix
628  , bool SO2 > // Storage order of the foreign matrix
630  : m_ ( (~m).rows() ) // The current number of rows of the matrix
631  , n_ ( (~m).columns() ) // The current number of columns of the matrix
632  , nn_ ( adjustColumns( n_ ) ) // The alignment adjusted number of columns
633  , capacity_( m_*nn_ ) // The maximum capacity of the matrix
634  , v_ ( allocate<Type>( capacity_ ) ) // The matrix elements
635 {
636  using blaze::assign;
637 
638  if( IsNumeric<Type>::value ) {
639  for( size_t i=0UL; i<m_; ++i ) {
640  for( size_t j=( IsSparseMatrix<MT>::value )?( 0UL ):( n_ ); j<nn_; ++j )
641  v_[i*nn_+j] = Type();
642  }
643  }
644 
645  assign( *this, ~m );
646 }
647 //*************************************************************************************************
648 
649 
650 
651 
652 //=================================================================================================
653 //
654 // DESTRUCTOR
655 //
656 //=================================================================================================
657 
658 //*************************************************************************************************
661 template< typename Type // Data type of the matrix
662  , bool SO > // Storage order
664 {
665  deallocate( v_ );
666 }
667 //*************************************************************************************************
668 
669 
670 
671 
672 //=================================================================================================
673 //
674 // DATA ACCESS FUNCTIONS
675 //
676 //=================================================================================================
677 
678 //*************************************************************************************************
685 template< typename Type // Data type of the matrix
686  , bool SO > // Storage order
687 inline typename DynamicMatrix<Type,SO>::Reference
689 {
690  BLAZE_USER_ASSERT( i<m_, "Invalid row access index" );
691  BLAZE_USER_ASSERT( j<n_, "Invalid column access index" );
692  return v_[i*nn_+j];
693 }
694 //*************************************************************************************************
695 
696 
697 //*************************************************************************************************
704 template< typename Type // Data type of the matrix
705  , bool SO > // Storage order
707  DynamicMatrix<Type,SO>::operator()( size_t i, size_t j ) const
708 {
709  BLAZE_USER_ASSERT( i<m_, "Invalid row access index" );
710  BLAZE_USER_ASSERT( j<n_, "Invalid column access index" );
711  return v_[i*nn_+j];
712 }
713 //*************************************************************************************************
714 
715 
716 //*************************************************************************************************
725 template< typename Type // Data type of the matrix
726  , bool SO > // Storage order
728 {
729  return v_;
730 }
731 //*************************************************************************************************
732 
733 
734 //*************************************************************************************************
743 template< typename Type // Data type of the matrix
744  , bool SO > // Storage order
745 inline const Type* DynamicMatrix<Type,SO>::data() const
746 {
747  return v_;
748 }
749 //*************************************************************************************************
750 
751 
752 //*************************************************************************************************
760 template< typename Type // Data type of the matrix
761  , bool SO > // Storage order
762 inline Type* DynamicMatrix<Type,SO>::data( size_t i )
763 {
764  BLAZE_USER_ASSERT( i < m_, "Invalid dense matrix row access index" );
765  return v_ + i*nn_;
766 }
767 //*************************************************************************************************
768 
769 
770 //*************************************************************************************************
778 template< typename Type // Data type of the matrix
779  , bool SO > // Storage order
780 inline const Type* DynamicMatrix<Type,SO>::data( size_t i ) const
781 {
782  BLAZE_USER_ASSERT( i < m_, "Invalid dense matrix row access index" );
783  return v_ + i*nn_;
784 }
785 //*************************************************************************************************
786 
787 
788 //*************************************************************************************************
799 template< typename Type // Data type of the matrix
800  , bool SO > // Storage order
801 inline typename DynamicMatrix<Type,SO>::Iterator
803 {
804  BLAZE_USER_ASSERT( i < m_, "Invalid dense matrix row access index" );
805  return Iterator( v_ + i*nn_ );
806 }
807 //*************************************************************************************************
808 
809 
810 //*************************************************************************************************
821 template< typename Type // Data type of the matrix
822  , bool SO > // Storage order
825 {
826  BLAZE_USER_ASSERT( i < m_, "Invalid dense matrix row access index" );
827  return ConstIterator( v_ + i*nn_ );
828 }
829 //*************************************************************************************************
830 
831 
832 //*************************************************************************************************
843 template< typename Type // Data type of the matrix
844  , bool SO > // Storage order
847 {
848  BLAZE_USER_ASSERT( i < m_, "Invalid dense matrix row access index" );
849  return ConstIterator( v_ + i*nn_ );
850 }
851 //*************************************************************************************************
852 
853 
854 //*************************************************************************************************
865 template< typename Type // Data type of the matrix
866  , bool SO > // Storage order
867 inline typename DynamicMatrix<Type,SO>::Iterator
869 {
870  BLAZE_USER_ASSERT( i < m_, "Invalid dense matrix row access index" );
871  return Iterator( v_ + i*nn_ + n_ );
872 }
873 //*************************************************************************************************
874 
875 
876 //*************************************************************************************************
887 template< typename Type // Data type of the matrix
888  , bool SO > // Storage order
890  DynamicMatrix<Type,SO>::end( size_t i ) const
891 {
892  BLAZE_USER_ASSERT( i < m_, "Invalid dense matrix row access index" );
893  return ConstIterator( v_ + i*nn_ + n_ );
894 }
895 //*************************************************************************************************
896 
897 
898 //*************************************************************************************************
909 template< typename Type // Data type of the matrix
910  , bool SO > // Storage order
913 {
914  BLAZE_USER_ASSERT( i < m_, "Invalid dense matrix row access index" );
915  return ConstIterator( v_ + i*nn_ + n_ );
916 }
917 //*************************************************************************************************
918 
919 
920 
921 
922 //=================================================================================================
923 //
924 // ASSIGNMENT OPERATORS
925 //
926 //=================================================================================================
927 
928 //*************************************************************************************************
949 template< typename Type // Data type of the matrix
950  , bool SO > // Storage order
951 template< typename Other // Data type of the initialization array
952  , size_t M // Number of rows of the initialization array
953  , size_t N > // Number of columns of the initialization array
954 inline DynamicMatrix<Type,SO>& DynamicMatrix<Type,SO>::operator=( const Other (&array)[M][N] )
955 {
956  resize( M, N, false );
957 
958  for( size_t i=0UL; i<M; ++i )
959  for( size_t j=0UL; j<N; ++j )
960  v_[i*nn_+j] = array[i][j];
961 
962  return *this;
963 }
964 //*************************************************************************************************
965 
966 
967 //*************************************************************************************************
973 template< typename Type // Data type of the matrix
974  , bool SO > // Storage order
976 {
977  for( size_t i=0UL; i<m_; ++i )
978  for( size_t j=0UL; j<n_; ++j )
979  v_[i*nn_+j] = rhs;
980 
981  return *this;
982 }
983 //*************************************************************************************************
984 
985 
986 //*************************************************************************************************
995 template< typename Type // Data type of the matrix
996  , bool SO > // Storage order
998 {
999  if( &rhs == this ) return *this;
1000 
1001  resize( rhs.m_, rhs.n_, false );
1002 
1003  for( size_t i=0UL; i<m_; ++i )
1004  for( size_t j=0UL; j<n_; ++j )
1005  v_[i*nn_+j] = rhs(i,j);
1006 
1007  return *this;
1008 }
1009 //*************************************************************************************************
1010 
1011 
1012 //*************************************************************************************************
1021 template< typename Type // Data type of the matrix
1022  , bool SO > // Storage order
1023 template< typename MT // Type of the right-hand side matrix
1024  , bool SO2 > // Storage order of the right-hand side matrix
1026 {
1027  using blaze::assign;
1028 
1029  if( (~rhs).canAlias( this ) ) {
1030  DynamicMatrix tmp( ~rhs );
1031  swap( tmp );
1032  }
1033  else {
1034  resize( (~rhs).rows(), (~rhs).columns(), false );
1036  reset();
1037  assign( *this, ~rhs );
1038  }
1039 
1040  return *this;
1041 }
1042 //*************************************************************************************************
1043 
1044 
1045 //*************************************************************************************************
1055 template< typename Type // Data type of the matrix
1056  , bool SO > // Storage order
1057 template< typename MT // Type of the right-hand side matrix
1058  , bool SO2 > // Storage order of the right-hand side matrix
1060 {
1061  using blaze::addAssign;
1062 
1063  if( (~rhs).rows() != m_ || (~rhs).columns() != n_ )
1064  throw std::invalid_argument( "Matrix sizes do not match" );
1065 
1066  if( (~rhs).canAlias( this ) ) {
1067  typename MT::ResultType tmp( ~rhs );
1068  addAssign( *this, tmp );
1069  }
1070  else {
1071  addAssign( *this, ~rhs );
1072  }
1073 
1074  return *this;
1075 }
1076 //*************************************************************************************************
1077 
1078 
1079 //*************************************************************************************************
1089 template< typename Type // Data type of the matrix
1090  , bool SO > // Storage order
1091 template< typename MT // Type of the right-hand side matrix
1092  , bool SO2 > // Storage order of the right-hand side matrix
1094 {
1095  using blaze::subAssign;
1096 
1097  if( (~rhs).rows() != m_ || (~rhs).columns() != n_ )
1098  throw std::invalid_argument( "Matrix sizes do not match" );
1099 
1100  if( (~rhs).canAlias( this ) ) {
1101  typename MT::ResultType tmp( ~rhs );
1102  subAssign( *this, tmp );
1103  }
1104  else {
1105  subAssign( *this, ~rhs );
1106  }
1107 
1108  return *this;
1109 }
1110 //*************************************************************************************************
1111 
1112 
1113 //*************************************************************************************************
1123 template< typename Type // Data type of the matrix
1124  , bool SO > // Storage order
1125 template< typename MT // Type of the right-hand side matrix
1126  , bool SO2 > // Storage order of the right-hand side matrix
1128 {
1129  if( (~rhs).rows() != n_ )
1130  throw std::invalid_argument( "Matrix sizes do not match" );
1131 
1132  DynamicMatrix tmp( *this * (~rhs) );
1133  swap( tmp );
1134 
1135  return *this;
1136 }
1137 //*************************************************************************************************
1138 
1139 
1140 //*************************************************************************************************
1147 template< typename Type // Data type of the matrix
1148  , bool SO > // Storage order
1149 template< typename Other > // Data type of the right-hand side scalar
1150 inline typename EnableIf< IsNumeric<Other>, DynamicMatrix<Type,SO> >::Type&
1152 {
1153  using blaze::assign;
1154 
1155  assign( *this, (*this) * rhs );
1156  return *this;
1157 }
1158 //*************************************************************************************************
1159 
1160 
1161 //*************************************************************************************************
1168 template< typename Type // Data type of the matrix
1169  , bool SO > // Storage order
1170 template< typename Other > // Data type of the right-hand side scalar
1171 inline typename EnableIf< IsNumeric<Other>, DynamicMatrix<Type,SO> >::Type&
1173 {
1174  using blaze::assign;
1175 
1176  BLAZE_USER_ASSERT( rhs != Other(0), "Division by zero detected" );
1177 
1178  assign( *this, (*this) / rhs );
1179  return *this;
1180 }
1181 //*************************************************************************************************
1182 
1183 
1184 
1185 
1186 //=================================================================================================
1187 //
1188 // UTILITY FUNCTIONS
1189 //
1190 //=================================================================================================
1191 
1192 //*************************************************************************************************
1197 template< typename Type // Data type of the matrix
1198  , bool SO > // Storage order
1199 inline size_t DynamicMatrix<Type,SO>::rows() const
1200 {
1201  return m_;
1202 }
1203 //*************************************************************************************************
1204 
1205 
1206 //*************************************************************************************************
1211 template< typename Type // Data type of the matrix
1212  , bool SO > // Storage order
1213 inline size_t DynamicMatrix<Type,SO>::columns() const
1214 {
1215  return n_;
1216 }
1217 //*************************************************************************************************
1218 
1219 
1220 //*************************************************************************************************
1230 template< typename Type // Data type of the matrix
1231  , bool SO > // Storage order
1232 inline size_t DynamicMatrix<Type,SO>::spacing() const
1233 {
1234  return nn_;
1235 }
1236 //*************************************************************************************************
1237 
1238 
1239 //*************************************************************************************************
1244 template< typename Type // Data type of the matrix
1245  , bool SO > // Storage order
1247 {
1248  return capacity_;
1249 }
1250 //*************************************************************************************************
1251 
1252 
1253 //*************************************************************************************************
1264 template< typename Type // Data type of the sparse matrix
1265  , bool SO > // Storage order
1266 inline size_t DynamicMatrix<Type,SO>::capacity( size_t i ) const
1267 {
1268  UNUSED_PARAMETER( i );
1269  BLAZE_USER_ASSERT( i < rows(), "Invalid row access index" );
1270  return nn_;
1271 }
1272 //*************************************************************************************************
1273 
1274 
1275 //*************************************************************************************************
1280 template< typename Type // Data type of the matrix
1281  , bool SO > // Storage order
1283 {
1284  size_t nonzeros( 0UL );
1285 
1286  for( size_t i=0UL; i<m_; ++i )
1287  for( size_t j=0UL; j<n_; ++j )
1288  if( !isDefault( v_[i*nn_+j] ) )
1289  ++nonzeros;
1290 
1291  return nonzeros;
1292 }
1293 //*************************************************************************************************
1294 
1295 
1296 //*************************************************************************************************
1302 template< typename Type // Data type of the matrix
1303  , bool SO > // Storage order
1304 inline size_t DynamicMatrix<Type,SO>::nonZeros( size_t i ) const
1305 {
1306  BLAZE_USER_ASSERT( i < rows(), "Invalid row access index" );
1307 
1308  const size_t jend( (i+1UL)*nn_ );
1309  size_t nonzeros( 0UL );
1310 
1311  for( size_t j=i*nn_; j<jend; ++j )
1312  if( !isDefault( v_[j] ) )
1313  ++nonzeros;
1314 
1315  return nonzeros;
1316 }
1317 //*************************************************************************************************
1318 
1319 
1320 //*************************************************************************************************
1325 template< typename Type // Data type of the matrix
1326  , bool SO > // Storage order
1328 {
1329  using blaze::reset;
1330 
1331  for( size_t i=0UL; i<m_; ++i )
1332  for( size_t j=0UL; j<n_; ++j )
1333  reset( v_[i*nn_+j] );
1334 }
1335 //*************************************************************************************************
1336 
1337 
1338 //*************************************************************************************************
1349 template< typename Type // Data type of the sparse matrix
1350  , bool SO > // Storage order
1351 inline void DynamicMatrix<Type,SO>::reset( size_t i )
1352 {
1353  using blaze::reset;
1354 
1355  BLAZE_USER_ASSERT( i < rows(), "Invalid row access index" );
1356  for( size_t j=0UL; j<n_; ++j )
1357  reset( v_[i*nn_+j] );
1358 }
1359 //*************************************************************************************************
1360 
1361 
1362 //*************************************************************************************************
1369 template< typename Type // Data type of the matrix
1370  , bool SO > // Storage order
1372 {
1373  resize( 0UL, 0UL, false );
1374 }
1375 //*************************************************************************************************
1376 
1377 
1378 //*************************************************************************************************
1411 template< typename Type // Data type of the matrix
1412  , bool SO > // Storage order
1413 void DynamicMatrix<Type,SO>::resize( size_t m, size_t n, bool preserve )
1414 {
1415  using blaze::min;
1416 
1417  if( m == m_ && n == n_ ) return;
1418 
1419  const size_t nn( adjustColumns( n ) );
1420 
1421  if( preserve )
1422  {
1423  Type* BLAZE_RESTRICT v = allocate<Type>( m*nn );
1424  const size_t min_m( min( m, m_ ) );
1425  const size_t min_n( min( n, n_ ) );
1426 
1427  for( size_t i=0UL; i<min_m; ++i )
1428  for( size_t j=0UL; j<min_n; ++j )
1429  v[i*nn+j] = v_[i*nn_+j];
1430 
1431  std::swap( v_, v );
1432  deallocate( v );
1433  capacity_ = m*nn;
1434  }
1435  else if( m*nn > capacity_ ) {
1436  Type* BLAZE_RESTRICT v = allocate<Type>( m*nn );
1437  std::swap( v_, v );
1438  deallocate( v );
1439  capacity_ = m*nn;
1440  }
1441 
1442  if( IsNumeric<Type>::value ) {
1443  for( size_t i=0UL; i<m; ++i )
1444  for( size_t j=n; j<nn; ++j )
1445  v_[i*nn+j] = Type();
1446  }
1447 
1448  m_ = m;
1449  n_ = n;
1450  nn_ = nn;
1451 }
1452 //*************************************************************************************************
1453 
1454 
1455 //*************************************************************************************************
1469 template< typename Type // Data type of the matrix
1470  , bool SO > // Storage order
1471 inline void DynamicMatrix<Type,SO>::extend( size_t m, size_t n, bool preserve )
1472 {
1473  resize( m_+m, n_+n, preserve );
1474 }
1475 //*************************************************************************************************
1476 
1477 
1478 //*************************************************************************************************
1487 template< typename Type // Data type of the matrix
1488  , bool SO > // Storage order
1489 inline void DynamicMatrix<Type,SO>::reserve( size_t elements )
1490 {
1491  if( elements > capacity_ )
1492  {
1493  // Allocating a new array
1494  Type* BLAZE_RESTRICT tmp = allocate<Type>( elements );
1495 
1496  // Initializing the new array
1497  std::copy( v_, v_+capacity_, tmp );
1498 
1499  if( IsNumeric<Type>::value ) {
1500  for( size_t i=capacity_; i<elements; ++i )
1501  tmp[i] = Type();
1502  }
1503 
1504  // Replacing the old array
1505  std::swap( tmp, v_ );
1506  deallocate( tmp );
1507  capacity_ = elements;
1508  }
1509 }
1510 //*************************************************************************************************
1511 
1512 
1513 //*************************************************************************************************
1518 template< typename Type // Data type of the matrix
1519  , bool SO > // Storage order
1521 {
1522  DynamicMatrix tmp( trans(*this) );
1523  swap( tmp );
1524  return *this;
1525 }
1526 //*************************************************************************************************
1527 
1528 
1529 //*************************************************************************************************
1535 template< typename Type // Data type of the matrix
1536  , bool SO > // Storage order
1537 template< typename Other > // Data type of the scalar value
1539 {
1540  for( size_t i=0UL; i<m_; ++i )
1541  for( size_t j=0UL; j<n_; ++j )
1542  v_[i*nn_+j] *= scalar;
1543 
1544  return *this;
1545 }
1546 //*************************************************************************************************
1547 
1548 
1549 //*************************************************************************************************
1556 template< typename Type // Data type of the matrix
1557  , bool SO > // Storage order
1558 inline void DynamicMatrix<Type,SO>::swap( DynamicMatrix& m ) /* throw() */
1559 {
1560  std::swap( m_ , m.m_ );
1561  std::swap( n_ , m.n_ );
1562  std::swap( nn_, m.nn_ );
1564  std::swap( v_ , m.v_ );
1565 }
1566 //*************************************************************************************************
1567 
1568 
1569 //*************************************************************************************************
1575 template< typename Type // Data type of the matrix
1576  , bool SO > // Storage order
1577 inline size_t DynamicMatrix<Type,SO>::adjustColumns( size_t minColumns ) const
1578 {
1580  return minColumns + ( IT::size - ( minColumns % IT::size ) ) % IT::size;
1581  else return minColumns;
1582 }
1583 //*************************************************************************************************
1584 
1585 
1586 
1587 
1588 //=================================================================================================
1589 //
1590 // EXPRESSION TEMPLATE EVALUATION FUNCTIONS
1591 //
1592 //=================================================================================================
1593 
1594 //*************************************************************************************************
1604 template< typename Type // Data type of the matrix
1605  , bool SO > // Storage order
1606 template< typename Other > // Data type of the foreign expression
1607 inline bool DynamicMatrix<Type,SO>::canAlias( const Other* alias ) const
1608 {
1609  return static_cast<const void*>( this ) == static_cast<const void*>( alias );
1610 }
1611 //*************************************************************************************************
1612 
1613 
1614 //*************************************************************************************************
1624 template< typename Type // Data type of the matrix
1625  , bool SO > // Storage order
1626 template< typename Other > // Data type of the foreign expression
1627 inline bool DynamicMatrix<Type,SO>::isAliased( const Other* alias ) const
1628 {
1629  return static_cast<const void*>( this ) == static_cast<const void*>( alias );
1630 }
1631 //*************************************************************************************************
1632 
1633 
1634 //*************************************************************************************************
1649 template< typename Type // Data type of the matrix
1650  , bool SO > // Storage order
1652  DynamicMatrix<Type,SO>::load( size_t i, size_t j ) const
1653 {
1654  using blaze::load;
1655 
1657 
1658  BLAZE_INTERNAL_ASSERT( i < m_ , "Invalid row access index" );
1659  BLAZE_INTERNAL_ASSERT( j < n_ , "Invalid column access index" );
1660  BLAZE_INTERNAL_ASSERT( j + IT::size <= nn_, "Invalid column access index" );
1661  BLAZE_INTERNAL_ASSERT( j % IT::size == 0UL, "Invalid column access index" );
1662 
1663  return load( v_+i*nn_+j );
1664 }
1665 //*************************************************************************************************
1666 
1667 
1668 //*************************************************************************************************
1683 template< typename Type // Data type of the matrix
1684  , bool SO > // Storage order
1686  DynamicMatrix<Type,SO>::loadu( size_t i, size_t j ) const
1687 {
1688  using blaze::loadu;
1689 
1691 
1692  BLAZE_INTERNAL_ASSERT( i < m_ , "Invalid row access index" );
1693  BLAZE_INTERNAL_ASSERT( j < n_ , "Invalid column access index" );
1694  BLAZE_INTERNAL_ASSERT( j + IT::size <= nn_, "Invalid column access index" );
1695 
1696  return loadu( v_+i*nn_+j );
1697 }
1698 //*************************************************************************************************
1699 
1700 
1701 //*************************************************************************************************
1717 template< typename Type // Data type of the matrix
1718  , bool SO > // Storage order
1719 inline void DynamicMatrix<Type,SO>::store( size_t i, size_t j, const IntrinsicType& value )
1720 {
1721  using blaze::store;
1722 
1724 
1725  BLAZE_INTERNAL_ASSERT( i < m_ , "Invalid row access index" );
1726  BLAZE_INTERNAL_ASSERT( j < n_ , "Invalid column access index" );
1727  BLAZE_INTERNAL_ASSERT( j + IT::size <= nn_, "Invalid column access index" );
1728  BLAZE_INTERNAL_ASSERT( j % IT::size == 0UL, "Invalid column access index" );
1729 
1730  store( v_+i*nn_+j, value );
1731 }
1732 //*************************************************************************************************
1733 
1734 
1735 //*************************************************************************************************
1751 template< typename Type // Data type of the matrix
1752  , bool SO > // Storage order
1753 inline void DynamicMatrix<Type,SO>::storeu( size_t i, size_t j, const IntrinsicType& value )
1754 {
1755  using blaze::storeu;
1756 
1758 
1759  BLAZE_INTERNAL_ASSERT( i < m_ , "Invalid row access index" );
1760  BLAZE_INTERNAL_ASSERT( j < n_ , "Invalid column access index" );
1761  BLAZE_INTERNAL_ASSERT( j + IT::size <= nn_, "Invalid column access index" );
1762 
1763  storeu( v_+i*nn_+j, value );
1764 }
1765 //*************************************************************************************************
1766 
1767 
1768 //*************************************************************************************************
1784 template< typename Type // Data type of the matrix
1785  , bool SO > // Storage order
1786 inline void DynamicMatrix<Type,SO>::stream( size_t i, size_t j, const IntrinsicType& value )
1787 {
1788  using blaze::stream;
1789 
1791 
1792  BLAZE_INTERNAL_ASSERT( i < m_ , "Invalid row access index" );
1793  BLAZE_INTERNAL_ASSERT( j < n_ , "Invalid column access index" );
1794  BLAZE_INTERNAL_ASSERT( j + IT::size <= nn_, "Invalid column access index" );
1795  BLAZE_INTERNAL_ASSERT( j % IT::size == 0UL, "Invalid column access index" );
1796 
1797  stream( v_+i*nn_+j, value );
1798 }
1799 //*************************************************************************************************
1800 
1801 
1802 //*************************************************************************************************
1813 template< typename Type // Data type of the matrix
1814  , bool SO > // Storage order
1815 template< typename MT > // Type of the right-hand side dense matrix
1816 inline typename DisableIf< typename DynamicMatrix<Type,SO>::BLAZE_TEMPLATE VectorizedAssign<MT> >::Type
1818 {
1819  BLAZE_INTERNAL_ASSERT( m_ == (~rhs).rows() , "Invalid number of rows" );
1820  BLAZE_INTERNAL_ASSERT( n_ == (~rhs).columns(), "Invalid number of columns" );
1821 
1822  const size_t jend( n_ & size_t(-2) );
1823  BLAZE_INTERNAL_ASSERT( ( n_ - ( n_ % 2UL ) ) == jend, "Invalid end calculation" );
1824 
1825  for( size_t i=0UL; i<m_; ++i ) {
1826  for( size_t j=0UL; j<jend; j+=2UL ) {
1827  v_[i*nn_+j ] = (~rhs)(i,j );
1828  v_[i*nn_+j+1UL] = (~rhs)(i,j+1UL);
1829  }
1830  if( jend < n_ ) {
1831  v_[i*nn_+jend] = (~rhs)(i,jend);
1832  }
1833  }
1834 }
1835 //*************************************************************************************************
1836 
1837 
1838 //*************************************************************************************************
1849 template< typename Type // Data type of the matrix
1850  , bool SO > // Storage order
1851 template< typename MT > // Type of the right-hand side dense matrix
1852 inline typename EnableIf< typename DynamicMatrix<Type,SO>::BLAZE_TEMPLATE VectorizedAssign<MT> >::Type
1854 {
1855  using blaze::store;
1856  using blaze::stream;
1857 
1858  BLAZE_INTERNAL_ASSERT( m_ == (~rhs).rows() , "Invalid number of rows" );
1859  BLAZE_INTERNAL_ASSERT( n_ == (~rhs).columns(), "Invalid number of columns" );
1860 
1862 
1863  if( useStreaming && m_*n_ > ( cacheSize / ( sizeof(Type) * 3UL ) ) && !(~rhs).isAliased( this ) )
1864  {
1865  for( size_t i=0UL; i<m_; ++i )
1866  for( size_t j=0UL; j<n_; j+=IT::size )
1867  stream( v_+i*nn_+j, (~rhs).load(i,j) );
1868  }
1869  else
1870  {
1871  const size_t jend( n_ & size_t(-IT::size*4) );
1872  BLAZE_INTERNAL_ASSERT( ( n_ - ( n_ % (IT::size*4UL) ) ) == jend, "Invalid end calculation" );
1873 
1874  for( size_t i=0UL; i<m_; ++i ) {
1875  typename MT::ConstIterator it( (~rhs).begin(i) );
1876  for( size_t j=0UL; j<jend; j+=IT::size*4UL ) {
1877  store( v_+i*nn_+j , it.load() ); it += IT::size;
1878  store( v_+i*nn_+j+IT::size , it.load() ); it += IT::size;
1879  store( v_+i*nn_+j+IT::size*2UL, it.load() ); it += IT::size;
1880  store( v_+i*nn_+j+IT::size*3UL, it.load() ); it += IT::size;
1881  }
1882  for( size_t j=jend; j<n_; j+=IT::size, it+=IT::size ) {
1883  store( v_+i*nn_+j, it.load() );
1884  }
1885  }
1886  }
1887 }
1888 //*************************************************************************************************
1889 
1890 
1891 //*************************************************************************************************
1902 template< typename Type // Data type of the matrix
1903  , bool SO > // Storage order
1904 template< typename MT > // Type of the right-hand side dense matrix
1906 {
1907  BLAZE_INTERNAL_ASSERT( m_ == (~rhs).rows() , "Invalid number of rows" );
1908  BLAZE_INTERNAL_ASSERT( n_ == (~rhs).columns(), "Invalid number of columns" );
1909 
1910  const size_t block( 16UL );
1911 
1912  for( size_t ii=0UL; ii<m_; ii+=block ) {
1913  const size_t iend( ( m_<(ii+block) )?( m_ ):( ii+block ) );
1914  for( size_t jj=0UL; jj<n_; jj+=block ) {
1915  const size_t jend( ( n_<(jj+block) )?( n_ ):( jj+block ) );
1916  for( size_t i=ii; i<iend; ++i ) {
1917  for( size_t j=jj; j<jend; ++j ) {
1918  v_[i*nn_+j] = (~rhs)(i,j);
1919  }
1920  }
1921  }
1922  }
1923 }
1924 //*************************************************************************************************
1925 
1926 
1927 //*************************************************************************************************
1938 template< typename Type // Data type of the matrix
1939  , bool SO > // Storage order
1940 template< typename MT > // Type of the right-hand side sparse matrix
1942 {
1943  BLAZE_INTERNAL_ASSERT( m_ == (~rhs).rows() , "Invalid number of rows" );
1944  BLAZE_INTERNAL_ASSERT( n_ == (~rhs).columns(), "Invalid number of columns" );
1945 
1946  for( size_t i=0UL; i<m_; ++i )
1947  for( typename MT::ConstIterator element=(~rhs).begin(i); element!=(~rhs).end(i); ++element )
1948  v_[i*nn_+element->index()] = element->value();
1949 }
1950 //*************************************************************************************************
1951 
1952 
1953 //*************************************************************************************************
1964 template< typename Type // Data type of the matrix
1965  , bool SO > // Storage order
1966 template< typename MT > // Type of the right-hand side sparse matrix
1968 {
1969  BLAZE_INTERNAL_ASSERT( m_ == (~rhs).rows() , "Invalid number of rows" );
1970  BLAZE_INTERNAL_ASSERT( n_ == (~rhs).columns(), "Invalid number of columns" );
1971 
1972  for( size_t j=0UL; j<n_; ++j )
1973  for( typename MT::ConstIterator element=(~rhs).begin(j); element!=(~rhs).end(j); ++element )
1974  v_[element->index()*nn_+j] = element->value();
1975 }
1976 //*************************************************************************************************
1977 
1978 
1979 //*************************************************************************************************
1990 template< typename Type // Data type of the matrix
1991  , bool SO > // Storage order
1992 template< typename MT > // Type of the right-hand side dense matrix
1993 inline typename DisableIf< typename DynamicMatrix<Type,SO>::BLAZE_TEMPLATE VectorizedAddAssign<MT> >::Type
1995 {
1996  BLAZE_INTERNAL_ASSERT( m_ == (~rhs).rows() , "Invalid number of rows" );
1997  BLAZE_INTERNAL_ASSERT( n_ == (~rhs).columns(), "Invalid number of columns" );
1998 
1999  const size_t jend( n_ & size_t(-2) );
2000  BLAZE_INTERNAL_ASSERT( ( n_ - ( n_ % 2UL ) ) == jend, "Invalid end calculation" );
2001 
2002  for( size_t i=0UL; i<m_; ++i ) {
2003  for( size_t j=0UL; j<jend; j+=2UL ) {
2004  v_[i*nn_+j ] += (~rhs)(i,j );
2005  v_[i*nn_+j+1UL] += (~rhs)(i,j+1UL);
2006  }
2007  if( jend < n_ ) {
2008  v_[i*nn_+jend] += (~rhs)(i,jend);
2009  }
2010  }
2011 }
2012 //*************************************************************************************************
2013 
2014 
2015 //*************************************************************************************************
2026 template< typename Type // Data type of the matrix
2027  , bool SO > // Storage order
2028 template< typename MT > // Type of the right-hand side dense matrix
2029 inline typename EnableIf< typename DynamicMatrix<Type,SO>::BLAZE_TEMPLATE VectorizedAddAssign<MT> >::Type
2031 {
2032  using blaze::load;
2033  using blaze::store;
2034 
2035  BLAZE_INTERNAL_ASSERT( m_ == (~rhs).rows() , "Invalid number of rows" );
2036  BLAZE_INTERNAL_ASSERT( n_ == (~rhs).columns(), "Invalid number of columns" );
2037 
2039 
2040  const size_t jend( n_ & size_t(-IT::size*4) );
2041  BLAZE_INTERNAL_ASSERT( ( n_ - ( n_ % (IT::size*4UL) ) ) == jend, "Invalid end calculation" );
2042 
2043  for( size_t i=0UL; i<m_; ++i ) {
2044  typename MT::ConstIterator it( (~rhs).begin(i) );
2045  for( size_t j=0UL; j<jend; j+=IT::size*4UL ) {
2046  store( v_+i*nn_+j , load( v_+i*nn_+j ) + it.load() ); it += IT::size;
2047  store( v_+i*nn_+j+IT::size , load( v_+i*nn_+j+IT::size ) + it.load() ); it += IT::size;
2048  store( v_+i*nn_+j+IT::size*2UL, load( v_+i*nn_+j+IT::size*2UL ) + it.load() ); it += IT::size;
2049  store( v_+i*nn_+j+IT::size*3UL, load( v_+i*nn_+j+IT::size*3UL ) + it.load() ); it += IT::size;
2050  }
2051  for( size_t j=jend; j<n_; j+=IT::size, it+=IT::size ) {
2052  store( v_+i*nn_+j, load( v_+i*nn_+j ) + it.load() );
2053  }
2054  }
2055 }
2056 //*************************************************************************************************
2057 
2058 
2059 //*************************************************************************************************
2070 template< typename Type // Data type of the matrix
2071  , bool SO > // Storage order
2072 template< typename MT > // Type of the right-hand side dense matrix
2074 {
2075  BLAZE_INTERNAL_ASSERT( m_ == (~rhs).rows() , "Invalid number of rows" );
2076  BLAZE_INTERNAL_ASSERT( n_ == (~rhs).columns(), "Invalid number of columns" );
2077 
2078  const size_t block( 16UL );
2079 
2080  for( size_t ii=0UL; ii<m_; ii+=block ) {
2081  const size_t iend( ( m_<(ii+block) )?( m_ ):( ii+block ) );
2082  for( size_t jj=0UL; jj<n_; jj+=block ) {
2083  const size_t jend( ( n_<(jj+block) )?( n_ ):( jj+block ) );
2084  for( size_t i=ii; i<iend; ++i ) {
2085  for( size_t j=jj; j<jend; ++j ) {
2086  v_[i*nn_+j] += (~rhs)(i,j);
2087  }
2088  }
2089  }
2090  }
2091 }
2092 //*************************************************************************************************
2093 
2094 
2095 //*************************************************************************************************
2106 template< typename Type // Data type of the matrix
2107  , bool SO > // Storage order
2108 template< typename MT > // Type of the right-hand side sparse matrix
2110 {
2111  BLAZE_INTERNAL_ASSERT( m_ == (~rhs).rows() , "Invalid number of rows" );
2112  BLAZE_INTERNAL_ASSERT( n_ == (~rhs).columns(), "Invalid number of columns" );
2113 
2114  for( size_t i=0UL; i<m_; ++i )
2115  for( typename MT::ConstIterator element=(~rhs).begin(i); element!=(~rhs).end(i); ++element )
2116  v_[i*nn_+element->index()] += element->value();
2117 }
2118 //*************************************************************************************************
2119 
2120 
2121 //*************************************************************************************************
2132 template< typename Type // Data type of the matrix
2133  , bool SO > // Storage order
2134 template< typename MT > // Type of the right-hand side sparse matrix
2136 {
2137  BLAZE_INTERNAL_ASSERT( m_ == (~rhs).rows() , "Invalid number of rows" );
2138  BLAZE_INTERNAL_ASSERT( n_ == (~rhs).columns(), "Invalid number of columns" );
2139 
2140  for( size_t j=0UL; j<n_; ++j )
2141  for( typename MT::ConstIterator element=(~rhs).begin(j); element!=(~rhs).end(j); ++element )
2142  v_[element->index()*nn_+j] += element->value();
2143 }
2144 //*************************************************************************************************
2145 
2146 
2147 //*************************************************************************************************
2158 template< typename Type // Data type of the matrix
2159  , bool SO > // Storage order
2160 template< typename MT > // Type of the right-hand side dense matrix
2161 inline typename DisableIf< typename DynamicMatrix<Type,SO>::BLAZE_TEMPLATE VectorizedSubAssign<MT> >::Type
2163 {
2164  BLAZE_INTERNAL_ASSERT( m_ == (~rhs).rows() , "Invalid number of rows" );
2165  BLAZE_INTERNAL_ASSERT( n_ == (~rhs).columns(), "Invalid number of columns" );
2166 
2167  const size_t jend( n_ & size_t(-2) );
2168  BLAZE_INTERNAL_ASSERT( ( n_ - ( n_ % 2UL ) ) == jend, "Invalid end calculation" );
2169 
2170  for( size_t i=0UL; i<m_; ++i ) {
2171  for( size_t j=0UL; j<jend; j+=2UL ) {
2172  v_[i*nn_+j ] -= (~rhs)(i,j );
2173  v_[i*nn_+j+1UL] -= (~rhs)(i,j+1UL);
2174  }
2175  if( jend < n_ ) {
2176  v_[i*nn_+jend] -= (~rhs)(i,jend);
2177  }
2178  }
2179 }
2180 //*************************************************************************************************
2181 
2182 
2183 //*************************************************************************************************
2194 template< typename Type // Data type of the matrix
2195  , bool SO > // Storage order
2196 template< typename MT > // Type of the right-hand side dense matrix
2197 inline typename EnableIf< typename DynamicMatrix<Type,SO>::BLAZE_TEMPLATE VectorizedSubAssign<MT> >::Type
2199 {
2200  using blaze::load;
2201  using blaze::store;
2202 
2203  BLAZE_INTERNAL_ASSERT( m_ == (~rhs).rows() , "Invalid number of rows" );
2204  BLAZE_INTERNAL_ASSERT( n_ == (~rhs).columns(), "Invalid number of columns" );
2205 
2207 
2208  const size_t jend( n_ & size_t(-IT::size*4) );
2209  BLAZE_INTERNAL_ASSERT( ( n_ - ( n_ % (IT::size*4UL) ) ) == jend, "Invalid end calculation" );
2210 
2211  for( size_t i=0UL; i<m_; ++i ) {
2212  typename MT::ConstIterator it( (~rhs).begin(i) );
2213  for( size_t j=0UL; j<jend; j+=IT::size*4UL ) {
2214  store( v_+i*nn_+j , load( v_+i*nn_+j ) - it.load() ); it += IT::size;
2215  store( v_+i*nn_+j+IT::size , load( v_+i*nn_+j+IT::size ) - it.load() ); it += IT::size;
2216  store( v_+i*nn_+j+IT::size*2UL, load( v_+i*nn_+j+IT::size*2UL ) - it.load() ); it += IT::size;
2217  store( v_+i*nn_+j+IT::size*3UL, load( v_+i*nn_+j+IT::size*3UL ) - it.load() ); it += IT::size;
2218  }
2219  for( size_t j=jend; j<n_; j+=IT::size, it+=IT::size ) {
2220  store( v_+i*nn_+j, load( v_+i*nn_+j ) - it.load() );
2221  }
2222  }
2223 }
2224 //*************************************************************************************************
2225 
2226 
2227 //*************************************************************************************************
2238 template< typename Type // Data type of the matrix
2239  , bool SO > // Storage order
2240 template< typename MT > // Type of the right-hand side dense matrix
2242 {
2243  BLAZE_INTERNAL_ASSERT( m_ == (~rhs).rows() , "Invalid number of rows" );
2244  BLAZE_INTERNAL_ASSERT( n_ == (~rhs).columns(), "Invalid number of columns" );
2245 
2246  const size_t block( 16UL );
2247 
2248  for( size_t ii=0UL; ii<m_; ii+=block ) {
2249  const size_t iend( ( m_<(ii+block) )?( m_ ):( ii+block ) );
2250  for( size_t jj=0UL; jj<n_; jj+=block ) {
2251  const size_t jend( ( n_<(jj+block) )?( n_ ):( jj+block ) );
2252  for( size_t i=ii; i<iend; ++i ) {
2253  for( size_t j=jj; j<jend; ++j ) {
2254  v_[i*nn_+j] -= (~rhs)(i,j);
2255  }
2256  }
2257  }
2258  }
2259 }
2260 //*************************************************************************************************
2261 
2262 
2263 //*************************************************************************************************
2274 template< typename Type // Data type of the matrix
2275  , bool SO > // Storage order
2276 template< typename MT > // Type of the right-hand side sparse matrix
2278 {
2279  BLAZE_INTERNAL_ASSERT( m_ == (~rhs).rows() , "Invalid number of rows" );
2280  BLAZE_INTERNAL_ASSERT( n_ == (~rhs).columns(), "Invalid number of columns" );
2281 
2282  for( size_t i=0UL; i<m_; ++i )
2283  for( typename MT::ConstIterator element=(~rhs).begin(i); element!=(~rhs).end(i); ++element )
2284  v_[i*nn_+element->index()] -= element->value();
2285 }
2286 //*************************************************************************************************
2287 
2288 
2289 //*************************************************************************************************
2300 template< typename Type // Data type of the matrix
2301  , bool SO > // Storage order
2302 template< typename MT > // Type of the right-hand side sparse matrix
2304 {
2305  BLAZE_INTERNAL_ASSERT( m_ == (~rhs).rows() , "Invalid number of rows" );
2306  BLAZE_INTERNAL_ASSERT( n_ == (~rhs).columns(), "Invalid number of columns" );
2307 
2308  for( size_t j=0UL; j<n_; ++j )
2309  for( typename MT::ConstIterator element=(~rhs).begin(j); element!=(~rhs).end(j); ++element )
2310  v_[element->index()*nn_+j] -= element->value();
2311 }
2312 //*************************************************************************************************
2313 
2314 
2315 
2316 
2317 
2318 
2319 
2320 
2321 //=================================================================================================
2322 //
2323 // CLASS TEMPLATE SPECIALIZATION FOR COLUMN-MAJOR MATRICES
2324 //
2325 //=================================================================================================
2326 
2327 //*************************************************************************************************
2335 template< typename Type > // Data type of the matrix
2336 class DynamicMatrix<Type,true> : public DenseMatrix< DynamicMatrix<Type,true>, true >
2337 {
2338  private:
2339  //**Type definitions****************************************************************************
2340  typedef IntrinsicTrait<Type> IT;
2341  //**********************************************************************************************
2342 
2343  public:
2344  //**Type definitions****************************************************************************
2345  typedef DynamicMatrix<Type,true> This;
2346  typedef This ResultType;
2349  typedef Type ElementType;
2350  typedef typename IT::Type IntrinsicType;
2351  typedef const Type& ReturnType;
2352  typedef const This& CompositeType;
2353  typedef Type& Reference;
2354  typedef const Type& ConstReference;
2355  typedef DenseIterator<Type> Iterator;
2357  //**********************************************************************************************
2358 
2359  //**Compilation flags***************************************************************************
2361 
2365  enum { vectorizable = IsVectorizable<Type>::value };
2366  //**********************************************************************************************
2367 
2368  //**Constructors********************************************************************************
2371  explicit inline DynamicMatrix();
2372  explicit inline DynamicMatrix( size_t m, size_t n );
2373  explicit inline DynamicMatrix( size_t m, size_t n, const Type& init );
2374  template< typename Other > explicit inline DynamicMatrix( size_t m, size_t n, const Other* array );
2375 
2376  template< typename Other, size_t M, size_t N >
2377  explicit inline DynamicMatrix( const Other (&array)[M][N] );
2378 
2379  inline DynamicMatrix( const DynamicMatrix& m );
2380  template< typename MT, bool SO > inline DynamicMatrix( const Matrix<MT,SO>& m );
2382  //**********************************************************************************************
2383 
2384  //**Destructor**********************************************************************************
2387  inline ~DynamicMatrix();
2389  //**********************************************************************************************
2390 
2391  //**Data access functions***********************************************************************
2394  inline Reference operator()( size_t i, size_t j );
2395  inline ConstReference operator()( size_t i, size_t j ) const;
2396  inline Type* data ();
2397  inline const Type* data () const;
2398  inline Type* data ( size_t j );
2399  inline const Type* data ( size_t j ) const;
2400  inline Iterator begin ( size_t j );
2401  inline ConstIterator begin ( size_t j ) const;
2402  inline ConstIterator cbegin( size_t j ) const;
2403  inline Iterator end ( size_t j );
2404  inline ConstIterator end ( size_t j ) const;
2405  inline ConstIterator cend ( size_t j ) const;
2407  //**********************************************************************************************
2408 
2409  //**Assignment operators************************************************************************
2412  template< typename Other, size_t M, size_t N >
2413  inline DynamicMatrix& operator=( const Other (&array)[M][N] );
2414 
2415  inline DynamicMatrix& operator= ( Type set );
2416  inline DynamicMatrix& operator= ( const DynamicMatrix& set );
2417  template< typename MT, bool SO > inline DynamicMatrix& operator= ( const Matrix<MT,SO>& rhs );
2418  template< typename MT, bool SO > inline DynamicMatrix& operator+=( const Matrix<MT,SO>& rhs );
2419  template< typename MT, bool SO > inline DynamicMatrix& operator-=( const Matrix<MT,SO>& rhs );
2420  template< typename MT, bool SO > inline DynamicMatrix& operator*=( const Matrix<MT,SO>& rhs );
2421 
2422  template< typename Other >
2423  inline typename EnableIf< IsNumeric<Other>, DynamicMatrix >::Type&
2424  operator*=( Other rhs );
2425 
2426  template< typename Other >
2427  inline typename EnableIf< IsNumeric<Other>, DynamicMatrix >::Type&
2428  operator/=( Other rhs );
2430  //**********************************************************************************************
2431 
2432  //**Utility functions***************************************************************************
2435  inline size_t rows() const;
2436  inline size_t columns() const;
2437  inline size_t spacing() const;
2438  inline size_t capacity() const;
2439  inline size_t capacity( size_t j ) const;
2440  inline size_t nonZeros() const;
2441  inline size_t nonZeros( size_t j ) const;
2442  inline void reset();
2443  inline void reset( size_t j );
2444  inline void clear();
2445  void resize ( size_t m, size_t n, bool preserve=true );
2446  inline void extend ( size_t m, size_t n, bool preserve=true );
2447  inline void reserve( size_t elements );
2448  inline DynamicMatrix& transpose();
2449  template< typename Other > inline DynamicMatrix& scale( Other scalar );
2450  inline void swap( DynamicMatrix& m ) /* throw() */;
2452  //**********************************************************************************************
2453 
2454  private:
2455  //**********************************************************************************************
2457  template< typename MT >
2458  struct VectorizedAssign {
2459  enum { value = vectorizable && MT::vectorizable &&
2460  IsSame<Type,typename MT::ElementType>::value };
2461  };
2462  //**********************************************************************************************
2463 
2464  //**********************************************************************************************
2466  template< typename MT >
2467  struct VectorizedAddAssign {
2468  enum { value = vectorizable && MT::vectorizable &&
2469  IsSame<Type,typename MT::ElementType>::value &&
2470  IntrinsicTrait<Type>::addition };
2471  };
2472  //**********************************************************************************************
2473 
2474  //**********************************************************************************************
2476  template< typename MT >
2477  struct VectorizedSubAssign {
2478  enum { value = vectorizable && MT::vectorizable &&
2479  IsSame<Type,typename MT::ElementType>::value &&
2480  IntrinsicTrait<Type>::subtraction };
2481  };
2482  //**********************************************************************************************
2483 
2484  public:
2485  //**Expression template evaluation functions****************************************************
2488  template< typename Other > inline bool canAlias ( const Other* alias ) const;
2489  template< typename Other > inline bool isAliased( const Other* alias ) const;
2490 
2491  inline IntrinsicType load ( size_t i, size_t j ) const;
2492  inline IntrinsicType loadu ( size_t i, size_t j ) const;
2493  inline void store ( size_t i, size_t j, const IntrinsicType& value );
2494  inline void storeu( size_t i, size_t j, const IntrinsicType& value );
2495  inline void stream( size_t i, size_t j, const IntrinsicType& value );
2496 
2497  template< typename MT >
2498  inline typename DisableIf< VectorizedAssign<MT> >::Type
2499  assign( const DenseMatrix<MT,true>& rhs );
2500 
2501  template< typename MT >
2502  inline typename EnableIf< VectorizedAssign<MT> >::Type
2503  assign( const DenseMatrix<MT,true>& rhs );
2504 
2505  template< typename MT > inline void assign( const DenseMatrix<MT,false>& rhs );
2506  template< typename MT > inline void assign( const SparseMatrix<MT,true>& rhs );
2507  template< typename MT > inline void assign( const SparseMatrix<MT,false>& rhs );
2508 
2509  template< typename MT >
2510  inline typename DisableIf< VectorizedAddAssign<MT> >::Type
2511  addAssign( const DenseMatrix<MT,true>& rhs );
2512 
2513  template< typename MT >
2514  inline typename EnableIf< VectorizedAddAssign<MT> >::Type
2515  addAssign( const DenseMatrix<MT,true>& rhs );
2516 
2517  template< typename MT > inline void addAssign( const DenseMatrix<MT,false>& rhs );
2518  template< typename MT > inline void addAssign( const SparseMatrix<MT,true>& rhs );
2519  template< typename MT > inline void addAssign( const SparseMatrix<MT,false>& rhs );
2520 
2521  template< typename MT >
2522  inline typename DisableIf< VectorizedSubAssign<MT> >::Type
2523  subAssign ( const DenseMatrix<MT,true>& rhs );
2524 
2525  template< typename MT >
2526  inline typename EnableIf< VectorizedSubAssign<MT> >::Type
2527  subAssign ( const DenseMatrix<MT,true>& rhs );
2528 
2529  template< typename MT > inline void subAssign( const DenseMatrix<MT,false>& rhs );
2530  template< typename MT > inline void subAssign( const SparseMatrix<MT,true>& rhs );
2531  template< typename MT > inline void subAssign( const SparseMatrix<MT,false>& rhs );
2533  //**********************************************************************************************
2534 
2535  private:
2536  //**Utility functions***************************************************************************
2539  inline size_t adjustRows( size_t minRows ) const;
2541  //**********************************************************************************************
2542 
2543  //**Member variables****************************************************************************
2546  size_t m_;
2547  size_t mm_;
2548  size_t n_;
2549  size_t capacity_;
2550  Type* BLAZE_RESTRICT v_;
2551 
2561  //**********************************************************************************************
2562 
2563  //**Compile time checks*************************************************************************
2568  //**********************************************************************************************
2569 };
2571 //*************************************************************************************************
2572 
2573 
2574 
2575 
2576 //=================================================================================================
2577 //
2578 // CONSTRUCTORS
2579 //
2580 //=================================================================================================
2581 
2582 //*************************************************************************************************
2586 template< typename Type > // Data type of the matrix
2588  : m_ ( 0UL ) // The current number of rows of the matrix
2589  , mm_ ( 0UL ) // The alignment adjusted number of rows
2590  , n_ ( 0UL ) // The current number of columns of the matrix
2591  , capacity_( 0UL ) // The maximum capacity of the matrix
2592  , v_ ( NULL ) // The matrix elements
2593 {}
2595 //*************************************************************************************************
2596 
2597 
2598 //*************************************************************************************************
2608 template< typename Type > // Data type of the matrix
2609 inline DynamicMatrix<Type,true>::DynamicMatrix( size_t m, size_t n )
2610  : m_ ( m ) // The current number of rows of the matrix
2611  , mm_ ( adjustRows( m ) ) // The alignment adjusted number of rows
2612  , n_ ( n ) // The current number of columns of the matrix
2613  , capacity_( mm_*n_ ) // The maximum capacity of the matrix
2614  , v_ ( allocate<Type>( capacity_ ) ) // The matrix elements
2615 {
2616  if( IsNumeric<Type>::value ) {
2617  for( size_t j=0UL; j<n_; ++j )
2618  for( size_t i=m_; i<mm_; ++i ) {
2619  v_[i+j*mm_] = Type();
2620  }
2621  }
2622 }
2624 //*************************************************************************************************
2625 
2626 
2627 //*************************************************************************************************
2637 template< typename Type > // Data type of the matrix
2638 inline DynamicMatrix<Type,true>::DynamicMatrix( size_t m, size_t n, const Type& init )
2639  : m_ ( m ) // The current number of rows of the matrix
2640  , mm_ ( adjustRows( m ) ) // The alignment adjusted number of rows
2641  , n_ ( n ) // The current number of columns of the matrix
2642  , capacity_( mm_*n_ ) // The maximum capacity of the matrix
2643  , v_ ( allocate<Type>( capacity_ ) ) // The matrix elements
2644 {
2645  for( size_t j=0UL; j<n_; ++j ) {
2646  for( size_t i=0UL; i<m_; ++i )
2647  v_[i+j*mm_] = init;
2648 
2649  if( IsNumeric<Type>::value ) {
2650  for( size_t i=m_; i<mm_; ++i )
2651  v_[i+j*mm_] = Type();
2652  }
2653  }
2654 }
2656 //*************************************************************************************************
2657 
2658 
2659 //*************************************************************************************************
2683 template< typename Type > // Data type of the matrix
2684 template< typename Other > // Data type of the initialization array
2685 inline DynamicMatrix<Type,true>::DynamicMatrix( size_t m, size_t n, const Other* array )
2686  : m_ ( m ) // The current number of rows of the matrix
2687  , mm_ ( adjustRows( m ) ) // The alignment adjusted number of rows
2688  , n_ ( n ) // The current number of columns of the matrix
2689  , capacity_( mm_*n_ ) // The maximum capacity of the matrix
2690  , v_ ( allocate<Type>( capacity_ ) ) // The matrix elements
2691 {
2692  for( size_t j=0UL; j<n; ++j ) {
2693  for( size_t i=0UL; i<m; ++i )
2694  v_[i+j*mm_] = array[i+j*m];
2695 
2696  if( IsNumeric<Type>::value ) {
2697  for( size_t i=m; i<mm_; ++i )
2698  v_[i+j*mm_] = Type();
2699  }
2700  }
2701 }
2703 //*************************************************************************************************
2704 
2705 
2706 //*************************************************************************************************
2728 template< typename Type > // Data type of the matrix
2729 template< typename Other // Data type of the initialization array
2730  , size_t M // Number of rows of the initialization array
2731  , size_t N > // Number of columns of the initialization array
2732 inline DynamicMatrix<Type,true>::DynamicMatrix( const Other (&array)[M][N] )
2733  : m_ ( M ) // The current number of rows of the matrix
2734  , mm_ ( adjustRows( M ) ) // The alignment adjusted number of rows
2735  , n_ ( N ) // The current number of columns of the matrix
2736  , capacity_( mm_*n_ ) // The maximum capacity of the matrix
2737  , v_ ( allocate<Type>( capacity_ ) ) // The matrix elements
2738 {
2739  for( size_t j=0UL; j<N; ++j ) {
2740  for( size_t i=0UL; i<M; ++i )
2741  v_[i+j*mm_] = array[i][j];
2742 
2743  if( IsNumeric<Type>::value ) {
2744  for( size_t i=M; i<mm_; ++i )
2745  v_[i+j*mm_] = Type();
2746  }
2747  }
2748 }
2750 //*************************************************************************************************
2751 
2752 
2753 //*************************************************************************************************
2762 template< typename Type > // Data type of the matrix
2763 inline DynamicMatrix<Type,true>::DynamicMatrix( const DynamicMatrix& m )
2764  : m_ ( m.m_ ) // The current number of rows of the matrix
2765  , mm_ ( m.mm_ ) // The alignment adjusted number of rows
2766  , n_ ( m.n_ ) // The current number of columns of the matrix
2767  , capacity_( mm_*n_ ) // The maximum capacity of the matrix
2768  , v_ ( allocate<Type>( capacity_ ) ) // The matrix elements
2769 {
2770  BLAZE_INTERNAL_ASSERT( capacity_ <= m.capacity_, "Invalid capacity estimation" );
2771 
2772  for( size_t i=0UL; i<capacity_; ++i )
2773  v_[i] = m.v_[i];
2774 }
2776 //*************************************************************************************************
2777 
2778 
2779 //*************************************************************************************************
2785 template< typename Type > // Data type of the matrix
2786 template< typename MT // Type of the foreign matrix
2787  , bool SO > // Storage order of the foreign matrix
2788 inline DynamicMatrix<Type,true>::DynamicMatrix( const Matrix<MT,SO>& m )
2789  : m_ ( (~m).rows() ) // The current number of rows of the matrix
2790  , mm_ ( adjustRows( m_ ) ) // The alignment adjusted number of rows
2791  , n_ ( (~m).columns() ) // The current number of columns of the matrix
2792  , capacity_( mm_*n_ ) // The maximum capacity of the matrix
2793  , v_ ( allocate<Type>( capacity_ ) ) // The matrix elements
2794 {
2795  using blaze::assign;
2796 
2797  if( IsNumeric<Type>::value ) {
2798  for( size_t j=0UL; j<n_; ++j )
2799  for( size_t i=( IsSparseMatrix<MT>::value )?( 0UL ):( m_ ); i<mm_; ++i ) {
2800  v_[i+j*mm_] = Type();
2801  }
2802  }
2803 
2804  assign( *this, ~m );
2805 }
2807 //*************************************************************************************************
2808 
2809 
2810 
2811 
2812 //=================================================================================================
2813 //
2814 // DESTRUCTOR
2815 //
2816 //=================================================================================================
2817 
2818 //*************************************************************************************************
2822 template< typename Type > // Data type of the matrix
2824 {
2825  deallocate( v_ );
2826 }
2828 //*************************************************************************************************
2829 
2830 
2831 
2832 
2833 //=================================================================================================
2834 //
2835 // DATA ACCESS FUNCTIONS
2836 //
2837 //=================================================================================================
2838 
2839 //*************************************************************************************************
2847 template< typename Type > // Data type of the matrix
2849  DynamicMatrix<Type,true>::operator()( size_t i, size_t j )
2850 {
2851  BLAZE_USER_ASSERT( i<m_, "Invalid row access index" );
2852  BLAZE_USER_ASSERT( j<n_, "Invalid column access index" );
2853  return v_[i+j*mm_];
2854 }
2856 //*************************************************************************************************
2857 
2858 
2859 //*************************************************************************************************
2867 template< typename Type > // Data type of the matrix
2869  DynamicMatrix<Type,true>::operator()( size_t i, size_t j ) const
2870 {
2871  BLAZE_USER_ASSERT( i<m_, "Invalid row access index" );
2872  BLAZE_USER_ASSERT( j<n_, "Invalid column access index" );
2873  return v_[i+j*mm_];
2874 }
2876 //*************************************************************************************************
2877 
2878 
2879 //*************************************************************************************************
2889 template< typename Type > // Data type of the matrix
2890 inline Type* DynamicMatrix<Type,true>::data()
2891 {
2892  return v_;
2893 }
2895 //*************************************************************************************************
2896 
2897 
2898 //*************************************************************************************************
2908 template< typename Type > // Data type of the matrix
2909 inline const Type* DynamicMatrix<Type,true>::data() const
2910 {
2911  return v_;
2912 }
2914 //*************************************************************************************************
2915 
2916 
2917 //*************************************************************************************************
2926 template< typename Type > // Data type of the matrix
2927 inline Type* DynamicMatrix<Type,true>::data( size_t j )
2928 {
2929  BLAZE_USER_ASSERT( j < n_, "Invalid dense matrix column access index" );
2930  return v_ + j*mm_;
2931 }
2933 //*************************************************************************************************
2934 
2935 
2936 //*************************************************************************************************
2945 template< typename Type > // Data type of the matrix
2946 inline const Type* DynamicMatrix<Type,true>::data( size_t j ) const
2947 {
2948  BLAZE_USER_ASSERT( j < n_, "Invalid dense matrix column access index" );
2949  return v_ + j*mm_;
2950 }
2952 //*************************************************************************************************
2953 
2954 
2955 //*************************************************************************************************
2962 template< typename Type > // Data type of the matrix
2963 inline typename DynamicMatrix<Type,true>::Iterator
2965 {
2966  BLAZE_USER_ASSERT( j < n_, "Invalid dense matrix column access index" );
2967  return Iterator( v_ + j*mm_ );
2968 }
2970 //*************************************************************************************************
2971 
2972 
2973 //*************************************************************************************************
2980 template< typename Type > // Data type of the matrix
2982  DynamicMatrix<Type,true>::begin( size_t j ) const
2983 {
2984  BLAZE_USER_ASSERT( j < n_, "Invalid dense matrix column access index" );
2985  return ConstIterator( v_ + j*mm_ );
2986 }
2988 //*************************************************************************************************
2989 
2990 
2991 //*************************************************************************************************
2998 template< typename Type > // Data type of the matrix
3000  DynamicMatrix<Type,true>::cbegin( size_t j ) const
3001 {
3002  BLAZE_USER_ASSERT( j < n_, "Invalid dense matrix column access index" );
3003  return ConstIterator( v_ + j*mm_ );
3004 }
3006 //*************************************************************************************************
3007 
3008 
3009 //*************************************************************************************************
3016 template< typename Type > // Data type of the matrix
3017 inline typename DynamicMatrix<Type,true>::Iterator
3018  DynamicMatrix<Type,true>::end( size_t j )
3019 {
3020  BLAZE_USER_ASSERT( j < n_, "Invalid dense matrix column access index" );
3021  return Iterator( v_ + j*mm_ + m_ );
3022 }
3024 //*************************************************************************************************
3025 
3026 
3027 //*************************************************************************************************
3034 template< typename Type > // Data type of the matrix
3036  DynamicMatrix<Type,true>::end( size_t j ) const
3037 {
3038  BLAZE_USER_ASSERT( j < n_, "Invalid dense matrix column access index" );
3039  return ConstIterator( v_ + j*mm_ + m_ );
3040 }
3042 //*************************************************************************************************
3043 
3044 
3045 //*************************************************************************************************
3052 template< typename Type > // Data type of the matrix
3054  DynamicMatrix<Type,true>::cend( size_t j ) const
3055 {
3056  BLAZE_USER_ASSERT( j < n_, "Invalid dense matrix column access index" );
3057  return ConstIterator( v_ + j*mm_ + m_ );
3058 }
3060 //*************************************************************************************************
3061 
3062 
3063 
3064 
3065 //=================================================================================================
3066 //
3067 // ASSIGNMENT OPERATORS
3068 //
3069 //=================================================================================================
3070 
3071 //*************************************************************************************************
3093 template< typename Type > // Data type of the matrix
3094 template< typename Other // Data type of the initialization array
3095  , size_t M // Number of rows of the initialization array
3096  , size_t N > // Number of columns of the initialization array
3097 inline DynamicMatrix<Type,true>& DynamicMatrix<Type,true>::operator=( const Other (&array)[M][N] )
3098 {
3099  resize( M, N, false );
3100 
3101  for( size_t j=0UL; j<N; ++j )
3102  for( size_t i=0UL; i<M; ++i )
3103  v_[i+j*mm_] = array[i][j];
3104 
3105  return *this;
3106 }
3108 //*************************************************************************************************
3109 
3110 
3111 //*************************************************************************************************
3118 template< typename Type > // Data type of the matrix
3119 inline DynamicMatrix<Type,true>& DynamicMatrix<Type,true>::operator=( Type rhs )
3120 {
3121  for( size_t j=0UL; j<n_; ++j )
3122  for( size_t i=0UL; i<m_; ++i )
3123  v_[i+j*mm_] = rhs;
3124 
3125  return *this;
3126 }
3128 //*************************************************************************************************
3129 
3130 
3131 //*************************************************************************************************
3141 template< typename Type > // Data type of the matrix
3142 inline DynamicMatrix<Type,true>& DynamicMatrix<Type,true>::operator=( const DynamicMatrix& rhs )
3143 {
3144  if( &rhs == this ) return *this;
3145 
3146  resize( rhs.m_, rhs.n_, false );
3147 
3148  for( size_t j=0UL; j<n_; ++j )
3149  for( size_t i=0UL; i<m_; ++i )
3150  v_[i+j*mm_] = rhs(i,j);
3151 
3152  return *this;
3153 }
3155 //*************************************************************************************************
3156 
3157 
3158 //*************************************************************************************************
3168 template< typename Type > // Data type of the matrix
3169 template< typename MT // Type of the right-hand side matrix
3170  , bool SO > // Storage order of the right-hand side matrix
3171 inline DynamicMatrix<Type,true>& DynamicMatrix<Type,true>::operator=( const Matrix<MT,SO>& rhs )
3172 {
3173  using blaze::assign;
3174 
3175  if( (~rhs).canAlias( this ) ) {
3176  DynamicMatrix tmp( ~rhs );
3177  swap( tmp );
3178  }
3179  else {
3180  resize( (~rhs).rows(), (~rhs).columns(), false );
3181  if( IsSparseMatrix<MT>::value )
3182  reset();
3183  assign( *this, ~rhs );
3184  }
3185 
3186  return *this;
3187 }
3189 //*************************************************************************************************
3190 
3191 
3192 //*************************************************************************************************
3203 template< typename Type > // Data type of the matrix
3204 template< typename MT // Type of the right-hand side matrix
3205  , bool SO > // Storage order of the right-hand side matrix
3206 inline DynamicMatrix<Type,true>& DynamicMatrix<Type,true>::operator+=( const Matrix<MT,SO>& rhs )
3207 {
3208  using blaze::addAssign;
3209 
3210  if( (~rhs).rows() != m_ || (~rhs).columns() != n_ )
3211  throw std::invalid_argument( "Matrix sizes do not match" );
3212 
3213  if( (~rhs).canAlias( this ) ) {
3214  typename MT::ResultType tmp( ~rhs );
3215  addAssign( *this, tmp );
3216  }
3217  else {
3218  addAssign( *this, ~rhs );
3219  }
3220 
3221  return *this;
3222 }
3224 //*************************************************************************************************
3225 
3226 
3227 //*************************************************************************************************
3238 template< typename Type > // Data type of the matrix
3239 template< typename MT // Type of the right-hand side matrix
3240  , bool SO > // Storage order of the right-hand side matrix
3241 inline DynamicMatrix<Type,true>& DynamicMatrix<Type,true>::operator-=( const Matrix<MT,SO>& rhs )
3242 {
3243  using blaze::subAssign;
3244 
3245  if( (~rhs).rows() != m_ || (~rhs).columns() != n_ )
3246  throw std::invalid_argument( "Matrix sizes do not match" );
3247 
3248  if( (~rhs).canAlias( this ) ) {
3249  typename MT::ResultType tmp( ~rhs );
3250  subAssign( *this, tmp );
3251  }
3252  else {
3253  subAssign( *this, ~rhs );
3254  }
3255 
3256  return *this;
3257 }
3259 //*************************************************************************************************
3260 
3261 
3262 //*************************************************************************************************
3273 template< typename Type > // Data type of the matrix
3274 template< typename MT // Type of the right-hand side matrix
3275  , bool SO > // Storage order of the right-hand side matrix
3276 inline DynamicMatrix<Type,true>& DynamicMatrix<Type,true>::operator*=( const Matrix<MT,SO>& rhs )
3277 {
3278  if( (~rhs).rows() != n_ )
3279  throw std::invalid_argument( "Matrix sizes do not match" );
3280 
3281  DynamicMatrix tmp( *this * (~rhs) );
3282  swap( tmp );
3283 
3284  return *this;
3285 }
3287 //*************************************************************************************************
3288 
3289 
3290 //*************************************************************************************************
3298 template< typename Type > // Data type of the matrix
3299 template< typename Other > // Data type of the right-hand side scalar
3300 inline typename EnableIf< IsNumeric<Other>, DynamicMatrix<Type,true> >::Type&
3301  DynamicMatrix<Type,true>::operator*=( Other rhs )
3302 {
3303  using blaze::assign;
3304 
3305  assign( *this, (*this) * rhs );
3306  return *this;
3307 }
3309 //*************************************************************************************************
3310 
3311 
3312 //*************************************************************************************************
3320 template< typename Type > // Data type of the matrix
3321 template< typename Other > // Data type of the right-hand side scalar
3322 inline typename EnableIf< IsNumeric<Other>, DynamicMatrix<Type,true> >::Type&
3323  DynamicMatrix<Type,true>::operator/=( Other rhs )
3324 {
3325  using blaze::assign;
3326 
3327  BLAZE_USER_ASSERT( rhs != Other(0), "Division by zero detected" );
3328 
3329  assign( *this, (*this) / rhs );
3330  return *this;
3331 }
3333 //*************************************************************************************************
3334 
3335 
3336 
3337 
3338 //=================================================================================================
3339 //
3340 // UTILITY FUNCTIONS
3341 //
3342 //=================================================================================================
3343 
3344 //*************************************************************************************************
3350 template< typename Type > // Data type of the matrix
3351 inline size_t DynamicMatrix<Type,true>::rows() const
3352 {
3353  return m_;
3354 }
3356 //*************************************************************************************************
3357 
3358 
3359 //*************************************************************************************************
3365 template< typename Type > // Data type of the matrix
3366 inline size_t DynamicMatrix<Type,true>::columns() const
3367 {
3368  return n_;
3369 }
3371 //*************************************************************************************************
3372 
3373 
3374 //*************************************************************************************************
3383 template< typename Type > // Data type of the matrix
3384 inline size_t DynamicMatrix<Type,true>::spacing() const
3385 {
3386  return mm_;
3387 }
3389 //*************************************************************************************************
3390 
3391 
3392 //*************************************************************************************************
3398 template< typename Type > // Data type of the matrix
3399 inline size_t DynamicMatrix<Type,true>::capacity() const
3400 {
3401  return capacity_;
3402 }
3404 //*************************************************************************************************
3405 
3406 
3407 //*************************************************************************************************
3414 template< typename Type > // Data type of the sparse matrix
3415 inline size_t DynamicMatrix<Type,true>::capacity( size_t j ) const
3416 {
3417  UNUSED_PARAMETER( j );
3418  BLAZE_USER_ASSERT( j < columns(), "Invalid column access index" );
3419  return mm_;
3420 }
3422 //*************************************************************************************************
3423 
3424 
3425 //*************************************************************************************************
3431 template< typename Type > // Data type of the matrix
3432 inline size_t DynamicMatrix<Type,true>::nonZeros() const
3433 {
3434  size_t nonzeros( 0UL );
3435 
3436  for( size_t j=0UL; j<n_; ++j )
3437  for( size_t i=0UL; i<m_; ++i )
3438  if( !isDefault( v_[i+j*mm_] ) )
3439  ++nonzeros;
3440 
3441  return nonzeros;
3442 }
3444 //*************************************************************************************************
3445 
3446 
3447 //*************************************************************************************************
3454 template< typename Type > // Data type of the matrix
3455 inline size_t DynamicMatrix<Type,true>::nonZeros( size_t j ) const
3456 {
3457  BLAZE_USER_ASSERT( j < columns(), "Invalid column access index" );
3458 
3459  const size_t iend( (j+1UL)*mm_ );
3460  size_t nonzeros( 0UL );
3461 
3462  for( size_t i=j*mm_; i<iend; ++i )
3463  if( !isDefault( v_[i] ) )
3464  ++nonzeros;
3465 
3466  return nonzeros;
3467 }
3469 //*************************************************************************************************
3470 
3471 
3472 //*************************************************************************************************
3478 template< typename Type > // Data type of the matrix
3479 inline void DynamicMatrix<Type,true>::reset()
3480 {
3481  using blaze::reset;
3482 
3483  for( size_t j=0UL; j<n_; ++j )
3484  for( size_t i=0UL; i<m_; ++i )
3485  reset( v_[i+j*mm_] );
3486 }
3488 //*************************************************************************************************
3489 
3490 
3491 //*************************************************************************************************
3501 template< typename Type > // Data type of the sparse matrix
3502 inline void DynamicMatrix<Type,true>::reset( size_t j )
3503 {
3504  using blaze::reset;
3505 
3506  BLAZE_USER_ASSERT( j < columns(), "Invalid column access index" );
3507  for( size_t i=0UL; i<m_; ++i )
3508  reset( v_[i+j*mm_] );
3509 }
3511 //*************************************************************************************************
3512 
3513 
3514 //*************************************************************************************************
3522 template< typename Type > // Data type of the matrix
3523 inline void DynamicMatrix<Type,true>::clear()
3524 {
3525  resize( 0UL, 0UL, false );
3526 }
3528 //*************************************************************************************************
3529 
3530 
3531 //*************************************************************************************************
3565 template< typename Type > // Data type of the matrix
3566 void DynamicMatrix<Type,true>::resize( size_t m, size_t n, bool preserve )
3567 {
3568  using blaze::min;
3569 
3570  if( m == m_ && n == n_ ) return;
3571 
3572  const size_t mm( adjustRows( m ) );
3573 
3574  if( preserve )
3575  {
3576  Type* BLAZE_RESTRICT v = allocate<Type>( mm*n );
3577  const size_t min_m( min( m, m_ ) );
3578  const size_t min_n( min( n, n_ ) );
3579 
3580  for( size_t j=0UL; j<min_n; ++j )
3581  for( size_t i=0UL; i<min_m; ++i )
3582  v[i+j*mm] = v_[i+j*mm_];
3583 
3584  std::swap( v_, v );
3585  deallocate( v );
3586  capacity_ = mm*n;
3587  }
3588  else if( mm*n > capacity_ ) {
3589  Type* BLAZE_RESTRICT v = allocate<Type>( mm*n );
3590  std::swap( v_, v );
3591  deallocate( v );
3592  capacity_ = mm*n;
3593  }
3594 
3595  if( IsNumeric<Type>::value ) {
3596  for( size_t j=0UL; j<n; ++j )
3597  for( size_t i=m; i<mm; ++i )
3598  v_[i+j*mm] = Type();
3599  }
3600 
3601  m_ = m;
3602  mm_ = mm;
3603  n_ = n;
3604 }
3606 //*************************************************************************************************
3607 
3608 
3609 //*************************************************************************************************
3624 template< typename Type > // Data type of the matrix
3625 inline void DynamicMatrix<Type,true>::extend( size_t m, size_t n, bool preserve )
3626 {
3627  resize( m_+m, n_+n, preserve );
3628 }
3630 //*************************************************************************************************
3631 
3632 
3633 //*************************************************************************************************
3643 template< typename Type > // Data type of the matrix
3644 inline void DynamicMatrix<Type,true>::reserve( size_t elements )
3645 {
3646  if( elements > capacity_ )
3647  {
3648  // Allocating a new array
3649  Type* BLAZE_RESTRICT tmp = allocate<Type>( elements );
3650 
3651  // Initializing the new array
3652  std::copy( v_, v_+capacity_, tmp );
3653 
3654  if( IsNumeric<Type>::value ) {
3655  for( size_t i=capacity_; i<elements; ++i )
3656  tmp[i] = Type();
3657  }
3658 
3659  // Replacing the old array
3660  std::swap( tmp, v_ );
3661  deallocate( tmp );
3662  capacity_ = elements;
3663  }
3664 }
3666 //*************************************************************************************************
3667 
3668 
3669 //*************************************************************************************************
3675 template< typename Type > // Data type of the matrix
3676 inline DynamicMatrix<Type,true>& DynamicMatrix<Type,true>::transpose()
3677 {
3678  DynamicMatrix tmp( trans(*this) );
3679  swap( tmp );
3680  return *this;
3681 }
3683 //*************************************************************************************************
3684 
3685 
3686 //*************************************************************************************************
3693 template< typename Type > // Data type of the matrix
3694 template< typename Other > // Data type of the scalar value
3695 inline DynamicMatrix<Type,true>& DynamicMatrix<Type,true>::scale( Other scalar )
3696 {
3697  for( size_t j=0UL; j<n_; ++j )
3698  for( size_t i=0UL; i<m_; ++i )
3699  v_[i+j*mm_] *= scalar;
3700 
3701  return *this;
3702 }
3704 //*************************************************************************************************
3705 
3706 
3707 //*************************************************************************************************
3715 template< typename Type > // Data type of the matrix
3716 inline void DynamicMatrix<Type,true>::swap( DynamicMatrix& m ) /* throw() */
3717 {
3718  std::swap( m_ , m.m_ );
3719  std::swap( mm_, m.mm_ );
3720  std::swap( n_ , m.n_ );
3721  std::swap( capacity_, m.capacity_ );
3722  std::swap( v_ , m.v_ );
3723 }
3725 //*************************************************************************************************
3726 
3727 
3728 //*************************************************************************************************
3735 template< typename Type > // Data type of the matrix
3736 inline size_t DynamicMatrix<Type,true>::adjustRows( size_t minRows ) const
3737 {
3738  if( IsNumeric<Type>::value )
3739  return minRows + ( IT::size - ( minRows % IT::size ) ) % IT::size;
3740  else return minRows;
3741 }
3743 //*************************************************************************************************
3744 
3745 
3746 
3747 
3748 //=================================================================================================
3749 //
3750 // EXPRESSION TEMPLATE EVALUATION FUNCTIONS
3751 //
3752 //=================================================================================================
3753 
3754 //*************************************************************************************************
3765 template< typename Type > // Data type of the matrix
3766 template< typename Other > // Data type of the foreign expression
3767 inline bool DynamicMatrix<Type,true>::canAlias( const Other* alias ) const
3768 {
3769  return static_cast<const void*>( this ) == static_cast<const void*>( alias );
3770 }
3772 //*************************************************************************************************
3773 
3774 
3775 //*************************************************************************************************
3786 template< typename Type > // Data type of the matrix
3787 template< typename Other > // Data type of the foreign expression
3788 inline bool DynamicMatrix<Type,true>::isAliased( const Other* alias ) const
3789 {
3790  return static_cast<const void*>( this ) == static_cast<const void*>( alias );
3791 }
3793 //*************************************************************************************************
3794 
3795 
3796 //*************************************************************************************************
3811 template< typename Type > // Data type of the matrix
3812 inline typename DynamicMatrix<Type,true>::IntrinsicType
3813  DynamicMatrix<Type,true>::load( size_t i, size_t j ) const
3814 {
3815  using blaze::load;
3816 
3818 
3819  BLAZE_INTERNAL_ASSERT( i < m_ , "Invalid row access index" );
3820  BLAZE_INTERNAL_ASSERT( i + IT::size <= mm_, "Invalid row access index" );
3821  BLAZE_INTERNAL_ASSERT( i % IT::size == 0UL, "Invalid row access index" );
3822  BLAZE_INTERNAL_ASSERT( j < n_ , "Invalid column access index" );
3823 
3824  return load( v_+i+j*mm_ );
3825 }
3827 //*************************************************************************************************
3828 
3829 
3830 //*************************************************************************************************
3845 template< typename Type > // Data type of the matrix
3846 inline typename DynamicMatrix<Type,true>::IntrinsicType
3847  DynamicMatrix<Type,true>::loadu( size_t i, size_t j ) const
3848 {
3849  using blaze::loadu;
3850 
3852 
3853  BLAZE_INTERNAL_ASSERT( i < m_ , "Invalid row access index" );
3854  BLAZE_INTERNAL_ASSERT( i + IT::size <= mm_, "Invalid row access index" );
3855  BLAZE_INTERNAL_ASSERT( j < n_ , "Invalid column access index" );
3856 
3857  return loadu( v_+i+j*mm_ );
3858 }
3860 //*************************************************************************************************
3861 
3862 
3863 //*************************************************************************************************
3879 template< typename Type > // Data type of the matrix
3880 inline void DynamicMatrix<Type,true>::store( size_t i, size_t j, const IntrinsicType& value )
3881 {
3882  using blaze::store;
3883 
3885 
3886  BLAZE_INTERNAL_ASSERT( i < m_ , "Invalid row access index" );
3887  BLAZE_INTERNAL_ASSERT( i + IT::size <= mm_, "Invalid row access index" );
3888  BLAZE_INTERNAL_ASSERT( i % IT::size == 0UL, "Invalid row access index" );
3889  BLAZE_INTERNAL_ASSERT( j < n_ , "Invalid column access index" );
3890 
3891  store( v_+i+j*mm_, value );
3892 }
3894 //*************************************************************************************************
3895 
3896 
3897 //*************************************************************************************************
3913 template< typename Type > // Data type of the matrix
3914 inline void DynamicMatrix<Type,true>::storeu( size_t i, size_t j, const IntrinsicType& value )
3915 {
3916  using blaze::storeu;
3917 
3919 
3920  BLAZE_INTERNAL_ASSERT( i < m_ , "Invalid row access index" );
3921  BLAZE_INTERNAL_ASSERT( i + IT::size <= mm_, "Invalid row access index" );
3922  BLAZE_INTERNAL_ASSERT( j < n_ , "Invalid column access index" );
3923 
3924  storeu( v_+i+j*mm_, value );
3925 }
3927 //*************************************************************************************************
3928 
3929 
3930 //*************************************************************************************************
3947 template< typename Type > // Data type of the matrix
3948 inline void DynamicMatrix<Type,true>::stream( size_t i, size_t j, const IntrinsicType& value )
3949 {
3950  using blaze::stream;
3951 
3953 
3954  BLAZE_INTERNAL_ASSERT( i < m_ , "Invalid row access index" );
3955  BLAZE_INTERNAL_ASSERT( i + IT::size <= mm_, "Invalid row access index" );
3956  BLAZE_INTERNAL_ASSERT( i % IT::size == 0UL, "Invalid row access index" );
3957  BLAZE_INTERNAL_ASSERT( j < n_ , "Invalid column access index" );
3958 
3959  stream( v_+i+j*mm_, value );
3960 }
3962 //*************************************************************************************************
3963 
3964 
3965 //*************************************************************************************************
3977 template< typename Type > // Data type of the matrix
3978 template< typename MT > // Type of the right-hand side dense matrix
3979 inline typename DisableIf< typename DynamicMatrix<Type,true>::BLAZE_TEMPLATE VectorizedAssign<MT> >::Type
3980  DynamicMatrix<Type,true>::assign( const DenseMatrix<MT,true>& rhs )
3981 {
3982  BLAZE_INTERNAL_ASSERT( m_ == (~rhs).rows() , "Invalid number of rows" );
3983  BLAZE_INTERNAL_ASSERT( n_ == (~rhs).columns(), "Invalid number of columns" );
3984 
3985  const size_t iend( m_ & size_t(-2) );
3986  BLAZE_INTERNAL_ASSERT( ( m_ - ( m_ % 2UL ) ) == iend, "Invalid end calculation" );
3987 
3988  for( size_t j=0UL; j<n_; ++j ) {
3989  for( size_t i=0UL; i<iend; i+=2UL ) {
3990  v_[i +j*mm_] = (~rhs)(i ,j);
3991  v_[i+1UL+j*mm_] = (~rhs)(i+1UL,j);
3992  }
3993  if( iend < m_ ) {
3994  v_[iend+j*mm_] = (~rhs)(iend,j);
3995  }
3996  }
3997 }
3999 //*************************************************************************************************
4000 
4001 
4002 //*************************************************************************************************
4014 template< typename Type > // Data type of the matrix
4015 template< typename MT > // Type of the right-hand side dense matrix
4016 inline typename EnableIf< typename DynamicMatrix<Type,true>::BLAZE_TEMPLATE VectorizedAssign<MT> >::Type
4017  DynamicMatrix<Type,true>::assign( const DenseMatrix<MT,true>& rhs )
4018 {
4019  using blaze::store;
4020  using blaze::stream;
4021 
4022  BLAZE_INTERNAL_ASSERT( m_ == (~rhs).rows() , "Invalid number of rows" );
4023  BLAZE_INTERNAL_ASSERT( n_ == (~rhs).columns(), "Invalid number of columns" );
4024 
4026 
4027  if( useStreaming && m_*n_ > ( cacheSize / ( sizeof(Type) * 3UL ) ) && !(~rhs).isAliased( this ) )
4028  {
4029  for( size_t j=0UL; j<n_; ++j )
4030  for( size_t i=0UL; i<m_; i+=IT::size )
4031  stream( v_+i+j*mm_, (~rhs).load(i,j) );
4032  }
4033  else
4034  {
4035  const size_t iend( m_ & size_t(-IT::size*4) );
4036  BLAZE_INTERNAL_ASSERT( ( m_ - ( m_ % (IT::size*4UL) ) ) == iend, "Invalid end calculation" );
4037 
4038  for( size_t j=0UL; j<n_; ++j ) {
4039  typename MT::ConstIterator it( (~rhs).begin(j) );
4040  for( size_t i=0UL; i<iend; i+=IT::size*4UL ) {
4041  store( v_+i+j*mm_ , it.load() ); it += IT::size;
4042  store( v_+i+j*mm_+IT::size , it.load() ); it += IT::size;
4043  store( v_+i+j*mm_+IT::size*2UL, it.load() ); it += IT::size;
4044  store( v_+i+j*mm_+IT::size*3UL, it.load() ); it += IT::size;
4045  }
4046  for( size_t i=iend; i<m_; i+=IT::size, it+=IT::size ) {
4047  store( v_+i+j*mm_, it.load() );
4048  }
4049  }
4050  }
4051 }
4053 //*************************************************************************************************
4054 
4055 
4056 //*************************************************************************************************
4068 template< typename Type > // Data type of the matrix
4069 template< typename MT > // Type of the right-hand side dense matrix
4070 inline void DynamicMatrix<Type,true>::assign( const DenseMatrix<MT,false>& rhs )
4071 {
4072  BLAZE_INTERNAL_ASSERT( m_ == (~rhs).rows() , "Invalid number of rows" );
4073  BLAZE_INTERNAL_ASSERT( n_ == (~rhs).columns(), "Invalid number of columns" );
4074 
4075  const size_t block( 16UL );
4076 
4077  for( size_t jj=0UL; jj<n_; jj+=block ) {
4078  const size_t jend( ( n_<(jj+block) )?( n_ ):( jj+block ) );
4079  for( size_t ii=0UL; ii<m_; ii+=block ) {
4080  const size_t iend( ( m_<(ii+block) )?( m_ ):( ii+block ) );
4081  for( size_t j=jj; j<jend; ++j ) {
4082  for( size_t i=ii; i<iend; ++i ) {
4083  v_[i+j*mm_] = (~rhs)(i,j);
4084  }
4085  }
4086  }
4087  }
4088 }
4090 //*************************************************************************************************
4091 
4092 
4093 //*************************************************************************************************
4105 template< typename Type > // Data type of the matrix
4106 template< typename MT > // Type of the right-hand side sparse matrix
4107 inline void DynamicMatrix<Type,true>::assign( const SparseMatrix<MT,true>& rhs )
4108 {
4109  for( size_t j=0UL; j<(~rhs).columns(); ++j )
4110  for( typename MT::ConstIterator element=(~rhs).begin(j); element!=(~rhs).end(j); ++element )
4111  v_[element->index()+j*mm_] = element->value();
4112 }
4114 //*************************************************************************************************
4115 
4116 
4117 //*************************************************************************************************
4129 template< typename Type > // Data type of the matrix
4130 template< typename MT > // Type of the right-hand side sparse matrix
4131 inline void DynamicMatrix<Type,true>::assign( const SparseMatrix<MT,false>& rhs )
4132 {
4133  for( size_t i=0UL; i<(~rhs).rows(); ++i )
4134  for( typename MT::ConstIterator element=(~rhs).begin(i); element!=(~rhs).end(i); ++element )
4135  v_[i+element->index()*mm_] = element->value();
4136 }
4138 //*************************************************************************************************
4139 
4140 
4141 //*************************************************************************************************
4153 template< typename Type > // Data type of the matrix
4154 template< typename MT > // Type of the right-hand side dense matrix
4155 inline typename DisableIf< typename DynamicMatrix<Type,true>::BLAZE_TEMPLATE VectorizedAddAssign<MT> >::Type
4156  DynamicMatrix<Type,true>::addAssign( const DenseMatrix<MT,true>& rhs )
4157 {
4158  BLAZE_INTERNAL_ASSERT( m_ == (~rhs).rows() , "Invalid number of rows" );
4159  BLAZE_INTERNAL_ASSERT( n_ == (~rhs).columns(), "Invalid number of columns" );
4160 
4161  const size_t iend( m_ & size_t(-2) );
4162  BLAZE_INTERNAL_ASSERT( ( m_ - ( m_ % 2UL ) ) == iend, "Invalid end calculation" );
4163 
4164  for( size_t j=0UL; j<n_; ++j ) {
4165  for( size_t i=0UL; i<iend; i+=2UL ) {
4166  v_[i +j*mm_] += (~rhs)(i ,j);
4167  v_[i+1UL+j*mm_] += (~rhs)(i+1UL,j);
4168  }
4169  if( iend < m_ ) {
4170  v_[iend+j*mm_] += (~rhs)(iend,j);
4171  }
4172  }
4173 }
4175 //*************************************************************************************************
4176 
4177 
4178 //*************************************************************************************************
4190 template< typename Type > // Data type of the matrix
4191 template< typename MT > // Type of the right-hand side dense matrix
4192 inline typename EnableIf< typename DynamicMatrix<Type,true>::BLAZE_TEMPLATE VectorizedAddAssign<MT> >::Type
4193  DynamicMatrix<Type,true>::addAssign( const DenseMatrix<MT,true>& rhs )
4194 {
4195  using blaze::load;
4196  using blaze::store;
4197 
4198  BLAZE_INTERNAL_ASSERT( m_ == (~rhs).rows() , "Invalid number of rows" );
4199  BLAZE_INTERNAL_ASSERT( n_ == (~rhs).columns(), "Invalid number of columns" );
4200 
4202 
4203  const size_t iend( m_ & size_t(-IT::size*4) );
4204  BLAZE_INTERNAL_ASSERT( ( m_ - ( m_ % (IT::size*4UL) ) ) == iend, "Invalid end calculation" );
4205 
4206  for( size_t j=0UL; j<n_; ++j ) {
4207  typename MT::ConstIterator it( (~rhs).begin(j) );
4208  for( size_t i=0UL; i<iend; i+=IT::size*4UL ) {
4209  store( v_+i+j*mm_ , load( v_+i+j*mm_ ) + it.load() ); it += IT::size;
4210  store( v_+i+j*mm_+IT::size , load( v_+i+j*mm_+IT::size ) + it.load() ); it += IT::size;
4211  store( v_+i+j*mm_+IT::size*2UL, load( v_+i+j*mm_+IT::size*2UL ) + it.load() ); it += IT::size;
4212  store( v_+i+j*mm_+IT::size*3UL, load( v_+i+j*mm_+IT::size*3UL ) + it.load() ); it += IT::size;
4213  }
4214  for( size_t i=iend; i<m_; i+=IT::size, it+=IT::size ) {
4215  store( v_+i+j*mm_, load( v_+i+j*mm_ ) + it.load() );
4216  }
4217  }
4218 }
4220 //*************************************************************************************************
4221 
4222 
4223 //*************************************************************************************************
4235 template< typename Type > // Data type of the matrix
4236 template< typename MT > // Type of the right-hand side dense matrix
4237 inline void DynamicMatrix<Type,true>::addAssign( const DenseMatrix<MT,false>& rhs )
4238 {
4239  BLAZE_INTERNAL_ASSERT( m_ == (~rhs).rows() , "Invalid number of rows" );
4240  BLAZE_INTERNAL_ASSERT( n_ == (~rhs).columns(), "Invalid number of columns" );
4241 
4242  const size_t block( 16UL );
4243 
4244  for( size_t jj=0UL; jj<n_; jj+=block ) {
4245  const size_t jend( ( n_<(jj+block) )?( n_ ):( jj+block ) );
4246  for( size_t ii=0UL; ii<m_; ii+=block ) {
4247  const size_t iend( ( m_<(ii+block) )?( m_ ):( ii+block ) );
4248  for( size_t j=jj; j<jend; ++j ) {
4249  for( size_t i=ii; i<iend; ++i ) {
4250  v_[i+j*mm_] += (~rhs)(i,j);
4251  }
4252  }
4253  }
4254  }
4255 }
4257 //*************************************************************************************************
4258 
4259 
4260 //*************************************************************************************************
4272 template< typename Type > // Data type of the matrix
4273 template< typename MT > // Type of the right-hand side sparse matrix
4274 inline void DynamicMatrix<Type,true>::addAssign( const SparseMatrix<MT,true>& rhs )
4275 {
4276  for( size_t j=0UL; j<(~rhs).columns(); ++j )
4277  for( typename MT::ConstIterator element=(~rhs).begin(j); element!=(~rhs).end(j); ++element )
4278  v_[element->index()+j*mm_] += element->value();
4279 }
4281 //*************************************************************************************************
4282 
4283 
4284 //*************************************************************************************************
4296 template< typename Type > // Data type of the matrix
4297 template< typename MT > // Type of the right-hand side sparse matrix
4298 inline void DynamicMatrix<Type,true>::addAssign( const SparseMatrix<MT,false>& rhs )
4299 {
4300  for( size_t i=0UL; i<(~rhs).rows(); ++i )
4301  for( typename MT::ConstIterator element=(~rhs).begin(i); element!=(~rhs).end(i); ++element )
4302  v_[i+element->index()*mm_] += element->value();
4303 }
4305 //*************************************************************************************************
4306 
4307 
4308 //*************************************************************************************************
4320 template< typename Type > // Data type of the matrix
4321 template< typename MT > // Type of the right-hand side dense matrix
4322 inline typename DisableIf< typename DynamicMatrix<Type,true>::BLAZE_TEMPLATE VectorizedSubAssign<MT> >::Type
4323  DynamicMatrix<Type,true>::subAssign( const DenseMatrix<MT,true>& rhs )
4324 {
4325  BLAZE_INTERNAL_ASSERT( m_ == (~rhs).rows() , "Invalid number of rows" );
4326  BLAZE_INTERNAL_ASSERT( n_ == (~rhs).columns(), "Invalid number of columns" );
4327 
4328  const size_t iend( m_ & size_t(-2) );
4329  BLAZE_INTERNAL_ASSERT( ( m_ - ( m_ % 2UL ) ) == iend, "Invalid end calculation" );
4330 
4331  for( size_t j=0UL; j<n_; ++j ) {
4332  for( size_t i=0UL; i<iend; i+=2UL ) {
4333  v_[i +j*mm_] -= (~rhs)(i ,j);
4334  v_[i+1+j*mm_] -= (~rhs)(i+1,j);
4335  }
4336  if( iend < m_ ) {
4337  v_[iend+j*mm_] -= (~rhs)(iend,j);
4338  }
4339  }
4340 }
4342 //*************************************************************************************************
4343 
4344 
4345 //*************************************************************************************************
4358 template< typename Type > // Data type of the matrix
4359 template< typename MT > // Type of the right-hand side dense matrix
4360 inline typename EnableIf< typename DynamicMatrix<Type,true>::BLAZE_TEMPLATE VectorizedSubAssign<MT> >::Type
4361  DynamicMatrix<Type,true>::subAssign( const DenseMatrix<MT,true>& rhs )
4362 {
4363  using blaze::load;
4364  using blaze::store;
4365 
4366  BLAZE_INTERNAL_ASSERT( m_ == (~rhs).rows() , "Invalid number of rows" );
4367  BLAZE_INTERNAL_ASSERT( n_ == (~rhs).columns(), "Invalid number of columns" );
4368 
4370 
4371  const size_t iend( m_ & size_t(-IT::size*4) );
4372  BLAZE_INTERNAL_ASSERT( ( m_ - ( m_ % (IT::size*4UL) ) ) == iend, "Invalid end calculation" );
4373 
4374  for( size_t j=0UL; j<n_; ++j ) {
4375  typename MT::ConstIterator it( (~rhs).begin(j) );
4376  for( size_t i=0UL; i<iend; i+=IT::size*4UL ) {
4377  store( v_+i+j*mm_ , load( v_+i+j*mm_ ) - it.load() ); it += IT::size;
4378  store( v_+i+j*mm_+IT::size , load( v_+i+j*mm_+IT::size ) - it.load() ); it += IT::size;
4379  store( v_+i+j*mm_+IT::size*2UL, load( v_+i+j*mm_+IT::size*2UL ) - it.load() ); it += IT::size;
4380  store( v_+i+j*mm_+IT::size*3UL, load( v_+i+j*mm_+IT::size*3UL ) - it.load() ); it += IT::size;
4381  }
4382  for( size_t i=iend; i<m_; i+=IT::size, it+=IT::size ) {
4383  store( v_+i+j*mm_, load( v_+i+j*mm_ ) - it.load() );
4384  }
4385  }
4386 }
4388 //*************************************************************************************************
4389 
4390 
4391 //*************************************************************************************************
4403 template< typename Type > // Data type of the matrix
4404 template< typename MT > // Type of the right-hand side dense matrix
4405 inline void DynamicMatrix<Type,true>::subAssign( const DenseMatrix<MT,false>& rhs )
4406 {
4407  const size_t block( 16UL );
4408 
4409  for( size_t jj=0UL; jj<n_; jj+=block ) {
4410  const size_t jend( ( n_<(jj+block) )?( n_ ):( jj+block ) );
4411  for( size_t ii=0UL; ii<m_; ii+=block ) {
4412  const size_t iend( ( m_<(ii+block) )?( m_ ):( ii+block ) );
4413  for( size_t j=jj; j<jend; ++j ) {
4414  for( size_t i=ii; i<iend; ++i ) {
4415  v_[i+j*mm_] -= (~rhs)(i,j);
4416  }
4417  }
4418  }
4419  }
4420 }
4422 //*************************************************************************************************
4423 
4424 
4425 //*************************************************************************************************
4437 template< typename Type > // Data type of the matrix
4438 template< typename MT > // Type of the right-hand side sparse matrix
4439 inline void DynamicMatrix<Type,true>::subAssign( const SparseMatrix<MT,true>& rhs )
4440 {
4441  for( size_t j=0UL; j<(~rhs).columns(); ++j )
4442  for( typename MT::ConstIterator element=(~rhs).begin(j); element!=(~rhs).end(j); ++element )
4443  v_[element->index()+j*mm_] -= element->value();
4444 }
4446 //*************************************************************************************************
4447 
4448 
4449 //*************************************************************************************************
4461 template< typename Type > // Data type of the matrix
4462 template< typename MT > // Type of the right-hand side sparse matrix
4463 inline void DynamicMatrix<Type,true>::subAssign( const SparseMatrix<MT,false>& rhs )
4464 {
4465  for( size_t i=0UL; i<(~rhs).rows(); ++i )
4466  for( typename MT::ConstIterator element=(~rhs).begin(i); element!=(~rhs).end(i); ++element )
4467  v_[i+element->index()*mm_] -= element->value();
4468 }
4470 //*************************************************************************************************
4471 
4472 
4473 
4474 
4475 
4476 
4477 
4478 
4479 //=================================================================================================
4480 //
4481 // DYNAMICMATRIX OPERATORS
4482 //
4483 //=================================================================================================
4484 
4485 //*************************************************************************************************
4488 template< typename Type, bool SO >
4489 inline void reset( DynamicMatrix<Type,SO>& m );
4490 
4491 template< typename Type, bool SO >
4492 inline void clear( DynamicMatrix<Type,SO>& m );
4493 
4494 template< typename Type, bool SO >
4495 inline bool isDefault( const DynamicMatrix<Type,SO>& m );
4496 
4497 template< typename Type, bool SO >
4498 inline void swap( DynamicMatrix<Type,SO>& a, DynamicMatrix<Type,SO>& b ) /* throw() */;
4500 //*************************************************************************************************
4501 
4502 
4503 //*************************************************************************************************
4510 template< typename Type // Data type of the matrix
4511  , bool SO > // Storage order
4513 {
4514  m.reset();
4515 }
4516 //*************************************************************************************************
4517 
4518 
4519 //*************************************************************************************************
4526 template< typename Type // Data type of the matrix
4527  , bool SO > // Storage order
4529 {
4530  m.clear();
4531 }
4532 //*************************************************************************************************
4533 
4534 
4535 //*************************************************************************************************
4553 template< typename Type // Data type of the matrix
4554  , bool SO > // Storage order
4555 inline bool isDefault( const DynamicMatrix<Type,SO>& m )
4556 {
4557  if( SO == rowMajor ) {
4558  for( size_t i=0UL; i<m.rows(); ++i )
4559  for( size_t j=0UL; j<m.columns(); ++j )
4560  if( !isDefault( m(i,j) ) ) return false;
4561  }
4562  else {
4563  for( size_t j=0UL; j<m.columns(); ++j )
4564  for( size_t i=0UL; i<m.rows(); ++i )
4565  if( !isDefault( m(i,j) ) ) return false;
4566  }
4567 
4568  return true;
4569 }
4570 //*************************************************************************************************
4571 
4572 
4573 //*************************************************************************************************
4582 template< typename Type // Data type of the matrix
4583  , bool SO > // Storage order
4584 inline void swap( DynamicMatrix<Type,SO>& a, DynamicMatrix<Type,SO>& b ) /* throw() */
4585 {
4586  a.swap( b );
4587 }
4588 //*************************************************************************************************
4589 
4590 
4591 
4592 
4593 //=================================================================================================
4594 //
4595 // ISRESIZABLE SPECIALIZATIONS
4596 //
4597 //=================================================================================================
4598 
4599 //*************************************************************************************************
4601 template< typename T, bool SO >
4602 struct IsResizable< DynamicMatrix<T,SO> > : public TrueType
4603 {
4604  enum { value = 1 };
4605  typedef TrueType Type;
4606 };
4607 
4608 template< typename T, bool SO >
4609 struct IsResizable< const DynamicMatrix<T,SO> > : public TrueType
4610 {
4611  enum { value = 1 };
4612  typedef TrueType Type;
4613 };
4614 
4615 template< typename T, bool SO >
4616 struct IsResizable< volatile DynamicMatrix<T,SO> > : public TrueType
4617 {
4618  enum { value = 1 };
4619  typedef TrueType Type;
4620 };
4621 
4622 template< typename T, bool SO >
4623 struct IsResizable< const volatile DynamicMatrix<T,SO> > : public TrueType
4624 {
4625  enum { value = 1 };
4626  typedef TrueType Type;
4627 };
4629 //*************************************************************************************************
4630 
4631 
4632 
4633 
4634 //=================================================================================================
4635 //
4636 // ADDTRAIT SPECIALIZATIONS
4637 //
4638 //=================================================================================================
4639 
4640 //*************************************************************************************************
4642 template< typename T1, bool SO, typename T2, size_t M, size_t N >
4643 struct AddTrait< DynamicMatrix<T1,SO>, StaticMatrix<T2,M,N,SO> >
4644 {
4645  typedef StaticMatrix< typename AddTrait<T1,T2>::Type, M, N, SO > Type;
4646 };
4647 
4648 template< typename T1, bool SO1, typename T2, size_t M, size_t N, bool SO2 >
4649 struct AddTrait< DynamicMatrix<T1,SO1>, StaticMatrix<T2,M,N,SO2> >
4650 {
4651  typedef StaticMatrix< typename AddTrait<T1,T2>::Type, M, N, false > Type;
4652 };
4653 
4654 template< typename T1, size_t M, size_t N, bool SO, typename T2 >
4655 struct AddTrait< StaticMatrix<T1,M,N,SO>, DynamicMatrix<T2,SO> >
4656 {
4657  typedef StaticMatrix< typename AddTrait<T1,T2>::Type, M, N, SO > Type;
4658 };
4659 
4660 template< typename T1, size_t M, size_t N, bool SO1, typename T2, bool SO2 >
4661 struct AddTrait< StaticMatrix<T1,M,N,SO1>, DynamicMatrix<T2,SO2> >
4662 {
4663  typedef StaticMatrix< typename AddTrait<T1,T2>::Type, M, N, false > Type;
4664 };
4665 
4666 template< typename T1, bool SO, typename T2 >
4667 struct AddTrait< DynamicMatrix<T1,SO>, DynamicMatrix<T2,SO> >
4668 {
4669  typedef DynamicMatrix< typename AddTrait<T1,T2>::Type , SO > Type;
4670 };
4671 
4672 template< typename T1, bool SO1, typename T2, bool SO2 >
4673 struct AddTrait< DynamicMatrix<T1,SO1>, DynamicMatrix<T2,SO2> >
4674 {
4675  typedef DynamicMatrix< typename AddTrait<T1,T2>::Type , false > Type;
4676 };
4678 //*************************************************************************************************
4679 
4680 
4681 
4682 
4683 //=================================================================================================
4684 //
4685 // SUBTRAIT SPECIALIZATIONS
4686 //
4687 //=================================================================================================
4688 
4689 //*************************************************************************************************
4691 template< typename T1, bool SO, typename T2, size_t M, size_t N >
4692 struct SubTrait< DynamicMatrix<T1,SO>, StaticMatrix<T2,M,N,SO> >
4693 {
4694  typedef StaticMatrix< typename SubTrait<T1,T2>::Type, M, N, SO > Type;
4695 };
4696 
4697 template< typename T1, bool SO1, typename T2, size_t M, size_t N, bool SO2 >
4698 struct SubTrait< DynamicMatrix<T1,SO1>, StaticMatrix<T2,M,N,SO2> >
4699 {
4700  typedef StaticMatrix< typename SubTrait<T1,T2>::Type, M, N, false > Type;
4701 };
4702 
4703 template< typename T1, size_t M, size_t N, bool SO, typename T2 >
4704 struct SubTrait< StaticMatrix<T1,M,N,SO>, DynamicMatrix<T2,SO> >
4705 {
4706  typedef StaticMatrix< typename SubTrait<T1,T2>::Type, M, N, SO > Type;
4707 };
4708 
4709 template< typename T1, size_t M, size_t N, bool SO1, typename T2, bool SO2 >
4710 struct SubTrait< StaticMatrix<T1,M,N,SO1>, DynamicMatrix<T2,SO2> >
4711 {
4712  typedef StaticMatrix< typename SubTrait<T1,T2>::Type, M, N, false > Type;
4713 };
4714 
4715 template< typename T1, bool SO, typename T2 >
4716 struct SubTrait< DynamicMatrix<T1,SO>, DynamicMatrix<T2,SO> >
4717 {
4718  typedef DynamicMatrix< typename SubTrait<T1,T2>::Type , SO > Type;
4719 };
4720 
4721 template< typename T1, bool SO1, typename T2, bool SO2 >
4722 struct SubTrait< DynamicMatrix<T1,SO1>, DynamicMatrix<T2,SO2> >
4723 {
4724  typedef DynamicMatrix< typename SubTrait<T1,T2>::Type , false > Type;
4725 };
4727 //*************************************************************************************************
4728 
4729 
4730 
4731 
4732 //=================================================================================================
4733 //
4734 // MULTTRAIT SPECIALIZATIONS
4735 //
4736 //=================================================================================================
4737 
4738 //*************************************************************************************************
4740 template< typename T1, bool SO, typename T2 >
4741 struct MultTrait< DynamicMatrix<T1,SO>, T2 >
4742 {
4743  typedef DynamicMatrix< typename MultTrait<T1,T2>::Type, SO > Type;
4745 };
4746 
4747 template< typename T1, typename T2, bool SO >
4748 struct MultTrait< T1, DynamicMatrix<T2,SO> >
4749 {
4750  typedef DynamicMatrix< typename MultTrait<T1,T2>::Type, SO > Type;
4752 };
4753 
4754 template< typename T1, bool SO, typename T2, size_t N >
4755 struct MultTrait< DynamicMatrix<T1,SO>, StaticVector<T2,N,false> >
4756 {
4757  typedef DynamicVector< typename MultTrait<T1,T2>::Type, false > Type;
4758 };
4759 
4760 template< typename T1, size_t N, typename T2, bool SO >
4761 struct MultTrait< StaticVector<T1,N,true>, DynamicMatrix<T2,SO> >
4762 {
4763  typedef DynamicVector< typename MultTrait<T1,T2>::Type, true > Type;
4764 };
4765 
4766 template< typename T1, bool SO, typename T2, size_t N >
4767 struct MultTrait< DynamicMatrix<T1,SO>, HybridVector<T2,N,false> >
4768 {
4769  typedef DynamicVector< typename MultTrait<T1,T2>::Type, false > Type;
4770 };
4771 
4772 template< typename T1, size_t N, typename T2, bool SO >
4773 struct MultTrait< HybridVector<T1,N,true>, DynamicMatrix<T2,SO> >
4774 {
4775  typedef DynamicVector< typename MultTrait<T1,T2>::Type, true > Type;
4776 };
4777 
4778 template< typename T1, bool SO, typename T2 >
4779 struct MultTrait< DynamicMatrix<T1,SO>, DynamicVector<T2,false> >
4780 {
4781  typedef DynamicVector< typename MultTrait<T1,T2>::Type, false > Type;
4782 };
4783 
4784 template< typename T1, typename T2, bool SO >
4785 struct MultTrait< DynamicVector<T1,true>, DynamicMatrix<T2,SO> >
4786 {
4787  typedef DynamicVector< typename MultTrait<T1,T2>::Type, true > Type;
4788 };
4789 
4790 template< typename T1, bool SO, typename T2 >
4791 struct MultTrait< DynamicMatrix<T1,SO>, CompressedVector<T2,false> >
4792 {
4793  typedef DynamicVector< typename MultTrait<T1,T2>::Type, false > Type;
4794 };
4795 
4796 template< typename T1, typename T2, bool SO >
4797 struct MultTrait< CompressedVector<T1,true>, DynamicMatrix<T2,SO> >
4798 {
4799  typedef DynamicVector< typename MultTrait<T1,T2>::Type, true > Type;
4800 };
4801 
4802 template< typename T1, bool SO1, typename T2, size_t M, size_t N, bool SO2 >
4803 struct MultTrait< DynamicMatrix<T1,SO1>, StaticMatrix<T2,M,N,SO2> >
4804 {
4805  typedef DynamicMatrix< typename MultTrait<T1,T2>::Type, SO1 > Type;
4806 };
4807 
4808 template< typename T1, size_t M, size_t N, bool SO1, typename T2, bool SO2 >
4809 struct MultTrait< StaticMatrix<T1,M,N,SO1>, DynamicMatrix<T2,SO2> >
4810 {
4811  typedef DynamicMatrix< typename MultTrait<T1,T2>::Type, SO1 > Type;
4812 };
4813 
4814 template< typename T1, bool SO1, typename T2, bool SO2 >
4815 struct MultTrait< DynamicMatrix<T1,SO1>, DynamicMatrix<T2,SO2> >
4816 {
4817  typedef DynamicMatrix< typename MultTrait<T1,T2>::Type, SO1 > Type;
4818 };
4820 //*************************************************************************************************
4821 
4822 
4823 
4824 
4825 //=================================================================================================
4826 //
4827 // DIVTRAIT SPECIALIZATIONS
4828 //
4829 //=================================================================================================
4830 
4831 //*************************************************************************************************
4833 template< typename T1, bool SO, typename T2 >
4834 struct DivTrait< DynamicMatrix<T1,SO>, T2 >
4835 {
4836  typedef DynamicMatrix< typename DivTrait<T1,T2>::Type , SO > Type;
4838 };
4840 //*************************************************************************************************
4841 
4842 
4843 
4844 
4845 //=================================================================================================
4846 //
4847 // MATHTRAIT SPECIALIZATIONS
4848 //
4849 //=================================================================================================
4850 
4851 //*************************************************************************************************
4853 template< typename T1, bool SO, typename T2 >
4854 struct MathTrait< DynamicMatrix<T1,SO>, DynamicMatrix<T2,SO> >
4855 {
4856  typedef DynamicMatrix< typename MathTrait<T1,T2>::HighType, SO > HighType;
4857  typedef DynamicMatrix< typename MathTrait<T1,T2>::LowType , SO > LowType;
4858 };
4860 //*************************************************************************************************
4861 
4862 
4863 
4864 
4865 //=================================================================================================
4866 //
4867 // SUBMATRIXTRAIT SPECIALIZATIONS
4868 //
4869 //=================================================================================================
4870 
4871 //*************************************************************************************************
4873 template< typename T1, bool SO >
4874 struct SubmatrixTrait< DynamicMatrix<T1,SO> >
4875 {
4876  typedef DynamicMatrix<T1,SO> Type;
4877 };
4879 //*************************************************************************************************
4880 
4881 
4882 
4883 
4884 //=================================================================================================
4885 //
4886 // ROWTRAIT SPECIALIZATIONS
4887 //
4888 //=================================================================================================
4889 
4890 //*************************************************************************************************
4892 template< typename T1, bool SO >
4893 struct RowTrait< DynamicMatrix<T1,SO> >
4894 {
4895  typedef DynamicVector<T1,true> Type;
4896 };
4898 //*************************************************************************************************
4899 
4900 
4901 
4902 
4903 //=================================================================================================
4904 //
4905 // COLUMNTRAIT SPECIALIZATIONS
4906 //
4907 //=================================================================================================
4908 
4909 //*************************************************************************************************
4911 template< typename T1, bool SO >
4912 struct ColumnTrait< DynamicMatrix<T1,SO> >
4913 {
4914  typedef DynamicVector<T1,false> Type;
4915 };
4917 //*************************************************************************************************
4918 
4919 } // namespace blaze
4920 
4921 #endif
Compile time check for vectorizable types.Depending on the available instruction set (SSE...
Definition: IsVectorizable.h:107
Constraint on the data type.
#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
Reference operator()(size_t i, size_t j)
2D-access to the matrix elements.
Definition: DynamicMatrix.h:688
size_t n_
The current number of columns of the matrix.
Definition: DynamicMatrix.h:393
Compile time check for numeric types.This type trait tests whether or not the given template paramete...
Definition: IsNumeric.h:98
Constraint on the data type.
Header file for mathematical functions.
void reserve(size_t elements)
Setting the minimum capacity of the matrix.
Definition: DynamicMatrix.h:1489
void reset(DynamicMatrix< Type, SO > &m)
Resetting the given dense matrix.
Definition: DynamicMatrix.h:4512
#define BLAZE_USER_ASSERT(expr, msg)
Run time assertion macro for user checks.In case of an invalid run time expression, the program execution is terminated. The BLAZE_USER_ASSERT macro can be disabled by setting the BLAZE_USER_ASSERT flag to zero or by defining NDEBUG during the compilation.
Definition: Assert.h:117
EnableIf< IsIntegral< T >, Load< T, sizeof(T)> >::Type::Type load(const T *address)
Loads a vector of integral values.
Definition: Load.h:222
Header file for the UNUSED_PARAMETER function template.
Header file for the subtraction trait.
const bool defaultStorageOrder
The default storage order for all matrices of the Blaze library.This value specifies the default stor...
Definition: StorageOrder.h:56
ConstIterator cbegin(size_t i) const
Returns an iterator to the first element of row/column i.
Definition: DynamicMatrix.h:846
Header file for the row trait.
Type *BLAZE_RESTRICT v_
The dynamically allocated matrix elements.
Definition: DynamicMatrix.h:396
const DMatTransExpr< MT,!SO > trans(const DenseMatrix< MT, SO > &dm)
Calculation of the transpose of the given dense matrix.
Definition: DMatTransExpr.h:446
void deallocate(T *address)
Deallocation of memory.
Definition: Memory.h:113
Header file for the IsSparseMatrix type trait.
bool isDefault(const DynamicMatrix< Type, SO > &m)
Returns whether the given dense matrix is in default state.
Definition: DynamicMatrix.h:4555
Efficient implementation of a compressed matrix.The CompressedMatrix class template is the represent...
Definition: CompressedMatrix.h:196
void resize(size_t m, size_t n, bool preserve=true)
Changing the size of the matrix.
Definition: DynamicMatrix.h:1413
EnableIf< IsIntegral< T >, Loadu< T, sizeof(T)> >::Type::Type loadu(const T *address)
Loads a vector of integral values.
Definition: Loadu.h:219
Header file for the IsSame and IsStrictlySame type traits.
size_t columns() const
Returns the current number of columns of the matrix.
Definition: DynamicMatrix.h:1213
const blaze::Null NULL
Global NULL pointer.This instance of the Null class replaces the NULL macro to ensure a type-safe NUL...
Definition: Null.h:300
const bool useStreaming
Configuration of the streaming behavior.For large vectors and matrices non-temporal stores can provid...
Definition: Streaming.h:50
void storeu(size_t i, size_t j, const IntrinsicType &value)
Unaligned store of an intrinsic element of the matrix.
Definition: DynamicMatrix.h:1753
void storeu(float *address, const sse_float_t &value)
Unaligned store of a vector of &#39;float&#39; values.
Definition: Storeu.h:234
Header file for a safe C++ NULL pointer implementation.
void UNUSED_PARAMETER(const T1 &)
Suppression of unused parameter warnings.
Definition: Unused.h:84
#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
Access proxy for sparse, matrices.The MatrixAccessProxy provides safe access to the elements of a no...
Definition: MatrixAccessProxy.h:86
DynamicMatrix()
The default constructor for DynamicMatrix.
Definition: DynamicMatrix.h:434
Type relationship analysis.This class tests if the two data types A and B are equal. For this type comparison, the cv-qualifiers of both data types are ignored. If A and B are the same data type (ignoring the cv-qualifiers), then the value member enumeration is set to 1, the nested type definition Type is TrueType, and the class derives from TrueType. Otherwise value is set to 0, Type is FalseType, and the class derives from FalseType.
Definition: IsSame.h:158
Header file for memory allocation and deallocation functionality.
size_t spacing() const
Returns the spacing between the beginning of two rows/columns.
Definition: DynamicMatrix.h:1232
Efficient implementation of a dynamic matrix.The DynamicMatrix class template is the representation ...
Definition: DynamicMatrix.h:176
void clear(DynamicMatrix< Type, SO > &m)
Clearing the given dense matrix.
Definition: DynamicMatrix.h:4528
Base class for dense matrices.The DenseMatrix class is a base class for all dense matrix classes...
Definition: DenseMatrix.h:70
const This & CompositeType
Data type for composite expression templates.
Definition: DynamicMatrix.h:192
Base class for sparse matrices.The SparseMatrix class is a base class for all sparse matrix classes...
Definition: Forward.h:104
Constraint on the data type.
size_t capacity_
The current capacity of the pointer array.
Definition: CompressedMatrix.h:2513
~DynamicMatrix()
The destructor for DynamicMatrix.
Definition: DynamicMatrix.h:663
This ResultType
Result type for expression template evaluations.
Definition: DynamicMatrix.h:186
Header file for the SparseMatrix base class.
size_t nonZeros() const
Returns the total number of non-zero elements in the matrix.
Definition: DynamicMatrix.h:1282
size_t adjustColumns(size_t minColumns) const
Adjusting the number columns of the matrix according to its data type Type.
Definition: DynamicMatrix.h:1577
void stream(float *address, const sse_float_t &value)
Aligned, non-temporal store of a vector of &#39;float&#39; values.
Definition: Stream.h:233
Header file for the DisableIf class template.
ConstIterator cend(size_t i) const
Returns an iterator just past the last element of row/column i.
Definition: DynamicMatrix.h:912
Header file for the multiplication trait.
IntrinsicType loadu(size_t i, size_t j) const
Unaligned load of an intrinsic element of the matrix.
Definition: DynamicMatrix.h:1686
Header file for nested template disabiguation.
void swap(CompressedMatrix< Type, SO > &a, CompressedMatrix< Type, SO > &b)
Swapping the contents of two sparse matrices.
Definition: CompressedMatrix.h:4541
Type ElementType
Type of the matrix elements.
Definition: DynamicMatrix.h:189
Header file for all forward declarations of the math module.
const Element * ConstIterator
Iterator over constant elements.
Definition: CompressedMatrix.h:2379
#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
IntrinsicTrait< Type > IT
Intrinsic trait for the matrix element type.
Definition: DynamicMatrix.h:180
DynamicMatrix< Type, SO > This
Type of this DynamicMatrix instance.
Definition: DynamicMatrix.h:185
Header file for the DenseMatrix base class.
Header file for the DenseIterator class template.
const Type & ReturnType
Return type for expression template evaluations.
Definition: DynamicMatrix.h:191
void assign(Matrix< MT1, SO1 > &lhs, const Matrix< MT2, SO2 > &rhs)
Default implementation of the assignment of a matrix to a matrix.
Definition: Matrix.h:179
Constraint on the data type.
size_t n_
The current number of columns of the sparse matrix.
Definition: CompressedMatrix.h:2512
void extend(size_t m, size_t n, bool preserve=true)
Extending the size of the matrix.
Definition: DynamicMatrix.h:1471
size_t rows() const
Returns the current number of rows of the matrix.
Definition: DynamicMatrix.h:1199
#define BLAZE_RESTRICT
Platform dependent setup of the restrict keyword.
Definition: Restrict.h:81
Header file for the default storage order for all vectors of the Blaze library.
#define BLAZE_CONSTRAINT_MUST_BE_VECTORIZABLE_TYPE(T)
Constraint on the data type.In case the given data type T is not a vectorizable data type...
Definition: Vectorizable.h:79
void reset()
Reset to the default initial values.
Definition: DynamicMatrix.h:1327
Iterator end(size_t i)
Returns an iterator just past the last element of row/column i.
Definition: DynamicMatrix.h:868
const Type & ConstReference
Reference to a constant matrix value.
Definition: CompressedMatrix.h:2377
System settings for streaming (non-temporal stores)
Header file for the EnableIf class template.
T * allocate(size_t size)
Aligned array allocation.
Definition: Memory.h:85
DynamicMatrix< Type,!SO > OppositeType
Result type with opposite storage order for expression template evaluations.
Definition: DynamicMatrix.h:187
size_t capacity() const
Returns the maximum capacity of the matrix.
Definition: DynamicMatrix.h:1246
Header file for the equal shim.
Header file for the IsVectorizable type trait.
ColumnIterator< const MT > ConstIterator
Iterator over constant elements.
Definition: DenseColumn.h:1972
Header file for the IsNumeric type trait.
size_t nn_
The alignment adjusted number of columns.
Definition: DynamicMatrix.h:394
void store(size_t i, size_t j, const IntrinsicType &value)
Aligned store of an intrinsic element of the matrix.
Definition: DynamicMatrix.h:1719
Intrinsic characteristics of data types.The IntrinsicTrait class template provides the intrinsic char...
Definition: IntrinsicTrait.h:648
Header file for run time assertion macros.
Header file for the addition trait.
void clear()
Clearing the matrix.
Definition: DynamicMatrix.h:1371
Header file for the division trait.
void swap(DynamicMatrix< Type, SO > &a, DynamicMatrix< Type, SO > &b)
Swapping the contents of two matrices.
Definition: DynamicMatrix.h:4584
void addAssign(Matrix< MT1, SO1 > &lhs, const Matrix< MT2, SO2 > &rhs)
Default implementation of the addition assignment of a matrix to a matrix.
Definition: Matrix.h:209
Header file for the submatrix trait.
Type * data()
Low-level data access to the matrix elements.
Definition: DynamicMatrix.h:727
Constraint on the data type.
Substitution Failure Is Not An Error (SFINAE) class.The EnableIf class template is an auxiliary tool ...
Definition: EnableIf.h:184
#define BLAZE_CONSTRAINT_MUST_BE_NUMERIC_TYPE(T)
Constraint on the data type.In case the given data type T is not a numeric (integral or floating poin...
Definition: Numeric.h:79
size_t m_
The current number of rows of the matrix.
Definition: DynamicMatrix.h:392
Iterator begin(size_t i)
Returns an iterator to the first element of row/column i.
Definition: DynamicMatrix.h:802
Header file for the reset shim.
bool isAliased(const Other *alias) const
Returns whether the matrix is aliased with the given address alias.
Definition: DynamicMatrix.h:1627
Header file for the cache size of the target architecture.
void subAssign(Matrix< MT1, SO1 > &lhs, const Matrix< MT2, SO2 > &rhs)
Default implementation of the subtraction assignment of a matrix to matrix.
Definition: Matrix.h:239
#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:2378
Header file for the column trait.
Header file for the isDefault shim.
System settings for the restrict keyword.
Base class for matrices.The Matrix class is a base class for all dense and sparse matrix classes with...
Definition: Forward.h:85
Constraint on the data type.
void swap(DynamicMatrix &m)
Swapping the contents of two matrices.
Definition: DynamicMatrix.h:1558
IntrinsicType load(size_t i, size_t j) const
Aligned load of an intrinsic element of the matrix.
Definition: DynamicMatrix.h:1652
size_t m_
The current number of rows of the sparse matrix.
Definition: CompressedMatrix.h:2511
Substitution Failure Is Not An Error (SFINAE) class.The DisableIf class template is an auxiliary tool...
Definition: DisableIf.h:184
Implementation of a generic iterator for dense vectors and matrices.The DenseIterator represents a ge...
Definition: DenseIterator.h:58
Header file for all intrinsic functionality.
Header file for the mathematical trait.
Type & Reference
Reference to a non-constant matrix value.
Definition: DynamicMatrix.h:193
DenseIterator< const Type > ConstIterator
Iterator over constant elements.
Definition: DynamicMatrix.h:196
const bool rowMajor
Storage order flag for row-major matrices.
Definition: StorageOrder.h:71
IT::Type IntrinsicType
Intrinsic type of the matrix elements.
Definition: DynamicMatrix.h:190
size_t capacity_
The maximum capacity of the matrix.
Definition: DynamicMatrix.h:395
This ResultType
Result type for expression template evaluations.
Definition: CompressedMatrix.h:2370
size_t columns(const Matrix< MT, SO > &m)
Returns the current number of columns of the matrix.
Definition: Matrix.h:154
Header file for basic type definitions.
Compile time check for sparse matrix types.This type trait tests whether or not the given template pa...
Definition: IsSparseMatrix.h:103
DenseIterator< Type > Iterator
Iterator over non-constant elements.
Definition: DynamicMatrix.h:195
MatrixAccessProxy< This > Reference
Reference to a non-constant matrix value.
Definition: CompressedMatrix.h:2376
const VT::ElementType min(const SparseVector< VT, TF > &sv)
Returns the smallest element of the sparse vector.
Definition: SparseVector.h:348
SelectType< useConst, ConstIterator, ColumnIterator< MT > >::Type Iterator
Iterator over non-constant elements.
Definition: DenseColumn.h:1980
boost::true_type TrueType
Type traits base class.The TrueType class is used as base class for type traits and value traits that...
Definition: TrueType.h:61
const size_t cacheSize
Cache size of the target architecture.This setting specifies the available cache size in Byte of the ...
Definition: CacheSize.h:48
Header file for the IsResizable type trait.
size_t rows(const Matrix< MT, SO > &m)
Returns the current number of rows of the matrix.
Definition: Matrix.h:138
#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
bool canAlias(const Other *alias) const
Returns whether the matrix can alias with the given address alias.
Definition: DynamicMatrix.h:1607
DynamicMatrix & transpose()
Transposing the matrix.
Definition: DynamicMatrix.h:1520
const Type & ConstReference
Reference to a constant matrix value.
Definition: DynamicMatrix.h:194
EnableIf< IsIntegral< T >, Set< T, sizeof(T)> >::Type::Type set(T value)
Sets all values in the vector to the given integral value.
Definition: Set.h:209
DynamicMatrix< Type,!SO > TransposeType
Transpose type for expression template evaluations.
Definition: DynamicMatrix.h:188
void store(float *address, const sse_float_t &value)
Aligned store of a vector of &#39;float&#39; values.
Definition: Store.h:242
void stream(size_t i, size_t j, const IntrinsicType &value)
Aligned, non-temporal store of an intrinsic element of the matrix.
Definition: DynamicMatrix.h:1786