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>
65 #include <blaze/system/CacheSize.h>
66 #include <blaze/system/Restrict.h>
68 #include <blaze/system/Streaming.h>
70 #include <blaze/util/Assert.h>
77 #include <blaze/util/DisableIf.h>
78 #include <blaze/util/EnableIf.h>
79 #include <blaze/util/Memory.h>
80 #include <blaze/util/Null.h>
81 #include <blaze/util/Template.h>
82 #include <blaze/util/Types.h>
86 #include <blaze/util/Unused.h>
87 
88 
89 namespace blaze {
90 
91 //=================================================================================================
92 //
93 // CLASS DEFINITION
94 //
95 //=================================================================================================
96 
97 //*************************************************************************************************
176 template< typename Type // Data type of the matrix
177  , bool SO = defaultStorageOrder > // Storage order
178 class DynamicMatrix : public DenseMatrix< DynamicMatrix<Type,SO>, SO >
179 {
180  private:
181  //**Type definitions****************************************************************************
183  //**********************************************************************************************
184 
185  public:
186  //**Type definitions****************************************************************************
188  typedef This ResultType;
191  typedef Type ElementType;
192  typedef typename IT::Type IntrinsicType;
193  typedef const Type& ReturnType;
194  typedef const This& CompositeType;
195  typedef Type& Reference;
196  typedef const Type& ConstReference;
197  typedef Type* Pointer;
198  typedef const Type* ConstPointer;
201  //**********************************************************************************************
202 
203  //**Compilation flags***************************************************************************
205 
209  enum { vectorizable = IsVectorizable<Type>::value };
210 
212 
215  enum { smpAssignable = !IsSMPAssignable<Type>::value };
216  //**********************************************************************************************
217 
218  //**Constructors********************************************************************************
221  explicit inline DynamicMatrix();
222  explicit inline DynamicMatrix( size_t m, size_t n );
223  explicit inline DynamicMatrix( size_t m, size_t n, const Type& init );
224  template< typename Other > explicit inline DynamicMatrix( size_t m, size_t n, const Other* array );
225 
226  template< typename Other, size_t M, size_t N >
227  explicit inline DynamicMatrix( const Other (&array)[M][N] );
228 
229  inline DynamicMatrix( const DynamicMatrix& m );
230  template< typename MT, bool SO2 > inline DynamicMatrix( const Matrix<MT,SO2>& m );
232  //**********************************************************************************************
233 
234  //**Destructor**********************************************************************************
237  inline ~DynamicMatrix();
239  //**********************************************************************************************
240 
241  //**Data access functions***********************************************************************
244  inline Reference operator()( size_t i, size_t j );
245  inline ConstReference operator()( size_t i, size_t j ) const;
246  inline Pointer data ();
247  inline ConstPointer data () const;
248  inline Pointer data ( size_t i );
249  inline ConstPointer data ( size_t i ) const;
250  inline Iterator begin ( size_t i );
251  inline ConstIterator begin ( size_t i ) const;
252  inline ConstIterator cbegin( size_t i ) const;
253  inline Iterator end ( size_t i );
254  inline ConstIterator end ( size_t i ) const;
255  inline ConstIterator cend ( size_t i ) const;
257  //**********************************************************************************************
258 
259  //**Assignment operators************************************************************************
262  template< typename Other, size_t M, size_t N >
263  inline DynamicMatrix& operator=( const Other (&array)[M][N] );
264 
265  inline DynamicMatrix& operator= ( Type set );
266  inline DynamicMatrix& operator= ( const DynamicMatrix& set );
267  template< typename MT, bool SO2 > inline DynamicMatrix& operator= ( const Matrix<MT,SO2>& rhs );
268  template< typename MT, bool SO2 > inline DynamicMatrix& operator+=( const Matrix<MT,SO2>& rhs );
269  template< typename MT, bool SO2 > inline DynamicMatrix& operator-=( const Matrix<MT,SO2>& rhs );
270  template< typename MT, bool SO2 > inline DynamicMatrix& operator*=( const Matrix<MT,SO2>& rhs );
271 
272  template< typename Other >
273  inline typename EnableIf< IsNumeric<Other>, DynamicMatrix >::Type&
274  operator*=( Other rhs );
275 
276  template< typename Other >
277  inline typename EnableIf< IsNumeric<Other>, DynamicMatrix >::Type&
278  operator/=( Other rhs );
280  //**********************************************************************************************
281 
282  //**Utility functions***************************************************************************
285  inline size_t rows() const;
286  inline size_t columns() const;
287  inline size_t spacing() const;
288  inline size_t capacity() const;
289  inline size_t capacity( size_t i ) const;
290  inline size_t nonZeros() const;
291  inline size_t nonZeros( size_t i ) const;
292  inline void reset();
293  inline void reset( size_t i );
294  inline void clear();
295  void resize ( size_t m, size_t n, bool preserve=true );
296  inline void extend ( size_t m, size_t n, bool preserve=true );
297  inline void reserve( size_t elements );
298  inline DynamicMatrix& transpose();
299  template< typename Other > inline DynamicMatrix& scale( Other scalar );
300  inline void swap( DynamicMatrix& m ) /* throw() */;
302  //**********************************************************************************************
303 
304  private:
305  //**********************************************************************************************
307  template< typename MT >
309  struct VectorizedAssign {
310  enum { value = vectorizable && MT::vectorizable &&
311  IsSame<Type,typename MT::ElementType>::value };
312  };
314  //**********************************************************************************************
315 
316  //**********************************************************************************************
318  template< typename MT >
320  struct VectorizedAddAssign {
321  enum { value = vectorizable && MT::vectorizable &&
322  IsSame<Type,typename MT::ElementType>::value &&
323  IntrinsicTrait<Type>::addition };
324  };
326  //**********************************************************************************************
327 
328  //**********************************************************************************************
330  template< typename MT >
332  struct VectorizedSubAssign {
333  enum { value = vectorizable && MT::vectorizable &&
334  IsSame<Type,typename MT::ElementType>::value &&
335  IntrinsicTrait<Type>::subtraction };
336  };
338  //**********************************************************************************************
339 
340  public:
341  //**Expression template evaluation functions****************************************************
344  template< typename Other > inline bool canAlias ( const Other* alias ) const;
345  template< typename Other > inline bool isAliased( const Other* alias ) const;
346 
347  inline bool isAligned () const;
348  inline bool canSMPAssign() const;
349 
350  inline IntrinsicType load ( size_t i, size_t j ) const;
351  inline IntrinsicType loadu ( size_t i, size_t j ) const;
352  inline void store ( size_t i, size_t j, const IntrinsicType& value );
353  inline void storeu( size_t i, size_t j, const IntrinsicType& value );
354  inline void stream( size_t i, size_t j, const IntrinsicType& value );
355 
356  template< typename MT >
357  inline typename DisableIf< VectorizedAssign<MT> >::Type
358  assign( const DenseMatrix<MT,SO>& rhs );
359 
360  template< typename MT >
361  inline typename EnableIf< VectorizedAssign<MT> >::Type
362  assign( const DenseMatrix<MT,SO>& rhs );
363 
364  template< typename MT > inline void assign( const DenseMatrix<MT,!SO>& rhs );
365  template< typename MT > inline void assign( const SparseMatrix<MT,SO>& rhs );
366  template< typename MT > inline void assign( const SparseMatrix<MT,!SO>& rhs );
367 
368  template< typename MT >
369  inline typename DisableIf< VectorizedAddAssign<MT> >::Type
370  addAssign( const DenseMatrix<MT,SO>& rhs );
371 
372  template< typename MT >
373  inline typename EnableIf< VectorizedAddAssign<MT> >::Type
374  addAssign( const DenseMatrix<MT,SO>& rhs );
375 
376  template< typename MT > inline void addAssign( const DenseMatrix<MT,!SO>& rhs );
377  template< typename MT > inline void addAssign( const SparseMatrix<MT,SO>& rhs );
378  template< typename MT > inline void addAssign( const SparseMatrix<MT,!SO>& rhs );
379 
380  template< typename MT >
381  inline typename DisableIf< VectorizedSubAssign<MT> >::Type
382  subAssign( const DenseMatrix<MT,SO>& rhs );
383 
384  template< typename MT >
385  inline typename EnableIf< VectorizedSubAssign<MT> >::Type
386  subAssign( const DenseMatrix<MT,SO>& rhs );
387 
388  template< typename MT > inline void subAssign( const DenseMatrix<MT,!SO>& rhs );
389  template< typename MT > inline void subAssign( const SparseMatrix<MT,SO>& rhs );
390  template< typename MT > inline void subAssign( const SparseMatrix<MT,!SO>& rhs );
392  //**********************************************************************************************
393 
394  private:
395  //**Utility functions***************************************************************************
398  inline size_t adjustColumns( size_t minColumns ) const;
400  //**********************************************************************************************
401 
402  //**Member variables****************************************************************************
405  size_t m_;
406  size_t n_;
407  size_t nn_;
408  size_t capacity_;
410 
420  //**********************************************************************************************
421 
422  //**Compile time checks*************************************************************************
429  //**********************************************************************************************
430 };
431 //*************************************************************************************************
432 
433 
434 
435 
436 //=================================================================================================
437 //
438 // CONSTRUCTORS
439 //
440 //=================================================================================================
441 
442 //*************************************************************************************************
445 template< typename Type // Data type of the matrix
446  , bool SO > // Storage order
448  : m_ ( 0UL ) // The current number of rows of the matrix
449  , n_ ( 0UL ) // The current number of columns of the matrix
450  , nn_ ( 0UL ) // The alignment adjusted number of columns
451  , capacity_( 0UL ) // The maximum capacity of the matrix
452  , v_ ( NULL ) // The matrix elements
453 {}
454 //*************************************************************************************************
455 
456 
457 //*************************************************************************************************
466 template< typename Type // Data type of the matrix
467  , bool SO > // Storage order
468 inline DynamicMatrix<Type,SO>::DynamicMatrix( size_t m, size_t n )
469  : m_ ( m ) // The current number of rows of the matrix
470  , n_ ( n ) // The current number of columns of the matrix
471  , nn_ ( adjustColumns( n ) ) // The alignment adjusted number of columns
472  , capacity_( m_*nn_ ) // The maximum capacity of the matrix
473  , v_ ( allocate<Type>( capacity_ ) ) // The matrix elements
474 {
476  for( size_t i=0UL; i<m_; ++i ) {
477  for( size_t j=n_; j<nn_; ++j )
478  v_[i*nn_+j] = Type();
479  }
480  }
481 }
482 //*************************************************************************************************
483 
484 
485 //*************************************************************************************************
494 template< typename Type // Data type of the matrix
495  , bool SO > // Storage order
496 inline DynamicMatrix<Type,SO>::DynamicMatrix( size_t m, size_t n, const Type& init )
497  : m_ ( m ) // The current number of rows of the matrix
498  , n_ ( n ) // The current number of columns of the matrix
499  , nn_ ( adjustColumns( n ) ) // The alignment adjusted number of columns
500  , capacity_( m_*nn_ ) // The maximum capacity of the matrix
501  , v_ ( allocate<Type>( capacity_ ) ) // The matrix elements
502 {
503  for( size_t i=0UL; i<m; ++i ) {
504  for( size_t j=0UL; j<n_; ++j )
505  v_[i*nn_+j] = init;
506 
508  for( size_t j=n_; j<nn_; ++j )
509  v_[i*nn_+j] = Type();
510  }
511  }
512 }
513 //*************************************************************************************************
514 
515 
516 //*************************************************************************************************
539 template< typename Type // Data type of the matrix
540  , bool SO > // Storage order
541 template< typename Other > // Data type of the initialization array
542 inline DynamicMatrix<Type,SO>::DynamicMatrix( size_t m, size_t n, const Other* array )
543  : m_ ( m ) // The current number of rows of the matrix
544  , n_ ( n ) // The current number of columns of the matrix
545  , nn_ ( adjustColumns( n ) ) // The alignment adjusted number of columns
546  , capacity_( m_*nn_ ) // The maximum capacity of the matrix
547  , v_ ( allocate<Type>( capacity_ ) ) // The matrix elements
548 {
549  for( size_t i=0UL; i<m; ++i ) {
550  for( size_t j=0UL; j<n; ++j )
551  v_[i*nn_+j] = array[i*n+j];
552 
554  for( size_t j=n; j<nn_; ++j )
555  v_[i*nn_+j] = Type();
556  }
557  }
558 }
559 //*************************************************************************************************
560 
561 
562 //*************************************************************************************************
583 template< typename Type // Data type of the matrix
584  , bool SO > // Storage order
585 template< typename Other // Data type of the initialization array
586  , size_t M // Number of rows of the initialization array
587  , size_t N > // Number of columns of the initialization array
588 inline DynamicMatrix<Type,SO>::DynamicMatrix( const Other (&array)[M][N] )
589  : m_ ( M ) // The current number of rows of the matrix
590  , n_ ( N ) // The current number of columns of the matrix
591  , nn_ ( adjustColumns( N ) ) // The alignment adjusted number of columns
592  , capacity_( m_*nn_ ) // The maximum capacity of the matrix
593  , v_ ( allocate<Type>( capacity_ ) ) // The matrix elements
594 {
595  for( size_t i=0UL; i<M; ++i ) {
596  for( size_t j=0UL; j<N; ++j )
597  v_[i*nn_+j] = array[i][j];
598 
600  for( size_t j=N; j<nn_; ++j )
601  v_[i*nn_+j] = Type();
602  }
603  }
604 }
605 //*************************************************************************************************
606 
607 
608 //*************************************************************************************************
616 template< typename Type // Data type of the matrix
617  , bool SO > // Storage order
619  : m_ ( m.m_ ) // The current number of rows of the matrix
620  , n_ ( m.n_ ) // The current number of columns of the matrix
621  , nn_ ( m.nn_ ) // The alignment adjusted number of columns
622  , capacity_( m_*nn_ ) // The maximum capacity of the matrix
623  , v_ ( allocate<Type>( capacity_ ) ) // The matrix elements
624 {
625  BLAZE_INTERNAL_ASSERT( capacity_ <= m.capacity_, "Invalid capacity estimation" );
626 
627  for( size_t i=0UL; i<capacity_; ++i )
628  v_[i] = m.v_[i];
629 }
630 //*************************************************************************************************
631 
632 
633 //*************************************************************************************************
638 template< typename Type // Data type of the matrix
639  , bool SO > // Storage order
640 template< typename MT // Type of the foreign matrix
641  , bool SO2 > // Storage order of the foreign matrix
643  : m_ ( (~m).rows() ) // The current number of rows of the matrix
644  , n_ ( (~m).columns() ) // The current number of columns of the matrix
645  , nn_ ( adjustColumns( n_ ) ) // The alignment adjusted number of columns
646  , capacity_( m_*nn_ ) // The maximum capacity of the matrix
647  , v_ ( allocate<Type>( capacity_ ) ) // The matrix elements
648 {
649  for( size_t i=0UL; i<m_; ++i ) {
650  for( size_t j=( IsSparseMatrix<MT>::value ? 0UL : n_ );
651  j<( IsVectorizable<Type>::value ? nn_ : n_ ); ++j ) {
652  v_[i*nn_+j] = Type();
653  }
654  }
655 
656  smpAssign( *this, ~m );
657 }
658 //*************************************************************************************************
659 
660 
661 
662 
663 //=================================================================================================
664 //
665 // DESTRUCTOR
666 //
667 //=================================================================================================
668 
669 //*************************************************************************************************
672 template< typename Type // Data type of the matrix
673  , bool SO > // Storage order
675 {
676  deallocate( v_ );
677 }
678 //*************************************************************************************************
679 
680 
681 
682 
683 //=================================================================================================
684 //
685 // DATA ACCESS FUNCTIONS
686 //
687 //=================================================================================================
688 
689 //*************************************************************************************************
696 template< typename Type // Data type of the matrix
697  , bool SO > // Storage order
698 inline typename DynamicMatrix<Type,SO>::Reference
700 {
701  BLAZE_USER_ASSERT( i<m_, "Invalid row access index" );
702  BLAZE_USER_ASSERT( j<n_, "Invalid column access index" );
703  return v_[i*nn_+j];
704 }
705 //*************************************************************************************************
706 
707 
708 //*************************************************************************************************
715 template< typename Type // Data type of the matrix
716  , bool SO > // Storage order
718  DynamicMatrix<Type,SO>::operator()( size_t i, size_t j ) const
719 {
720  BLAZE_USER_ASSERT( i<m_, "Invalid row access index" );
721  BLAZE_USER_ASSERT( j<n_, "Invalid column access index" );
722  return v_[i*nn_+j];
723 }
724 //*************************************************************************************************
725 
726 
727 //*************************************************************************************************
739 template< typename Type // Data type of the matrix
740  , bool SO > // Storage order
742 {
743  return v_;
744 }
745 //*************************************************************************************************
746 
747 
748 //*************************************************************************************************
760 template< typename Type // Data type of the matrix
761  , bool SO > // Storage order
763 {
764  return v_;
765 }
766 //*************************************************************************************************
767 
768 
769 //*************************************************************************************************
777 template< typename Type // Data type of the matrix
778  , bool SO > // Storage order
780 {
781  BLAZE_USER_ASSERT( i < m_, "Invalid dense matrix row access index" );
782  return v_ + i*nn_;
783 }
784 //*************************************************************************************************
785 
786 
787 //*************************************************************************************************
795 template< typename Type // Data type of the matrix
796  , bool SO > // Storage order
798 {
799  BLAZE_USER_ASSERT( i < m_, "Invalid dense matrix row access index" );
800  return v_ + i*nn_;
801 }
802 //*************************************************************************************************
803 
804 
805 //*************************************************************************************************
816 template< typename Type // Data type of the matrix
817  , bool SO > // Storage order
818 inline typename DynamicMatrix<Type,SO>::Iterator
820 {
821  BLAZE_USER_ASSERT( i < m_, "Invalid dense matrix row access index" );
822  return Iterator( v_ + i*nn_ );
823 }
824 //*************************************************************************************************
825 
826 
827 //*************************************************************************************************
838 template< typename Type // Data type of the matrix
839  , bool SO > // Storage order
842 {
843  BLAZE_USER_ASSERT( i < m_, "Invalid dense matrix row access index" );
844  return ConstIterator( v_ + i*nn_ );
845 }
846 //*************************************************************************************************
847 
848 
849 //*************************************************************************************************
860 template< typename Type // Data type of the matrix
861  , bool SO > // Storage order
864 {
865  BLAZE_USER_ASSERT( i < m_, "Invalid dense matrix row access index" );
866  return ConstIterator( v_ + i*nn_ );
867 }
868 //*************************************************************************************************
869 
870 
871 //*************************************************************************************************
882 template< typename Type // Data type of the matrix
883  , bool SO > // Storage order
884 inline typename DynamicMatrix<Type,SO>::Iterator
886 {
887  BLAZE_USER_ASSERT( i < m_, "Invalid dense matrix row access index" );
888  return Iterator( v_ + i*nn_ + n_ );
889 }
890 //*************************************************************************************************
891 
892 
893 //*************************************************************************************************
904 template< typename Type // Data type of the matrix
905  , bool SO > // Storage order
907  DynamicMatrix<Type,SO>::end( size_t i ) const
908 {
909  BLAZE_USER_ASSERT( i < m_, "Invalid dense matrix row access index" );
910  return ConstIterator( v_ + i*nn_ + n_ );
911 }
912 //*************************************************************************************************
913 
914 
915 //*************************************************************************************************
926 template< typename Type // Data type of the matrix
927  , bool SO > // Storage order
930 {
931  BLAZE_USER_ASSERT( i < m_, "Invalid dense matrix row access index" );
932  return ConstIterator( v_ + i*nn_ + n_ );
933 }
934 //*************************************************************************************************
935 
936 
937 
938 
939 //=================================================================================================
940 //
941 // ASSIGNMENT OPERATORS
942 //
943 //=================================================================================================
944 
945 //*************************************************************************************************
966 template< typename Type // Data type of the matrix
967  , bool SO > // Storage order
968 template< typename Other // Data type of the initialization array
969  , size_t M // Number of rows of the initialization array
970  , size_t N > // Number of columns of the initialization array
971 inline DynamicMatrix<Type,SO>& DynamicMatrix<Type,SO>::operator=( const Other (&array)[M][N] )
972 {
973  resize( M, N, false );
974 
975  for( size_t i=0UL; i<M; ++i )
976  for( size_t j=0UL; j<N; ++j )
977  v_[i*nn_+j] = array[i][j];
978 
979  return *this;
980 }
981 //*************************************************************************************************
982 
983 
984 //*************************************************************************************************
990 template< typename Type // Data type of the matrix
991  , bool SO > // Storage order
993 {
994  for( size_t i=0UL; i<m_; ++i )
995  for( size_t j=0UL; j<n_; ++j )
996  v_[i*nn_+j] = rhs;
997 
998  return *this;
999 }
1000 //*************************************************************************************************
1001 
1002 
1003 //*************************************************************************************************
1012 template< typename Type // Data type of the matrix
1013  , bool SO > // Storage order
1015 {
1016  if( &rhs == this ) return *this;
1017 
1018  resize( rhs.m_, rhs.n_, false );
1019  smpAssign( *this, ~rhs );
1020 
1021  return *this;
1022 }
1023 //*************************************************************************************************
1024 
1025 
1026 //*************************************************************************************************
1035 template< typename Type // Data type of the matrix
1036  , bool SO > // Storage order
1037 template< typename MT // Type of the right-hand side matrix
1038  , bool SO2 > // Storage order of the right-hand side matrix
1040 {
1041  if( (~rhs).canAlias( this ) ) {
1042  DynamicMatrix tmp( ~rhs );
1043  swap( tmp );
1044  }
1045  else {
1046  resize( (~rhs).rows(), (~rhs).columns(), false );
1048  reset();
1049  smpAssign( *this, ~rhs );
1050  }
1051 
1052  return *this;
1053 }
1054 //*************************************************************************************************
1055 
1056 
1057 //*************************************************************************************************
1067 template< typename Type // Data type of the matrix
1068  , bool SO > // Storage order
1069 template< typename MT // Type of the right-hand side matrix
1070  , bool SO2 > // Storage order of the right-hand side matrix
1072 {
1073  if( (~rhs).rows() != m_ || (~rhs).columns() != n_ )
1074  throw std::invalid_argument( "Matrix sizes do not match" );
1075 
1076  if( (~rhs).canAlias( this ) ) {
1077  typename MT::ResultType tmp( ~rhs );
1078  smpAddAssign( *this, tmp );
1079  }
1080  else {
1081  smpAddAssign( *this, ~rhs );
1082  }
1083 
1084  return *this;
1085 }
1086 //*************************************************************************************************
1087 
1088 
1089 //*************************************************************************************************
1099 template< typename Type // Data type of the matrix
1100  , bool SO > // Storage order
1101 template< typename MT // Type of the right-hand side matrix
1102  , bool SO2 > // Storage order of the right-hand side matrix
1104 {
1105  if( (~rhs).rows() != m_ || (~rhs).columns() != n_ )
1106  throw std::invalid_argument( "Matrix sizes do not match" );
1107 
1108  if( (~rhs).canAlias( this ) ) {
1109  typename MT::ResultType tmp( ~rhs );
1110  smpSubAssign( *this, tmp );
1111  }
1112  else {
1113  smpSubAssign( *this, ~rhs );
1114  }
1115 
1116  return *this;
1117 }
1118 //*************************************************************************************************
1119 
1120 
1121 //*************************************************************************************************
1131 template< typename Type // Data type of the matrix
1132  , bool SO > // Storage order
1133 template< typename MT // Type of the right-hand side matrix
1134  , bool SO2 > // Storage order of the right-hand side matrix
1136 {
1137  if( (~rhs).rows() != n_ )
1138  throw std::invalid_argument( "Matrix sizes do not match" );
1139 
1140  DynamicMatrix tmp( *this * (~rhs) );
1141  swap( tmp );
1142 
1143  return *this;
1144 }
1145 //*************************************************************************************************
1146 
1147 
1148 //*************************************************************************************************
1155 template< typename Type // Data type of the matrix
1156  , bool SO > // Storage order
1157 template< typename Other > // Data type of the right-hand side scalar
1158 inline typename EnableIf< IsNumeric<Other>, DynamicMatrix<Type,SO> >::Type&
1160 {
1161  smpAssign( *this, (*this) * rhs );
1162  return *this;
1163 }
1164 //*************************************************************************************************
1165 
1166 
1167 //*************************************************************************************************
1174 template< typename Type // Data type of the matrix
1175  , bool SO > // Storage order
1176 template< typename Other > // Data type of the right-hand side scalar
1177 inline typename EnableIf< IsNumeric<Other>, DynamicMatrix<Type,SO> >::Type&
1179 {
1180  BLAZE_USER_ASSERT( rhs != Other(0), "Division by zero detected" );
1181 
1182  smpAssign( *this, (*this) / rhs );
1183  return *this;
1184 }
1185 //*************************************************************************************************
1186 
1187 
1188 
1189 
1190 //=================================================================================================
1191 //
1192 // UTILITY FUNCTIONS
1193 //
1194 //=================================================================================================
1195 
1196 //*************************************************************************************************
1201 template< typename Type // Data type of the matrix
1202  , bool SO > // Storage order
1203 inline size_t DynamicMatrix<Type,SO>::rows() const
1204 {
1205  return m_;
1206 }
1207 //*************************************************************************************************
1208 
1209 
1210 //*************************************************************************************************
1215 template< typename Type // Data type of the matrix
1216  , bool SO > // Storage order
1217 inline size_t DynamicMatrix<Type,SO>::columns() const
1218 {
1219  return n_;
1220 }
1221 //*************************************************************************************************
1222 
1223 
1224 //*************************************************************************************************
1234 template< typename Type // Data type of the matrix
1235  , bool SO > // Storage order
1236 inline size_t DynamicMatrix<Type,SO>::spacing() const
1237 {
1238  return nn_;
1239 }
1240 //*************************************************************************************************
1241 
1242 
1243 //*************************************************************************************************
1248 template< typename Type // Data type of the matrix
1249  , bool SO > // Storage order
1251 {
1252  return capacity_;
1253 }
1254 //*************************************************************************************************
1255 
1256 
1257 //*************************************************************************************************
1268 template< typename Type // Data type of the sparse matrix
1269  , bool SO > // Storage order
1270 inline size_t DynamicMatrix<Type,SO>::capacity( size_t i ) const
1271 {
1272  UNUSED_PARAMETER( i );
1273  BLAZE_USER_ASSERT( i < rows(), "Invalid row access index" );
1274  return nn_;
1275 }
1276 //*************************************************************************************************
1277 
1278 
1279 //*************************************************************************************************
1284 template< typename Type // Data type of the matrix
1285  , bool SO > // Storage order
1287 {
1288  size_t nonzeros( 0UL );
1289 
1290  for( size_t i=0UL; i<m_; ++i )
1291  for( size_t j=0UL; j<n_; ++j )
1292  if( !isDefault( v_[i*nn_+j] ) )
1293  ++nonzeros;
1294 
1295  return nonzeros;
1296 }
1297 //*************************************************************************************************
1298 
1299 
1300 //*************************************************************************************************
1311 template< typename Type // Data type of the matrix
1312  , bool SO > // Storage order
1313 inline size_t DynamicMatrix<Type,SO>::nonZeros( size_t i ) const
1314 {
1315  BLAZE_USER_ASSERT( i < rows(), "Invalid row access index" );
1316 
1317  const size_t jend( (i+1UL)*nn_ );
1318  size_t nonzeros( 0UL );
1319 
1320  for( size_t j=i*nn_; j<jend; ++j )
1321  if( !isDefault( v_[j] ) )
1322  ++nonzeros;
1323 
1324  return nonzeros;
1325 }
1326 //*************************************************************************************************
1327 
1328 
1329 //*************************************************************************************************
1334 template< typename Type // Data type of the matrix
1335  , bool SO > // Storage order
1337 {
1338  using blaze::reset;
1339 
1340  for( size_t i=0UL; i<m_; ++i )
1341  for( size_t j=0UL; j<n_; ++j )
1342  reset( v_[i*nn_+j] );
1343 }
1344 //*************************************************************************************************
1345 
1346 
1347 //*************************************************************************************************
1358 template< typename Type // Data type of the sparse matrix
1359  , bool SO > // Storage order
1360 inline void DynamicMatrix<Type,SO>::reset( size_t i )
1361 {
1362  using blaze::reset;
1363 
1364  BLAZE_USER_ASSERT( i < rows(), "Invalid row access index" );
1365  for( size_t j=0UL; j<n_; ++j )
1366  reset( v_[i*nn_+j] );
1367 }
1368 //*************************************************************************************************
1369 
1370 
1371 //*************************************************************************************************
1378 template< typename Type // Data type of the matrix
1379  , bool SO > // Storage order
1381 {
1382  resize( 0UL, 0UL, false );
1383 }
1384 //*************************************************************************************************
1385 
1386 
1387 //*************************************************************************************************
1421 template< typename Type // Data type of the matrix
1422  , bool SO > // Storage order
1423 void DynamicMatrix<Type,SO>::resize( size_t m, size_t n, bool preserve )
1424 {
1425  using blaze::min;
1426 
1427  if( m == m_ && n == n_ ) return;
1428 
1429  const size_t nn( adjustColumns( n ) );
1430 
1431  if( preserve )
1432  {
1433  Type* BLAZE_RESTRICT v = allocate<Type>( m*nn );
1434  const size_t min_m( min( m, m_ ) );
1435  const size_t min_n( min( n, n_ ) );
1436 
1437  for( size_t i=0UL; i<min_m; ++i )
1438  for( size_t j=0UL; j<min_n; ++j )
1439  v[i*nn+j] = v_[i*nn_+j];
1440 
1441  std::swap( v_, v );
1442  deallocate( v );
1443  capacity_ = m*nn;
1444  }
1445  else if( m*nn > capacity_ ) {
1446  Type* BLAZE_RESTRICT v = allocate<Type>( m*nn );
1447  std::swap( v_, v );
1448  deallocate( v );
1449  capacity_ = m*nn;
1450  }
1451 
1453  for( size_t i=0UL; i<m; ++i )
1454  for( size_t j=n; j<nn; ++j )
1455  v_[i*nn+j] = Type();
1456  }
1457 
1458  m_ = m;
1459  n_ = n;
1460  nn_ = nn;
1461 }
1462 //*************************************************************************************************
1463 
1464 
1465 //*************************************************************************************************
1479 template< typename Type // Data type of the matrix
1480  , bool SO > // Storage order
1481 inline void DynamicMatrix<Type,SO>::extend( size_t m, size_t n, bool preserve )
1482 {
1483  resize( m_+m, n_+n, preserve );
1484 }
1485 //*************************************************************************************************
1486 
1487 
1488 //*************************************************************************************************
1497 template< typename Type // Data type of the matrix
1498  , bool SO > // Storage order
1499 inline void DynamicMatrix<Type,SO>::reserve( size_t elements )
1500 {
1501  if( elements > capacity_ )
1502  {
1503  // Allocating a new array
1504  Type* BLAZE_RESTRICT tmp = allocate<Type>( elements );
1505 
1506  // Initializing the new array
1507  std::copy( v_, v_+capacity_, tmp );
1508 
1510  for( size_t i=capacity_; i<elements; ++i )
1511  tmp[i] = Type();
1512  }
1513 
1514  // Replacing the old array
1515  std::swap( tmp, v_ );
1516  deallocate( tmp );
1517  capacity_ = elements;
1518  }
1519 }
1520 //*************************************************************************************************
1521 
1522 
1523 //*************************************************************************************************
1528 template< typename Type // Data type of the matrix
1529  , bool SO > // Storage order
1531 {
1532  DynamicMatrix tmp( trans(*this) );
1533  swap( tmp );
1534  return *this;
1535 }
1536 //*************************************************************************************************
1537 
1538 
1539 //*************************************************************************************************
1545 template< typename Type // Data type of the matrix
1546  , bool SO > // Storage order
1547 template< typename Other > // Data type of the scalar value
1549 {
1550  for( size_t i=0UL; i<m_; ++i )
1551  for( size_t j=0UL; j<n_; ++j )
1552  v_[i*nn_+j] *= scalar;
1553 
1554  return *this;
1555 }
1556 //*************************************************************************************************
1557 
1558 
1559 //*************************************************************************************************
1566 template< typename Type // Data type of the matrix
1567  , bool SO > // Storage order
1568 inline void DynamicMatrix<Type,SO>::swap( DynamicMatrix& m ) /* throw() */
1569 {
1570  std::swap( m_ , m.m_ );
1571  std::swap( n_ , m.n_ );
1572  std::swap( nn_, m.nn_ );
1574  std::swap( v_ , m.v_ );
1575 }
1576 //*************************************************************************************************
1577 
1578 
1579 //*************************************************************************************************
1585 template< typename Type // Data type of the matrix
1586  , bool SO > // Storage order
1587 inline size_t DynamicMatrix<Type,SO>::adjustColumns( size_t minColumns ) const
1588 {
1590  return minColumns + ( IT::size - ( minColumns % IT::size ) ) % IT::size;
1591  else return minColumns;
1592 }
1593 //*************************************************************************************************
1594 
1595 
1596 
1597 
1598 //=================================================================================================
1599 //
1600 // EXPRESSION TEMPLATE EVALUATION FUNCTIONS
1601 //
1602 //=================================================================================================
1603 
1604 //*************************************************************************************************
1614 template< typename Type // Data type of the matrix
1615  , bool SO > // Storage order
1616 template< typename Other > // Data type of the foreign expression
1617 inline bool DynamicMatrix<Type,SO>::canAlias( const Other* alias ) const
1618 {
1619  return static_cast<const void*>( this ) == static_cast<const void*>( alias );
1620 }
1621 //*************************************************************************************************
1622 
1623 
1624 //*************************************************************************************************
1634 template< typename Type // Data type of the matrix
1635  , bool SO > // Storage order
1636 template< typename Other > // Data type of the foreign expression
1637 inline bool DynamicMatrix<Type,SO>::isAliased( const Other* alias ) const
1638 {
1639  return static_cast<const void*>( this ) == static_cast<const void*>( alias );
1640 }
1641 //*************************************************************************************************
1642 
1643 
1644 //*************************************************************************************************
1653 template< typename Type // Data type of the matrix
1654  , bool SO > // Storage order
1656 {
1657  return true;
1658 }
1659 //*************************************************************************************************
1660 
1661 
1662 //*************************************************************************************************
1672 template< typename Type // Data type of the matrix
1673  , bool SO > // Storage order
1675 {
1676  return ( rows() > SMP_DMATASSIGN_THRESHOLD );
1677 }
1678 //*************************************************************************************************
1679 
1680 
1681 //*************************************************************************************************
1696 template< typename Type // Data type of the matrix
1697  , bool SO > // Storage order
1699  DynamicMatrix<Type,SO>::load( size_t i, size_t j ) const
1700 {
1701  using blaze::load;
1702 
1704 
1705  BLAZE_INTERNAL_ASSERT( i < m_ , "Invalid row access index" );
1706  BLAZE_INTERNAL_ASSERT( j < n_ , "Invalid column access index" );
1707  BLAZE_INTERNAL_ASSERT( j + IT::size <= nn_, "Invalid column access index" );
1708  BLAZE_INTERNAL_ASSERT( j % IT::size == 0UL, "Invalid column access index" );
1709 
1710  return load( v_+i*nn_+j );
1711 }
1712 //*************************************************************************************************
1713 
1714 
1715 //*************************************************************************************************
1730 template< typename Type // Data type of the matrix
1731  , bool SO > // Storage order
1733  DynamicMatrix<Type,SO>::loadu( size_t i, size_t j ) const
1734 {
1735  using blaze::loadu;
1736 
1738 
1739  BLAZE_INTERNAL_ASSERT( i < m_ , "Invalid row access index" );
1740  BLAZE_INTERNAL_ASSERT( j < n_ , "Invalid column access index" );
1741  BLAZE_INTERNAL_ASSERT( j + IT::size <= nn_, "Invalid column access index" );
1742 
1743  return loadu( v_+i*nn_+j );
1744 }
1745 //*************************************************************************************************
1746 
1747 
1748 //*************************************************************************************************
1764 template< typename Type // Data type of the matrix
1765  , bool SO > // Storage order
1766 inline void DynamicMatrix<Type,SO>::store( size_t i, size_t j, const IntrinsicType& value )
1767 {
1768  using blaze::store;
1769 
1771 
1772  BLAZE_INTERNAL_ASSERT( i < m_ , "Invalid row access index" );
1773  BLAZE_INTERNAL_ASSERT( j < n_ , "Invalid column access index" );
1774  BLAZE_INTERNAL_ASSERT( j + IT::size <= nn_, "Invalid column access index" );
1775  BLAZE_INTERNAL_ASSERT( j % IT::size == 0UL, "Invalid column access index" );
1776 
1777  store( v_+i*nn_+j, value );
1778 }
1779 //*************************************************************************************************
1780 
1781 
1782 //*************************************************************************************************
1798 template< typename Type // Data type of the matrix
1799  , bool SO > // Storage order
1800 inline void DynamicMatrix<Type,SO>::storeu( size_t i, size_t j, const IntrinsicType& value )
1801 {
1802  using blaze::storeu;
1803 
1805 
1806  BLAZE_INTERNAL_ASSERT( i < m_ , "Invalid row access index" );
1807  BLAZE_INTERNAL_ASSERT( j < n_ , "Invalid column access index" );
1808  BLAZE_INTERNAL_ASSERT( j + IT::size <= nn_, "Invalid column access index" );
1809 
1810  storeu( v_+i*nn_+j, value );
1811 }
1812 //*************************************************************************************************
1813 
1814 
1815 //*************************************************************************************************
1831 template< typename Type // Data type of the matrix
1832  , bool SO > // Storage order
1833 inline void DynamicMatrix<Type,SO>::stream( size_t i, size_t j, const IntrinsicType& value )
1834 {
1835  using blaze::stream;
1836 
1838 
1839  BLAZE_INTERNAL_ASSERT( i < m_ , "Invalid row access index" );
1840  BLAZE_INTERNAL_ASSERT( j < n_ , "Invalid column access index" );
1841  BLAZE_INTERNAL_ASSERT( j + IT::size <= nn_, "Invalid column access index" );
1842  BLAZE_INTERNAL_ASSERT( j % IT::size == 0UL, "Invalid column access index" );
1843 
1844  stream( v_+i*nn_+j, value );
1845 }
1846 //*************************************************************************************************
1847 
1848 
1849 //*************************************************************************************************
1860 template< typename Type // Data type of the matrix
1861  , bool SO > // Storage order
1862 template< typename MT > // Type of the right-hand side dense matrix
1863 inline typename DisableIf< typename DynamicMatrix<Type,SO>::BLAZE_TEMPLATE VectorizedAssign<MT> >::Type
1865 {
1866  BLAZE_INTERNAL_ASSERT( m_ == (~rhs).rows() , "Invalid number of rows" );
1867  BLAZE_INTERNAL_ASSERT( n_ == (~rhs).columns(), "Invalid number of columns" );
1868 
1869  const size_t jend( n_ & size_t(-2) );
1870  BLAZE_INTERNAL_ASSERT( ( n_ - ( n_ % 2UL ) ) == jend, "Invalid end calculation" );
1871 
1872  for( size_t i=0UL; i<m_; ++i ) {
1873  for( size_t j=0UL; j<jend; j+=2UL ) {
1874  v_[i*nn_+j ] = (~rhs)(i,j );
1875  v_[i*nn_+j+1UL] = (~rhs)(i,j+1UL);
1876  }
1877  if( jend < n_ ) {
1878  v_[i*nn_+jend] = (~rhs)(i,jend);
1879  }
1880  }
1881 }
1882 //*************************************************************************************************
1883 
1884 
1885 //*************************************************************************************************
1896 template< typename Type // Data type of the matrix
1897  , bool SO > // Storage order
1898 template< typename MT > // Type of the right-hand side dense matrix
1899 inline typename EnableIf< typename DynamicMatrix<Type,SO>::BLAZE_TEMPLATE VectorizedAssign<MT> >::Type
1901 {
1902  using blaze::store;
1903  using blaze::stream;
1904 
1905  BLAZE_INTERNAL_ASSERT( m_ == (~rhs).rows() , "Invalid number of rows" );
1906  BLAZE_INTERNAL_ASSERT( n_ == (~rhs).columns(), "Invalid number of columns" );
1907 
1909 
1910  if( useStreaming && m_*n_ > ( cacheSize / ( sizeof(Type) * 3UL ) ) && !(~rhs).isAliased( this ) )
1911  {
1912  for( size_t i=0UL; i<m_; ++i )
1913  for( size_t j=0UL; j<n_; j+=IT::size )
1914  stream( v_+i*nn_+j, (~rhs).load(i,j) );
1915  }
1916  else
1917  {
1918  const size_t jend( n_ & size_t(-IT::size*4) );
1919  BLAZE_INTERNAL_ASSERT( ( n_ - ( n_ % (IT::size*4UL) ) ) == jend, "Invalid end calculation" );
1920 
1921  for( size_t i=0UL; i<m_; ++i ) {
1922  typename MT::ConstIterator it( (~rhs).begin(i) );
1923  for( size_t j=0UL; j<jend; j+=IT::size*4UL ) {
1924  store( v_+i*nn_+j , it.load() ); it += IT::size;
1925  store( v_+i*nn_+j+IT::size , it.load() ); it += IT::size;
1926  store( v_+i*nn_+j+IT::size*2UL, it.load() ); it += IT::size;
1927  store( v_+i*nn_+j+IT::size*3UL, it.load() ); it += IT::size;
1928  }
1929  for( size_t j=jend; j<n_; j+=IT::size, it+=IT::size ) {
1930  store( v_+i*nn_+j, it.load() );
1931  }
1932  }
1933  }
1934 }
1935 //*************************************************************************************************
1936 
1937 
1938 //*************************************************************************************************
1949 template< typename Type // Data type of the matrix
1950  , bool SO > // Storage order
1951 template< typename MT > // Type of the right-hand side dense matrix
1953 {
1954  BLAZE_INTERNAL_ASSERT( m_ == (~rhs).rows() , "Invalid number of rows" );
1955  BLAZE_INTERNAL_ASSERT( n_ == (~rhs).columns(), "Invalid number of columns" );
1956 
1957  const size_t block( 16UL );
1958 
1959  for( size_t ii=0UL; ii<m_; ii+=block ) {
1960  const size_t iend( ( m_<(ii+block) )?( m_ ):( ii+block ) );
1961  for( size_t jj=0UL; jj<n_; jj+=block ) {
1962  const size_t jend( ( n_<(jj+block) )?( n_ ):( jj+block ) );
1963  for( size_t i=ii; i<iend; ++i ) {
1964  for( size_t j=jj; j<jend; ++j ) {
1965  v_[i*nn_+j] = (~rhs)(i,j);
1966  }
1967  }
1968  }
1969  }
1970 }
1971 //*************************************************************************************************
1972 
1973 
1974 //*************************************************************************************************
1985 template< typename Type // Data type of the matrix
1986  , bool SO > // Storage order
1987 template< typename MT > // Type of the right-hand side sparse matrix
1989 {
1990  BLAZE_INTERNAL_ASSERT( m_ == (~rhs).rows() , "Invalid number of rows" );
1991  BLAZE_INTERNAL_ASSERT( n_ == (~rhs).columns(), "Invalid number of columns" );
1992 
1993  for( size_t i=0UL; i<m_; ++i )
1994  for( typename MT::ConstIterator element=(~rhs).begin(i); element!=(~rhs).end(i); ++element )
1995  v_[i*nn_+element->index()] = element->value();
1996 }
1997 //*************************************************************************************************
1998 
1999 
2000 //*************************************************************************************************
2011 template< typename Type // Data type of the matrix
2012  , bool SO > // Storage order
2013 template< typename MT > // Type of the right-hand side sparse matrix
2015 {
2016  BLAZE_INTERNAL_ASSERT( m_ == (~rhs).rows() , "Invalid number of rows" );
2017  BLAZE_INTERNAL_ASSERT( n_ == (~rhs).columns(), "Invalid number of columns" );
2018 
2019  for( size_t j=0UL; j<n_; ++j )
2020  for( typename MT::ConstIterator element=(~rhs).begin(j); element!=(~rhs).end(j); ++element )
2021  v_[element->index()*nn_+j] = element->value();
2022 }
2023 //*************************************************************************************************
2024 
2025 
2026 //*************************************************************************************************
2037 template< typename Type // Data type of the matrix
2038  , bool SO > // Storage order
2039 template< typename MT > // Type of the right-hand side dense matrix
2040 inline typename DisableIf< typename DynamicMatrix<Type,SO>::BLAZE_TEMPLATE VectorizedAddAssign<MT> >::Type
2042 {
2043  BLAZE_INTERNAL_ASSERT( m_ == (~rhs).rows() , "Invalid number of rows" );
2044  BLAZE_INTERNAL_ASSERT( n_ == (~rhs).columns(), "Invalid number of columns" );
2045 
2046  const size_t jend( n_ & size_t(-2) );
2047  BLAZE_INTERNAL_ASSERT( ( n_ - ( n_ % 2UL ) ) == jend, "Invalid end calculation" );
2048 
2049  for( size_t i=0UL; i<m_; ++i ) {
2050  for( size_t j=0UL; j<jend; j+=2UL ) {
2051  v_[i*nn_+j ] += (~rhs)(i,j );
2052  v_[i*nn_+j+1UL] += (~rhs)(i,j+1UL);
2053  }
2054  if( jend < n_ ) {
2055  v_[i*nn_+jend] += (~rhs)(i,jend);
2056  }
2057  }
2058 }
2059 //*************************************************************************************************
2060 
2061 
2062 //*************************************************************************************************
2073 template< typename Type // Data type of the matrix
2074  , bool SO > // Storage order
2075 template< typename MT > // Type of the right-hand side dense matrix
2076 inline typename EnableIf< typename DynamicMatrix<Type,SO>::BLAZE_TEMPLATE VectorizedAddAssign<MT> >::Type
2078 {
2079  using blaze::load;
2080  using blaze::store;
2081 
2082  BLAZE_INTERNAL_ASSERT( m_ == (~rhs).rows() , "Invalid number of rows" );
2083  BLAZE_INTERNAL_ASSERT( n_ == (~rhs).columns(), "Invalid number of columns" );
2084 
2086 
2087  const size_t jend( n_ & size_t(-IT::size*4) );
2088  BLAZE_INTERNAL_ASSERT( ( n_ - ( n_ % (IT::size*4UL) ) ) == jend, "Invalid end calculation" );
2089 
2090  for( size_t i=0UL; i<m_; ++i ) {
2091  typename MT::ConstIterator it( (~rhs).begin(i) );
2092  for( size_t j=0UL; j<jend; j+=IT::size*4UL ) {
2093  store( v_+i*nn_+j , load( v_+i*nn_+j ) + it.load() ); it += IT::size;
2094  store( v_+i*nn_+j+IT::size , load( v_+i*nn_+j+IT::size ) + it.load() ); it += IT::size;
2095  store( v_+i*nn_+j+IT::size*2UL, load( v_+i*nn_+j+IT::size*2UL ) + it.load() ); it += IT::size;
2096  store( v_+i*nn_+j+IT::size*3UL, load( v_+i*nn_+j+IT::size*3UL ) + it.load() ); it += IT::size;
2097  }
2098  for( size_t j=jend; j<n_; j+=IT::size, it+=IT::size ) {
2099  store( v_+i*nn_+j, load( v_+i*nn_+j ) + it.load() );
2100  }
2101  }
2102 }
2103 //*************************************************************************************************
2104 
2105 
2106 //*************************************************************************************************
2117 template< typename Type // Data type of the matrix
2118  , bool SO > // Storage order
2119 template< typename MT > // Type of the right-hand side dense matrix
2121 {
2122  BLAZE_INTERNAL_ASSERT( m_ == (~rhs).rows() , "Invalid number of rows" );
2123  BLAZE_INTERNAL_ASSERT( n_ == (~rhs).columns(), "Invalid number of columns" );
2124 
2125  const size_t block( 16UL );
2126 
2127  for( size_t ii=0UL; ii<m_; ii+=block ) {
2128  const size_t iend( ( m_<(ii+block) )?( m_ ):( ii+block ) );
2129  for( size_t jj=0UL; jj<n_; jj+=block ) {
2130  const size_t jend( ( n_<(jj+block) )?( n_ ):( jj+block ) );
2131  for( size_t i=ii; i<iend; ++i ) {
2132  for( size_t j=jj; j<jend; ++j ) {
2133  v_[i*nn_+j] += (~rhs)(i,j);
2134  }
2135  }
2136  }
2137  }
2138 }
2139 //*************************************************************************************************
2140 
2141 
2142 //*************************************************************************************************
2153 template< typename Type // Data type of the matrix
2154  , bool SO > // Storage order
2155 template< typename MT > // Type of the right-hand side sparse matrix
2157 {
2158  BLAZE_INTERNAL_ASSERT( m_ == (~rhs).rows() , "Invalid number of rows" );
2159  BLAZE_INTERNAL_ASSERT( n_ == (~rhs).columns(), "Invalid number of columns" );
2160 
2161  for( size_t i=0UL; i<m_; ++i )
2162  for( typename MT::ConstIterator element=(~rhs).begin(i); element!=(~rhs).end(i); ++element )
2163  v_[i*nn_+element->index()] += element->value();
2164 }
2165 //*************************************************************************************************
2166 
2167 
2168 //*************************************************************************************************
2179 template< typename Type // Data type of the matrix
2180  , bool SO > // Storage order
2181 template< typename MT > // Type of the right-hand side sparse matrix
2183 {
2184  BLAZE_INTERNAL_ASSERT( m_ == (~rhs).rows() , "Invalid number of rows" );
2185  BLAZE_INTERNAL_ASSERT( n_ == (~rhs).columns(), "Invalid number of columns" );
2186 
2187  for( size_t j=0UL; j<n_; ++j )
2188  for( typename MT::ConstIterator element=(~rhs).begin(j); element!=(~rhs).end(j); ++element )
2189  v_[element->index()*nn_+j] += element->value();
2190 }
2191 //*************************************************************************************************
2192 
2193 
2194 //*************************************************************************************************
2205 template< typename Type // Data type of the matrix
2206  , bool SO > // Storage order
2207 template< typename MT > // Type of the right-hand side dense matrix
2208 inline typename DisableIf< typename DynamicMatrix<Type,SO>::BLAZE_TEMPLATE VectorizedSubAssign<MT> >::Type
2210 {
2211  BLAZE_INTERNAL_ASSERT( m_ == (~rhs).rows() , "Invalid number of rows" );
2212  BLAZE_INTERNAL_ASSERT( n_ == (~rhs).columns(), "Invalid number of columns" );
2213 
2214  const size_t jend( n_ & size_t(-2) );
2215  BLAZE_INTERNAL_ASSERT( ( n_ - ( n_ % 2UL ) ) == jend, "Invalid end calculation" );
2216 
2217  for( size_t i=0UL; i<m_; ++i ) {
2218  for( size_t j=0UL; j<jend; j+=2UL ) {
2219  v_[i*nn_+j ] -= (~rhs)(i,j );
2220  v_[i*nn_+j+1UL] -= (~rhs)(i,j+1UL);
2221  }
2222  if( jend < n_ ) {
2223  v_[i*nn_+jend] -= (~rhs)(i,jend);
2224  }
2225  }
2226 }
2227 //*************************************************************************************************
2228 
2229 
2230 //*************************************************************************************************
2241 template< typename Type // Data type of the matrix
2242  , bool SO > // Storage order
2243 template< typename MT > // Type of the right-hand side dense matrix
2244 inline typename EnableIf< typename DynamicMatrix<Type,SO>::BLAZE_TEMPLATE VectorizedSubAssign<MT> >::Type
2246 {
2247  using blaze::load;
2248  using blaze::store;
2249 
2250  BLAZE_INTERNAL_ASSERT( m_ == (~rhs).rows() , "Invalid number of rows" );
2251  BLAZE_INTERNAL_ASSERT( n_ == (~rhs).columns(), "Invalid number of columns" );
2252 
2254 
2255  const size_t jend( n_ & size_t(-IT::size*4) );
2256  BLAZE_INTERNAL_ASSERT( ( n_ - ( n_ % (IT::size*4UL) ) ) == jend, "Invalid end calculation" );
2257 
2258  for( size_t i=0UL; i<m_; ++i ) {
2259  typename MT::ConstIterator it( (~rhs).begin(i) );
2260  for( size_t j=0UL; j<jend; j+=IT::size*4UL ) {
2261  store( v_+i*nn_+j , load( v_+i*nn_+j ) - it.load() ); it += IT::size;
2262  store( v_+i*nn_+j+IT::size , load( v_+i*nn_+j+IT::size ) - it.load() ); it += IT::size;
2263  store( v_+i*nn_+j+IT::size*2UL, load( v_+i*nn_+j+IT::size*2UL ) - it.load() ); it += IT::size;
2264  store( v_+i*nn_+j+IT::size*3UL, load( v_+i*nn_+j+IT::size*3UL ) - it.load() ); it += IT::size;
2265  }
2266  for( size_t j=jend; j<n_; j+=IT::size, it+=IT::size ) {
2267  store( v_+i*nn_+j, load( v_+i*nn_+j ) - it.load() );
2268  }
2269  }
2270 }
2271 //*************************************************************************************************
2272 
2273 
2274 //*************************************************************************************************
2285 template< typename Type // Data type of the matrix
2286  , bool SO > // Storage order
2287 template< typename MT > // Type of the right-hand side dense matrix
2289 {
2290  BLAZE_INTERNAL_ASSERT( m_ == (~rhs).rows() , "Invalid number of rows" );
2291  BLAZE_INTERNAL_ASSERT( n_ == (~rhs).columns(), "Invalid number of columns" );
2292 
2293  const size_t block( 16UL );
2294 
2295  for( size_t ii=0UL; ii<m_; ii+=block ) {
2296  const size_t iend( ( m_<(ii+block) )?( m_ ):( ii+block ) );
2297  for( size_t jj=0UL; jj<n_; jj+=block ) {
2298  const size_t jend( ( n_<(jj+block) )?( n_ ):( jj+block ) );
2299  for( size_t i=ii; i<iend; ++i ) {
2300  for( size_t j=jj; j<jend; ++j ) {
2301  v_[i*nn_+j] -= (~rhs)(i,j);
2302  }
2303  }
2304  }
2305  }
2306 }
2307 //*************************************************************************************************
2308 
2309 
2310 //*************************************************************************************************
2321 template< typename Type // Data type of the matrix
2322  , bool SO > // Storage order
2323 template< typename MT > // Type of the right-hand side sparse matrix
2325 {
2326  BLAZE_INTERNAL_ASSERT( m_ == (~rhs).rows() , "Invalid number of rows" );
2327  BLAZE_INTERNAL_ASSERT( n_ == (~rhs).columns(), "Invalid number of columns" );
2328 
2329  for( size_t i=0UL; i<m_; ++i )
2330  for( typename MT::ConstIterator element=(~rhs).begin(i); element!=(~rhs).end(i); ++element )
2331  v_[i*nn_+element->index()] -= element->value();
2332 }
2333 //*************************************************************************************************
2334 
2335 
2336 //*************************************************************************************************
2347 template< typename Type // Data type of the matrix
2348  , bool SO > // Storage order
2349 template< typename MT > // Type of the right-hand side sparse matrix
2351 {
2352  BLAZE_INTERNAL_ASSERT( m_ == (~rhs).rows() , "Invalid number of rows" );
2353  BLAZE_INTERNAL_ASSERT( n_ == (~rhs).columns(), "Invalid number of columns" );
2354 
2355  for( size_t j=0UL; j<n_; ++j )
2356  for( typename MT::ConstIterator element=(~rhs).begin(j); element!=(~rhs).end(j); ++element )
2357  v_[element->index()*nn_+j] -= element->value();
2358 }
2359 //*************************************************************************************************
2360 
2361 
2362 
2363 
2364 
2365 
2366 
2367 
2368 //=================================================================================================
2369 //
2370 // CLASS TEMPLATE SPECIALIZATION FOR COLUMN-MAJOR MATRICES
2371 //
2372 //=================================================================================================
2373 
2374 //*************************************************************************************************
2382 template< typename Type > // Data type of the matrix
2383 class DynamicMatrix<Type,true> : public DenseMatrix< DynamicMatrix<Type,true>, true >
2384 {
2385  private:
2386  //**Type definitions****************************************************************************
2387  typedef IntrinsicTrait<Type> IT;
2388  //**********************************************************************************************
2389 
2390  public:
2391  //**Type definitions****************************************************************************
2392  typedef DynamicMatrix<Type,true> This;
2393  typedef This ResultType;
2396  typedef Type ElementType;
2397  typedef typename IT::Type IntrinsicType;
2398  typedef const Type& ReturnType;
2399  typedef const This& CompositeType;
2400  typedef Type& Reference;
2401  typedef const Type& ConstReference;
2402  typedef Type* Pointer;
2403  typedef const Type* ConstPointer;
2404  typedef DenseIterator<Type> Iterator;
2406  //**********************************************************************************************
2407 
2408  //**Compilation flags***************************************************************************
2410 
2414  enum { vectorizable = IsVectorizable<Type>::value };
2415 
2417 
2420  enum { smpAssignable = !IsSMPAssignable<Type>::value };
2421  //**********************************************************************************************
2422 
2423  //**Constructors********************************************************************************
2426  explicit inline DynamicMatrix();
2427  explicit inline DynamicMatrix( size_t m, size_t n );
2428  explicit inline DynamicMatrix( size_t m, size_t n, const Type& init );
2429  template< typename Other > explicit inline DynamicMatrix( size_t m, size_t n, const Other* array );
2430 
2431  template< typename Other, size_t M, size_t N >
2432  explicit inline DynamicMatrix( const Other (&array)[M][N] );
2433 
2434  inline DynamicMatrix( const DynamicMatrix& m );
2435  template< typename MT, bool SO > inline DynamicMatrix( const Matrix<MT,SO>& m );
2437  //**********************************************************************************************
2438 
2439  //**Destructor**********************************************************************************
2442  inline ~DynamicMatrix();
2444  //**********************************************************************************************
2445 
2446  //**Data access functions***********************************************************************
2449  inline Reference operator()( size_t i, size_t j );
2450  inline ConstReference operator()( size_t i, size_t j ) const;
2451  inline Pointer data ();
2452  inline ConstPointer data () const;
2453  inline Pointer data ( size_t j );
2454  inline ConstPointer data ( size_t j ) const;
2455  inline Iterator begin ( size_t j );
2456  inline ConstIterator begin ( size_t j ) const;
2457  inline ConstIterator cbegin( size_t j ) const;
2458  inline Iterator end ( size_t j );
2459  inline ConstIterator end ( size_t j ) const;
2460  inline ConstIterator cend ( size_t j ) const;
2462  //**********************************************************************************************
2463 
2464  //**Assignment operators************************************************************************
2467  template< typename Other, size_t M, size_t N >
2468  inline DynamicMatrix& operator=( const Other (&array)[M][N] );
2469 
2470  inline DynamicMatrix& operator= ( Type set );
2471  inline DynamicMatrix& operator= ( const DynamicMatrix& set );
2472  template< typename MT, bool SO > inline DynamicMatrix& operator= ( const Matrix<MT,SO>& rhs );
2473  template< typename MT, bool SO > inline DynamicMatrix& operator+=( const Matrix<MT,SO>& rhs );
2474  template< typename MT, bool SO > inline DynamicMatrix& operator-=( const Matrix<MT,SO>& rhs );
2475  template< typename MT, bool SO > inline DynamicMatrix& operator*=( const Matrix<MT,SO>& rhs );
2476 
2477  template< typename Other >
2478  inline typename EnableIf< IsNumeric<Other>, DynamicMatrix >::Type&
2479  operator*=( Other rhs );
2480 
2481  template< typename Other >
2482  inline typename EnableIf< IsNumeric<Other>, DynamicMatrix >::Type&
2483  operator/=( Other rhs );
2485  //**********************************************************************************************
2486 
2487  //**Utility functions***************************************************************************
2490  inline size_t rows() const;
2491  inline size_t columns() const;
2492  inline size_t spacing() const;
2493  inline size_t capacity() const;
2494  inline size_t capacity( size_t j ) const;
2495  inline size_t nonZeros() const;
2496  inline size_t nonZeros( size_t j ) const;
2497  inline void reset();
2498  inline void reset( size_t j );
2499  inline void clear();
2500  void resize ( size_t m, size_t n, bool preserve=true );
2501  inline void extend ( size_t m, size_t n, bool preserve=true );
2502  inline void reserve( size_t elements );
2503  inline DynamicMatrix& transpose();
2504  template< typename Other > inline DynamicMatrix& scale( Other scalar );
2505  inline void swap( DynamicMatrix& m ) /* throw() */;
2507  //**********************************************************************************************
2508 
2509  private:
2510  //**********************************************************************************************
2512  template< typename MT >
2513  struct VectorizedAssign {
2514  enum { value = vectorizable && MT::vectorizable &&
2515  IsSame<Type,typename MT::ElementType>::value };
2516  };
2517  //**********************************************************************************************
2518 
2519  //**********************************************************************************************
2521  template< typename MT >
2522  struct VectorizedAddAssign {
2523  enum { value = vectorizable && MT::vectorizable &&
2524  IsSame<Type,typename MT::ElementType>::value &&
2525  IntrinsicTrait<Type>::addition };
2526  };
2527  //**********************************************************************************************
2528 
2529  //**********************************************************************************************
2531  template< typename MT >
2532  struct VectorizedSubAssign {
2533  enum { value = vectorizable && MT::vectorizable &&
2534  IsSame<Type,typename MT::ElementType>::value &&
2535  IntrinsicTrait<Type>::subtraction };
2536  };
2537  //**********************************************************************************************
2538 
2539  public:
2540  //**Expression template evaluation functions****************************************************
2543  template< typename Other > inline bool canAlias ( const Other* alias ) const;
2544  template< typename Other > inline bool isAliased( const Other* alias ) const;
2545 
2546  inline bool isAligned () const;
2547  inline bool canSMPAssign() const;
2548 
2549  inline IntrinsicType load ( size_t i, size_t j ) const;
2550  inline IntrinsicType loadu ( size_t i, size_t j ) const;
2551  inline void store ( size_t i, size_t j, const IntrinsicType& value );
2552  inline void storeu( size_t i, size_t j, const IntrinsicType& value );
2553  inline void stream( size_t i, size_t j, const IntrinsicType& value );
2554 
2555  template< typename MT >
2556  inline typename DisableIf< VectorizedAssign<MT> >::Type
2557  assign( const DenseMatrix<MT,true>& rhs );
2558 
2559  template< typename MT >
2560  inline typename EnableIf< VectorizedAssign<MT> >::Type
2561  assign( const DenseMatrix<MT,true>& rhs );
2562 
2563  template< typename MT > inline void assign( const DenseMatrix<MT,false>& rhs );
2564  template< typename MT > inline void assign( const SparseMatrix<MT,true>& rhs );
2565  template< typename MT > inline void assign( const SparseMatrix<MT,false>& rhs );
2566 
2567  template< typename MT >
2568  inline typename DisableIf< VectorizedAddAssign<MT> >::Type
2569  addAssign( const DenseMatrix<MT,true>& rhs );
2570 
2571  template< typename MT >
2572  inline typename EnableIf< VectorizedAddAssign<MT> >::Type
2573  addAssign( const DenseMatrix<MT,true>& rhs );
2574 
2575  template< typename MT > inline void addAssign( const DenseMatrix<MT,false>& rhs );
2576  template< typename MT > inline void addAssign( const SparseMatrix<MT,true>& rhs );
2577  template< typename MT > inline void addAssign( const SparseMatrix<MT,false>& rhs );
2578 
2579  template< typename MT >
2580  inline typename DisableIf< VectorizedSubAssign<MT> >::Type
2581  subAssign ( const DenseMatrix<MT,true>& rhs );
2582 
2583  template< typename MT >
2584  inline typename EnableIf< VectorizedSubAssign<MT> >::Type
2585  subAssign ( const DenseMatrix<MT,true>& rhs );
2586 
2587  template< typename MT > inline void subAssign( const DenseMatrix<MT,false>& rhs );
2588  template< typename MT > inline void subAssign( const SparseMatrix<MT,true>& rhs );
2589  template< typename MT > inline void subAssign( const SparseMatrix<MT,false>& rhs );
2591  //**********************************************************************************************
2592 
2593  private:
2594  //**Utility functions***************************************************************************
2597  inline size_t adjustRows( size_t minRows ) const;
2599  //**********************************************************************************************
2600 
2601  //**Member variables****************************************************************************
2604  size_t m_;
2605  size_t mm_;
2606  size_t n_;
2607  size_t capacity_;
2608  Type* BLAZE_RESTRICT v_;
2609 
2619  //**********************************************************************************************
2620 
2621  //**Compile time checks*************************************************************************
2626  //**********************************************************************************************
2627 };
2629 //*************************************************************************************************
2630 
2631 
2632 
2633 
2634 //=================================================================================================
2635 //
2636 // CONSTRUCTORS
2637 //
2638 //=================================================================================================
2639 
2640 //*************************************************************************************************
2644 template< typename Type > // Data type of the matrix
2646  : m_ ( 0UL ) // The current number of rows of the matrix
2647  , mm_ ( 0UL ) // The alignment adjusted number of rows
2648  , n_ ( 0UL ) // The current number of columns of the matrix
2649  , capacity_( 0UL ) // The maximum capacity of the matrix
2650  , v_ ( NULL ) // The matrix elements
2651 {}
2653 //*************************************************************************************************
2654 
2655 
2656 //*************************************************************************************************
2666 template< typename Type > // Data type of the matrix
2667 inline DynamicMatrix<Type,true>::DynamicMatrix( size_t m, size_t n )
2668  : m_ ( m ) // The current number of rows of the matrix
2669  , mm_ ( adjustRows( m ) ) // The alignment adjusted number of rows
2670  , n_ ( n ) // The current number of columns of the matrix
2671  , capacity_( mm_*n_ ) // The maximum capacity of the matrix
2672  , v_ ( allocate<Type>( capacity_ ) ) // The matrix elements
2673 {
2674  if( IsVectorizable<Type>::value ) {
2675  for( size_t j=0UL; j<n_; ++j )
2676  for( size_t i=m_; i<mm_; ++i ) {
2677  v_[i+j*mm_] = Type();
2678  }
2679  }
2680 }
2682 //*************************************************************************************************
2683 
2684 
2685 //*************************************************************************************************
2695 template< typename Type > // Data type of the matrix
2696 inline DynamicMatrix<Type,true>::DynamicMatrix( size_t m, size_t n, const Type& init )
2697  : m_ ( m ) // The current number of rows of the matrix
2698  , mm_ ( adjustRows( m ) ) // The alignment adjusted number of rows
2699  , n_ ( n ) // The current number of columns of the matrix
2700  , capacity_( mm_*n_ ) // The maximum capacity of the matrix
2701  , v_ ( allocate<Type>( capacity_ ) ) // The matrix elements
2702 {
2703  for( size_t j=0UL; j<n_; ++j ) {
2704  for( size_t i=0UL; i<m_; ++i )
2705  v_[i+j*mm_] = init;
2706 
2707  if( IsVectorizable<Type>::value ) {
2708  for( size_t i=m_; i<mm_; ++i )
2709  v_[i+j*mm_] = Type();
2710  }
2711  }
2712 }
2714 //*************************************************************************************************
2715 
2716 
2717 //*************************************************************************************************
2741 template< typename Type > // Data type of the matrix
2742 template< typename Other > // Data type of the initialization array
2743 inline DynamicMatrix<Type,true>::DynamicMatrix( size_t m, size_t n, const Other* array )
2744  : m_ ( m ) // The current number of rows of the matrix
2745  , mm_ ( adjustRows( m ) ) // The alignment adjusted number of rows
2746  , n_ ( n ) // The current number of columns of the matrix
2747  , capacity_( mm_*n_ ) // The maximum capacity of the matrix
2748  , v_ ( allocate<Type>( capacity_ ) ) // The matrix elements
2749 {
2750  for( size_t j=0UL; j<n; ++j ) {
2751  for( size_t i=0UL; i<m; ++i )
2752  v_[i+j*mm_] = array[i+j*m];
2753 
2754  if( IsVectorizable<Type>::value ) {
2755  for( size_t i=m; i<mm_; ++i )
2756  v_[i+j*mm_] = Type();
2757  }
2758  }
2759 }
2761 //*************************************************************************************************
2762 
2763 
2764 //*************************************************************************************************
2786 template< typename Type > // Data type of the matrix
2787 template< typename Other // Data type of the initialization array
2788  , size_t M // Number of rows of the initialization array
2789  , size_t N > // Number of columns of the initialization array
2790 inline DynamicMatrix<Type,true>::DynamicMatrix( const Other (&array)[M][N] )
2791  : m_ ( M ) // The current number of rows of the matrix
2792  , mm_ ( adjustRows( M ) ) // The alignment adjusted number of rows
2793  , n_ ( N ) // The current number of columns of the matrix
2794  , capacity_( mm_*n_ ) // The maximum capacity of the matrix
2795  , v_ ( allocate<Type>( capacity_ ) ) // The matrix elements
2796 {
2797  for( size_t j=0UL; j<N; ++j ) {
2798  for( size_t i=0UL; i<M; ++i )
2799  v_[i+j*mm_] = array[i][j];
2800 
2801  if( IsVectorizable<Type>::value ) {
2802  for( size_t i=M; i<mm_; ++i )
2803  v_[i+j*mm_] = Type();
2804  }
2805  }
2806 }
2808 //*************************************************************************************************
2809 
2810 
2811 //*************************************************************************************************
2820 template< typename Type > // Data type of the matrix
2821 inline DynamicMatrix<Type,true>::DynamicMatrix( const DynamicMatrix& m )
2822  : m_ ( m.m_ ) // The current number of rows of the matrix
2823  , mm_ ( m.mm_ ) // The alignment adjusted number of rows
2824  , n_ ( m.n_ ) // The current number of columns of the matrix
2825  , capacity_( mm_*n_ ) // The maximum capacity of the matrix
2826  , v_ ( allocate<Type>( capacity_ ) ) // The matrix elements
2827 {
2828  BLAZE_INTERNAL_ASSERT( capacity_ <= m.capacity_, "Invalid capacity estimation" );
2829 
2830  for( size_t i=0UL; i<capacity_; ++i )
2831  v_[i] = m.v_[i];
2832 }
2834 //*************************************************************************************************
2835 
2836 
2837 //*************************************************************************************************
2843 template< typename Type > // Data type of the matrix
2844 template< typename MT // Type of the foreign matrix
2845  , bool SO > // Storage order of the foreign matrix
2846 inline DynamicMatrix<Type,true>::DynamicMatrix( const Matrix<MT,SO>& m )
2847  : m_ ( (~m).rows() ) // The current number of rows of the matrix
2848  , mm_ ( adjustRows( m_ ) ) // The alignment adjusted number of rows
2849  , n_ ( (~m).columns() ) // The current number of columns of the matrix
2850  , capacity_( mm_*n_ ) // The maximum capacity of the matrix
2851  , v_ ( allocate<Type>( capacity_ ) ) // The matrix elements
2852 {
2853  for( size_t j=0UL; j<n_; ++j ) {
2854  for( size_t i=( IsSparseMatrix<MT>::value ? 0UL : m_ );
2855  i<( IsVectorizable<Type>::value ? mm_ : m_ ); ++i ) {
2856  v_[i+j*mm_] = Type();
2857  }
2858  }
2859 
2860  smpAssign( *this, ~m );
2861 }
2863 //*************************************************************************************************
2864 
2865 
2866 
2867 
2868 //=================================================================================================
2869 //
2870 // DESTRUCTOR
2871 //
2872 //=================================================================================================
2873 
2874 //*************************************************************************************************
2878 template< typename Type > // Data type of the matrix
2880 {
2881  deallocate( v_ );
2882 }
2884 //*************************************************************************************************
2885 
2886 
2887 
2888 
2889 //=================================================================================================
2890 //
2891 // DATA ACCESS FUNCTIONS
2892 //
2893 //=================================================================================================
2894 
2895 //*************************************************************************************************
2903 template< typename Type > // Data type of the matrix
2905  DynamicMatrix<Type,true>::operator()( size_t i, size_t j )
2906 {
2907  BLAZE_USER_ASSERT( i<m_, "Invalid row access index" );
2908  BLAZE_USER_ASSERT( j<n_, "Invalid column access index" );
2909  return v_[i+j*mm_];
2910 }
2912 //*************************************************************************************************
2913 
2914 
2915 //*************************************************************************************************
2923 template< typename Type > // Data type of the matrix
2925  DynamicMatrix<Type,true>::operator()( size_t i, size_t j ) const
2926 {
2927  BLAZE_USER_ASSERT( i<m_, "Invalid row access index" );
2928  BLAZE_USER_ASSERT( j<n_, "Invalid column access index" );
2929  return v_[i+j*mm_];
2930 }
2932 //*************************************************************************************************
2933 
2934 
2935 //*************************************************************************************************
2947 template< typename Type > // Data type of the matrix
2948 inline typename DynamicMatrix<Type,true>::Pointer DynamicMatrix<Type,true>::data()
2949 {
2950  return v_;
2951 }
2953 //*************************************************************************************************
2954 
2955 
2956 //*************************************************************************************************
2968 template< typename Type > // Data type of the matrix
2969 inline typename DynamicMatrix<Type,true>::ConstPointer DynamicMatrix<Type,true>::data() const
2970 {
2971  return v_;
2972 }
2974 //*************************************************************************************************
2975 
2976 
2977 //*************************************************************************************************
2986 template< typename Type > // Data type of the matrix
2987 inline typename DynamicMatrix<Type,true>::Pointer DynamicMatrix<Type,true>::data( size_t j )
2988 {
2989  BLAZE_USER_ASSERT( j < n_, "Invalid dense matrix column access index" );
2990  return v_ + j*mm_;
2991 }
2993 //*************************************************************************************************
2994 
2995 
2996 //*************************************************************************************************
3005 template< typename Type > // Data type of the matrix
3006 inline typename DynamicMatrix<Type,true>::ConstPointer DynamicMatrix<Type,true>::data( size_t j ) const
3007 {
3008  BLAZE_USER_ASSERT( j < n_, "Invalid dense matrix column access index" );
3009  return v_ + j*mm_;
3010 }
3012 //*************************************************************************************************
3013 
3014 
3015 //*************************************************************************************************
3022 template< typename Type > // Data type of the matrix
3023 inline typename DynamicMatrix<Type,true>::Iterator
3025 {
3026  BLAZE_USER_ASSERT( j < n_, "Invalid dense matrix column access index" );
3027  return Iterator( v_ + j*mm_ );
3028 }
3030 //*************************************************************************************************
3031 
3032 
3033 //*************************************************************************************************
3040 template< typename Type > // Data type of the matrix
3042  DynamicMatrix<Type,true>::begin( size_t j ) const
3043 {
3044  BLAZE_USER_ASSERT( j < n_, "Invalid dense matrix column access index" );
3045  return ConstIterator( v_ + j*mm_ );
3046 }
3048 //*************************************************************************************************
3049 
3050 
3051 //*************************************************************************************************
3058 template< typename Type > // Data type of the matrix
3060  DynamicMatrix<Type,true>::cbegin( size_t j ) const
3061 {
3062  BLAZE_USER_ASSERT( j < n_, "Invalid dense matrix column access index" );
3063  return ConstIterator( v_ + j*mm_ );
3064 }
3066 //*************************************************************************************************
3067 
3068 
3069 //*************************************************************************************************
3076 template< typename Type > // Data type of the matrix
3077 inline typename DynamicMatrix<Type,true>::Iterator
3078  DynamicMatrix<Type,true>::end( size_t j )
3079 {
3080  BLAZE_USER_ASSERT( j < n_, "Invalid dense matrix column access index" );
3081  return Iterator( v_ + j*mm_ + m_ );
3082 }
3084 //*************************************************************************************************
3085 
3086 
3087 //*************************************************************************************************
3094 template< typename Type > // Data type of the matrix
3096  DynamicMatrix<Type,true>::end( size_t j ) const
3097 {
3098  BLAZE_USER_ASSERT( j < n_, "Invalid dense matrix column access index" );
3099  return ConstIterator( v_ + j*mm_ + m_ );
3100 }
3102 //*************************************************************************************************
3103 
3104 
3105 //*************************************************************************************************
3112 template< typename Type > // Data type of the matrix
3114  DynamicMatrix<Type,true>::cend( size_t j ) const
3115 {
3116  BLAZE_USER_ASSERT( j < n_, "Invalid dense matrix column access index" );
3117  return ConstIterator( v_ + j*mm_ + m_ );
3118 }
3120 //*************************************************************************************************
3121 
3122 
3123 
3124 
3125 //=================================================================================================
3126 //
3127 // ASSIGNMENT OPERATORS
3128 //
3129 //=================================================================================================
3130 
3131 //*************************************************************************************************
3153 template< typename Type > // Data type of the matrix
3154 template< typename Other // Data type of the initialization array
3155  , size_t M // Number of rows of the initialization array
3156  , size_t N > // Number of columns of the initialization array
3157 inline DynamicMatrix<Type,true>& DynamicMatrix<Type,true>::operator=( const Other (&array)[M][N] )
3158 {
3159  resize( M, N, false );
3160 
3161  for( size_t j=0UL; j<N; ++j )
3162  for( size_t i=0UL; i<M; ++i )
3163  v_[i+j*mm_] = array[i][j];
3164 
3165  return *this;
3166 }
3168 //*************************************************************************************************
3169 
3170 
3171 //*************************************************************************************************
3178 template< typename Type > // Data type of the matrix
3179 inline DynamicMatrix<Type,true>& DynamicMatrix<Type,true>::operator=( Type rhs )
3180 {
3181  for( size_t j=0UL; j<n_; ++j )
3182  for( size_t i=0UL; i<m_; ++i )
3183  v_[i+j*mm_] = rhs;
3184 
3185  return *this;
3186 }
3188 //*************************************************************************************************
3189 
3190 
3191 //*************************************************************************************************
3201 template< typename Type > // Data type of the matrix
3202 inline DynamicMatrix<Type,true>& DynamicMatrix<Type,true>::operator=( const DynamicMatrix& rhs )
3203 {
3204  if( &rhs == this ) return *this;
3205 
3206  resize( rhs.m_, rhs.n_, false );
3207  smpAssign( *this, ~rhs );
3208 
3209  return *this;
3210 }
3212 //*************************************************************************************************
3213 
3214 
3215 //*************************************************************************************************
3225 template< typename Type > // Data type of the matrix
3226 template< typename MT // Type of the right-hand side matrix
3227  , bool SO > // Storage order of the right-hand side matrix
3228 inline DynamicMatrix<Type,true>& DynamicMatrix<Type,true>::operator=( const Matrix<MT,SO>& rhs )
3229 {
3230  if( (~rhs).canAlias( this ) ) {
3231  DynamicMatrix tmp( ~rhs );
3232  swap( tmp );
3233  }
3234  else {
3235  resize( (~rhs).rows(), (~rhs).columns(), false );
3236  if( IsSparseMatrix<MT>::value )
3237  reset();
3238  smpAssign( *this, ~rhs );
3239  }
3240 
3241  return *this;
3242 }
3244 //*************************************************************************************************
3245 
3246 
3247 //*************************************************************************************************
3258 template< typename Type > // Data type of the matrix
3259 template< typename MT // Type of the right-hand side matrix
3260  , bool SO > // Storage order of the right-hand side matrix
3261 inline DynamicMatrix<Type,true>& DynamicMatrix<Type,true>::operator+=( const Matrix<MT,SO>& rhs )
3262 {
3263  if( (~rhs).rows() != m_ || (~rhs).columns() != n_ )
3264  throw std::invalid_argument( "Matrix sizes do not match" );
3265 
3266  if( (~rhs).canAlias( this ) ) {
3267  typename MT::ResultType tmp( ~rhs );
3268  smpAddAssign( *this, tmp );
3269  }
3270  else {
3271  smpAddAssign( *this, ~rhs );
3272  }
3273 
3274  return *this;
3275 }
3277 //*************************************************************************************************
3278 
3279 
3280 //*************************************************************************************************
3291 template< typename Type > // Data type of the matrix
3292 template< typename MT // Type of the right-hand side matrix
3293  , bool SO > // Storage order of the right-hand side matrix
3294 inline DynamicMatrix<Type,true>& DynamicMatrix<Type,true>::operator-=( const Matrix<MT,SO>& rhs )
3295 {
3296  if( (~rhs).rows() != m_ || (~rhs).columns() != n_ )
3297  throw std::invalid_argument( "Matrix sizes do not match" );
3298 
3299  if( (~rhs).canAlias( this ) ) {
3300  typename MT::ResultType tmp( ~rhs );
3301  smpSubAssign( *this, tmp );
3302  }
3303  else {
3304  smpSubAssign( *this, ~rhs );
3305  }
3306 
3307  return *this;
3308 }
3310 //*************************************************************************************************
3311 
3312 
3313 //*************************************************************************************************
3324 template< typename Type > // Data type of the matrix
3325 template< typename MT // Type of the right-hand side matrix
3326  , bool SO > // Storage order of the right-hand side matrix
3327 inline DynamicMatrix<Type,true>& DynamicMatrix<Type,true>::operator*=( const Matrix<MT,SO>& rhs )
3328 {
3329  if( (~rhs).rows() != n_ )
3330  throw std::invalid_argument( "Matrix sizes do not match" );
3331 
3332  DynamicMatrix tmp( *this * (~rhs) );
3333  swap( tmp );
3334 
3335  return *this;
3336 }
3338 //*************************************************************************************************
3339 
3340 
3341 //*************************************************************************************************
3349 template< typename Type > // Data type of the matrix
3350 template< typename Other > // Data type of the right-hand side scalar
3351 inline typename EnableIf< IsNumeric<Other>, DynamicMatrix<Type,true> >::Type&
3352  DynamicMatrix<Type,true>::operator*=( Other rhs )
3353 {
3354  smpAssign( *this, (*this) * rhs );
3355  return *this;
3356 }
3358 //*************************************************************************************************
3359 
3360 
3361 //*************************************************************************************************
3369 template< typename Type > // Data type of the matrix
3370 template< typename Other > // Data type of the right-hand side scalar
3371 inline typename EnableIf< IsNumeric<Other>, DynamicMatrix<Type,true> >::Type&
3372  DynamicMatrix<Type,true>::operator/=( Other rhs )
3373 {
3374  BLAZE_USER_ASSERT( rhs != Other(0), "Division by zero detected" );
3375 
3376  smpAssign( *this, (*this) / rhs );
3377  return *this;
3378 }
3380 //*************************************************************************************************
3381 
3382 
3383 
3384 
3385 //=================================================================================================
3386 //
3387 // UTILITY FUNCTIONS
3388 //
3389 //=================================================================================================
3390 
3391 //*************************************************************************************************
3397 template< typename Type > // Data type of the matrix
3398 inline size_t DynamicMatrix<Type,true>::rows() const
3399 {
3400  return m_;
3401 }
3403 //*************************************************************************************************
3404 
3405 
3406 //*************************************************************************************************
3412 template< typename Type > // Data type of the matrix
3413 inline size_t DynamicMatrix<Type,true>::columns() const
3414 {
3415  return n_;
3416 }
3418 //*************************************************************************************************
3419 
3420 
3421 //*************************************************************************************************
3430 template< typename Type > // Data type of the matrix
3431 inline size_t DynamicMatrix<Type,true>::spacing() const
3432 {
3433  return mm_;
3434 }
3436 //*************************************************************************************************
3437 
3438 
3439 //*************************************************************************************************
3445 template< typename Type > // Data type of the matrix
3446 inline size_t DynamicMatrix<Type,true>::capacity() const
3447 {
3448  return capacity_;
3449 }
3451 //*************************************************************************************************
3452 
3453 
3454 //*************************************************************************************************
3461 template< typename Type > // Data type of the sparse matrix
3462 inline size_t DynamicMatrix<Type,true>::capacity( size_t j ) const
3463 {
3464  UNUSED_PARAMETER( j );
3465  BLAZE_USER_ASSERT( j < columns(), "Invalid column access index" );
3466  return mm_;
3467 }
3469 //*************************************************************************************************
3470 
3471 
3472 //*************************************************************************************************
3478 template< typename Type > // Data type of the matrix
3479 inline size_t DynamicMatrix<Type,true>::nonZeros() const
3480 {
3481  size_t nonzeros( 0UL );
3482 
3483  for( size_t j=0UL; j<n_; ++j )
3484  for( size_t i=0UL; i<m_; ++i )
3485  if( !isDefault( v_[i+j*mm_] ) )
3486  ++nonzeros;
3487 
3488  return nonzeros;
3489 }
3491 //*************************************************************************************************
3492 
3493 
3494 //*************************************************************************************************
3501 template< typename Type > // Data type of the matrix
3502 inline size_t DynamicMatrix<Type,true>::nonZeros( size_t j ) const
3503 {
3504  BLAZE_USER_ASSERT( j < columns(), "Invalid column access index" );
3505 
3506  const size_t iend( (j+1UL)*mm_ );
3507  size_t nonzeros( 0UL );
3508 
3509  for( size_t i=j*mm_; i<iend; ++i )
3510  if( !isDefault( v_[i] ) )
3511  ++nonzeros;
3512 
3513  return nonzeros;
3514 }
3516 //*************************************************************************************************
3517 
3518 
3519 //*************************************************************************************************
3525 template< typename Type > // Data type of the matrix
3526 inline void DynamicMatrix<Type,true>::reset()
3527 {
3528  using blaze::reset;
3529 
3530  for( size_t j=0UL; j<n_; ++j )
3531  for( size_t i=0UL; i<m_; ++i )
3532  reset( v_[i+j*mm_] );
3533 }
3535 //*************************************************************************************************
3536 
3537 
3538 //*************************************************************************************************
3548 template< typename Type > // Data type of the sparse matrix
3549 inline void DynamicMatrix<Type,true>::reset( size_t j )
3550 {
3551  using blaze::reset;
3552 
3553  BLAZE_USER_ASSERT( j < columns(), "Invalid column access index" );
3554  for( size_t i=0UL; i<m_; ++i )
3555  reset( v_[i+j*mm_] );
3556 }
3558 //*************************************************************************************************
3559 
3560 
3561 //*************************************************************************************************
3569 template< typename Type > // Data type of the matrix
3570 inline void DynamicMatrix<Type,true>::clear()
3571 {
3572  resize( 0UL, 0UL, false );
3573 }
3575 //*************************************************************************************************
3576 
3577 
3578 //*************************************************************************************************
3613 template< typename Type > // Data type of the matrix
3614 void DynamicMatrix<Type,true>::resize( size_t m, size_t n, bool preserve )
3615 {
3616  using blaze::min;
3617 
3618  if( m == m_ && n == n_ ) return;
3619 
3620  const size_t mm( adjustRows( m ) );
3621 
3622  if( preserve )
3623  {
3624  Type* BLAZE_RESTRICT v = allocate<Type>( mm*n );
3625  const size_t min_m( min( m, m_ ) );
3626  const size_t min_n( min( n, n_ ) );
3627 
3628  for( size_t j=0UL; j<min_n; ++j )
3629  for( size_t i=0UL; i<min_m; ++i )
3630  v[i+j*mm] = v_[i+j*mm_];
3631 
3632  std::swap( v_, v );
3633  deallocate( v );
3634  capacity_ = mm*n;
3635  }
3636  else if( mm*n > capacity_ ) {
3637  Type* BLAZE_RESTRICT v = allocate<Type>( mm*n );
3638  std::swap( v_, v );
3639  deallocate( v );
3640  capacity_ = mm*n;
3641  }
3642 
3643  if( IsVectorizable<Type>::value ) {
3644  for( size_t j=0UL; j<n; ++j )
3645  for( size_t i=m; i<mm; ++i )
3646  v_[i+j*mm] = Type();
3647  }
3648 
3649  m_ = m;
3650  mm_ = mm;
3651  n_ = n;
3652 }
3654 //*************************************************************************************************
3655 
3656 
3657 //*************************************************************************************************
3672 template< typename Type > // Data type of the matrix
3673 inline void DynamicMatrix<Type,true>::extend( size_t m, size_t n, bool preserve )
3674 {
3675  resize( m_+m, n_+n, preserve );
3676 }
3678 //*************************************************************************************************
3679 
3680 
3681 //*************************************************************************************************
3691 template< typename Type > // Data type of the matrix
3692 inline void DynamicMatrix<Type,true>::reserve( size_t elements )
3693 {
3694  if( elements > capacity_ )
3695  {
3696  // Allocating a new array
3697  Type* BLAZE_RESTRICT tmp = allocate<Type>( elements );
3698 
3699  // Initializing the new array
3700  std::copy( v_, v_+capacity_, tmp );
3701 
3702  if( IsVectorizable<Type>::value ) {
3703  for( size_t i=capacity_; i<elements; ++i )
3704  tmp[i] = Type();
3705  }
3706 
3707  // Replacing the old array
3708  std::swap( tmp, v_ );
3709  deallocate( tmp );
3710  capacity_ = elements;
3711  }
3712 }
3714 //*************************************************************************************************
3715 
3716 
3717 //*************************************************************************************************
3723 template< typename Type > // Data type of the matrix
3724 inline DynamicMatrix<Type,true>& DynamicMatrix<Type,true>::transpose()
3725 {
3726  DynamicMatrix tmp( trans(*this) );
3727  swap( tmp );
3728  return *this;
3729 }
3731 //*************************************************************************************************
3732 
3733 
3734 //*************************************************************************************************
3741 template< typename Type > // Data type of the matrix
3742 template< typename Other > // Data type of the scalar value
3743 inline DynamicMatrix<Type,true>& DynamicMatrix<Type,true>::scale( Other scalar )
3744 {
3745  for( size_t j=0UL; j<n_; ++j )
3746  for( size_t i=0UL; i<m_; ++i )
3747  v_[i+j*mm_] *= scalar;
3748 
3749  return *this;
3750 }
3752 //*************************************************************************************************
3753 
3754 
3755 //*************************************************************************************************
3763 template< typename Type > // Data type of the matrix
3764 inline void DynamicMatrix<Type,true>::swap( DynamicMatrix& m ) /* throw() */
3765 {
3766  std::swap( m_ , m.m_ );
3767  std::swap( mm_, m.mm_ );
3768  std::swap( n_ , m.n_ );
3769  std::swap( capacity_, m.capacity_ );
3770  std::swap( v_ , m.v_ );
3771 }
3773 //*************************************************************************************************
3774 
3775 
3776 //*************************************************************************************************
3783 template< typename Type > // Data type of the matrix
3784 inline size_t DynamicMatrix<Type,true>::adjustRows( size_t minRows ) const
3785 {
3786  if( IsVectorizable<Type>::value )
3787  return minRows + ( IT::size - ( minRows % IT::size ) ) % IT::size;
3788  else return minRows;
3789 }
3791 //*************************************************************************************************
3792 
3793 
3794 
3795 
3796 //=================================================================================================
3797 //
3798 // EXPRESSION TEMPLATE EVALUATION FUNCTIONS
3799 //
3800 //=================================================================================================
3801 
3802 //*************************************************************************************************
3813 template< typename Type > // Data type of the matrix
3814 template< typename Other > // Data type of the foreign expression
3815 inline bool DynamicMatrix<Type,true>::canAlias( const Other* alias ) const
3816 {
3817  return static_cast<const void*>( this ) == static_cast<const void*>( alias );
3818 }
3820 //*************************************************************************************************
3821 
3822 
3823 //*************************************************************************************************
3834 template< typename Type > // Data type of the matrix
3835 template< typename Other > // Data type of the foreign expression
3836 inline bool DynamicMatrix<Type,true>::isAliased( const Other* alias ) const
3837 {
3838  return static_cast<const void*>( this ) == static_cast<const void*>( alias );
3839 }
3841 //*************************************************************************************************
3842 
3843 
3844 //*************************************************************************************************
3854 template< typename Type > // Data type of the matrix
3855 inline bool DynamicMatrix<Type,true>::isAligned() const
3856 {
3857  return true;
3858 }
3860 //*************************************************************************************************
3861 
3862 
3863 //*************************************************************************************************
3874 template< typename Type > // Data type of the matrix
3875 inline bool DynamicMatrix<Type,true>::canSMPAssign() const
3876 {
3877  return ( columns() > SMP_DMATASSIGN_THRESHOLD );
3878 }
3880 //*************************************************************************************************
3881 
3882 
3883 //*************************************************************************************************
3898 template< typename Type > // Data type of the matrix
3899 inline typename DynamicMatrix<Type,true>::IntrinsicType
3900  DynamicMatrix<Type,true>::load( size_t i, size_t j ) const
3901 {
3902  using blaze::load;
3903 
3905 
3906  BLAZE_INTERNAL_ASSERT( i < m_ , "Invalid row access index" );
3907  BLAZE_INTERNAL_ASSERT( i + IT::size <= mm_, "Invalid row access index" );
3908  BLAZE_INTERNAL_ASSERT( i % IT::size == 0UL, "Invalid row access index" );
3909  BLAZE_INTERNAL_ASSERT( j < n_ , "Invalid column access index" );
3910 
3911  return load( v_+i+j*mm_ );
3912 }
3914 //*************************************************************************************************
3915 
3916 
3917 //*************************************************************************************************
3932 template< typename Type > // Data type of the matrix
3933 inline typename DynamicMatrix<Type,true>::IntrinsicType
3934  DynamicMatrix<Type,true>::loadu( size_t i, size_t j ) const
3935 {
3936  using blaze::loadu;
3937 
3939 
3940  BLAZE_INTERNAL_ASSERT( i < m_ , "Invalid row access index" );
3941  BLAZE_INTERNAL_ASSERT( i + IT::size <= mm_, "Invalid row access index" );
3942  BLAZE_INTERNAL_ASSERT( j < n_ , "Invalid column access index" );
3943 
3944  return loadu( v_+i+j*mm_ );
3945 }
3947 //*************************************************************************************************
3948 
3949 
3950 //*************************************************************************************************
3966 template< typename Type > // Data type of the matrix
3967 inline void DynamicMatrix<Type,true>::store( size_t i, size_t j, const IntrinsicType& value )
3968 {
3969  using blaze::store;
3970 
3972 
3973  BLAZE_INTERNAL_ASSERT( i < m_ , "Invalid row access index" );
3974  BLAZE_INTERNAL_ASSERT( i + IT::size <= mm_, "Invalid row access index" );
3975  BLAZE_INTERNAL_ASSERT( i % IT::size == 0UL, "Invalid row access index" );
3976  BLAZE_INTERNAL_ASSERT( j < n_ , "Invalid column access index" );
3977 
3978  store( v_+i+j*mm_, value );
3979 }
3981 //*************************************************************************************************
3982 
3983 
3984 //*************************************************************************************************
4000 template< typename Type > // Data type of the matrix
4001 inline void DynamicMatrix<Type,true>::storeu( size_t i, size_t j, const IntrinsicType& value )
4002 {
4003  using blaze::storeu;
4004 
4006 
4007  BLAZE_INTERNAL_ASSERT( i < m_ , "Invalid row access index" );
4008  BLAZE_INTERNAL_ASSERT( i + IT::size <= mm_, "Invalid row access index" );
4009  BLAZE_INTERNAL_ASSERT( j < n_ , "Invalid column access index" );
4010 
4011  storeu( v_+i+j*mm_, value );
4012 }
4014 //*************************************************************************************************
4015 
4016 
4017 //*************************************************************************************************
4034 template< typename Type > // Data type of the matrix
4035 inline void DynamicMatrix<Type,true>::stream( size_t i, size_t j, const IntrinsicType& value )
4036 {
4037  using blaze::stream;
4038 
4040 
4041  BLAZE_INTERNAL_ASSERT( i < m_ , "Invalid row access index" );
4042  BLAZE_INTERNAL_ASSERT( i + IT::size <= mm_, "Invalid row access index" );
4043  BLAZE_INTERNAL_ASSERT( i % IT::size == 0UL, "Invalid row access index" );
4044  BLAZE_INTERNAL_ASSERT( j < n_ , "Invalid column access index" );
4045 
4046  stream( v_+i+j*mm_, value );
4047 }
4049 //*************************************************************************************************
4050 
4051 
4052 //*************************************************************************************************
4064 template< typename Type > // Data type of the matrix
4065 template< typename MT > // Type of the right-hand side dense matrix
4066 inline typename DisableIf< typename DynamicMatrix<Type,true>::BLAZE_TEMPLATE VectorizedAssign<MT> >::Type
4067  DynamicMatrix<Type,true>::assign( const DenseMatrix<MT,true>& rhs )
4068 {
4069  BLAZE_INTERNAL_ASSERT( m_ == (~rhs).rows() , "Invalid number of rows" );
4070  BLAZE_INTERNAL_ASSERT( n_ == (~rhs).columns(), "Invalid number of columns" );
4071 
4072  const size_t iend( m_ & size_t(-2) );
4073  BLAZE_INTERNAL_ASSERT( ( m_ - ( m_ % 2UL ) ) == iend, "Invalid end calculation" );
4074 
4075  for( size_t j=0UL; j<n_; ++j ) {
4076  for( size_t i=0UL; i<iend; i+=2UL ) {
4077  v_[i +j*mm_] = (~rhs)(i ,j);
4078  v_[i+1UL+j*mm_] = (~rhs)(i+1UL,j);
4079  }
4080  if( iend < m_ ) {
4081  v_[iend+j*mm_] = (~rhs)(iend,j);
4082  }
4083  }
4084 }
4086 //*************************************************************************************************
4087 
4088 
4089 //*************************************************************************************************
4101 template< typename Type > // Data type of the matrix
4102 template< typename MT > // Type of the right-hand side dense matrix
4103 inline typename EnableIf< typename DynamicMatrix<Type,true>::BLAZE_TEMPLATE VectorizedAssign<MT> >::Type
4104  DynamicMatrix<Type,true>::assign( const DenseMatrix<MT,true>& rhs )
4105 {
4106  using blaze::store;
4107  using blaze::stream;
4108 
4109  BLAZE_INTERNAL_ASSERT( m_ == (~rhs).rows() , "Invalid number of rows" );
4110  BLAZE_INTERNAL_ASSERT( n_ == (~rhs).columns(), "Invalid number of columns" );
4111 
4113 
4114  if( useStreaming && m_*n_ > ( cacheSize / ( sizeof(Type) * 3UL ) ) && !(~rhs).isAliased( this ) )
4115  {
4116  for( size_t j=0UL; j<n_; ++j )
4117  for( size_t i=0UL; i<m_; i+=IT::size )
4118  stream( v_+i+j*mm_, (~rhs).load(i,j) );
4119  }
4120  else
4121  {
4122  const size_t iend( m_ & size_t(-IT::size*4) );
4123  BLAZE_INTERNAL_ASSERT( ( m_ - ( m_ % (IT::size*4UL) ) ) == iend, "Invalid end calculation" );
4124 
4125  for( size_t j=0UL; j<n_; ++j ) {
4126  typename MT::ConstIterator it( (~rhs).begin(j) );
4127  for( size_t i=0UL; i<iend; i+=IT::size*4UL ) {
4128  store( v_+i+j*mm_ , it.load() ); it += IT::size;
4129  store( v_+i+j*mm_+IT::size , it.load() ); it += IT::size;
4130  store( v_+i+j*mm_+IT::size*2UL, it.load() ); it += IT::size;
4131  store( v_+i+j*mm_+IT::size*3UL, it.load() ); it += IT::size;
4132  }
4133  for( size_t i=iend; i<m_; i+=IT::size, it+=IT::size ) {
4134  store( v_+i+j*mm_, it.load() );
4135  }
4136  }
4137  }
4138 }
4140 //*************************************************************************************************
4141 
4142 
4143 //*************************************************************************************************
4155 template< typename Type > // Data type of the matrix
4156 template< typename MT > // Type of the right-hand side dense matrix
4157 inline void DynamicMatrix<Type,true>::assign( const DenseMatrix<MT,false>& rhs )
4158 {
4159  BLAZE_INTERNAL_ASSERT( m_ == (~rhs).rows() , "Invalid number of rows" );
4160  BLAZE_INTERNAL_ASSERT( n_ == (~rhs).columns(), "Invalid number of columns" );
4161 
4162  const size_t block( 16UL );
4163 
4164  for( size_t jj=0UL; jj<n_; jj+=block ) {
4165  const size_t jend( ( n_<(jj+block) )?( n_ ):( jj+block ) );
4166  for( size_t ii=0UL; ii<m_; ii+=block ) {
4167  const size_t iend( ( m_<(ii+block) )?( m_ ):( ii+block ) );
4168  for( size_t j=jj; j<jend; ++j ) {
4169  for( size_t i=ii; i<iend; ++i ) {
4170  v_[i+j*mm_] = (~rhs)(i,j);
4171  }
4172  }
4173  }
4174  }
4175 }
4177 //*************************************************************************************************
4178 
4179 
4180 //*************************************************************************************************
4192 template< typename Type > // Data type of the matrix
4193 template< typename MT > // Type of the right-hand side sparse matrix
4194 inline void DynamicMatrix<Type,true>::assign( const SparseMatrix<MT,true>& rhs )
4195 {
4196  for( size_t j=0UL; j<(~rhs).columns(); ++j )
4197  for( typename MT::ConstIterator element=(~rhs).begin(j); element!=(~rhs).end(j); ++element )
4198  v_[element->index()+j*mm_] = element->value();
4199 }
4201 //*************************************************************************************************
4202 
4203 
4204 //*************************************************************************************************
4216 template< typename Type > // Data type of the matrix
4217 template< typename MT > // Type of the right-hand side sparse matrix
4218 inline void DynamicMatrix<Type,true>::assign( const SparseMatrix<MT,false>& rhs )
4219 {
4220  for( size_t i=0UL; i<(~rhs).rows(); ++i )
4221  for( typename MT::ConstIterator element=(~rhs).begin(i); element!=(~rhs).end(i); ++element )
4222  v_[i+element->index()*mm_] = element->value();
4223 }
4225 //*************************************************************************************************
4226 
4227 
4228 //*************************************************************************************************
4240 template< typename Type > // Data type of the matrix
4241 template< typename MT > // Type of the right-hand side dense matrix
4242 inline typename DisableIf< typename DynamicMatrix<Type,true>::BLAZE_TEMPLATE VectorizedAddAssign<MT> >::Type
4243  DynamicMatrix<Type,true>::addAssign( const DenseMatrix<MT,true>& rhs )
4244 {
4245  BLAZE_INTERNAL_ASSERT( m_ == (~rhs).rows() , "Invalid number of rows" );
4246  BLAZE_INTERNAL_ASSERT( n_ == (~rhs).columns(), "Invalid number of columns" );
4247 
4248  const size_t iend( m_ & size_t(-2) );
4249  BLAZE_INTERNAL_ASSERT( ( m_ - ( m_ % 2UL ) ) == iend, "Invalid end calculation" );
4250 
4251  for( size_t j=0UL; j<n_; ++j ) {
4252  for( size_t i=0UL; i<iend; i+=2UL ) {
4253  v_[i +j*mm_] += (~rhs)(i ,j);
4254  v_[i+1UL+j*mm_] += (~rhs)(i+1UL,j);
4255  }
4256  if( iend < m_ ) {
4257  v_[iend+j*mm_] += (~rhs)(iend,j);
4258  }
4259  }
4260 }
4262 //*************************************************************************************************
4263 
4264 
4265 //*************************************************************************************************
4277 template< typename Type > // Data type of the matrix
4278 template< typename MT > // Type of the right-hand side dense matrix
4279 inline typename EnableIf< typename DynamicMatrix<Type,true>::BLAZE_TEMPLATE VectorizedAddAssign<MT> >::Type
4280  DynamicMatrix<Type,true>::addAssign( const DenseMatrix<MT,true>& rhs )
4281 {
4282  using blaze::load;
4283  using blaze::store;
4284 
4285  BLAZE_INTERNAL_ASSERT( m_ == (~rhs).rows() , "Invalid number of rows" );
4286  BLAZE_INTERNAL_ASSERT( n_ == (~rhs).columns(), "Invalid number of columns" );
4287 
4289 
4290  const size_t iend( m_ & size_t(-IT::size*4) );
4291  BLAZE_INTERNAL_ASSERT( ( m_ - ( m_ % (IT::size*4UL) ) ) == iend, "Invalid end calculation" );
4292 
4293  for( size_t j=0UL; j<n_; ++j ) {
4294  typename MT::ConstIterator it( (~rhs).begin(j) );
4295  for( size_t i=0UL; i<iend; i+=IT::size*4UL ) {
4296  store( v_+i+j*mm_ , load( v_+i+j*mm_ ) + it.load() ); it += IT::size;
4297  store( v_+i+j*mm_+IT::size , load( v_+i+j*mm_+IT::size ) + it.load() ); it += IT::size;
4298  store( v_+i+j*mm_+IT::size*2UL, load( v_+i+j*mm_+IT::size*2UL ) + it.load() ); it += IT::size;
4299  store( v_+i+j*mm_+IT::size*3UL, load( v_+i+j*mm_+IT::size*3UL ) + it.load() ); it += IT::size;
4300  }
4301  for( size_t i=iend; i<m_; i+=IT::size, it+=IT::size ) {
4302  store( v_+i+j*mm_, load( v_+i+j*mm_ ) + it.load() );
4303  }
4304  }
4305 }
4307 //*************************************************************************************************
4308 
4309 
4310 //*************************************************************************************************
4322 template< typename Type > // Data type of the matrix
4323 template< typename MT > // Type of the right-hand side dense matrix
4324 inline void DynamicMatrix<Type,true>::addAssign( const DenseMatrix<MT,false>& rhs )
4325 {
4326  BLAZE_INTERNAL_ASSERT( m_ == (~rhs).rows() , "Invalid number of rows" );
4327  BLAZE_INTERNAL_ASSERT( n_ == (~rhs).columns(), "Invalid number of columns" );
4328 
4329  const size_t block( 16UL );
4330 
4331  for( size_t jj=0UL; jj<n_; jj+=block ) {
4332  const size_t jend( ( n_<(jj+block) )?( n_ ):( jj+block ) );
4333  for( size_t ii=0UL; ii<m_; ii+=block ) {
4334  const size_t iend( ( m_<(ii+block) )?( m_ ):( ii+block ) );
4335  for( size_t j=jj; j<jend; ++j ) {
4336  for( size_t i=ii; i<iend; ++i ) {
4337  v_[i+j*mm_] += (~rhs)(i,j);
4338  }
4339  }
4340  }
4341  }
4342 }
4344 //*************************************************************************************************
4345 
4346 
4347 //*************************************************************************************************
4359 template< typename Type > // Data type of the matrix
4360 template< typename MT > // Type of the right-hand side sparse matrix
4361 inline void DynamicMatrix<Type,true>::addAssign( const SparseMatrix<MT,true>& rhs )
4362 {
4363  for( size_t j=0UL; j<(~rhs).columns(); ++j )
4364  for( typename MT::ConstIterator element=(~rhs).begin(j); element!=(~rhs).end(j); ++element )
4365  v_[element->index()+j*mm_] += element->value();
4366 }
4368 //*************************************************************************************************
4369 
4370 
4371 //*************************************************************************************************
4383 template< typename Type > // Data type of the matrix
4384 template< typename MT > // Type of the right-hand side sparse matrix
4385 inline void DynamicMatrix<Type,true>::addAssign( const SparseMatrix<MT,false>& rhs )
4386 {
4387  for( size_t i=0UL; i<(~rhs).rows(); ++i )
4388  for( typename MT::ConstIterator element=(~rhs).begin(i); element!=(~rhs).end(i); ++element )
4389  v_[i+element->index()*mm_] += element->value();
4390 }
4392 //*************************************************************************************************
4393 
4394 
4395 //*************************************************************************************************
4407 template< typename Type > // Data type of the matrix
4408 template< typename MT > // Type of the right-hand side dense matrix
4409 inline typename DisableIf< typename DynamicMatrix<Type,true>::BLAZE_TEMPLATE VectorizedSubAssign<MT> >::Type
4410  DynamicMatrix<Type,true>::subAssign( const DenseMatrix<MT,true>& rhs )
4411 {
4412  BLAZE_INTERNAL_ASSERT( m_ == (~rhs).rows() , "Invalid number of rows" );
4413  BLAZE_INTERNAL_ASSERT( n_ == (~rhs).columns(), "Invalid number of columns" );
4414 
4415  const size_t iend( m_ & size_t(-2) );
4416  BLAZE_INTERNAL_ASSERT( ( m_ - ( m_ % 2UL ) ) == iend, "Invalid end calculation" );
4417 
4418  for( size_t j=0UL; j<n_; ++j ) {
4419  for( size_t i=0UL; i<iend; i+=2UL ) {
4420  v_[i +j*mm_] -= (~rhs)(i ,j);
4421  v_[i+1+j*mm_] -= (~rhs)(i+1,j);
4422  }
4423  if( iend < m_ ) {
4424  v_[iend+j*mm_] -= (~rhs)(iend,j);
4425  }
4426  }
4427 }
4429 //*************************************************************************************************
4430 
4431 
4432 //*************************************************************************************************
4445 template< typename Type > // Data type of the matrix
4446 template< typename MT > // Type of the right-hand side dense matrix
4447 inline typename EnableIf< typename DynamicMatrix<Type,true>::BLAZE_TEMPLATE VectorizedSubAssign<MT> >::Type
4448  DynamicMatrix<Type,true>::subAssign( const DenseMatrix<MT,true>& rhs )
4449 {
4450  using blaze::load;
4451  using blaze::store;
4452 
4453  BLAZE_INTERNAL_ASSERT( m_ == (~rhs).rows() , "Invalid number of rows" );
4454  BLAZE_INTERNAL_ASSERT( n_ == (~rhs).columns(), "Invalid number of columns" );
4455 
4457 
4458  const size_t iend( m_ & size_t(-IT::size*4) );
4459  BLAZE_INTERNAL_ASSERT( ( m_ - ( m_ % (IT::size*4UL) ) ) == iend, "Invalid end calculation" );
4460 
4461  for( size_t j=0UL; j<n_; ++j ) {
4462  typename MT::ConstIterator it( (~rhs).begin(j) );
4463  for( size_t i=0UL; i<iend; i+=IT::size*4UL ) {
4464  store( v_+i+j*mm_ , load( v_+i+j*mm_ ) - it.load() ); it += IT::size;
4465  store( v_+i+j*mm_+IT::size , load( v_+i+j*mm_+IT::size ) - it.load() ); it += IT::size;
4466  store( v_+i+j*mm_+IT::size*2UL, load( v_+i+j*mm_+IT::size*2UL ) - it.load() ); it += IT::size;
4467  store( v_+i+j*mm_+IT::size*3UL, load( v_+i+j*mm_+IT::size*3UL ) - it.load() ); it += IT::size;
4468  }
4469  for( size_t i=iend; i<m_; i+=IT::size, it+=IT::size ) {
4470  store( v_+i+j*mm_, load( v_+i+j*mm_ ) - it.load() );
4471  }
4472  }
4473 }
4475 //*************************************************************************************************
4476 
4477 
4478 //*************************************************************************************************
4490 template< typename Type > // Data type of the matrix
4491 template< typename MT > // Type of the right-hand side dense matrix
4492 inline void DynamicMatrix<Type,true>::subAssign( const DenseMatrix<MT,false>& rhs )
4493 {
4494  const size_t block( 16UL );
4495 
4496  for( size_t jj=0UL; jj<n_; jj+=block ) {
4497  const size_t jend( ( n_<(jj+block) )?( n_ ):( jj+block ) );
4498  for( size_t ii=0UL; ii<m_; ii+=block ) {
4499  const size_t iend( ( m_<(ii+block) )?( m_ ):( ii+block ) );
4500  for( size_t j=jj; j<jend; ++j ) {
4501  for( size_t i=ii; i<iend; ++i ) {
4502  v_[i+j*mm_] -= (~rhs)(i,j);
4503  }
4504  }
4505  }
4506  }
4507 }
4509 //*************************************************************************************************
4510 
4511 
4512 //*************************************************************************************************
4524 template< typename Type > // Data type of the matrix
4525 template< typename MT > // Type of the right-hand side sparse matrix
4526 inline void DynamicMatrix<Type,true>::subAssign( const SparseMatrix<MT,true>& rhs )
4527 {
4528  for( size_t j=0UL; j<(~rhs).columns(); ++j )
4529  for( typename MT::ConstIterator element=(~rhs).begin(j); element!=(~rhs).end(j); ++element )
4530  v_[element->index()+j*mm_] -= element->value();
4531 }
4533 //*************************************************************************************************
4534 
4535 
4536 //*************************************************************************************************
4548 template< typename Type > // Data type of the matrix
4549 template< typename MT > // Type of the right-hand side sparse matrix
4550 inline void DynamicMatrix<Type,true>::subAssign( const SparseMatrix<MT,false>& rhs )
4551 {
4552  for( size_t i=0UL; i<(~rhs).rows(); ++i )
4553  for( typename MT::ConstIterator element=(~rhs).begin(i); element!=(~rhs).end(i); ++element )
4554  v_[i+element->index()*mm_] -= element->value();
4555 }
4557 //*************************************************************************************************
4558 
4559 
4560 
4561 
4562 
4563 
4564 
4565 
4566 //=================================================================================================
4567 //
4568 // DYNAMICMATRIX OPERATORS
4569 //
4570 //=================================================================================================
4571 
4572 //*************************************************************************************************
4575 template< typename Type, bool SO >
4576 inline void reset( DynamicMatrix<Type,SO>& m );
4577 
4578 template< typename Type, bool SO >
4579 inline void clear( DynamicMatrix<Type,SO>& m );
4580 
4581 template< typename Type, bool SO >
4582 inline bool isDefault( const DynamicMatrix<Type,SO>& m );
4583 
4584 template< typename Type, bool SO >
4585 inline void swap( DynamicMatrix<Type,SO>& a, DynamicMatrix<Type,SO>& b ) /* throw() */;
4587 //*************************************************************************************************
4588 
4589 
4590 //*************************************************************************************************
4597 template< typename Type // Data type of the matrix
4598  , bool SO > // Storage order
4600 {
4601  m.reset();
4602 }
4603 //*************************************************************************************************
4604 
4605 
4606 //*************************************************************************************************
4613 template< typename Type // Data type of the matrix
4614  , bool SO > // Storage order
4616 {
4617  m.clear();
4618 }
4619 //*************************************************************************************************
4620 
4621 
4622 //*************************************************************************************************
4640 template< typename Type // Data type of the matrix
4641  , bool SO > // Storage order
4642 inline bool isDefault( const DynamicMatrix<Type,SO>& m )
4643 {
4644  if( SO == rowMajor ) {
4645  for( size_t i=0UL; i<m.rows(); ++i )
4646  for( size_t j=0UL; j<m.columns(); ++j )
4647  if( !isDefault( m(i,j) ) ) return false;
4648  }
4649  else {
4650  for( size_t j=0UL; j<m.columns(); ++j )
4651  for( size_t i=0UL; i<m.rows(); ++i )
4652  if( !isDefault( m(i,j) ) ) return false;
4653  }
4654 
4655  return true;
4656 }
4657 //*************************************************************************************************
4658 
4659 
4660 //*************************************************************************************************
4669 template< typename Type // Data type of the matrix
4670  , bool SO > // Storage order
4671 inline void swap( DynamicMatrix<Type,SO>& a, DynamicMatrix<Type,SO>& b ) /* throw() */
4672 {
4673  a.swap( b );
4674 }
4675 //*************************************************************************************************
4676 
4677 
4678 
4679 
4680 //=================================================================================================
4681 //
4682 // ISRESIZABLE SPECIALIZATIONS
4683 //
4684 //=================================================================================================
4685 
4686 //*************************************************************************************************
4688 template< typename T, bool SO >
4689 struct IsResizable< DynamicMatrix<T,SO> > : public TrueType
4690 {
4691  enum { value = 1 };
4692  typedef TrueType Type;
4693 };
4694 
4695 template< typename T, bool SO >
4696 struct IsResizable< const DynamicMatrix<T,SO> > : public TrueType
4697 {
4698  enum { value = 1 };
4699  typedef TrueType Type;
4700 };
4701 
4702 template< typename T, bool SO >
4703 struct IsResizable< volatile DynamicMatrix<T,SO> > : public TrueType
4704 {
4705  enum { value = 1 };
4706  typedef TrueType Type;
4707 };
4708 
4709 template< typename T, bool SO >
4710 struct IsResizable< const volatile DynamicMatrix<T,SO> > : public TrueType
4711 {
4712  enum { value = 1 };
4713  typedef TrueType Type;
4714 };
4716 //*************************************************************************************************
4717 
4718 
4719 
4720 
4721 //=================================================================================================
4722 //
4723 // ADDTRAIT SPECIALIZATIONS
4724 //
4725 //=================================================================================================
4726 
4727 //*************************************************************************************************
4729 template< typename T1, bool SO, typename T2, size_t M, size_t N >
4730 struct AddTrait< DynamicMatrix<T1,SO>, StaticMatrix<T2,M,N,SO> >
4731 {
4732  typedef StaticMatrix< typename AddTrait<T1,T2>::Type, M, N, SO > Type;
4733 };
4734 
4735 template< typename T1, bool SO1, typename T2, size_t M, size_t N, bool SO2 >
4736 struct AddTrait< DynamicMatrix<T1,SO1>, StaticMatrix<T2,M,N,SO2> >
4737 {
4738  typedef StaticMatrix< typename AddTrait<T1,T2>::Type, M, N, false > Type;
4739 };
4740 
4741 template< typename T1, size_t M, size_t N, bool SO, typename T2 >
4742 struct AddTrait< StaticMatrix<T1,M,N,SO>, DynamicMatrix<T2,SO> >
4743 {
4744  typedef StaticMatrix< typename AddTrait<T1,T2>::Type, M, N, SO > Type;
4745 };
4746 
4747 template< typename T1, size_t M, size_t N, bool SO1, typename T2, bool SO2 >
4748 struct AddTrait< StaticMatrix<T1,M,N,SO1>, DynamicMatrix<T2,SO2> >
4749 {
4750  typedef StaticMatrix< typename AddTrait<T1,T2>::Type, M, N, false > Type;
4751 };
4752 
4753 template< typename T1, bool SO, typename T2, size_t M, size_t N >
4754 struct AddTrait< DynamicMatrix<T1,SO>, HybridMatrix<T2,M,N,SO> >
4755 {
4756  typedef HybridMatrix< typename AddTrait<T1,T2>::Type, M, N, SO > Type;
4757 };
4758 
4759 template< typename T1, bool SO1, typename T2, size_t M, size_t N, bool SO2 >
4760 struct AddTrait< DynamicMatrix<T1,SO1>, HybridMatrix<T2,M,N,SO2> >
4761 {
4762  typedef HybridMatrix< typename AddTrait<T1,T2>::Type, M, N, false > Type;
4763 };
4764 
4765 template< typename T1, size_t M, size_t N, bool SO, typename T2 >
4766 struct AddTrait< HybridMatrix<T1,M,N,SO>, DynamicMatrix<T2,SO> >
4767 {
4768  typedef HybridMatrix< typename AddTrait<T1,T2>::Type, M, N, SO > Type;
4769 };
4770 
4771 template< typename T1, size_t M, size_t N, bool SO1, typename T2, bool SO2 >
4772 struct AddTrait< HybridMatrix<T1,M,N,SO1>, DynamicMatrix<T2,SO2> >
4773 {
4774  typedef HybridMatrix< typename AddTrait<T1,T2>::Type, M, N, false > Type;
4775 };
4776 
4777 template< typename T1, bool SO, typename T2 >
4778 struct AddTrait< DynamicMatrix<T1,SO>, DynamicMatrix<T2,SO> >
4779 {
4780  typedef DynamicMatrix< typename AddTrait<T1,T2>::Type , SO > Type;
4781 };
4782 
4783 template< typename T1, bool SO1, typename T2, bool SO2 >
4784 struct AddTrait< DynamicMatrix<T1,SO1>, DynamicMatrix<T2,SO2> >
4785 {
4786  typedef DynamicMatrix< typename AddTrait<T1,T2>::Type , false > Type;
4787 };
4789 //*************************************************************************************************
4790 
4791 
4792 
4793 
4794 //=================================================================================================
4795 //
4796 // SUBTRAIT SPECIALIZATIONS
4797 //
4798 //=================================================================================================
4799 
4800 //*************************************************************************************************
4802 template< typename T1, bool SO, typename T2, size_t M, size_t N >
4803 struct SubTrait< DynamicMatrix<T1,SO>, StaticMatrix<T2,M,N,SO> >
4804 {
4805  typedef StaticMatrix< typename SubTrait<T1,T2>::Type, M, N, SO > Type;
4806 };
4807 
4808 template< typename T1, bool SO1, typename T2, size_t M, size_t N, bool SO2 >
4809 struct SubTrait< DynamicMatrix<T1,SO1>, StaticMatrix<T2,M,N,SO2> >
4810 {
4811  typedef StaticMatrix< typename SubTrait<T1,T2>::Type, M, N, false > Type;
4812 };
4813 
4814 template< typename T1, size_t M, size_t N, bool SO, typename T2 >
4815 struct SubTrait< StaticMatrix<T1,M,N,SO>, DynamicMatrix<T2,SO> >
4816 {
4817  typedef StaticMatrix< typename SubTrait<T1,T2>::Type, M, N, SO > Type;
4818 };
4819 
4820 template< typename T1, size_t M, size_t N, bool SO1, typename T2, bool SO2 >
4821 struct SubTrait< StaticMatrix<T1,M,N,SO1>, DynamicMatrix<T2,SO2> >
4822 {
4823  typedef StaticMatrix< typename SubTrait<T1,T2>::Type, M, N, false > Type;
4824 };
4825 
4826 template< typename T1, bool SO, typename T2, size_t M, size_t N >
4827 struct SubTrait< DynamicMatrix<T1,SO>, HybridMatrix<T2,M,N,SO> >
4828 {
4829  typedef HybridMatrix< typename SubTrait<T1,T2>::Type, M, N, SO > Type;
4830 };
4831 
4832 template< typename T1, bool SO1, typename T2, size_t M, size_t N, bool SO2 >
4833 struct SubTrait< DynamicMatrix<T1,SO1>, HybridMatrix<T2,M,N,SO2> >
4834 {
4835  typedef HybridMatrix< typename SubTrait<T1,T2>::Type, M, N, false > Type;
4836 };
4837 
4838 template< typename T1, size_t M, size_t N, bool SO, typename T2 >
4839 struct SubTrait< HybridMatrix<T1,M,N,SO>, DynamicMatrix<T2,SO> >
4840 {
4841  typedef HybridMatrix< typename SubTrait<T1,T2>::Type, M, N, SO > Type;
4842 };
4843 
4844 template< typename T1, size_t M, size_t N, bool SO1, typename T2, bool SO2 >
4845 struct SubTrait< HybridMatrix<T1,M,N,SO1>, DynamicMatrix<T2,SO2> >
4846 {
4847  typedef HybridMatrix< typename SubTrait<T1,T2>::Type, M, N, false > Type;
4848 };
4849 
4850 template< typename T1, bool SO, typename T2 >
4851 struct SubTrait< DynamicMatrix<T1,SO>, DynamicMatrix<T2,SO> >
4852 {
4853  typedef DynamicMatrix< typename SubTrait<T1,T2>::Type , SO > Type;
4854 };
4855 
4856 template< typename T1, bool SO1, typename T2, bool SO2 >
4857 struct SubTrait< DynamicMatrix<T1,SO1>, DynamicMatrix<T2,SO2> >
4858 {
4859  typedef DynamicMatrix< typename SubTrait<T1,T2>::Type , false > Type;
4860 };
4862 //*************************************************************************************************
4863 
4864 
4865 
4866 
4867 //=================================================================================================
4868 //
4869 // MULTTRAIT SPECIALIZATIONS
4870 //
4871 //=================================================================================================
4872 
4873 //*************************************************************************************************
4875 template< typename T1, bool SO, typename T2 >
4876 struct MultTrait< DynamicMatrix<T1,SO>, T2 >
4877 {
4878  typedef DynamicMatrix< typename MultTrait<T1,T2>::Type, SO > Type;
4880 };
4881 
4882 template< typename T1, typename T2, bool SO >
4883 struct MultTrait< T1, DynamicMatrix<T2,SO> >
4884 {
4885  typedef DynamicMatrix< typename MultTrait<T1,T2>::Type, SO > Type;
4887 };
4888 
4889 template< typename T1, bool SO, typename T2, size_t N >
4890 struct MultTrait< DynamicMatrix<T1,SO>, StaticVector<T2,N,false> >
4891 {
4892  typedef DynamicVector< typename MultTrait<T1,T2>::Type, false > Type;
4893 };
4894 
4895 template< typename T1, size_t N, typename T2, bool SO >
4896 struct MultTrait< StaticVector<T1,N,true>, DynamicMatrix<T2,SO> >
4897 {
4898  typedef DynamicVector< typename MultTrait<T1,T2>::Type, true > Type;
4899 };
4900 
4901 template< typename T1, bool SO, typename T2, size_t N >
4902 struct MultTrait< DynamicMatrix<T1,SO>, HybridVector<T2,N,false> >
4903 {
4904  typedef DynamicVector< typename MultTrait<T1,T2>::Type, false > Type;
4905 };
4906 
4907 template< typename T1, size_t N, typename T2, bool SO >
4908 struct MultTrait< HybridVector<T1,N,true>, DynamicMatrix<T2,SO> >
4909 {
4910  typedef DynamicVector< typename MultTrait<T1,T2>::Type, true > Type;
4911 };
4912 
4913 template< typename T1, bool SO, typename T2 >
4914 struct MultTrait< DynamicMatrix<T1,SO>, DynamicVector<T2,false> >
4915 {
4916  typedef DynamicVector< typename MultTrait<T1,T2>::Type, false > Type;
4917 };
4918 
4919 template< typename T1, typename T2, bool SO >
4920 struct MultTrait< DynamicVector<T1,true>, DynamicMatrix<T2,SO> >
4921 {
4922  typedef DynamicVector< typename MultTrait<T1,T2>::Type, true > Type;
4923 };
4924 
4925 template< typename T1, bool SO, typename T2 >
4926 struct MultTrait< DynamicMatrix<T1,SO>, CompressedVector<T2,false> >
4927 {
4928  typedef DynamicVector< typename MultTrait<T1,T2>::Type, false > Type;
4929 };
4930 
4931 template< typename T1, typename T2, bool SO >
4932 struct MultTrait< CompressedVector<T1,true>, DynamicMatrix<T2,SO> >
4933 {
4934  typedef DynamicVector< typename MultTrait<T1,T2>::Type, true > Type;
4935 };
4936 
4937 template< typename T1, bool SO1, typename T2, size_t M, size_t N, bool SO2 >
4938 struct MultTrait< DynamicMatrix<T1,SO1>, StaticMatrix<T2,M,N,SO2> >
4939 {
4940  typedef DynamicMatrix< typename MultTrait<T1,T2>::Type, SO1 > Type;
4941 };
4942 
4943 template< typename T1, size_t M, size_t N, bool SO1, typename T2, bool SO2 >
4944 struct MultTrait< StaticMatrix<T1,M,N,SO1>, DynamicMatrix<T2,SO2> >
4945 {
4946  typedef DynamicMatrix< typename MultTrait<T1,T2>::Type, SO1 > Type;
4947 };
4948 
4949 template< typename T1, bool SO1, typename T2, size_t M, size_t N, bool SO2 >
4950 struct MultTrait< DynamicMatrix<T1,SO1>, HybridMatrix<T2,M,N,SO2> >
4951 {
4952  typedef DynamicMatrix< typename MultTrait<T1,T2>::Type, SO1 > Type;
4953 };
4954 
4955 template< typename T1, size_t M, size_t N, bool SO1, typename T2, bool SO2 >
4956 struct MultTrait< HybridMatrix<T1,M,N,SO1>, DynamicMatrix<T2,SO2> >
4957 {
4958  typedef DynamicMatrix< typename MultTrait<T1,T2>::Type, SO1 > Type;
4959 };
4960 
4961 template< typename T1, bool SO1, typename T2, bool SO2 >
4962 struct MultTrait< DynamicMatrix<T1,SO1>, DynamicMatrix<T2,SO2> >
4963 {
4964  typedef DynamicMatrix< typename MultTrait<T1,T2>::Type, SO1 > Type;
4965 };
4967 //*************************************************************************************************
4968 
4969 
4970 
4971 
4972 //=================================================================================================
4973 //
4974 // DIVTRAIT SPECIALIZATIONS
4975 //
4976 //=================================================================================================
4977 
4978 //*************************************************************************************************
4980 template< typename T1, bool SO, typename T2 >
4981 struct DivTrait< DynamicMatrix<T1,SO>, T2 >
4982 {
4983  typedef DynamicMatrix< typename DivTrait<T1,T2>::Type , SO > Type;
4985 };
4987 //*************************************************************************************************
4988 
4989 
4990 
4991 
4992 //=================================================================================================
4993 //
4994 // MATHTRAIT SPECIALIZATIONS
4995 //
4996 //=================================================================================================
4997 
4998 //*************************************************************************************************
5000 template< typename T1, bool SO, typename T2 >
5001 struct MathTrait< DynamicMatrix<T1,SO>, DynamicMatrix<T2,SO> >
5002 {
5003  typedef DynamicMatrix< typename MathTrait<T1,T2>::HighType, SO > HighType;
5004  typedef DynamicMatrix< typename MathTrait<T1,T2>::LowType , SO > LowType;
5005 };
5007 //*************************************************************************************************
5008 
5009 
5010 
5011 
5012 //=================================================================================================
5013 //
5014 // SUBMATRIXTRAIT SPECIALIZATIONS
5015 //
5016 //=================================================================================================
5017 
5018 //*************************************************************************************************
5020 template< typename T1, bool SO >
5021 struct SubmatrixTrait< DynamicMatrix<T1,SO> >
5022 {
5023  typedef DynamicMatrix<T1,SO> Type;
5024 };
5026 //*************************************************************************************************
5027 
5028 
5029 
5030 
5031 //=================================================================================================
5032 //
5033 // ROWTRAIT SPECIALIZATIONS
5034 //
5035 //=================================================================================================
5036 
5037 //*************************************************************************************************
5039 template< typename T1, bool SO >
5040 struct RowTrait< DynamicMatrix<T1,SO> >
5041 {
5042  typedef DynamicVector<T1,true> Type;
5043 };
5045 //*************************************************************************************************
5046 
5047 
5048 
5049 
5050 //=================================================================================================
5051 //
5052 // COLUMNTRAIT SPECIALIZATIONS
5053 //
5054 //=================================================================================================
5055 
5056 //*************************************************************************************************
5058 template< typename T1, bool SO >
5059 struct ColumnTrait< DynamicMatrix<T1,SO> >
5060 {
5061  typedef DynamicVector<T1,false> Type;
5062 };
5064 //*************************************************************************************************
5065 
5066 } // namespace blaze
5067 
5068 #endif
Compile time check for vectorizable types.Depending on the available instruction set (SSE...
Definition: IsVectorizable.h:108
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:699
size_t n_
The current number of columns of the matrix.
Definition: DynamicMatrix.h:406
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:1499
void reset(DynamicMatrix< Type, SO > &m)
Resetting the given dense matrix.
Definition: DynamicMatrix.h:4599
#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 > >::Type store(T *address, const typename Store< T, sizeof(T)>::Type &value)
Aligned store of a vector of integral values.
Definition: Store.h:223
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:863
Header file for the row trait.
Type *BLAZE_RESTRICT v_
The dynamically allocated matrix elements.
Definition: DynamicMatrix.h:409
void smpSubAssign(DenseMatrix< MT1, SO1 > &lhs, const Matrix< MT2, SO2 > &rhs)
Default implementation of the SMP subtraction assignment of a matrix to dense matrix.
Definition: DenseMatrix.h:152
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:4642
Efficient implementation of a compressed matrix.The CompressedMatrix class template is the represent...
Definition: CompressedMatrix.h:199
void resize(size_t m, size_t n, bool preserve=true)
Changing the size of the matrix.
Definition: DynamicMatrix.h:1423
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:1217
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:1800
size_t m_
The current number of rows of the sparse matrix.
Definition: CompressedMatrix.h:2555
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
DynamicMatrix()
The default constructor for DynamicMatrix.
Definition: DynamicMatrix.h:447
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:1236
Efficient implementation of a dynamic matrix.The DynamicMatrix class template is the representation ...
Definition: DynamicMatrix.h:178
void clear(DynamicMatrix< Type, SO > &m)
Clearing the given dense matrix.
Definition: DynamicMatrix.h:4615
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:194
Base class for sparse matrices.The SparseMatrix class is a base class for all sparse matrix classes...
Definition: Forward.h:107
Constraint on the data type.
size_t capacity_
The current capacity of the pointer array.
Definition: CompressedMatrix.h:2557
~DynamicMatrix()
The destructor for DynamicMatrix.
Definition: DynamicMatrix.h:674
This ResultType
Result type for expression template evaluations.
Definition: DynamicMatrix.h:188
Header file for the SparseMatrix base class.
void deallocate(T *address)
Deallocation of memory.
Definition: Memory.h:115
size_t nonZeros() const
Returns the total number of non-zero elements in the matrix.
Definition: DynamicMatrix.h:1286
size_t adjustColumns(size_t minColumns) const
Adjusting the number columns of the matrix according to its data type Type.
Definition: DynamicMatrix.h:1587
void smpAddAssign(DenseMatrix< MT1, SO1 > &lhs, const Matrix< MT2, SO2 > &rhs)
Default implementation of the SMP addition assignment of a matrix to a dense matrix.
Definition: DenseMatrix.h:122
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:929
Header file for the multiplication trait.
bool isAligned() const
Returns whether the matrix is properly aligned in memory.
Definition: DynamicMatrix.h:1655
IntrinsicType loadu(size_t i, size_t j) const
Unaligned load of an intrinsic element of the matrix.
Definition: DynamicMatrix.h:1733
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:4605
Type ElementType
Type of the matrix elements.
Definition: DynamicMatrix.h:191
Header file for all forward declarations of the math module.
const Element * ConstIterator
Iterator over constant elements.
Definition: CompressedMatrix.h:2412
#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
Header file for the IsSMPAssignable type trait.
IntrinsicTrait< Type > IT
Intrinsic trait for the matrix element type.
Definition: DynamicMatrix.h:182
DynamicMatrix< Type, SO > This
Type of this DynamicMatrix instance.
Definition: DynamicMatrix.h:187
Header file for the DenseMatrix base class.
Header file for the DenseIterator class template.
const size_t SMP_DMATASSIGN_THRESHOLD
SMP dense matrix assignment threshold.This threshold specifies when an assignment with a plain dense ...
Definition: Thresholds.h:690
const Type & ReturnType
Return type for expression template evaluations.
Definition: DynamicMatrix.h:193
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:271
Constraint on the data type.
void extend(size_t m, size_t n, bool preserve=true)
Extending the size of the matrix.
Definition: DynamicMatrix.h:1481
size_t rows() const
Returns the current number of rows of the matrix.
Definition: DynamicMatrix.h:1203
#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:1336
Iterator end(size_t i)
Returns an iterator just past the last element of row/column i.
Definition: DynamicMatrix.h:885
Compile time check for data types.This type trait tests whether or not the given template parameter i...
Definition: IsSMPAssignable.h:120
const Type & ConstReference
Reference to a constant matrix value.
Definition: CompressedMatrix.h:2410
System settings for streaming (non-temporal stores)
Header file for the EnableIf class template.
EnableIf< IsIntegral< T > >::Type storeu(T *address, const typename Storeu< T, sizeof(T)>::Type &value)
Unaligned store of a vector of integral values.
Definition: Storeu.h:216
DynamicMatrix< Type,!SO > OppositeType
Result type with opposite storage order for expression template evaluations.
Definition: DynamicMatrix.h:189
size_t capacity() const
Returns the maximum capacity of the matrix.
Definition: DynamicMatrix.h:1250
Header file for the equal shim.
Header file for the IsVectorizable type trait.
void smpAssign(DenseMatrix< MT1, SO1 > &lhs, const Matrix< MT2, SO2 > &rhs)
Default implementation of the SMP assignment of a matrix to a dense matrix.
Definition: DenseMatrix.h:92
Header file for the IsNumeric type trait.
size_t nn_
The alignment adjusted number of columns.
Definition: DynamicMatrix.h:407
void store(size_t i, size_t j, const IntrinsicType &value)
Aligned store of an intrinsic element of the matrix.
Definition: DynamicMatrix.h:1766
Type * Pointer
Pointer to a non-constant matrix value.
Definition: DynamicMatrix.h:197
EnableIf< IsIntegral< T > >::Type stream(T *address, const typename Stream< T, sizeof(T)>::Type &value)
Aligned, non-temporal store of a vector of integral values.
Definition: Stream.h:218
Intrinsic characteristics of data types.The IntrinsicTrait class template provides the intrinsic char...
Definition: IntrinsicTrait.h:748
Header file for run time assertion macros.
Header file for the addition trait.
void clear()
Clearing the matrix.
Definition: DynamicMatrix.h:1380
const Type * ConstPointer
Pointer to a constant matrix value.
Definition: DynamicMatrix.h:198
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:4671
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:301
Header file for the submatrix trait.
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:405
Iterator begin(size_t i)
Returns an iterator to the first element of row/column i.
Definition: DynamicMatrix.h:819
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:1637
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:331
#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:2411
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:87
Constraint on the data type.
void swap(DynamicMatrix &m)
Swapping the contents of two matrices.
Definition: DynamicMatrix.h:1568
IntrinsicType load(size_t i, size_t j) const
Aligned load of an intrinsic element of the matrix.
Definition: DynamicMatrix.h:1699
T * allocate(size_t size)
Aligned array allocation.
Definition: Memory.h:84
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:195
bool canSMPAssign() const
Returns whether the matrix can be used in SMP assignments.
Definition: DynamicMatrix.h:1674
size_t n_
The current number of columns of the sparse matrix.
Definition: CompressedMatrix.h:2556
DenseIterator< const Type > ConstIterator
Iterator over constant elements.
Definition: DynamicMatrix.h:200
const DMatTransExpr< MT,!SO > trans(const DenseMatrix< MT, SO > &dm)
Calculation of the transpose of the given dense matrix.
Definition: DMatTransExpr.h:907
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:192
size_t capacity_
The maximum capacity of the matrix.
Definition: DynamicMatrix.h:408
This ResultType
Result type for expression template evaluations.
Definition: CompressedMatrix.h:2403
size_t columns(const Matrix< MT, SO > &m)
Returns the current number of columns of the matrix.
Definition: Matrix.h:170
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:199
MatrixAccessProxy< This > Reference
Reference to a non-constant matrix value.
Definition: CompressedMatrix.h:2409
const VT::ElementType min(const SparseVector< VT, TF > &sv)
Returns the smallest element of the sparse vector.
Definition: SparseVector.h:351
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
Pointer data()
Low-level data access to the matrix elements.
Definition: DynamicMatrix.h:741
Header file for the IsResizable type trait.
Header file for the thresholds for matrix/vector and matrix/matrix multiplications.
size_t rows(const Matrix< MT, SO > &m)
Returns the current number of rows of the matrix.
Definition: Matrix.h:154
#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:1617
DynamicMatrix & transpose()
Transposing the matrix.
Definition: DynamicMatrix.h:1530
const Type & ConstReference
Reference to a constant matrix value.
Definition: DynamicMatrix.h:196
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:190
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:1833