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>
66 #include <blaze/system/CacheSize.h>
67 #include <blaze/system/Restrict.h>
69 #include <blaze/system/Streaming.h>
71 #include <blaze/util/Assert.h>
78 #include <blaze/util/DisableIf.h>
79 #include <blaze/util/EnableIf.h>
80 #include <blaze/util/Memory.h>
81 #include <blaze/util/Null.h>
82 #include <blaze/util/Template.h>
83 #include <blaze/util/Types.h>
87 #include <blaze/util/Unused.h>
88 
89 
90 namespace blaze {
91 
92 //=================================================================================================
93 //
94 // CLASS DEFINITION
95 //
96 //=================================================================================================
97 
98 //*************************************************************************************************
177 template< typename Type // Data type of the matrix
178  , bool SO = defaultStorageOrder > // Storage order
179 class DynamicMatrix : public DenseMatrix< DynamicMatrix<Type,SO>, SO >
180 {
181  private:
182  //**Type definitions****************************************************************************
184  //**********************************************************************************************
185 
186  public:
187  //**Type definitions****************************************************************************
189  typedef This ResultType;
192  typedef Type ElementType;
193  typedef typename IT::Type IntrinsicType;
194  typedef const Type& ReturnType;
195  typedef const This& CompositeType;
196  typedef Type& Reference;
197  typedef const Type& ConstReference;
200  //**********************************************************************************************
201 
202  //**Compilation flags***************************************************************************
204 
208  enum { vectorizable = IsVectorizable<Type>::value };
209 
211 
214  enum { smpAssignable = 1 };
215  //**********************************************************************************************
216 
217  //**Constructors********************************************************************************
220  explicit inline DynamicMatrix();
221  explicit inline DynamicMatrix( size_t m, size_t n );
222  explicit inline DynamicMatrix( size_t m, size_t n, const Type& init );
223  template< typename Other > explicit inline DynamicMatrix( size_t m, size_t n, const Other* array );
224 
225  template< typename Other, size_t M, size_t N >
226  explicit inline DynamicMatrix( const Other (&array)[M][N] );
227 
228  inline DynamicMatrix( const DynamicMatrix& m );
229  template< typename MT, bool SO2 > inline DynamicMatrix( const Matrix<MT,SO2>& m );
231  //**********************************************************************************************
232 
233  //**Destructor**********************************************************************************
236  inline ~DynamicMatrix();
238  //**********************************************************************************************
239 
240  //**Data access functions***********************************************************************
243  inline Reference operator()( size_t i, size_t j );
244  inline ConstReference operator()( size_t i, size_t j ) const;
245  inline Type* data ();
246  inline const Type* data () const;
247  inline Type* data ( size_t i );
248  inline const Type* data ( size_t i ) const;
249  inline Iterator begin ( size_t i );
250  inline ConstIterator begin ( size_t i ) const;
251  inline ConstIterator cbegin( size_t i ) const;
252  inline Iterator end ( size_t i );
253  inline ConstIterator end ( size_t i ) const;
254  inline ConstIterator cend ( size_t i ) const;
256  //**********************************************************************************************
257 
258  //**Assignment operators************************************************************************
261  template< typename Other, size_t M, size_t N >
262  inline DynamicMatrix& operator=( const Other (&array)[M][N] );
263 
264  inline DynamicMatrix& operator= ( Type set );
265  inline DynamicMatrix& operator= ( const DynamicMatrix& set );
266  template< typename MT, bool SO2 > inline DynamicMatrix& operator= ( const Matrix<MT,SO2>& rhs );
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 
271  template< typename Other >
272  inline typename EnableIf< IsNumeric<Other>, DynamicMatrix >::Type&
273  operator*=( Other rhs );
274 
275  template< typename Other >
276  inline typename EnableIf< IsNumeric<Other>, DynamicMatrix >::Type&
277  operator/=( Other rhs );
279  //**********************************************************************************************
280 
281  //**Utility functions***************************************************************************
284  inline size_t rows() const;
285  inline size_t columns() const;
286  inline size_t spacing() const;
287  inline size_t capacity() const;
288  inline size_t capacity( size_t i ) const;
289  inline size_t nonZeros() const;
290  inline size_t nonZeros( size_t i ) const;
291  inline void reset();
292  inline void reset( size_t i );
293  inline void clear();
294  void resize ( size_t m, size_t n, bool preserve=true );
295  inline void extend ( size_t m, size_t n, bool preserve=true );
296  inline void reserve( size_t elements );
297  inline DynamicMatrix& transpose();
298  template< typename Other > inline DynamicMatrix& scale( Other scalar );
299  inline void swap( DynamicMatrix& m ) /* throw() */;
301  //**********************************************************************************************
302 
303  private:
304  //**********************************************************************************************
306  template< typename MT >
308  struct VectorizedAssign {
309  enum { value = vectorizable && MT::vectorizable &&
310  IsSame<Type,typename MT::ElementType>::value };
311  };
313  //**********************************************************************************************
314 
315  //**********************************************************************************************
317  template< typename MT >
319  struct VectorizedAddAssign {
320  enum { value = vectorizable && MT::vectorizable &&
321  IsSame<Type,typename MT::ElementType>::value &&
322  IntrinsicTrait<Type>::addition };
323  };
325  //**********************************************************************************************
326 
327  //**********************************************************************************************
329  template< typename MT >
331  struct VectorizedSubAssign {
332  enum { value = vectorizable && MT::vectorizable &&
333  IsSame<Type,typename MT::ElementType>::value &&
334  IntrinsicTrait<Type>::subtraction };
335  };
337  //**********************************************************************************************
338 
339  public:
340  //**Expression template evaluation functions****************************************************
343  template< typename Other > inline bool canAlias ( const Other* alias ) const;
344  template< typename Other > inline bool isAliased( const Other* alias ) const;
345 
346  inline bool isAligned () const;
347  inline bool canSMPAssign() const;
348 
349  inline IntrinsicType load ( size_t i, size_t j ) const;
350  inline IntrinsicType loadu ( size_t i, size_t j ) const;
351  inline void store ( size_t i, size_t j, const IntrinsicType& value );
352  inline void storeu( size_t i, size_t j, const IntrinsicType& value );
353  inline void stream( size_t i, size_t j, const IntrinsicType& value );
354 
355  template< typename MT >
356  inline typename DisableIf< VectorizedAssign<MT> >::Type
357  assign( const DenseMatrix<MT,SO>& rhs );
358 
359  template< typename MT >
360  inline typename EnableIf< VectorizedAssign<MT> >::Type
361  assign( const DenseMatrix<MT,SO>& rhs );
362 
363  template< typename MT > inline void assign( const DenseMatrix<MT,!SO>& rhs );
364  template< typename MT > inline void assign( const SparseMatrix<MT,SO>& rhs );
365  template< typename MT > inline void assign( const SparseMatrix<MT,!SO>& rhs );
366 
367  template< typename MT >
368  inline typename DisableIf< VectorizedAddAssign<MT> >::Type
369  addAssign( const DenseMatrix<MT,SO>& rhs );
370 
371  template< typename MT >
372  inline typename EnableIf< VectorizedAddAssign<MT> >::Type
373  addAssign( const DenseMatrix<MT,SO>& rhs );
374 
375  template< typename MT > inline void addAssign( const DenseMatrix<MT,!SO>& rhs );
376  template< typename MT > inline void addAssign( const SparseMatrix<MT,SO>& rhs );
377  template< typename MT > inline void addAssign( const SparseMatrix<MT,!SO>& rhs );
378 
379  template< typename MT >
380  inline typename DisableIf< VectorizedSubAssign<MT> >::Type
381  subAssign( const DenseMatrix<MT,SO>& rhs );
382 
383  template< typename MT >
384  inline typename EnableIf< VectorizedSubAssign<MT> >::Type
385  subAssign( const DenseMatrix<MT,SO>& rhs );
386 
387  template< typename MT > inline void subAssign( const DenseMatrix<MT,!SO>& rhs );
388  template< typename MT > inline void subAssign( const SparseMatrix<MT,SO>& rhs );
389  template< typename MT > inline void subAssign( const SparseMatrix<MT,!SO>& rhs );
391  //**********************************************************************************************
392 
393  private:
394  //**Utility functions***************************************************************************
397  inline size_t adjustColumns( size_t minColumns ) const;
399  //**********************************************************************************************
400 
401  //**Member variables****************************************************************************
404  size_t m_;
405  size_t n_;
406  size_t nn_;
407  size_t capacity_;
409 
419  //**********************************************************************************************
420 
421  //**Compile time checks*************************************************************************
428  //**********************************************************************************************
429 };
430 //*************************************************************************************************
431 
432 
433 
434 
435 //=================================================================================================
436 //
437 // CONSTRUCTORS
438 //
439 //=================================================================================================
440 
441 //*************************************************************************************************
444 template< typename Type // Data type of the matrix
445  , bool SO > // Storage order
447  : m_ ( 0UL ) // The current number of rows of the matrix
448  , n_ ( 0UL ) // The current number of columns of the matrix
449  , nn_ ( 0UL ) // The alignment adjusted number of columns
450  , capacity_( 0UL ) // The maximum capacity of the matrix
451  , v_ ( NULL ) // The matrix elements
452 {}
453 //*************************************************************************************************
454 
455 
456 //*************************************************************************************************
465 template< typename Type // Data type of the matrix
466  , bool SO > // Storage order
467 inline DynamicMatrix<Type,SO>::DynamicMatrix( size_t m, size_t n )
468  : m_ ( m ) // The current number of rows of the matrix
469  , n_ ( n ) // The current number of columns of the matrix
470  , nn_ ( adjustColumns( n ) ) // The alignment adjusted number of columns
471  , capacity_( m_*nn_ ) // The maximum capacity of the matrix
472  , v_ ( allocate<Type>( capacity_ ) ) // The matrix elements
473 {
474  if( IsNumeric<Type>::value ) {
475  for( size_t i=0UL; i<m_; ++i ) {
476  for( size_t j=n_; j<nn_; ++j )
477  v_[i*nn_+j] = Type();
478  }
479  }
480 }
481 //*************************************************************************************************
482 
483 
484 //*************************************************************************************************
493 template< typename Type // Data type of the matrix
494  , bool SO > // Storage order
495 inline DynamicMatrix<Type,SO>::DynamicMatrix( size_t m, size_t n, const Type& init )
496  : m_ ( m ) // The current number of rows of the matrix
497  , n_ ( n ) // The current number of columns of the matrix
498  , nn_ ( adjustColumns( n ) ) // The alignment adjusted number of columns
499  , capacity_( m_*nn_ ) // The maximum capacity of the matrix
500  , v_ ( allocate<Type>( capacity_ ) ) // The matrix elements
501 {
502  for( size_t i=0UL; i<m; ++i ) {
503  for( size_t j=0UL; j<n_; ++j )
504  v_[i*nn_+j] = init;
505 
506  if( IsNumeric<Type>::value ) {
507  for( size_t j=n_; j<nn_; ++j )
508  v_[i*nn_+j] = Type();
509  }
510  }
511 }
512 //*************************************************************************************************
513 
514 
515 //*************************************************************************************************
538 template< typename Type // Data type of the matrix
539  , bool SO > // Storage order
540 template< typename Other > // Data type of the initialization array
541 inline DynamicMatrix<Type,SO>::DynamicMatrix( size_t m, size_t n, const Other* array )
542  : m_ ( m ) // The current number of rows of the matrix
543  , n_ ( n ) // The current number of columns of the matrix
544  , nn_ ( adjustColumns( n ) ) // The alignment adjusted number of columns
545  , capacity_( m_*nn_ ) // The maximum capacity of the matrix
546  , v_ ( allocate<Type>( capacity_ ) ) // The matrix elements
547 {
548  for( size_t i=0UL; i<m; ++i ) {
549  for( size_t j=0UL; j<n; ++j )
550  v_[i*nn_+j] = array[i*n+j];
551 
552  if( IsNumeric<Type>::value ) {
553  for( size_t j=n; j<nn_; ++j )
554  v_[i*nn_+j] = Type();
555  }
556  }
557 }
558 //*************************************************************************************************
559 
560 
561 //*************************************************************************************************
582 template< typename Type // Data type of the matrix
583  , bool SO > // Storage order
584 template< typename Other // Data type of the initialization array
585  , size_t M // Number of rows of the initialization array
586  , size_t N > // Number of columns of the initialization array
587 inline DynamicMatrix<Type,SO>::DynamicMatrix( const Other (&array)[M][N] )
588  : m_ ( M ) // The current number of rows of the matrix
589  , n_ ( N ) // The current number of columns of the matrix
590  , nn_ ( adjustColumns( N ) ) // The alignment adjusted number of columns
591  , capacity_( m_*nn_ ) // The maximum capacity of the matrix
592  , v_ ( allocate<Type>( capacity_ ) ) // The matrix elements
593 {
594  for( size_t i=0UL; i<M; ++i ) {
595  for( size_t j=0UL; j<N; ++j )
596  v_[i*nn_+j] = array[i][j];
597 
598  if( IsNumeric<Type>::value ) {
599  for( size_t j=N; j<nn_; ++j )
600  v_[i*nn_+j] = Type();
601  }
602  }
603 }
604 //*************************************************************************************************
605 
606 
607 //*************************************************************************************************
615 template< typename Type // Data type of the matrix
616  , bool SO > // Storage order
618  : m_ ( m.m_ ) // The current number of rows of the matrix
619  , n_ ( m.n_ ) // The current number of columns of the matrix
620  , nn_ ( m.nn_ ) // The alignment adjusted number of columns
621  , capacity_( m_*nn_ ) // The maximum capacity of the matrix
622  , v_ ( allocate<Type>( capacity_ ) ) // The matrix elements
623 {
624  BLAZE_INTERNAL_ASSERT( capacity_ <= m.capacity_, "Invalid capacity estimation" );
625 
626  for( size_t i=0UL; i<capacity_; ++i )
627  v_[i] = m.v_[i];
628 }
629 //*************************************************************************************************
630 
631 
632 //*************************************************************************************************
637 template< typename Type // Data type of the matrix
638  , bool SO > // Storage order
639 template< typename MT // Type of the foreign matrix
640  , bool SO2 > // Storage order of the foreign matrix
642  : m_ ( (~m).rows() ) // The current number of rows of the matrix
643  , n_ ( (~m).columns() ) // The current number of columns of the matrix
644  , nn_ ( adjustColumns( n_ ) ) // The alignment adjusted number of columns
645  , capacity_( m_*nn_ ) // The maximum capacity of the matrix
646  , v_ ( allocate<Type>( capacity_ ) ) // The matrix elements
647 {
648  if( IsNumeric<Type>::value ) {
649  for( size_t i=0UL; i<m_; ++i ) {
650  for( size_t j=( IsSparseMatrix<MT>::value )?( 0UL ):( n_ ); j<nn_; ++j )
651  v_[i*nn_+j] = Type();
652  }
653  }
654 
655  smpAssign( *this, ~m );
656 }
657 //*************************************************************************************************
658 
659 
660 
661 
662 //=================================================================================================
663 //
664 // DESTRUCTOR
665 //
666 //=================================================================================================
667 
668 //*************************************************************************************************
671 template< typename Type // Data type of the matrix
672  , bool SO > // Storage order
674 {
675  deallocate( v_ );
676 }
677 //*************************************************************************************************
678 
679 
680 
681 
682 //=================================================================================================
683 //
684 // DATA ACCESS FUNCTIONS
685 //
686 //=================================================================================================
687 
688 //*************************************************************************************************
695 template< typename Type // Data type of the matrix
696  , bool SO > // Storage order
697 inline typename DynamicMatrix<Type,SO>::Reference
699 {
700  BLAZE_USER_ASSERT( i<m_, "Invalid row access index" );
701  BLAZE_USER_ASSERT( j<n_, "Invalid column access index" );
702  return v_[i*nn_+j];
703 }
704 //*************************************************************************************************
705 
706 
707 //*************************************************************************************************
714 template< typename Type // Data type of the matrix
715  , bool SO > // Storage order
717  DynamicMatrix<Type,SO>::operator()( size_t i, size_t j ) const
718 {
719  BLAZE_USER_ASSERT( i<m_, "Invalid row access index" );
720  BLAZE_USER_ASSERT( j<n_, "Invalid column access index" );
721  return v_[i*nn_+j];
722 }
723 //*************************************************************************************************
724 
725 
726 //*************************************************************************************************
735 template< typename Type // Data type of the matrix
736  , bool SO > // Storage order
738 {
739  return v_;
740 }
741 //*************************************************************************************************
742 
743 
744 //*************************************************************************************************
753 template< typename Type // Data type of the matrix
754  , bool SO > // Storage order
755 inline const Type* DynamicMatrix<Type,SO>::data() const
756 {
757  return v_;
758 }
759 //*************************************************************************************************
760 
761 
762 //*************************************************************************************************
770 template< typename Type // Data type of the matrix
771  , bool SO > // Storage order
772 inline Type* DynamicMatrix<Type,SO>::data( size_t i )
773 {
774  BLAZE_USER_ASSERT( i < m_, "Invalid dense matrix row access index" );
775  return v_ + i*nn_;
776 }
777 //*************************************************************************************************
778 
779 
780 //*************************************************************************************************
788 template< typename Type // Data type of the matrix
789  , bool SO > // Storage order
790 inline const Type* DynamicMatrix<Type,SO>::data( size_t i ) const
791 {
792  BLAZE_USER_ASSERT( i < m_, "Invalid dense matrix row access index" );
793  return v_ + i*nn_;
794 }
795 //*************************************************************************************************
796 
797 
798 //*************************************************************************************************
809 template< typename Type // Data type of the matrix
810  , bool SO > // Storage order
811 inline typename DynamicMatrix<Type,SO>::Iterator
813 {
814  BLAZE_USER_ASSERT( i < m_, "Invalid dense matrix row access index" );
815  return Iterator( v_ + i*nn_ );
816 }
817 //*************************************************************************************************
818 
819 
820 //*************************************************************************************************
831 template< typename Type // Data type of the matrix
832  , bool SO > // Storage order
835 {
836  BLAZE_USER_ASSERT( i < m_, "Invalid dense matrix row access index" );
837  return ConstIterator( v_ + i*nn_ );
838 }
839 //*************************************************************************************************
840 
841 
842 //*************************************************************************************************
853 template< typename Type // Data type of the matrix
854  , bool SO > // Storage order
857 {
858  BLAZE_USER_ASSERT( i < m_, "Invalid dense matrix row access index" );
859  return ConstIterator( v_ + i*nn_ );
860 }
861 //*************************************************************************************************
862 
863 
864 //*************************************************************************************************
875 template< typename Type // Data type of the matrix
876  , bool SO > // Storage order
877 inline typename DynamicMatrix<Type,SO>::Iterator
879 {
880  BLAZE_USER_ASSERT( i < m_, "Invalid dense matrix row access index" );
881  return Iterator( v_ + i*nn_ + n_ );
882 }
883 //*************************************************************************************************
884 
885 
886 //*************************************************************************************************
897 template< typename Type // Data type of the matrix
898  , bool SO > // Storage order
900  DynamicMatrix<Type,SO>::end( size_t i ) const
901 {
902  BLAZE_USER_ASSERT( i < m_, "Invalid dense matrix row access index" );
903  return ConstIterator( v_ + i*nn_ + n_ );
904 }
905 //*************************************************************************************************
906 
907 
908 //*************************************************************************************************
919 template< typename Type // Data type of the matrix
920  , bool SO > // Storage order
923 {
924  BLAZE_USER_ASSERT( i < m_, "Invalid dense matrix row access index" );
925  return ConstIterator( v_ + i*nn_ + n_ );
926 }
927 //*************************************************************************************************
928 
929 
930 
931 
932 //=================================================================================================
933 //
934 // ASSIGNMENT OPERATORS
935 //
936 //=================================================================================================
937 
938 //*************************************************************************************************
959 template< typename Type // Data type of the matrix
960  , bool SO > // Storage order
961 template< typename Other // Data type of the initialization array
962  , size_t M // Number of rows of the initialization array
963  , size_t N > // Number of columns of the initialization array
964 inline DynamicMatrix<Type,SO>& DynamicMatrix<Type,SO>::operator=( const Other (&array)[M][N] )
965 {
966  resize( M, N, false );
967 
968  for( size_t i=0UL; i<M; ++i )
969  for( size_t j=0UL; j<N; ++j )
970  v_[i*nn_+j] = array[i][j];
971 
972  return *this;
973 }
974 //*************************************************************************************************
975 
976 
977 //*************************************************************************************************
983 template< typename Type // Data type of the matrix
984  , bool SO > // Storage order
986 {
987  for( size_t i=0UL; i<m_; ++i )
988  for( size_t j=0UL; j<n_; ++j )
989  v_[i*nn_+j] = rhs;
990 
991  return *this;
992 }
993 //*************************************************************************************************
994 
995 
996 //*************************************************************************************************
1005 template< typename Type // Data type of the matrix
1006  , bool SO > // Storage order
1008 {
1009  if( &rhs == this ) return *this;
1010 
1011  resize( rhs.m_, rhs.n_, false );
1012  smpAssign( *this, ~rhs );
1013 
1014  return *this;
1015 }
1016 //*************************************************************************************************
1017 
1018 
1019 //*************************************************************************************************
1028 template< typename Type // Data type of the matrix
1029  , bool SO > // Storage order
1030 template< typename MT // Type of the right-hand side matrix
1031  , bool SO2 > // Storage order of the right-hand side matrix
1033 {
1034  if( (~rhs).canAlias( this ) ) {
1035  DynamicMatrix tmp( ~rhs );
1036  swap( tmp );
1037  }
1038  else {
1039  resize( (~rhs).rows(), (~rhs).columns(), false );
1041  reset();
1042  smpAssign( *this, ~rhs );
1043  }
1044 
1045  return *this;
1046 }
1047 //*************************************************************************************************
1048 
1049 
1050 //*************************************************************************************************
1060 template< typename Type // Data type of the matrix
1061  , bool SO > // Storage order
1062 template< typename MT // Type of the right-hand side matrix
1063  , bool SO2 > // Storage order of the right-hand side matrix
1065 {
1066  if( (~rhs).rows() != m_ || (~rhs).columns() != n_ )
1067  throw std::invalid_argument( "Matrix sizes do not match" );
1068 
1069  if( (~rhs).canAlias( this ) ) {
1070  typename MT::ResultType tmp( ~rhs );
1071  smpAddAssign( *this, tmp );
1072  }
1073  else {
1074  smpAddAssign( *this, ~rhs );
1075  }
1076 
1077  return *this;
1078 }
1079 //*************************************************************************************************
1080 
1081 
1082 //*************************************************************************************************
1092 template< typename Type // Data type of the matrix
1093  , bool SO > // Storage order
1094 template< typename MT // Type of the right-hand side matrix
1095  , bool SO2 > // Storage order of the right-hand side matrix
1097 {
1098  if( (~rhs).rows() != m_ || (~rhs).columns() != n_ )
1099  throw std::invalid_argument( "Matrix sizes do not match" );
1100 
1101  if( (~rhs).canAlias( this ) ) {
1102  typename MT::ResultType tmp( ~rhs );
1103  smpSubAssign( *this, tmp );
1104  }
1105  else {
1106  smpSubAssign( *this, ~rhs );
1107  }
1108 
1109  return *this;
1110 }
1111 //*************************************************************************************************
1112 
1113 
1114 //*************************************************************************************************
1124 template< typename Type // Data type of the matrix
1125  , bool SO > // Storage order
1126 template< typename MT // Type of the right-hand side matrix
1127  , bool SO2 > // Storage order of the right-hand side matrix
1129 {
1130  if( (~rhs).rows() != n_ )
1131  throw std::invalid_argument( "Matrix sizes do not match" );
1132 
1133  DynamicMatrix tmp( *this * (~rhs) );
1134  swap( tmp );
1135 
1136  return *this;
1137 }
1138 //*************************************************************************************************
1139 
1140 
1141 //*************************************************************************************************
1148 template< typename Type // Data type of the matrix
1149  , bool SO > // Storage order
1150 template< typename Other > // Data type of the right-hand side scalar
1151 inline typename EnableIf< IsNumeric<Other>, DynamicMatrix<Type,SO> >::Type&
1153 {
1154  smpAssign( *this, (*this) * rhs );
1155  return *this;
1156 }
1157 //*************************************************************************************************
1158 
1159 
1160 //*************************************************************************************************
1167 template< typename Type // Data type of the matrix
1168  , bool SO > // Storage order
1169 template< typename Other > // Data type of the right-hand side scalar
1170 inline typename EnableIf< IsNumeric<Other>, DynamicMatrix<Type,SO> >::Type&
1172 {
1173  BLAZE_USER_ASSERT( rhs != Other(0), "Division by zero detected" );
1174 
1175  smpAssign( *this, (*this) / rhs );
1176  return *this;
1177 }
1178 //*************************************************************************************************
1179 
1180 
1181 
1182 
1183 //=================================================================================================
1184 //
1185 // UTILITY FUNCTIONS
1186 //
1187 //=================================================================================================
1188 
1189 //*************************************************************************************************
1194 template< typename Type // Data type of the matrix
1195  , bool SO > // Storage order
1196 inline size_t DynamicMatrix<Type,SO>::rows() const
1197 {
1198  return m_;
1199 }
1200 //*************************************************************************************************
1201 
1202 
1203 //*************************************************************************************************
1208 template< typename Type // Data type of the matrix
1209  , bool SO > // Storage order
1210 inline size_t DynamicMatrix<Type,SO>::columns() const
1211 {
1212  return n_;
1213 }
1214 //*************************************************************************************************
1215 
1216 
1217 //*************************************************************************************************
1227 template< typename Type // Data type of the matrix
1228  , bool SO > // Storage order
1229 inline size_t DynamicMatrix<Type,SO>::spacing() const
1230 {
1231  return nn_;
1232 }
1233 //*************************************************************************************************
1234 
1235 
1236 //*************************************************************************************************
1241 template< typename Type // Data type of the matrix
1242  , bool SO > // Storage order
1244 {
1245  return capacity_;
1246 }
1247 //*************************************************************************************************
1248 
1249 
1250 //*************************************************************************************************
1261 template< typename Type // Data type of the sparse matrix
1262  , bool SO > // Storage order
1263 inline size_t DynamicMatrix<Type,SO>::capacity( size_t i ) const
1264 {
1265  UNUSED_PARAMETER( i );
1266  BLAZE_USER_ASSERT( i < rows(), "Invalid row access index" );
1267  return nn_;
1268 }
1269 //*************************************************************************************************
1270 
1271 
1272 //*************************************************************************************************
1277 template< typename Type // Data type of the matrix
1278  , bool SO > // Storage order
1280 {
1281  size_t nonzeros( 0UL );
1282 
1283  for( size_t i=0UL; i<m_; ++i )
1284  for( size_t j=0UL; j<n_; ++j )
1285  if( !isDefault( v_[i*nn_+j] ) )
1286  ++nonzeros;
1287 
1288  return nonzeros;
1289 }
1290 //*************************************************************************************************
1291 
1292 
1293 //*************************************************************************************************
1299 template< typename Type // Data type of the matrix
1300  , bool SO > // Storage order
1301 inline size_t DynamicMatrix<Type,SO>::nonZeros( size_t i ) const
1302 {
1303  BLAZE_USER_ASSERT( i < rows(), "Invalid row access index" );
1304 
1305  const size_t jend( (i+1UL)*nn_ );
1306  size_t nonzeros( 0UL );
1307 
1308  for( size_t j=i*nn_; j<jend; ++j )
1309  if( !isDefault( v_[j] ) )
1310  ++nonzeros;
1311 
1312  return nonzeros;
1313 }
1314 //*************************************************************************************************
1315 
1316 
1317 //*************************************************************************************************
1322 template< typename Type // Data type of the matrix
1323  , bool SO > // Storage order
1325 {
1326  using blaze::reset;
1327 
1328  for( size_t i=0UL; i<m_; ++i )
1329  for( size_t j=0UL; j<n_; ++j )
1330  reset( v_[i*nn_+j] );
1331 }
1332 //*************************************************************************************************
1333 
1334 
1335 //*************************************************************************************************
1346 template< typename Type // Data type of the sparse matrix
1347  , bool SO > // Storage order
1348 inline void DynamicMatrix<Type,SO>::reset( size_t i )
1349 {
1350  using blaze::reset;
1351 
1352  BLAZE_USER_ASSERT( i < rows(), "Invalid row access index" );
1353  for( size_t j=0UL; j<n_; ++j )
1354  reset( v_[i*nn_+j] );
1355 }
1356 //*************************************************************************************************
1357 
1358 
1359 //*************************************************************************************************
1366 template< typename Type // Data type of the matrix
1367  , bool SO > // Storage order
1369 {
1370  resize( 0UL, 0UL, false );
1371 }
1372 //*************************************************************************************************
1373 
1374 
1375 //*************************************************************************************************
1408 template< typename Type // Data type of the matrix
1409  , bool SO > // Storage order
1410 void DynamicMatrix<Type,SO>::resize( size_t m, size_t n, bool preserve )
1411 {
1412  using blaze::min;
1413 
1414  if( m == m_ && n == n_ ) return;
1415 
1416  const size_t nn( adjustColumns( n ) );
1417 
1418  if( preserve )
1419  {
1420  Type* BLAZE_RESTRICT v = allocate<Type>( m*nn );
1421  const size_t min_m( min( m, m_ ) );
1422  const size_t min_n( min( n, n_ ) );
1423 
1424  for( size_t i=0UL; i<min_m; ++i )
1425  for( size_t j=0UL; j<min_n; ++j )
1426  v[i*nn+j] = v_[i*nn_+j];
1427 
1428  std::swap( v_, v );
1429  deallocate( v );
1430  capacity_ = m*nn;
1431  }
1432  else if( m*nn > capacity_ ) {
1433  Type* BLAZE_RESTRICT v = allocate<Type>( m*nn );
1434  std::swap( v_, v );
1435  deallocate( v );
1436  capacity_ = m*nn;
1437  }
1438 
1439  if( IsNumeric<Type>::value ) {
1440  for( size_t i=0UL; i<m; ++i )
1441  for( size_t j=n; j<nn; ++j )
1442  v_[i*nn+j] = Type();
1443  }
1444 
1445  m_ = m;
1446  n_ = n;
1447  nn_ = nn;
1448 }
1449 //*************************************************************************************************
1450 
1451 
1452 //*************************************************************************************************
1466 template< typename Type // Data type of the matrix
1467  , bool SO > // Storage order
1468 inline void DynamicMatrix<Type,SO>::extend( size_t m, size_t n, bool preserve )
1469 {
1470  resize( m_+m, n_+n, preserve );
1471 }
1472 //*************************************************************************************************
1473 
1474 
1475 //*************************************************************************************************
1484 template< typename Type // Data type of the matrix
1485  , bool SO > // Storage order
1486 inline void DynamicMatrix<Type,SO>::reserve( size_t elements )
1487 {
1488  if( elements > capacity_ )
1489  {
1490  // Allocating a new array
1491  Type* BLAZE_RESTRICT tmp = allocate<Type>( elements );
1492 
1493  // Initializing the new array
1494  std::copy( v_, v_+capacity_, tmp );
1495 
1496  if( IsNumeric<Type>::value ) {
1497  for( size_t i=capacity_; i<elements; ++i )
1498  tmp[i] = Type();
1499  }
1500 
1501  // Replacing the old array
1502  std::swap( tmp, v_ );
1503  deallocate( tmp );
1504  capacity_ = elements;
1505  }
1506 }
1507 //*************************************************************************************************
1508 
1509 
1510 //*************************************************************************************************
1515 template< typename Type // Data type of the matrix
1516  , bool SO > // Storage order
1518 {
1519  DynamicMatrix tmp( trans(*this) );
1520  swap( tmp );
1521  return *this;
1522 }
1523 //*************************************************************************************************
1524 
1525 
1526 //*************************************************************************************************
1532 template< typename Type // Data type of the matrix
1533  , bool SO > // Storage order
1534 template< typename Other > // Data type of the scalar value
1536 {
1537  for( size_t i=0UL; i<m_; ++i )
1538  for( size_t j=0UL; j<n_; ++j )
1539  v_[i*nn_+j] *= scalar;
1540 
1541  return *this;
1542 }
1543 //*************************************************************************************************
1544 
1545 
1546 //*************************************************************************************************
1553 template< typename Type // Data type of the matrix
1554  , bool SO > // Storage order
1555 inline void DynamicMatrix<Type,SO>::swap( DynamicMatrix& m ) /* throw() */
1556 {
1557  std::swap( m_ , m.m_ );
1558  std::swap( n_ , m.n_ );
1559  std::swap( nn_, m.nn_ );
1561  std::swap( v_ , m.v_ );
1562 }
1563 //*************************************************************************************************
1564 
1565 
1566 //*************************************************************************************************
1572 template< typename Type // Data type of the matrix
1573  , bool SO > // Storage order
1574 inline size_t DynamicMatrix<Type,SO>::adjustColumns( size_t minColumns ) const
1575 {
1577  return minColumns + ( IT::size - ( minColumns % IT::size ) ) % IT::size;
1578  else return minColumns;
1579 }
1580 //*************************************************************************************************
1581 
1582 
1583 
1584 
1585 //=================================================================================================
1586 //
1587 // EXPRESSION TEMPLATE EVALUATION FUNCTIONS
1588 //
1589 //=================================================================================================
1590 
1591 //*************************************************************************************************
1601 template< typename Type // Data type of the matrix
1602  , bool SO > // Storage order
1603 template< typename Other > // Data type of the foreign expression
1604 inline bool DynamicMatrix<Type,SO>::canAlias( const Other* alias ) const
1605 {
1606  return static_cast<const void*>( this ) == static_cast<const void*>( alias );
1607 }
1608 //*************************************************************************************************
1609 
1610 
1611 //*************************************************************************************************
1621 template< typename Type // Data type of the matrix
1622  , bool SO > // Storage order
1623 template< typename Other > // Data type of the foreign expression
1624 inline bool DynamicMatrix<Type,SO>::isAliased( const Other* alias ) const
1625 {
1626  return static_cast<const void*>( this ) == static_cast<const void*>( alias );
1627 }
1628 //*************************************************************************************************
1629 
1630 
1631 //*************************************************************************************************
1640 template< typename Type // Data type of the matrix
1641  , bool SO > // Storage order
1643 {
1644  return true;
1645 }
1646 //*************************************************************************************************
1647 
1648 
1649 //*************************************************************************************************
1659 template< typename Type // Data type of the matrix
1660  , bool SO > // Storage order
1662 {
1663  return ( rows() > OPENMP_DMATASSIGN_THRESHOLD );
1664 }
1665 //*************************************************************************************************
1666 
1667 
1668 //*************************************************************************************************
1683 template< typename Type // Data type of the matrix
1684  , bool SO > // Storage order
1686  DynamicMatrix<Type,SO>::load( size_t i, size_t j ) const
1687 {
1688  using blaze::load;
1689 
1691 
1692  BLAZE_INTERNAL_ASSERT( i < m_ , "Invalid row access index" );
1693  BLAZE_INTERNAL_ASSERT( j < n_ , "Invalid column access index" );
1694  BLAZE_INTERNAL_ASSERT( j + IT::size <= nn_, "Invalid column access index" );
1695  BLAZE_INTERNAL_ASSERT( j % IT::size == 0UL, "Invalid column access index" );
1696 
1697  return load( v_+i*nn_+j );
1698 }
1699 //*************************************************************************************************
1700 
1701 
1702 //*************************************************************************************************
1717 template< typename Type // Data type of the matrix
1718  , bool SO > // Storage order
1720  DynamicMatrix<Type,SO>::loadu( size_t i, size_t j ) const
1721 {
1722  using blaze::loadu;
1723 
1725 
1726  BLAZE_INTERNAL_ASSERT( i < m_ , "Invalid row access index" );
1727  BLAZE_INTERNAL_ASSERT( j < n_ , "Invalid column access index" );
1728  BLAZE_INTERNAL_ASSERT( j + IT::size <= nn_, "Invalid column access index" );
1729 
1730  return loadu( v_+i*nn_+j );
1731 }
1732 //*************************************************************************************************
1733 
1734 
1735 //*************************************************************************************************
1751 template< typename Type // Data type of the matrix
1752  , bool SO > // Storage order
1753 inline void DynamicMatrix<Type,SO>::store( size_t i, size_t j, const IntrinsicType& value )
1754 {
1755  using blaze::store;
1756 
1758 
1759  BLAZE_INTERNAL_ASSERT( i < m_ , "Invalid row access index" );
1760  BLAZE_INTERNAL_ASSERT( j < n_ , "Invalid column access index" );
1761  BLAZE_INTERNAL_ASSERT( j + IT::size <= nn_, "Invalid column access index" );
1762  BLAZE_INTERNAL_ASSERT( j % IT::size == 0UL, "Invalid column access index" );
1763 
1764  store( v_+i*nn_+j, value );
1765 }
1766 //*************************************************************************************************
1767 
1768 
1769 //*************************************************************************************************
1785 template< typename Type // Data type of the matrix
1786  , bool SO > // Storage order
1787 inline void DynamicMatrix<Type,SO>::storeu( size_t i, size_t j, const IntrinsicType& value )
1788 {
1789  using blaze::storeu;
1790 
1792 
1793  BLAZE_INTERNAL_ASSERT( i < m_ , "Invalid row access index" );
1794  BLAZE_INTERNAL_ASSERT( j < n_ , "Invalid column access index" );
1795  BLAZE_INTERNAL_ASSERT( j + IT::size <= nn_, "Invalid column access index" );
1796 
1797  storeu( v_+i*nn_+j, value );
1798 }
1799 //*************************************************************************************************
1800 
1801 
1802 //*************************************************************************************************
1818 template< typename Type // Data type of the matrix
1819  , bool SO > // Storage order
1820 inline void DynamicMatrix<Type,SO>::stream( size_t i, size_t j, const IntrinsicType& value )
1821 {
1822  using blaze::stream;
1823 
1825 
1826  BLAZE_INTERNAL_ASSERT( i < m_ , "Invalid row access index" );
1827  BLAZE_INTERNAL_ASSERT( j < n_ , "Invalid column access index" );
1828  BLAZE_INTERNAL_ASSERT( j + IT::size <= nn_, "Invalid column access index" );
1829  BLAZE_INTERNAL_ASSERT( j % IT::size == 0UL, "Invalid column access index" );
1830 
1831  stream( v_+i*nn_+j, value );
1832 }
1833 //*************************************************************************************************
1834 
1835 
1836 //*************************************************************************************************
1847 template< typename Type // Data type of the matrix
1848  , bool SO > // Storage order
1849 template< typename MT > // Type of the right-hand side dense matrix
1850 inline typename DisableIf< typename DynamicMatrix<Type,SO>::BLAZE_TEMPLATE VectorizedAssign<MT> >::Type
1852 {
1853  BLAZE_INTERNAL_ASSERT( m_ == (~rhs).rows() , "Invalid number of rows" );
1854  BLAZE_INTERNAL_ASSERT( n_ == (~rhs).columns(), "Invalid number of columns" );
1855 
1856  const size_t jend( n_ & size_t(-2) );
1857  BLAZE_INTERNAL_ASSERT( ( n_ - ( n_ % 2UL ) ) == jend, "Invalid end calculation" );
1858 
1859  for( size_t i=0UL; i<m_; ++i ) {
1860  for( size_t j=0UL; j<jend; j+=2UL ) {
1861  v_[i*nn_+j ] = (~rhs)(i,j );
1862  v_[i*nn_+j+1UL] = (~rhs)(i,j+1UL);
1863  }
1864  if( jend < n_ ) {
1865  v_[i*nn_+jend] = (~rhs)(i,jend);
1866  }
1867  }
1868 }
1869 //*************************************************************************************************
1870 
1871 
1872 //*************************************************************************************************
1883 template< typename Type // Data type of the matrix
1884  , bool SO > // Storage order
1885 template< typename MT > // Type of the right-hand side dense matrix
1886 inline typename EnableIf< typename DynamicMatrix<Type,SO>::BLAZE_TEMPLATE VectorizedAssign<MT> >::Type
1888 {
1889  using blaze::store;
1890  using blaze::stream;
1891 
1892  BLAZE_INTERNAL_ASSERT( m_ == (~rhs).rows() , "Invalid number of rows" );
1893  BLAZE_INTERNAL_ASSERT( n_ == (~rhs).columns(), "Invalid number of columns" );
1894 
1896 
1897  if( useStreaming && m_*n_ > ( cacheSize / ( sizeof(Type) * 3UL ) ) && !(~rhs).isAliased( this ) )
1898  {
1899  for( size_t i=0UL; i<m_; ++i )
1900  for( size_t j=0UL; j<n_; j+=IT::size )
1901  stream( v_+i*nn_+j, (~rhs).load(i,j) );
1902  }
1903  else
1904  {
1905  const size_t jend( n_ & size_t(-IT::size*4) );
1906  BLAZE_INTERNAL_ASSERT( ( n_ - ( n_ % (IT::size*4UL) ) ) == jend, "Invalid end calculation" );
1907 
1908  for( size_t i=0UL; i<m_; ++i ) {
1909  typename MT::ConstIterator it( (~rhs).begin(i) );
1910  for( size_t j=0UL; j<jend; j+=IT::size*4UL ) {
1911  store( v_+i*nn_+j , it.load() ); it += IT::size;
1912  store( v_+i*nn_+j+IT::size , it.load() ); it += IT::size;
1913  store( v_+i*nn_+j+IT::size*2UL, it.load() ); it += IT::size;
1914  store( v_+i*nn_+j+IT::size*3UL, it.load() ); it += IT::size;
1915  }
1916  for( size_t j=jend; j<n_; j+=IT::size, it+=IT::size ) {
1917  store( v_+i*nn_+j, it.load() );
1918  }
1919  }
1920  }
1921 }
1922 //*************************************************************************************************
1923 
1924 
1925 //*************************************************************************************************
1936 template< typename Type // Data type of the matrix
1937  , bool SO > // Storage order
1938 template< typename MT > // Type of the right-hand side dense matrix
1940 {
1941  BLAZE_INTERNAL_ASSERT( m_ == (~rhs).rows() , "Invalid number of rows" );
1942  BLAZE_INTERNAL_ASSERT( n_ == (~rhs).columns(), "Invalid number of columns" );
1943 
1944  const size_t block( 16UL );
1945 
1946  for( size_t ii=0UL; ii<m_; ii+=block ) {
1947  const size_t iend( ( m_<(ii+block) )?( m_ ):( ii+block ) );
1948  for( size_t jj=0UL; jj<n_; jj+=block ) {
1949  const size_t jend( ( n_<(jj+block) )?( n_ ):( jj+block ) );
1950  for( size_t i=ii; i<iend; ++i ) {
1951  for( size_t j=jj; j<jend; ++j ) {
1952  v_[i*nn_+j] = (~rhs)(i,j);
1953  }
1954  }
1955  }
1956  }
1957 }
1958 //*************************************************************************************************
1959 
1960 
1961 //*************************************************************************************************
1972 template< typename Type // Data type of the matrix
1973  , bool SO > // Storage order
1974 template< typename MT > // Type of the right-hand side sparse matrix
1976 {
1977  BLAZE_INTERNAL_ASSERT( m_ == (~rhs).rows() , "Invalid number of rows" );
1978  BLAZE_INTERNAL_ASSERT( n_ == (~rhs).columns(), "Invalid number of columns" );
1979 
1980  for( size_t i=0UL; i<m_; ++i )
1981  for( typename MT::ConstIterator element=(~rhs).begin(i); element!=(~rhs).end(i); ++element )
1982  v_[i*nn_+element->index()] = element->value();
1983 }
1984 //*************************************************************************************************
1985 
1986 
1987 //*************************************************************************************************
1998 template< typename Type // Data type of the matrix
1999  , bool SO > // Storage order
2000 template< typename MT > // Type of the right-hand side sparse matrix
2002 {
2003  BLAZE_INTERNAL_ASSERT( m_ == (~rhs).rows() , "Invalid number of rows" );
2004  BLAZE_INTERNAL_ASSERT( n_ == (~rhs).columns(), "Invalid number of columns" );
2005 
2006  for( size_t j=0UL; j<n_; ++j )
2007  for( typename MT::ConstIterator element=(~rhs).begin(j); element!=(~rhs).end(j); ++element )
2008  v_[element->index()*nn_+j] = element->value();
2009 }
2010 //*************************************************************************************************
2011 
2012 
2013 //*************************************************************************************************
2024 template< typename Type // Data type of the matrix
2025  , bool SO > // Storage order
2026 template< typename MT > // Type of the right-hand side dense matrix
2027 inline typename DisableIf< typename DynamicMatrix<Type,SO>::BLAZE_TEMPLATE VectorizedAddAssign<MT> >::Type
2029 {
2030  BLAZE_INTERNAL_ASSERT( m_ == (~rhs).rows() , "Invalid number of rows" );
2031  BLAZE_INTERNAL_ASSERT( n_ == (~rhs).columns(), "Invalid number of columns" );
2032 
2033  const size_t jend( n_ & size_t(-2) );
2034  BLAZE_INTERNAL_ASSERT( ( n_ - ( n_ % 2UL ) ) == jend, "Invalid end calculation" );
2035 
2036  for( size_t i=0UL; i<m_; ++i ) {
2037  for( size_t j=0UL; j<jend; j+=2UL ) {
2038  v_[i*nn_+j ] += (~rhs)(i,j );
2039  v_[i*nn_+j+1UL] += (~rhs)(i,j+1UL);
2040  }
2041  if( jend < n_ ) {
2042  v_[i*nn_+jend] += (~rhs)(i,jend);
2043  }
2044  }
2045 }
2046 //*************************************************************************************************
2047 
2048 
2049 //*************************************************************************************************
2060 template< typename Type // Data type of the matrix
2061  , bool SO > // Storage order
2062 template< typename MT > // Type of the right-hand side dense matrix
2063 inline typename EnableIf< typename DynamicMatrix<Type,SO>::BLAZE_TEMPLATE VectorizedAddAssign<MT> >::Type
2065 {
2066  using blaze::load;
2067  using blaze::store;
2068 
2069  BLAZE_INTERNAL_ASSERT( m_ == (~rhs).rows() , "Invalid number of rows" );
2070  BLAZE_INTERNAL_ASSERT( n_ == (~rhs).columns(), "Invalid number of columns" );
2071 
2073 
2074  const size_t jend( n_ & size_t(-IT::size*4) );
2075  BLAZE_INTERNAL_ASSERT( ( n_ - ( n_ % (IT::size*4UL) ) ) == jend, "Invalid end calculation" );
2076 
2077  for( size_t i=0UL; i<m_; ++i ) {
2078  typename MT::ConstIterator it( (~rhs).begin(i) );
2079  for( size_t j=0UL; j<jend; j+=IT::size*4UL ) {
2080  store( v_+i*nn_+j , load( v_+i*nn_+j ) + it.load() ); it += IT::size;
2081  store( v_+i*nn_+j+IT::size , load( v_+i*nn_+j+IT::size ) + it.load() ); it += IT::size;
2082  store( v_+i*nn_+j+IT::size*2UL, load( v_+i*nn_+j+IT::size*2UL ) + it.load() ); it += IT::size;
2083  store( v_+i*nn_+j+IT::size*3UL, load( v_+i*nn_+j+IT::size*3UL ) + it.load() ); it += IT::size;
2084  }
2085  for( size_t j=jend; j<n_; j+=IT::size, it+=IT::size ) {
2086  store( v_+i*nn_+j, load( v_+i*nn_+j ) + it.load() );
2087  }
2088  }
2089 }
2090 //*************************************************************************************************
2091 
2092 
2093 //*************************************************************************************************
2104 template< typename Type // Data type of the matrix
2105  , bool SO > // Storage order
2106 template< typename MT > // Type of the right-hand side dense matrix
2108 {
2109  BLAZE_INTERNAL_ASSERT( m_ == (~rhs).rows() , "Invalid number of rows" );
2110  BLAZE_INTERNAL_ASSERT( n_ == (~rhs).columns(), "Invalid number of columns" );
2111 
2112  const size_t block( 16UL );
2113 
2114  for( size_t ii=0UL; ii<m_; ii+=block ) {
2115  const size_t iend( ( m_<(ii+block) )?( m_ ):( ii+block ) );
2116  for( size_t jj=0UL; jj<n_; jj+=block ) {
2117  const size_t jend( ( n_<(jj+block) )?( n_ ):( jj+block ) );
2118  for( size_t i=ii; i<iend; ++i ) {
2119  for( size_t j=jj; j<jend; ++j ) {
2120  v_[i*nn_+j] += (~rhs)(i,j);
2121  }
2122  }
2123  }
2124  }
2125 }
2126 //*************************************************************************************************
2127 
2128 
2129 //*************************************************************************************************
2140 template< typename Type // Data type of the matrix
2141  , bool SO > // Storage order
2142 template< typename MT > // Type of the right-hand side sparse matrix
2144 {
2145  BLAZE_INTERNAL_ASSERT( m_ == (~rhs).rows() , "Invalid number of rows" );
2146  BLAZE_INTERNAL_ASSERT( n_ == (~rhs).columns(), "Invalid number of columns" );
2147 
2148  for( size_t i=0UL; i<m_; ++i )
2149  for( typename MT::ConstIterator element=(~rhs).begin(i); element!=(~rhs).end(i); ++element )
2150  v_[i*nn_+element->index()] += element->value();
2151 }
2152 //*************************************************************************************************
2153 
2154 
2155 //*************************************************************************************************
2166 template< typename Type // Data type of the matrix
2167  , bool SO > // Storage order
2168 template< typename MT > // Type of the right-hand side sparse matrix
2170 {
2171  BLAZE_INTERNAL_ASSERT( m_ == (~rhs).rows() , "Invalid number of rows" );
2172  BLAZE_INTERNAL_ASSERT( n_ == (~rhs).columns(), "Invalid number of columns" );
2173 
2174  for( size_t j=0UL; j<n_; ++j )
2175  for( typename MT::ConstIterator element=(~rhs).begin(j); element!=(~rhs).end(j); ++element )
2176  v_[element->index()*nn_+j] += element->value();
2177 }
2178 //*************************************************************************************************
2179 
2180 
2181 //*************************************************************************************************
2192 template< typename Type // Data type of the matrix
2193  , bool SO > // Storage order
2194 template< typename MT > // Type of the right-hand side dense matrix
2195 inline typename DisableIf< typename DynamicMatrix<Type,SO>::BLAZE_TEMPLATE VectorizedSubAssign<MT> >::Type
2197 {
2198  BLAZE_INTERNAL_ASSERT( m_ == (~rhs).rows() , "Invalid number of rows" );
2199  BLAZE_INTERNAL_ASSERT( n_ == (~rhs).columns(), "Invalid number of columns" );
2200 
2201  const size_t jend( n_ & size_t(-2) );
2202  BLAZE_INTERNAL_ASSERT( ( n_ - ( n_ % 2UL ) ) == jend, "Invalid end calculation" );
2203 
2204  for( size_t i=0UL; i<m_; ++i ) {
2205  for( size_t j=0UL; j<jend; j+=2UL ) {
2206  v_[i*nn_+j ] -= (~rhs)(i,j );
2207  v_[i*nn_+j+1UL] -= (~rhs)(i,j+1UL);
2208  }
2209  if( jend < n_ ) {
2210  v_[i*nn_+jend] -= (~rhs)(i,jend);
2211  }
2212  }
2213 }
2214 //*************************************************************************************************
2215 
2216 
2217 //*************************************************************************************************
2228 template< typename Type // Data type of the matrix
2229  , bool SO > // Storage order
2230 template< typename MT > // Type of the right-hand side dense matrix
2231 inline typename EnableIf< typename DynamicMatrix<Type,SO>::BLAZE_TEMPLATE VectorizedSubAssign<MT> >::Type
2233 {
2234  using blaze::load;
2235  using blaze::store;
2236 
2237  BLAZE_INTERNAL_ASSERT( m_ == (~rhs).rows() , "Invalid number of rows" );
2238  BLAZE_INTERNAL_ASSERT( n_ == (~rhs).columns(), "Invalid number of columns" );
2239 
2241 
2242  const size_t jend( n_ & size_t(-IT::size*4) );
2243  BLAZE_INTERNAL_ASSERT( ( n_ - ( n_ % (IT::size*4UL) ) ) == jend, "Invalid end calculation" );
2244 
2245  for( size_t i=0UL; i<m_; ++i ) {
2246  typename MT::ConstIterator it( (~rhs).begin(i) );
2247  for( size_t j=0UL; j<jend; j+=IT::size*4UL ) {
2248  store( v_+i*nn_+j , load( v_+i*nn_+j ) - it.load() ); it += IT::size;
2249  store( v_+i*nn_+j+IT::size , load( v_+i*nn_+j+IT::size ) - it.load() ); it += IT::size;
2250  store( v_+i*nn_+j+IT::size*2UL, load( v_+i*nn_+j+IT::size*2UL ) - it.load() ); it += IT::size;
2251  store( v_+i*nn_+j+IT::size*3UL, load( v_+i*nn_+j+IT::size*3UL ) - it.load() ); it += IT::size;
2252  }
2253  for( size_t j=jend; j<n_; j+=IT::size, it+=IT::size ) {
2254  store( v_+i*nn_+j, load( v_+i*nn_+j ) - it.load() );
2255  }
2256  }
2257 }
2258 //*************************************************************************************************
2259 
2260 
2261 //*************************************************************************************************
2272 template< typename Type // Data type of the matrix
2273  , bool SO > // Storage order
2274 template< typename MT > // Type of the right-hand side dense matrix
2276 {
2277  BLAZE_INTERNAL_ASSERT( m_ == (~rhs).rows() , "Invalid number of rows" );
2278  BLAZE_INTERNAL_ASSERT( n_ == (~rhs).columns(), "Invalid number of columns" );
2279 
2280  const size_t block( 16UL );
2281 
2282  for( size_t ii=0UL; ii<m_; ii+=block ) {
2283  const size_t iend( ( m_<(ii+block) )?( m_ ):( ii+block ) );
2284  for( size_t jj=0UL; jj<n_; jj+=block ) {
2285  const size_t jend( ( n_<(jj+block) )?( n_ ):( jj+block ) );
2286  for( size_t i=ii; i<iend; ++i ) {
2287  for( size_t j=jj; j<jend; ++j ) {
2288  v_[i*nn_+j] -= (~rhs)(i,j);
2289  }
2290  }
2291  }
2292  }
2293 }
2294 //*************************************************************************************************
2295 
2296 
2297 //*************************************************************************************************
2308 template< typename Type // Data type of the matrix
2309  , bool SO > // Storage order
2310 template< typename MT > // Type of the right-hand side sparse matrix
2312 {
2313  BLAZE_INTERNAL_ASSERT( m_ == (~rhs).rows() , "Invalid number of rows" );
2314  BLAZE_INTERNAL_ASSERT( n_ == (~rhs).columns(), "Invalid number of columns" );
2315 
2316  for( size_t i=0UL; i<m_; ++i )
2317  for( typename MT::ConstIterator element=(~rhs).begin(i); element!=(~rhs).end(i); ++element )
2318  v_[i*nn_+element->index()] -= element->value();
2319 }
2320 //*************************************************************************************************
2321 
2322 
2323 //*************************************************************************************************
2334 template< typename Type // Data type of the matrix
2335  , bool SO > // Storage order
2336 template< typename MT > // Type of the right-hand side sparse matrix
2338 {
2339  BLAZE_INTERNAL_ASSERT( m_ == (~rhs).rows() , "Invalid number of rows" );
2340  BLAZE_INTERNAL_ASSERT( n_ == (~rhs).columns(), "Invalid number of columns" );
2341 
2342  for( size_t j=0UL; j<n_; ++j )
2343  for( typename MT::ConstIterator element=(~rhs).begin(j); element!=(~rhs).end(j); ++element )
2344  v_[element->index()*nn_+j] -= element->value();
2345 }
2346 //*************************************************************************************************
2347 
2348 
2349 
2350 
2351 
2352 
2353 
2354 
2355 //=================================================================================================
2356 //
2357 // CLASS TEMPLATE SPECIALIZATION FOR COLUMN-MAJOR MATRICES
2358 //
2359 //=================================================================================================
2360 
2361 //*************************************************************************************************
2369 template< typename Type > // Data type of the matrix
2370 class DynamicMatrix<Type,true> : public DenseMatrix< DynamicMatrix<Type,true>, true >
2371 {
2372  private:
2373  //**Type definitions****************************************************************************
2374  typedef IntrinsicTrait<Type> IT;
2375  //**********************************************************************************************
2376 
2377  public:
2378  //**Type definitions****************************************************************************
2379  typedef DynamicMatrix<Type,true> This;
2380  typedef This ResultType;
2383  typedef Type ElementType;
2384  typedef typename IT::Type IntrinsicType;
2385  typedef const Type& ReturnType;
2386  typedef const This& CompositeType;
2387  typedef Type& Reference;
2388  typedef const Type& ConstReference;
2389  typedef DenseIterator<Type> Iterator;
2391  //**********************************************************************************************
2392 
2393  //**Compilation flags***************************************************************************
2395 
2399  enum { vectorizable = IsVectorizable<Type>::value };
2400 
2402 
2405  enum { smpAssignable = 1 };
2406  //**********************************************************************************************
2407 
2408  //**Constructors********************************************************************************
2411  explicit inline DynamicMatrix();
2412  explicit inline DynamicMatrix( size_t m, size_t n );
2413  explicit inline DynamicMatrix( size_t m, size_t n, const Type& init );
2414  template< typename Other > explicit inline DynamicMatrix( size_t m, size_t n, const Other* array );
2415 
2416  template< typename Other, size_t M, size_t N >
2417  explicit inline DynamicMatrix( const Other (&array)[M][N] );
2418 
2419  inline DynamicMatrix( const DynamicMatrix& m );
2420  template< typename MT, bool SO > inline DynamicMatrix( const Matrix<MT,SO>& m );
2422  //**********************************************************************************************
2423 
2424  //**Destructor**********************************************************************************
2427  inline ~DynamicMatrix();
2429  //**********************************************************************************************
2430 
2431  //**Data access functions***********************************************************************
2434  inline Reference operator()( size_t i, size_t j );
2435  inline ConstReference operator()( size_t i, size_t j ) const;
2436  inline Type* data ();
2437  inline const Type* data () const;
2438  inline Type* data ( size_t j );
2439  inline const Type* data ( size_t j ) const;
2440  inline Iterator begin ( size_t j );
2441  inline ConstIterator begin ( size_t j ) const;
2442  inline ConstIterator cbegin( size_t j ) const;
2443  inline Iterator end ( size_t j );
2444  inline ConstIterator end ( size_t j ) const;
2445  inline ConstIterator cend ( size_t j ) const;
2447  //**********************************************************************************************
2448 
2449  //**Assignment operators************************************************************************
2452  template< typename Other, size_t M, size_t N >
2453  inline DynamicMatrix& operator=( const Other (&array)[M][N] );
2454 
2455  inline DynamicMatrix& operator= ( Type set );
2456  inline DynamicMatrix& operator= ( const DynamicMatrix& set );
2457  template< typename MT, bool SO > inline DynamicMatrix& operator= ( const Matrix<MT,SO>& rhs );
2458  template< typename MT, bool SO > inline DynamicMatrix& operator+=( const Matrix<MT,SO>& rhs );
2459  template< typename MT, bool SO > inline DynamicMatrix& operator-=( const Matrix<MT,SO>& rhs );
2460  template< typename MT, bool SO > inline DynamicMatrix& operator*=( const Matrix<MT,SO>& rhs );
2461 
2462  template< typename Other >
2463  inline typename EnableIf< IsNumeric<Other>, DynamicMatrix >::Type&
2464  operator*=( Other rhs );
2465 
2466  template< typename Other >
2467  inline typename EnableIf< IsNumeric<Other>, DynamicMatrix >::Type&
2468  operator/=( Other rhs );
2470  //**********************************************************************************************
2471 
2472  //**Utility functions***************************************************************************
2475  inline size_t rows() const;
2476  inline size_t columns() const;
2477  inline size_t spacing() const;
2478  inline size_t capacity() const;
2479  inline size_t capacity( size_t j ) const;
2480  inline size_t nonZeros() const;
2481  inline size_t nonZeros( size_t j ) const;
2482  inline void reset();
2483  inline void reset( size_t j );
2484  inline void clear();
2485  void resize ( size_t m, size_t n, bool preserve=true );
2486  inline void extend ( size_t m, size_t n, bool preserve=true );
2487  inline void reserve( size_t elements );
2488  inline DynamicMatrix& transpose();
2489  template< typename Other > inline DynamicMatrix& scale( Other scalar );
2490  inline void swap( DynamicMatrix& m ) /* throw() */;
2492  //**********************************************************************************************
2493 
2494  private:
2495  //**********************************************************************************************
2497  template< typename MT >
2498  struct VectorizedAssign {
2499  enum { value = vectorizable && MT::vectorizable &&
2500  IsSame<Type,typename MT::ElementType>::value };
2501  };
2502  //**********************************************************************************************
2503 
2504  //**********************************************************************************************
2506  template< typename MT >
2507  struct VectorizedAddAssign {
2508  enum { value = vectorizable && MT::vectorizable &&
2509  IsSame<Type,typename MT::ElementType>::value &&
2510  IntrinsicTrait<Type>::addition };
2511  };
2512  //**********************************************************************************************
2513 
2514  //**********************************************************************************************
2516  template< typename MT >
2517  struct VectorizedSubAssign {
2518  enum { value = vectorizable && MT::vectorizable &&
2519  IsSame<Type,typename MT::ElementType>::value &&
2520  IntrinsicTrait<Type>::subtraction };
2521  };
2522  //**********************************************************************************************
2523 
2524  public:
2525  //**Expression template evaluation functions****************************************************
2528  template< typename Other > inline bool canAlias ( const Other* alias ) const;
2529  template< typename Other > inline bool isAliased( const Other* alias ) const;
2530 
2531  inline bool isAligned () const;
2532  inline bool canSMPAssign() const;
2533 
2534  inline IntrinsicType load ( size_t i, size_t j ) const;
2535  inline IntrinsicType loadu ( size_t i, size_t j ) const;
2536  inline void store ( size_t i, size_t j, const IntrinsicType& value );
2537  inline void storeu( size_t i, size_t j, const IntrinsicType& value );
2538  inline void stream( size_t i, size_t j, const IntrinsicType& value );
2539 
2540  template< typename MT >
2541  inline typename DisableIf< VectorizedAssign<MT> >::Type
2542  assign( const DenseMatrix<MT,true>& rhs );
2543 
2544  template< typename MT >
2545  inline typename EnableIf< VectorizedAssign<MT> >::Type
2546  assign( const DenseMatrix<MT,true>& rhs );
2547 
2548  template< typename MT > inline void assign( const DenseMatrix<MT,false>& rhs );
2549  template< typename MT > inline void assign( const SparseMatrix<MT,true>& rhs );
2550  template< typename MT > inline void assign( const SparseMatrix<MT,false>& rhs );
2551 
2552  template< typename MT >
2553  inline typename DisableIf< VectorizedAddAssign<MT> >::Type
2554  addAssign( const DenseMatrix<MT,true>& rhs );
2555 
2556  template< typename MT >
2557  inline typename EnableIf< VectorizedAddAssign<MT> >::Type
2558  addAssign( const DenseMatrix<MT,true>& rhs );
2559 
2560  template< typename MT > inline void addAssign( const DenseMatrix<MT,false>& rhs );
2561  template< typename MT > inline void addAssign( const SparseMatrix<MT,true>& rhs );
2562  template< typename MT > inline void addAssign( const SparseMatrix<MT,false>& rhs );
2563 
2564  template< typename MT >
2565  inline typename DisableIf< VectorizedSubAssign<MT> >::Type
2566  subAssign ( const DenseMatrix<MT,true>& rhs );
2567 
2568  template< typename MT >
2569  inline typename EnableIf< VectorizedSubAssign<MT> >::Type
2570  subAssign ( const DenseMatrix<MT,true>& rhs );
2571 
2572  template< typename MT > inline void subAssign( const DenseMatrix<MT,false>& rhs );
2573  template< typename MT > inline void subAssign( const SparseMatrix<MT,true>& rhs );
2574  template< typename MT > inline void subAssign( const SparseMatrix<MT,false>& rhs );
2576  //**********************************************************************************************
2577 
2578  private:
2579  //**Utility functions***************************************************************************
2582  inline size_t adjustRows( size_t minRows ) const;
2584  //**********************************************************************************************
2585 
2586  //**Member variables****************************************************************************
2589  size_t m_;
2590  size_t mm_;
2591  size_t n_;
2592  size_t capacity_;
2593  Type* BLAZE_RESTRICT v_;
2594 
2604  //**********************************************************************************************
2605 
2606  //**Compile time checks*************************************************************************
2611  //**********************************************************************************************
2612 };
2614 //*************************************************************************************************
2615 
2616 
2617 
2618 
2619 //=================================================================================================
2620 //
2621 // CONSTRUCTORS
2622 //
2623 //=================================================================================================
2624 
2625 //*************************************************************************************************
2629 template< typename Type > // Data type of the matrix
2631  : m_ ( 0UL ) // The current number of rows of the matrix
2632  , mm_ ( 0UL ) // The alignment adjusted number of rows
2633  , n_ ( 0UL ) // The current number of columns of the matrix
2634  , capacity_( 0UL ) // The maximum capacity of the matrix
2635  , v_ ( NULL ) // The matrix elements
2636 {}
2638 //*************************************************************************************************
2639 
2640 
2641 //*************************************************************************************************
2651 template< typename Type > // Data type of the matrix
2652 inline DynamicMatrix<Type,true>::DynamicMatrix( size_t m, size_t n )
2653  : m_ ( m ) // The current number of rows of the matrix
2654  , mm_ ( adjustRows( m ) ) // The alignment adjusted number of rows
2655  , n_ ( n ) // The current number of columns of the matrix
2656  , capacity_( mm_*n_ ) // The maximum capacity of the matrix
2657  , v_ ( allocate<Type>( capacity_ ) ) // The matrix elements
2658 {
2659  if( IsNumeric<Type>::value ) {
2660  for( size_t j=0UL; j<n_; ++j )
2661  for( size_t i=m_; i<mm_; ++i ) {
2662  v_[i+j*mm_] = Type();
2663  }
2664  }
2665 }
2667 //*************************************************************************************************
2668 
2669 
2670 //*************************************************************************************************
2680 template< typename Type > // Data type of the matrix
2681 inline DynamicMatrix<Type,true>::DynamicMatrix( size_t m, size_t n, const Type& init )
2682  : m_ ( m ) // The current number of rows of the matrix
2683  , mm_ ( adjustRows( m ) ) // The alignment adjusted number of rows
2684  , n_ ( n ) // The current number of columns of the matrix
2685  , capacity_( mm_*n_ ) // The maximum capacity of the matrix
2686  , v_ ( allocate<Type>( capacity_ ) ) // The matrix elements
2687 {
2688  for( size_t j=0UL; j<n_; ++j ) {
2689  for( size_t i=0UL; i<m_; ++i )
2690  v_[i+j*mm_] = init;
2691 
2692  if( IsNumeric<Type>::value ) {
2693  for( size_t i=m_; i<mm_; ++i )
2694  v_[i+j*mm_] = Type();
2695  }
2696  }
2697 }
2699 //*************************************************************************************************
2700 
2701 
2702 //*************************************************************************************************
2726 template< typename Type > // Data type of the matrix
2727 template< typename Other > // Data type of the initialization array
2728 inline DynamicMatrix<Type,true>::DynamicMatrix( size_t m, size_t n, const Other* array )
2729  : m_ ( m ) // The current number of rows of the matrix
2730  , mm_ ( adjustRows( m ) ) // The alignment adjusted number of rows
2731  , n_ ( n ) // The current number of columns of the matrix
2732  , capacity_( mm_*n_ ) // The maximum capacity of the matrix
2733  , v_ ( allocate<Type>( capacity_ ) ) // The matrix elements
2734 {
2735  for( size_t j=0UL; j<n; ++j ) {
2736  for( size_t i=0UL; i<m; ++i )
2737  v_[i+j*mm_] = array[i+j*m];
2738 
2739  if( IsNumeric<Type>::value ) {
2740  for( size_t i=m; i<mm_; ++i )
2741  v_[i+j*mm_] = Type();
2742  }
2743  }
2744 }
2746 //*************************************************************************************************
2747 
2748 
2749 //*************************************************************************************************
2771 template< typename Type > // Data type of the matrix
2772 template< typename Other // Data type of the initialization array
2773  , size_t M // Number of rows of the initialization array
2774  , size_t N > // Number of columns of the initialization array
2775 inline DynamicMatrix<Type,true>::DynamicMatrix( const Other (&array)[M][N] )
2776  : m_ ( M ) // The current number of rows of the matrix
2777  , mm_ ( adjustRows( M ) ) // The alignment adjusted number of rows
2778  , n_ ( N ) // The current number of columns of the matrix
2779  , capacity_( mm_*n_ ) // The maximum capacity of the matrix
2780  , v_ ( allocate<Type>( capacity_ ) ) // The matrix elements
2781 {
2782  for( size_t j=0UL; j<N; ++j ) {
2783  for( size_t i=0UL; i<M; ++i )
2784  v_[i+j*mm_] = array[i][j];
2785 
2786  if( IsNumeric<Type>::value ) {
2787  for( size_t i=M; i<mm_; ++i )
2788  v_[i+j*mm_] = Type();
2789  }
2790  }
2791 }
2793 //*************************************************************************************************
2794 
2795 
2796 //*************************************************************************************************
2805 template< typename Type > // Data type of the matrix
2806 inline DynamicMatrix<Type,true>::DynamicMatrix( const DynamicMatrix& m )
2807  : m_ ( m.m_ ) // The current number of rows of the matrix
2808  , mm_ ( m.mm_ ) // The alignment adjusted number of rows
2809  , n_ ( m.n_ ) // The current number of columns of the matrix
2810  , capacity_( mm_*n_ ) // The maximum capacity of the matrix
2811  , v_ ( allocate<Type>( capacity_ ) ) // The matrix elements
2812 {
2813  BLAZE_INTERNAL_ASSERT( capacity_ <= m.capacity_, "Invalid capacity estimation" );
2814 
2815  for( size_t i=0UL; i<capacity_; ++i )
2816  v_[i] = m.v_[i];
2817 }
2819 //*************************************************************************************************
2820 
2821 
2822 //*************************************************************************************************
2828 template< typename Type > // Data type of the matrix
2829 template< typename MT // Type of the foreign matrix
2830  , bool SO > // Storage order of the foreign matrix
2831 inline DynamicMatrix<Type,true>::DynamicMatrix( const Matrix<MT,SO>& m )
2832  : m_ ( (~m).rows() ) // The current number of rows of the matrix
2833  , mm_ ( adjustRows( m_ ) ) // The alignment adjusted number of rows
2834  , n_ ( (~m).columns() ) // The current number of columns of the matrix
2835  , capacity_( mm_*n_ ) // The maximum capacity of the matrix
2836  , v_ ( allocate<Type>( capacity_ ) ) // The matrix elements
2837 {
2838  if( IsNumeric<Type>::value ) {
2839  for( size_t j=0UL; j<n_; ++j )
2840  for( size_t i=( IsSparseMatrix<MT>::value )?( 0UL ):( m_ ); i<mm_; ++i ) {
2841  v_[i+j*mm_] = Type();
2842  }
2843  }
2844 
2845  smpAssign( *this, ~m );
2846 }
2848 //*************************************************************************************************
2849 
2850 
2851 
2852 
2853 //=================================================================================================
2854 //
2855 // DESTRUCTOR
2856 //
2857 //=================================================================================================
2858 
2859 //*************************************************************************************************
2863 template< typename Type > // Data type of the matrix
2865 {
2866  deallocate( v_ );
2867 }
2869 //*************************************************************************************************
2870 
2871 
2872 
2873 
2874 //=================================================================================================
2875 //
2876 // DATA ACCESS FUNCTIONS
2877 //
2878 //=================================================================================================
2879 
2880 //*************************************************************************************************
2888 template< typename Type > // Data type of the matrix
2890  DynamicMatrix<Type,true>::operator()( size_t i, size_t j )
2891 {
2892  BLAZE_USER_ASSERT( i<m_, "Invalid row access index" );
2893  BLAZE_USER_ASSERT( j<n_, "Invalid column access index" );
2894  return v_[i+j*mm_];
2895 }
2897 //*************************************************************************************************
2898 
2899 
2900 //*************************************************************************************************
2908 template< typename Type > // Data type of the matrix
2910  DynamicMatrix<Type,true>::operator()( size_t i, size_t j ) const
2911 {
2912  BLAZE_USER_ASSERT( i<m_, "Invalid row access index" );
2913  BLAZE_USER_ASSERT( j<n_, "Invalid column access index" );
2914  return v_[i+j*mm_];
2915 }
2917 //*************************************************************************************************
2918 
2919 
2920 //*************************************************************************************************
2930 template< typename Type > // Data type of the matrix
2931 inline Type* DynamicMatrix<Type,true>::data()
2932 {
2933  return v_;
2934 }
2936 //*************************************************************************************************
2937 
2938 
2939 //*************************************************************************************************
2949 template< typename Type > // Data type of the matrix
2950 inline const Type* DynamicMatrix<Type,true>::data() const
2951 {
2952  return v_;
2953 }
2955 //*************************************************************************************************
2956 
2957 
2958 //*************************************************************************************************
2967 template< typename Type > // Data type of the matrix
2968 inline Type* DynamicMatrix<Type,true>::data( size_t j )
2969 {
2970  BLAZE_USER_ASSERT( j < n_, "Invalid dense matrix column access index" );
2971  return v_ + j*mm_;
2972 }
2974 //*************************************************************************************************
2975 
2976 
2977 //*************************************************************************************************
2986 template< typename Type > // Data type of the matrix
2987 inline const Type* DynamicMatrix<Type,true>::data( size_t j ) const
2988 {
2989  BLAZE_USER_ASSERT( j < n_, "Invalid dense matrix column access index" );
2990  return v_ + j*mm_;
2991 }
2993 //*************************************************************************************************
2994 
2995 
2996 //*************************************************************************************************
3003 template< typename Type > // Data type of the matrix
3004 inline typename DynamicMatrix<Type,true>::Iterator
3006 {
3007  BLAZE_USER_ASSERT( j < n_, "Invalid dense matrix column access index" );
3008  return Iterator( v_ + j*mm_ );
3009 }
3011 //*************************************************************************************************
3012 
3013 
3014 //*************************************************************************************************
3021 template< typename Type > // Data type of the matrix
3023  DynamicMatrix<Type,true>::begin( size_t j ) const
3024 {
3025  BLAZE_USER_ASSERT( j < n_, "Invalid dense matrix column access index" );
3026  return ConstIterator( v_ + j*mm_ );
3027 }
3029 //*************************************************************************************************
3030 
3031 
3032 //*************************************************************************************************
3039 template< typename Type > // Data type of the matrix
3041  DynamicMatrix<Type,true>::cbegin( size_t j ) const
3042 {
3043  BLAZE_USER_ASSERT( j < n_, "Invalid dense matrix column access index" );
3044  return ConstIterator( v_ + j*mm_ );
3045 }
3047 //*************************************************************************************************
3048 
3049 
3050 //*************************************************************************************************
3057 template< typename Type > // Data type of the matrix
3058 inline typename DynamicMatrix<Type,true>::Iterator
3059  DynamicMatrix<Type,true>::end( size_t j )
3060 {
3061  BLAZE_USER_ASSERT( j < n_, "Invalid dense matrix column access index" );
3062  return Iterator( v_ + j*mm_ + m_ );
3063 }
3065 //*************************************************************************************************
3066 
3067 
3068 //*************************************************************************************************
3075 template< typename Type > // Data type of the matrix
3077  DynamicMatrix<Type,true>::end( size_t j ) const
3078 {
3079  BLAZE_USER_ASSERT( j < n_, "Invalid dense matrix column access index" );
3080  return ConstIterator( v_ + j*mm_ + m_ );
3081 }
3083 //*************************************************************************************************
3084 
3085 
3086 //*************************************************************************************************
3093 template< typename Type > // Data type of the matrix
3095  DynamicMatrix<Type,true>::cend( size_t j ) const
3096 {
3097  BLAZE_USER_ASSERT( j < n_, "Invalid dense matrix column access index" );
3098  return ConstIterator( v_ + j*mm_ + m_ );
3099 }
3101 //*************************************************************************************************
3102 
3103 
3104 
3105 
3106 //=================================================================================================
3107 //
3108 // ASSIGNMENT OPERATORS
3109 //
3110 //=================================================================================================
3111 
3112 //*************************************************************************************************
3134 template< typename Type > // Data type of the matrix
3135 template< typename Other // Data type of the initialization array
3136  , size_t M // Number of rows of the initialization array
3137  , size_t N > // Number of columns of the initialization array
3138 inline DynamicMatrix<Type,true>& DynamicMatrix<Type,true>::operator=( const Other (&array)[M][N] )
3139 {
3140  resize( M, N, false );
3141 
3142  for( size_t j=0UL; j<N; ++j )
3143  for( size_t i=0UL; i<M; ++i )
3144  v_[i+j*mm_] = array[i][j];
3145 
3146  return *this;
3147 }
3149 //*************************************************************************************************
3150 
3151 
3152 //*************************************************************************************************
3159 template< typename Type > // Data type of the matrix
3160 inline DynamicMatrix<Type,true>& DynamicMatrix<Type,true>::operator=( Type rhs )
3161 {
3162  for( size_t j=0UL; j<n_; ++j )
3163  for( size_t i=0UL; i<m_; ++i )
3164  v_[i+j*mm_] = rhs;
3165 
3166  return *this;
3167 }
3169 //*************************************************************************************************
3170 
3171 
3172 //*************************************************************************************************
3182 template< typename Type > // Data type of the matrix
3183 inline DynamicMatrix<Type,true>& DynamicMatrix<Type,true>::operator=( const DynamicMatrix& rhs )
3184 {
3185  if( &rhs == this ) return *this;
3186 
3187  resize( rhs.m_, rhs.n_, false );
3188  smpAssign( *this, ~rhs );
3189 
3190  return *this;
3191 }
3193 //*************************************************************************************************
3194 
3195 
3196 //*************************************************************************************************
3206 template< typename Type > // Data type of the matrix
3207 template< typename MT // Type of the right-hand side matrix
3208  , bool SO > // Storage order of the right-hand side matrix
3209 inline DynamicMatrix<Type,true>& DynamicMatrix<Type,true>::operator=( const Matrix<MT,SO>& rhs )
3210 {
3211  if( (~rhs).canAlias( this ) ) {
3212  DynamicMatrix tmp( ~rhs );
3213  swap( tmp );
3214  }
3215  else {
3216  resize( (~rhs).rows(), (~rhs).columns(), false );
3217  if( IsSparseMatrix<MT>::value )
3218  reset();
3219  smpAssign( *this, ~rhs );
3220  }
3221 
3222  return *this;
3223 }
3225 //*************************************************************************************************
3226 
3227 
3228 //*************************************************************************************************
3239 template< typename Type > // Data type of the matrix
3240 template< typename MT // Type of the right-hand side matrix
3241  , bool SO > // Storage order of the right-hand side matrix
3242 inline DynamicMatrix<Type,true>& DynamicMatrix<Type,true>::operator+=( const Matrix<MT,SO>& rhs )
3243 {
3244  if( (~rhs).rows() != m_ || (~rhs).columns() != n_ )
3245  throw std::invalid_argument( "Matrix sizes do not match" );
3246 
3247  if( (~rhs).canAlias( this ) ) {
3248  typename MT::ResultType tmp( ~rhs );
3249  smpAddAssign( *this, tmp );
3250  }
3251  else {
3252  smpAddAssign( *this, ~rhs );
3253  }
3254 
3255  return *this;
3256 }
3258 //*************************************************************************************************
3259 
3260 
3261 //*************************************************************************************************
3272 template< typename Type > // Data type of the matrix
3273 template< typename MT // Type of the right-hand side matrix
3274  , bool SO > // Storage order of the right-hand side matrix
3275 inline DynamicMatrix<Type,true>& DynamicMatrix<Type,true>::operator-=( const Matrix<MT,SO>& rhs )
3276 {
3277  if( (~rhs).rows() != m_ || (~rhs).columns() != n_ )
3278  throw std::invalid_argument( "Matrix sizes do not match" );
3279 
3280  if( (~rhs).canAlias( this ) ) {
3281  typename MT::ResultType tmp( ~rhs );
3282  smpSubAssign( *this, tmp );
3283  }
3284  else {
3285  smpSubAssign( *this, ~rhs );
3286  }
3287 
3288  return *this;
3289 }
3291 //*************************************************************************************************
3292 
3293 
3294 //*************************************************************************************************
3305 template< typename Type > // Data type of the matrix
3306 template< typename MT // Type of the right-hand side matrix
3307  , bool SO > // Storage order of the right-hand side matrix
3308 inline DynamicMatrix<Type,true>& DynamicMatrix<Type,true>::operator*=( const Matrix<MT,SO>& rhs )
3309 {
3310  if( (~rhs).rows() != n_ )
3311  throw std::invalid_argument( "Matrix sizes do not match" );
3312 
3313  DynamicMatrix tmp( *this * (~rhs) );
3314  swap( tmp );
3315 
3316  return *this;
3317 }
3319 //*************************************************************************************************
3320 
3321 
3322 //*************************************************************************************************
3330 template< typename Type > // Data type of the matrix
3331 template< typename Other > // Data type of the right-hand side scalar
3332 inline typename EnableIf< IsNumeric<Other>, DynamicMatrix<Type,true> >::Type&
3333  DynamicMatrix<Type,true>::operator*=( Other rhs )
3334 {
3335  smpAssign( *this, (*this) * rhs );
3336  return *this;
3337 }
3339 //*************************************************************************************************
3340 
3341 
3342 //*************************************************************************************************
3350 template< typename Type > // Data type of the matrix
3351 template< typename Other > // Data type of the right-hand side scalar
3352 inline typename EnableIf< IsNumeric<Other>, DynamicMatrix<Type,true> >::Type&
3353  DynamicMatrix<Type,true>::operator/=( Other rhs )
3354 {
3355  BLAZE_USER_ASSERT( rhs != Other(0), "Division by zero detected" );
3356 
3357  smpAssign( *this, (*this) / rhs );
3358  return *this;
3359 }
3361 //*************************************************************************************************
3362 
3363 
3364 
3365 
3366 //=================================================================================================
3367 //
3368 // UTILITY FUNCTIONS
3369 //
3370 //=================================================================================================
3371 
3372 //*************************************************************************************************
3378 template< typename Type > // Data type of the matrix
3379 inline size_t DynamicMatrix<Type,true>::rows() const
3380 {
3381  return m_;
3382 }
3384 //*************************************************************************************************
3385 
3386 
3387 //*************************************************************************************************
3393 template< typename Type > // Data type of the matrix
3394 inline size_t DynamicMatrix<Type,true>::columns() const
3395 {
3396  return n_;
3397 }
3399 //*************************************************************************************************
3400 
3401 
3402 //*************************************************************************************************
3411 template< typename Type > // Data type of the matrix
3412 inline size_t DynamicMatrix<Type,true>::spacing() const
3413 {
3414  return mm_;
3415 }
3417 //*************************************************************************************************
3418 
3419 
3420 //*************************************************************************************************
3426 template< typename Type > // Data type of the matrix
3427 inline size_t DynamicMatrix<Type,true>::capacity() const
3428 {
3429  return capacity_;
3430 }
3432 //*************************************************************************************************
3433 
3434 
3435 //*************************************************************************************************
3442 template< typename Type > // Data type of the sparse matrix
3443 inline size_t DynamicMatrix<Type,true>::capacity( size_t j ) const
3444 {
3445  UNUSED_PARAMETER( j );
3446  BLAZE_USER_ASSERT( j < columns(), "Invalid column access index" );
3447  return mm_;
3448 }
3450 //*************************************************************************************************
3451 
3452 
3453 //*************************************************************************************************
3459 template< typename Type > // Data type of the matrix
3460 inline size_t DynamicMatrix<Type,true>::nonZeros() const
3461 {
3462  size_t nonzeros( 0UL );
3463 
3464  for( size_t j=0UL; j<n_; ++j )
3465  for( size_t i=0UL; i<m_; ++i )
3466  if( !isDefault( v_[i+j*mm_] ) )
3467  ++nonzeros;
3468 
3469  return nonzeros;
3470 }
3472 //*************************************************************************************************
3473 
3474 
3475 //*************************************************************************************************
3482 template< typename Type > // Data type of the matrix
3483 inline size_t DynamicMatrix<Type,true>::nonZeros( size_t j ) const
3484 {
3485  BLAZE_USER_ASSERT( j < columns(), "Invalid column access index" );
3486 
3487  const size_t iend( (j+1UL)*mm_ );
3488  size_t nonzeros( 0UL );
3489 
3490  for( size_t i=j*mm_; i<iend; ++i )
3491  if( !isDefault( v_[i] ) )
3492  ++nonzeros;
3493 
3494  return nonzeros;
3495 }
3497 //*************************************************************************************************
3498 
3499 
3500 //*************************************************************************************************
3506 template< typename Type > // Data type of the matrix
3507 inline void DynamicMatrix<Type,true>::reset()
3508 {
3509  using blaze::reset;
3510 
3511  for( size_t j=0UL; j<n_; ++j )
3512  for( size_t i=0UL; i<m_; ++i )
3513  reset( v_[i+j*mm_] );
3514 }
3516 //*************************************************************************************************
3517 
3518 
3519 //*************************************************************************************************
3529 template< typename Type > // Data type of the sparse matrix
3530 inline void DynamicMatrix<Type,true>::reset( size_t j )
3531 {
3532  using blaze::reset;
3533 
3534  BLAZE_USER_ASSERT( j < columns(), "Invalid column access index" );
3535  for( size_t i=0UL; i<m_; ++i )
3536  reset( v_[i+j*mm_] );
3537 }
3539 //*************************************************************************************************
3540 
3541 
3542 //*************************************************************************************************
3550 template< typename Type > // Data type of the matrix
3551 inline void DynamicMatrix<Type,true>::clear()
3552 {
3553  resize( 0UL, 0UL, false );
3554 }
3556 //*************************************************************************************************
3557 
3558 
3559 //*************************************************************************************************
3593 template< typename Type > // Data type of the matrix
3594 void DynamicMatrix<Type,true>::resize( size_t m, size_t n, bool preserve )
3595 {
3596  using blaze::min;
3597 
3598  if( m == m_ && n == n_ ) return;
3599 
3600  const size_t mm( adjustRows( m ) );
3601 
3602  if( preserve )
3603  {
3604  Type* BLAZE_RESTRICT v = allocate<Type>( mm*n );
3605  const size_t min_m( min( m, m_ ) );
3606  const size_t min_n( min( n, n_ ) );
3607 
3608  for( size_t j=0UL; j<min_n; ++j )
3609  for( size_t i=0UL; i<min_m; ++i )
3610  v[i+j*mm] = v_[i+j*mm_];
3611 
3612  std::swap( v_, v );
3613  deallocate( v );
3614  capacity_ = mm*n;
3615  }
3616  else if( mm*n > capacity_ ) {
3617  Type* BLAZE_RESTRICT v = allocate<Type>( mm*n );
3618  std::swap( v_, v );
3619  deallocate( v );
3620  capacity_ = mm*n;
3621  }
3622 
3623  if( IsNumeric<Type>::value ) {
3624  for( size_t j=0UL; j<n; ++j )
3625  for( size_t i=m; i<mm; ++i )
3626  v_[i+j*mm] = Type();
3627  }
3628 
3629  m_ = m;
3630  mm_ = mm;
3631  n_ = n;
3632 }
3634 //*************************************************************************************************
3635 
3636 
3637 //*************************************************************************************************
3652 template< typename Type > // Data type of the matrix
3653 inline void DynamicMatrix<Type,true>::extend( size_t m, size_t n, bool preserve )
3654 {
3655  resize( m_+m, n_+n, preserve );
3656 }
3658 //*************************************************************************************************
3659 
3660 
3661 //*************************************************************************************************
3671 template< typename Type > // Data type of the matrix
3672 inline void DynamicMatrix<Type,true>::reserve( size_t elements )
3673 {
3674  if( elements > capacity_ )
3675  {
3676  // Allocating a new array
3677  Type* BLAZE_RESTRICT tmp = allocate<Type>( elements );
3678 
3679  // Initializing the new array
3680  std::copy( v_, v_+capacity_, tmp );
3681 
3682  if( IsNumeric<Type>::value ) {
3683  for( size_t i=capacity_; i<elements; ++i )
3684  tmp[i] = Type();
3685  }
3686 
3687  // Replacing the old array
3688  std::swap( tmp, v_ );
3689  deallocate( tmp );
3690  capacity_ = elements;
3691  }
3692 }
3694 //*************************************************************************************************
3695 
3696 
3697 //*************************************************************************************************
3703 template< typename Type > // Data type of the matrix
3704 inline DynamicMatrix<Type,true>& DynamicMatrix<Type,true>::transpose()
3705 {
3706  DynamicMatrix tmp( trans(*this) );
3707  swap( tmp );
3708  return *this;
3709 }
3711 //*************************************************************************************************
3712 
3713 
3714 //*************************************************************************************************
3721 template< typename Type > // Data type of the matrix
3722 template< typename Other > // Data type of the scalar value
3723 inline DynamicMatrix<Type,true>& DynamicMatrix<Type,true>::scale( Other scalar )
3724 {
3725  for( size_t j=0UL; j<n_; ++j )
3726  for( size_t i=0UL; i<m_; ++i )
3727  v_[i+j*mm_] *= scalar;
3728 
3729  return *this;
3730 }
3732 //*************************************************************************************************
3733 
3734 
3735 //*************************************************************************************************
3743 template< typename Type > // Data type of the matrix
3744 inline void DynamicMatrix<Type,true>::swap( DynamicMatrix& m ) /* throw() */
3745 {
3746  std::swap( m_ , m.m_ );
3747  std::swap( mm_, m.mm_ );
3748  std::swap( n_ , m.n_ );
3749  std::swap( capacity_, m.capacity_ );
3750  std::swap( v_ , m.v_ );
3751 }
3753 //*************************************************************************************************
3754 
3755 
3756 //*************************************************************************************************
3763 template< typename Type > // Data type of the matrix
3764 inline size_t DynamicMatrix<Type,true>::adjustRows( size_t minRows ) const
3765 {
3766  if( IsNumeric<Type>::value )
3767  return minRows + ( IT::size - ( minRows % IT::size ) ) % IT::size;
3768  else return minRows;
3769 }
3771 //*************************************************************************************************
3772 
3773 
3774 
3775 
3776 //=================================================================================================
3777 //
3778 // EXPRESSION TEMPLATE EVALUATION FUNCTIONS
3779 //
3780 //=================================================================================================
3781 
3782 //*************************************************************************************************
3793 template< typename Type > // Data type of the matrix
3794 template< typename Other > // Data type of the foreign expression
3795 inline bool DynamicMatrix<Type,true>::canAlias( const Other* alias ) const
3796 {
3797  return static_cast<const void*>( this ) == static_cast<const void*>( alias );
3798 }
3800 //*************************************************************************************************
3801 
3802 
3803 //*************************************************************************************************
3814 template< typename Type > // Data type of the matrix
3815 template< typename Other > // Data type of the foreign expression
3816 inline bool DynamicMatrix<Type,true>::isAliased( const Other* alias ) const
3817 {
3818  return static_cast<const void*>( this ) == static_cast<const void*>( alias );
3819 }
3821 //*************************************************************************************************
3822 
3823 
3824 //*************************************************************************************************
3834 template< typename Type > // Data type of the matrix
3835 inline bool DynamicMatrix<Type,true>::isAligned() const
3836 {
3837  return true;
3838 }
3840 //*************************************************************************************************
3841 
3842 
3843 //*************************************************************************************************
3854 template< typename Type > // Data type of the matrix
3855 inline bool DynamicMatrix<Type,true>::canSMPAssign() const
3856 {
3857  return ( columns() > OPENMP_DMATASSIGN_THRESHOLD );
3858 }
3860 //*************************************************************************************************
3861 
3862 
3863 //*************************************************************************************************
3878 template< typename Type > // Data type of the matrix
3879 inline typename DynamicMatrix<Type,true>::IntrinsicType
3880  DynamicMatrix<Type,true>::load( size_t i, size_t j ) const
3881 {
3882  using blaze::load;
3883 
3885 
3886  BLAZE_INTERNAL_ASSERT( i < m_ , "Invalid row access index" );
3887  BLAZE_INTERNAL_ASSERT( i + IT::size <= mm_, "Invalid row access index" );
3888  BLAZE_INTERNAL_ASSERT( i % IT::size == 0UL, "Invalid row access index" );
3889  BLAZE_INTERNAL_ASSERT( j < n_ , "Invalid column access index" );
3890 
3891  return load( v_+i+j*mm_ );
3892 }
3894 //*************************************************************************************************
3895 
3896 
3897 //*************************************************************************************************
3912 template< typename Type > // Data type of the matrix
3913 inline typename DynamicMatrix<Type,true>::IntrinsicType
3914  DynamicMatrix<Type,true>::loadu( size_t i, size_t j ) const
3915 {
3916  using blaze::loadu;
3917 
3919 
3920  BLAZE_INTERNAL_ASSERT( i < m_ , "Invalid row access index" );
3921  BLAZE_INTERNAL_ASSERT( i + IT::size <= mm_, "Invalid row access index" );
3922  BLAZE_INTERNAL_ASSERT( j < n_ , "Invalid column access index" );
3923 
3924  return loadu( v_+i+j*mm_ );
3925 }
3927 //*************************************************************************************************
3928 
3929 
3930 //*************************************************************************************************
3946 template< typename Type > // Data type of the matrix
3947 inline void DynamicMatrix<Type,true>::store( size_t i, size_t j, const IntrinsicType& value )
3948 {
3949  using blaze::store;
3950 
3952 
3953  BLAZE_INTERNAL_ASSERT( i < m_ , "Invalid row access index" );
3954  BLAZE_INTERNAL_ASSERT( i + IT::size <= mm_, "Invalid row access index" );
3955  BLAZE_INTERNAL_ASSERT( i % IT::size == 0UL, "Invalid row access index" );
3956  BLAZE_INTERNAL_ASSERT( j < n_ , "Invalid column access index" );
3957 
3958  store( v_+i+j*mm_, value );
3959 }
3961 //*************************************************************************************************
3962 
3963 
3964 //*************************************************************************************************
3980 template< typename Type > // Data type of the matrix
3981 inline void DynamicMatrix<Type,true>::storeu( size_t i, size_t j, const IntrinsicType& value )
3982 {
3983  using blaze::storeu;
3984 
3986 
3987  BLAZE_INTERNAL_ASSERT( i < m_ , "Invalid row access index" );
3988  BLAZE_INTERNAL_ASSERT( i + IT::size <= mm_, "Invalid row access index" );
3989  BLAZE_INTERNAL_ASSERT( j < n_ , "Invalid column access index" );
3990 
3991  storeu( v_+i+j*mm_, value );
3992 }
3994 //*************************************************************************************************
3995 
3996 
3997 //*************************************************************************************************
4014 template< typename Type > // Data type of the matrix
4015 inline void DynamicMatrix<Type,true>::stream( size_t i, size_t j, const IntrinsicType& value )
4016 {
4017  using blaze::stream;
4018 
4020 
4021  BLAZE_INTERNAL_ASSERT( i < m_ , "Invalid row access index" );
4022  BLAZE_INTERNAL_ASSERT( i + IT::size <= mm_, "Invalid row access index" );
4023  BLAZE_INTERNAL_ASSERT( i % IT::size == 0UL, "Invalid row access index" );
4024  BLAZE_INTERNAL_ASSERT( j < n_ , "Invalid column access index" );
4025 
4026  stream( v_+i+j*mm_, value );
4027 }
4029 //*************************************************************************************************
4030 
4031 
4032 //*************************************************************************************************
4044 template< typename Type > // Data type of the matrix
4045 template< typename MT > // Type of the right-hand side dense matrix
4046 inline typename DisableIf< typename DynamicMatrix<Type,true>::BLAZE_TEMPLATE VectorizedAssign<MT> >::Type
4047  DynamicMatrix<Type,true>::assign( const DenseMatrix<MT,true>& rhs )
4048 {
4049  BLAZE_INTERNAL_ASSERT( m_ == (~rhs).rows() , "Invalid number of rows" );
4050  BLAZE_INTERNAL_ASSERT( n_ == (~rhs).columns(), "Invalid number of columns" );
4051 
4052  const size_t iend( m_ & size_t(-2) );
4053  BLAZE_INTERNAL_ASSERT( ( m_ - ( m_ % 2UL ) ) == iend, "Invalid end calculation" );
4054 
4055  for( size_t j=0UL; j<n_; ++j ) {
4056  for( size_t i=0UL; i<iend; i+=2UL ) {
4057  v_[i +j*mm_] = (~rhs)(i ,j);
4058  v_[i+1UL+j*mm_] = (~rhs)(i+1UL,j);
4059  }
4060  if( iend < m_ ) {
4061  v_[iend+j*mm_] = (~rhs)(iend,j);
4062  }
4063  }
4064 }
4066 //*************************************************************************************************
4067 
4068 
4069 //*************************************************************************************************
4081 template< typename Type > // Data type of the matrix
4082 template< typename MT > // Type of the right-hand side dense matrix
4083 inline typename EnableIf< typename DynamicMatrix<Type,true>::BLAZE_TEMPLATE VectorizedAssign<MT> >::Type
4084  DynamicMatrix<Type,true>::assign( const DenseMatrix<MT,true>& rhs )
4085 {
4086  using blaze::store;
4087  using blaze::stream;
4088 
4089  BLAZE_INTERNAL_ASSERT( m_ == (~rhs).rows() , "Invalid number of rows" );
4090  BLAZE_INTERNAL_ASSERT( n_ == (~rhs).columns(), "Invalid number of columns" );
4091 
4093 
4094  if( useStreaming && m_*n_ > ( cacheSize / ( sizeof(Type) * 3UL ) ) && !(~rhs).isAliased( this ) )
4095  {
4096  for( size_t j=0UL; j<n_; ++j )
4097  for( size_t i=0UL; i<m_; i+=IT::size )
4098  stream( v_+i+j*mm_, (~rhs).load(i,j) );
4099  }
4100  else
4101  {
4102  const size_t iend( m_ & size_t(-IT::size*4) );
4103  BLAZE_INTERNAL_ASSERT( ( m_ - ( m_ % (IT::size*4UL) ) ) == iend, "Invalid end calculation" );
4104 
4105  for( size_t j=0UL; j<n_; ++j ) {
4106  typename MT::ConstIterator it( (~rhs).begin(j) );
4107  for( size_t i=0UL; i<iend; i+=IT::size*4UL ) {
4108  store( v_+i+j*mm_ , it.load() ); it += IT::size;
4109  store( v_+i+j*mm_+IT::size , it.load() ); it += IT::size;
4110  store( v_+i+j*mm_+IT::size*2UL, it.load() ); it += IT::size;
4111  store( v_+i+j*mm_+IT::size*3UL, it.load() ); it += IT::size;
4112  }
4113  for( size_t i=iend; i<m_; i+=IT::size, it+=IT::size ) {
4114  store( v_+i+j*mm_, it.load() );
4115  }
4116  }
4117  }
4118 }
4120 //*************************************************************************************************
4121 
4122 
4123 //*************************************************************************************************
4135 template< typename Type > // Data type of the matrix
4136 template< typename MT > // Type of the right-hand side dense matrix
4137 inline void DynamicMatrix<Type,true>::assign( const DenseMatrix<MT,false>& rhs )
4138 {
4139  BLAZE_INTERNAL_ASSERT( m_ == (~rhs).rows() , "Invalid number of rows" );
4140  BLAZE_INTERNAL_ASSERT( n_ == (~rhs).columns(), "Invalid number of columns" );
4141 
4142  const size_t block( 16UL );
4143 
4144  for( size_t jj=0UL; jj<n_; jj+=block ) {
4145  const size_t jend( ( n_<(jj+block) )?( n_ ):( jj+block ) );
4146  for( size_t ii=0UL; ii<m_; ii+=block ) {
4147  const size_t iend( ( m_<(ii+block) )?( m_ ):( ii+block ) );
4148  for( size_t j=jj; j<jend; ++j ) {
4149  for( size_t i=ii; i<iend; ++i ) {
4150  v_[i+j*mm_] = (~rhs)(i,j);
4151  }
4152  }
4153  }
4154  }
4155 }
4157 //*************************************************************************************************
4158 
4159 
4160 //*************************************************************************************************
4172 template< typename Type > // Data type of the matrix
4173 template< typename MT > // Type of the right-hand side sparse matrix
4174 inline void DynamicMatrix<Type,true>::assign( const SparseMatrix<MT,true>& rhs )
4175 {
4176  for( size_t j=0UL; j<(~rhs).columns(); ++j )
4177  for( typename MT::ConstIterator element=(~rhs).begin(j); element!=(~rhs).end(j); ++element )
4178  v_[element->index()+j*mm_] = element->value();
4179 }
4181 //*************************************************************************************************
4182 
4183 
4184 //*************************************************************************************************
4196 template< typename Type > // Data type of the matrix
4197 template< typename MT > // Type of the right-hand side sparse matrix
4198 inline void DynamicMatrix<Type,true>::assign( const SparseMatrix<MT,false>& rhs )
4199 {
4200  for( size_t i=0UL; i<(~rhs).rows(); ++i )
4201  for( typename MT::ConstIterator element=(~rhs).begin(i); element!=(~rhs).end(i); ++element )
4202  v_[i+element->index()*mm_] = element->value();
4203 }
4205 //*************************************************************************************************
4206 
4207 
4208 //*************************************************************************************************
4220 template< typename Type > // Data type of the matrix
4221 template< typename MT > // Type of the right-hand side dense matrix
4222 inline typename DisableIf< typename DynamicMatrix<Type,true>::BLAZE_TEMPLATE VectorizedAddAssign<MT> >::Type
4223  DynamicMatrix<Type,true>::addAssign( const DenseMatrix<MT,true>& rhs )
4224 {
4225  BLAZE_INTERNAL_ASSERT( m_ == (~rhs).rows() , "Invalid number of rows" );
4226  BLAZE_INTERNAL_ASSERT( n_ == (~rhs).columns(), "Invalid number of columns" );
4227 
4228  const size_t iend( m_ & size_t(-2) );
4229  BLAZE_INTERNAL_ASSERT( ( m_ - ( m_ % 2UL ) ) == iend, "Invalid end calculation" );
4230 
4231  for( size_t j=0UL; j<n_; ++j ) {
4232  for( size_t i=0UL; i<iend; i+=2UL ) {
4233  v_[i +j*mm_] += (~rhs)(i ,j);
4234  v_[i+1UL+j*mm_] += (~rhs)(i+1UL,j);
4235  }
4236  if( iend < m_ ) {
4237  v_[iend+j*mm_] += (~rhs)(iend,j);
4238  }
4239  }
4240 }
4242 //*************************************************************************************************
4243 
4244 
4245 //*************************************************************************************************
4257 template< typename Type > // Data type of the matrix
4258 template< typename MT > // Type of the right-hand side dense matrix
4259 inline typename EnableIf< typename DynamicMatrix<Type,true>::BLAZE_TEMPLATE VectorizedAddAssign<MT> >::Type
4260  DynamicMatrix<Type,true>::addAssign( const DenseMatrix<MT,true>& rhs )
4261 {
4262  using blaze::load;
4263  using blaze::store;
4264 
4265  BLAZE_INTERNAL_ASSERT( m_ == (~rhs).rows() , "Invalid number of rows" );
4266  BLAZE_INTERNAL_ASSERT( n_ == (~rhs).columns(), "Invalid number of columns" );
4267 
4269 
4270  const size_t iend( m_ & size_t(-IT::size*4) );
4271  BLAZE_INTERNAL_ASSERT( ( m_ - ( m_ % (IT::size*4UL) ) ) == iend, "Invalid end calculation" );
4272 
4273  for( size_t j=0UL; j<n_; ++j ) {
4274  typename MT::ConstIterator it( (~rhs).begin(j) );
4275  for( size_t i=0UL; i<iend; i+=IT::size*4UL ) {
4276  store( v_+i+j*mm_ , load( v_+i+j*mm_ ) + it.load() ); it += IT::size;
4277  store( v_+i+j*mm_+IT::size , load( v_+i+j*mm_+IT::size ) + it.load() ); it += IT::size;
4278  store( v_+i+j*mm_+IT::size*2UL, load( v_+i+j*mm_+IT::size*2UL ) + it.load() ); it += IT::size;
4279  store( v_+i+j*mm_+IT::size*3UL, load( v_+i+j*mm_+IT::size*3UL ) + it.load() ); it += IT::size;
4280  }
4281  for( size_t i=iend; i<m_; i+=IT::size, it+=IT::size ) {
4282  store( v_+i+j*mm_, load( v_+i+j*mm_ ) + it.load() );
4283  }
4284  }
4285 }
4287 //*************************************************************************************************
4288 
4289 
4290 //*************************************************************************************************
4302 template< typename Type > // Data type of the matrix
4303 template< typename MT > // Type of the right-hand side dense matrix
4304 inline void DynamicMatrix<Type,true>::addAssign( const DenseMatrix<MT,false>& rhs )
4305 {
4306  BLAZE_INTERNAL_ASSERT( m_ == (~rhs).rows() , "Invalid number of rows" );
4307  BLAZE_INTERNAL_ASSERT( n_ == (~rhs).columns(), "Invalid number of columns" );
4308 
4309  const size_t block( 16UL );
4310 
4311  for( size_t jj=0UL; jj<n_; jj+=block ) {
4312  const size_t jend( ( n_<(jj+block) )?( n_ ):( jj+block ) );
4313  for( size_t ii=0UL; ii<m_; ii+=block ) {
4314  const size_t iend( ( m_<(ii+block) )?( m_ ):( ii+block ) );
4315  for( size_t j=jj; j<jend; ++j ) {
4316  for( size_t i=ii; i<iend; ++i ) {
4317  v_[i+j*mm_] += (~rhs)(i,j);
4318  }
4319  }
4320  }
4321  }
4322 }
4324 //*************************************************************************************************
4325 
4326 
4327 //*************************************************************************************************
4339 template< typename Type > // Data type of the matrix
4340 template< typename MT > // Type of the right-hand side sparse matrix
4341 inline void DynamicMatrix<Type,true>::addAssign( const SparseMatrix<MT,true>& rhs )
4342 {
4343  for( size_t j=0UL; j<(~rhs).columns(); ++j )
4344  for( typename MT::ConstIterator element=(~rhs).begin(j); element!=(~rhs).end(j); ++element )
4345  v_[element->index()+j*mm_] += element->value();
4346 }
4348 //*************************************************************************************************
4349 
4350 
4351 //*************************************************************************************************
4363 template< typename Type > // Data type of the matrix
4364 template< typename MT > // Type of the right-hand side sparse matrix
4365 inline void DynamicMatrix<Type,true>::addAssign( const SparseMatrix<MT,false>& rhs )
4366 {
4367  for( size_t i=0UL; i<(~rhs).rows(); ++i )
4368  for( typename MT::ConstIterator element=(~rhs).begin(i); element!=(~rhs).end(i); ++element )
4369  v_[i+element->index()*mm_] += element->value();
4370 }
4372 //*************************************************************************************************
4373 
4374 
4375 //*************************************************************************************************
4387 template< typename Type > // Data type of the matrix
4388 template< typename MT > // Type of the right-hand side dense matrix
4389 inline typename DisableIf< typename DynamicMatrix<Type,true>::BLAZE_TEMPLATE VectorizedSubAssign<MT> >::Type
4390  DynamicMatrix<Type,true>::subAssign( const DenseMatrix<MT,true>& rhs )
4391 {
4392  BLAZE_INTERNAL_ASSERT( m_ == (~rhs).rows() , "Invalid number of rows" );
4393  BLAZE_INTERNAL_ASSERT( n_ == (~rhs).columns(), "Invalid number of columns" );
4394 
4395  const size_t iend( m_ & size_t(-2) );
4396  BLAZE_INTERNAL_ASSERT( ( m_ - ( m_ % 2UL ) ) == iend, "Invalid end calculation" );
4397 
4398  for( size_t j=0UL; j<n_; ++j ) {
4399  for( size_t i=0UL; i<iend; i+=2UL ) {
4400  v_[i +j*mm_] -= (~rhs)(i ,j);
4401  v_[i+1+j*mm_] -= (~rhs)(i+1,j);
4402  }
4403  if( iend < m_ ) {
4404  v_[iend+j*mm_] -= (~rhs)(iend,j);
4405  }
4406  }
4407 }
4409 //*************************************************************************************************
4410 
4411 
4412 //*************************************************************************************************
4425 template< typename Type > // Data type of the matrix
4426 template< typename MT > // Type of the right-hand side dense matrix
4427 inline typename EnableIf< typename DynamicMatrix<Type,true>::BLAZE_TEMPLATE VectorizedSubAssign<MT> >::Type
4428  DynamicMatrix<Type,true>::subAssign( const DenseMatrix<MT,true>& rhs )
4429 {
4430  using blaze::load;
4431  using blaze::store;
4432 
4433  BLAZE_INTERNAL_ASSERT( m_ == (~rhs).rows() , "Invalid number of rows" );
4434  BLAZE_INTERNAL_ASSERT( n_ == (~rhs).columns(), "Invalid number of columns" );
4435 
4437 
4438  const size_t iend( m_ & size_t(-IT::size*4) );
4439  BLAZE_INTERNAL_ASSERT( ( m_ - ( m_ % (IT::size*4UL) ) ) == iend, "Invalid end calculation" );
4440 
4441  for( size_t j=0UL; j<n_; ++j ) {
4442  typename MT::ConstIterator it( (~rhs).begin(j) );
4443  for( size_t i=0UL; i<iend; i+=IT::size*4UL ) {
4444  store( v_+i+j*mm_ , load( v_+i+j*mm_ ) - it.load() ); it += IT::size;
4445  store( v_+i+j*mm_+IT::size , load( v_+i+j*mm_+IT::size ) - it.load() ); it += IT::size;
4446  store( v_+i+j*mm_+IT::size*2UL, load( v_+i+j*mm_+IT::size*2UL ) - it.load() ); it += IT::size;
4447  store( v_+i+j*mm_+IT::size*3UL, load( v_+i+j*mm_+IT::size*3UL ) - it.load() ); it += IT::size;
4448  }
4449  for( size_t i=iend; i<m_; i+=IT::size, it+=IT::size ) {
4450  store( v_+i+j*mm_, load( v_+i+j*mm_ ) - it.load() );
4451  }
4452  }
4453 }
4455 //*************************************************************************************************
4456 
4457 
4458 //*************************************************************************************************
4470 template< typename Type > // Data type of the matrix
4471 template< typename MT > // Type of the right-hand side dense matrix
4472 inline void DynamicMatrix<Type,true>::subAssign( const DenseMatrix<MT,false>& rhs )
4473 {
4474  const size_t block( 16UL );
4475 
4476  for( size_t jj=0UL; jj<n_; jj+=block ) {
4477  const size_t jend( ( n_<(jj+block) )?( n_ ):( jj+block ) );
4478  for( size_t ii=0UL; ii<m_; ii+=block ) {
4479  const size_t iend( ( m_<(ii+block) )?( m_ ):( ii+block ) );
4480  for( size_t j=jj; j<jend; ++j ) {
4481  for( size_t i=ii; i<iend; ++i ) {
4482  v_[i+j*mm_] -= (~rhs)(i,j);
4483  }
4484  }
4485  }
4486  }
4487 }
4489 //*************************************************************************************************
4490 
4491 
4492 //*************************************************************************************************
4504 template< typename Type > // Data type of the matrix
4505 template< typename MT > // Type of the right-hand side sparse matrix
4506 inline void DynamicMatrix<Type,true>::subAssign( const SparseMatrix<MT,true>& rhs )
4507 {
4508  for( size_t j=0UL; j<(~rhs).columns(); ++j )
4509  for( typename MT::ConstIterator element=(~rhs).begin(j); element!=(~rhs).end(j); ++element )
4510  v_[element->index()+j*mm_] -= element->value();
4511 }
4513 //*************************************************************************************************
4514 
4515 
4516 //*************************************************************************************************
4528 template< typename Type > // Data type of the matrix
4529 template< typename MT > // Type of the right-hand side sparse matrix
4530 inline void DynamicMatrix<Type,true>::subAssign( const SparseMatrix<MT,false>& rhs )
4531 {
4532  for( size_t i=0UL; i<(~rhs).rows(); ++i )
4533  for( typename MT::ConstIterator element=(~rhs).begin(i); element!=(~rhs).end(i); ++element )
4534  v_[i+element->index()*mm_] -= element->value();
4535 }
4537 //*************************************************************************************************
4538 
4539 
4540 
4541 
4542 
4543 
4544 
4545 
4546 //=================================================================================================
4547 //
4548 // DYNAMICMATRIX OPERATORS
4549 //
4550 //=================================================================================================
4551 
4552 //*************************************************************************************************
4555 template< typename Type, bool SO >
4556 inline void reset( DynamicMatrix<Type,SO>& m );
4557 
4558 template< typename Type, bool SO >
4559 inline void clear( DynamicMatrix<Type,SO>& m );
4560 
4561 template< typename Type, bool SO >
4562 inline bool isDefault( const DynamicMatrix<Type,SO>& m );
4563 
4564 template< typename Type, bool SO >
4565 inline void swap( DynamicMatrix<Type,SO>& a, DynamicMatrix<Type,SO>& b ) /* throw() */;
4567 //*************************************************************************************************
4568 
4569 
4570 //*************************************************************************************************
4577 template< typename Type // Data type of the matrix
4578  , bool SO > // Storage order
4580 {
4581  m.reset();
4582 }
4583 //*************************************************************************************************
4584 
4585 
4586 //*************************************************************************************************
4593 template< typename Type // Data type of the matrix
4594  , bool SO > // Storage order
4596 {
4597  m.clear();
4598 }
4599 //*************************************************************************************************
4600 
4601 
4602 //*************************************************************************************************
4620 template< typename Type // Data type of the matrix
4621  , bool SO > // Storage order
4622 inline bool isDefault( const DynamicMatrix<Type,SO>& m )
4623 {
4624  if( SO == rowMajor ) {
4625  for( size_t i=0UL; i<m.rows(); ++i )
4626  for( size_t j=0UL; j<m.columns(); ++j )
4627  if( !isDefault( m(i,j) ) ) return false;
4628  }
4629  else {
4630  for( size_t j=0UL; j<m.columns(); ++j )
4631  for( size_t i=0UL; i<m.rows(); ++i )
4632  if( !isDefault( m(i,j) ) ) return false;
4633  }
4634 
4635  return true;
4636 }
4637 //*************************************************************************************************
4638 
4639 
4640 //*************************************************************************************************
4649 template< typename Type // Data type of the matrix
4650  , bool SO > // Storage order
4651 inline void swap( DynamicMatrix<Type,SO>& a, DynamicMatrix<Type,SO>& b ) /* throw() */
4652 {
4653  a.swap( b );
4654 }
4655 //*************************************************************************************************
4656 
4657 
4658 
4659 
4660 //=================================================================================================
4661 //
4662 // ISRESIZABLE SPECIALIZATIONS
4663 //
4664 //=================================================================================================
4665 
4666 //*************************************************************************************************
4668 template< typename T, bool SO >
4669 struct IsResizable< DynamicMatrix<T,SO> > : public TrueType
4670 {
4671  enum { value = 1 };
4672  typedef TrueType Type;
4673 };
4674 
4675 template< typename T, bool SO >
4676 struct IsResizable< const DynamicMatrix<T,SO> > : public TrueType
4677 {
4678  enum { value = 1 };
4679  typedef TrueType Type;
4680 };
4681 
4682 template< typename T, bool SO >
4683 struct IsResizable< volatile DynamicMatrix<T,SO> > : public TrueType
4684 {
4685  enum { value = 1 };
4686  typedef TrueType Type;
4687 };
4688 
4689 template< typename T, bool SO >
4690 struct IsResizable< const volatile DynamicMatrix<T,SO> > : public TrueType
4691 {
4692  enum { value = 1 };
4693  typedef TrueType Type;
4694 };
4696 //*************************************************************************************************
4697 
4698 
4699 
4700 
4701 //=================================================================================================
4702 //
4703 // ADDTRAIT SPECIALIZATIONS
4704 //
4705 //=================================================================================================
4706 
4707 //*************************************************************************************************
4709 template< typename T1, bool SO, typename T2, size_t M, size_t N >
4710 struct AddTrait< DynamicMatrix<T1,SO>, StaticMatrix<T2,M,N,SO> >
4711 {
4712  typedef StaticMatrix< typename AddTrait<T1,T2>::Type, M, N, SO > Type;
4713 };
4714 
4715 template< typename T1, bool SO1, typename T2, size_t M, size_t N, bool SO2 >
4716 struct AddTrait< DynamicMatrix<T1,SO1>, StaticMatrix<T2,M,N,SO2> >
4717 {
4718  typedef StaticMatrix< typename AddTrait<T1,T2>::Type, M, N, false > Type;
4719 };
4720 
4721 template< typename T1, size_t M, size_t N, bool SO, typename T2 >
4722 struct AddTrait< StaticMatrix<T1,M,N,SO>, DynamicMatrix<T2,SO> >
4723 {
4724  typedef StaticMatrix< typename AddTrait<T1,T2>::Type, M, N, SO > Type;
4725 };
4726 
4727 template< typename T1, size_t M, size_t N, bool SO1, typename T2, bool SO2 >
4728 struct AddTrait< StaticMatrix<T1,M,N,SO1>, DynamicMatrix<T2,SO2> >
4729 {
4730  typedef StaticMatrix< typename AddTrait<T1,T2>::Type, M, N, false > Type;
4731 };
4732 
4733 template< typename T1, bool SO, typename T2 >
4734 struct AddTrait< DynamicMatrix<T1,SO>, DynamicMatrix<T2,SO> >
4735 {
4736  typedef DynamicMatrix< typename AddTrait<T1,T2>::Type , SO > Type;
4737 };
4738 
4739 template< typename T1, bool SO1, typename T2, bool SO2 >
4740 struct AddTrait< DynamicMatrix<T1,SO1>, DynamicMatrix<T2,SO2> >
4741 {
4742  typedef DynamicMatrix< typename AddTrait<T1,T2>::Type , false > Type;
4743 };
4745 //*************************************************************************************************
4746 
4747 
4748 
4749 
4750 //=================================================================================================
4751 //
4752 // SUBTRAIT SPECIALIZATIONS
4753 //
4754 //=================================================================================================
4755 
4756 //*************************************************************************************************
4758 template< typename T1, bool SO, typename T2, size_t M, size_t N >
4759 struct SubTrait< DynamicMatrix<T1,SO>, StaticMatrix<T2,M,N,SO> >
4760 {
4761  typedef StaticMatrix< typename SubTrait<T1,T2>::Type, M, N, SO > Type;
4762 };
4763 
4764 template< typename T1, bool SO1, typename T2, size_t M, size_t N, bool SO2 >
4765 struct SubTrait< DynamicMatrix<T1,SO1>, StaticMatrix<T2,M,N,SO2> >
4766 {
4767  typedef StaticMatrix< typename SubTrait<T1,T2>::Type, M, N, false > Type;
4768 };
4769 
4770 template< typename T1, size_t M, size_t N, bool SO, typename T2 >
4771 struct SubTrait< StaticMatrix<T1,M,N,SO>, DynamicMatrix<T2,SO> >
4772 {
4773  typedef StaticMatrix< typename SubTrait<T1,T2>::Type, M, N, SO > Type;
4774 };
4775 
4776 template< typename T1, size_t M, size_t N, bool SO1, typename T2, bool SO2 >
4777 struct SubTrait< StaticMatrix<T1,M,N,SO1>, DynamicMatrix<T2,SO2> >
4778 {
4779  typedef StaticMatrix< typename SubTrait<T1,T2>::Type, M, N, false > Type;
4780 };
4781 
4782 template< typename T1, bool SO, typename T2 >
4783 struct SubTrait< DynamicMatrix<T1,SO>, DynamicMatrix<T2,SO> >
4784 {
4785  typedef DynamicMatrix< typename SubTrait<T1,T2>::Type , SO > Type;
4786 };
4787 
4788 template< typename T1, bool SO1, typename T2, bool SO2 >
4789 struct SubTrait< DynamicMatrix<T1,SO1>, DynamicMatrix<T2,SO2> >
4790 {
4791  typedef DynamicMatrix< typename SubTrait<T1,T2>::Type , false > Type;
4792 };
4794 //*************************************************************************************************
4795 
4796 
4797 
4798 
4799 //=================================================================================================
4800 //
4801 // MULTTRAIT SPECIALIZATIONS
4802 //
4803 //=================================================================================================
4804 
4805 //*************************************************************************************************
4807 template< typename T1, bool SO, typename T2 >
4808 struct MultTrait< DynamicMatrix<T1,SO>, T2 >
4809 {
4810  typedef DynamicMatrix< typename MultTrait<T1,T2>::Type, SO > Type;
4812 };
4813 
4814 template< typename T1, typename T2, bool SO >
4815 struct MultTrait< T1, DynamicMatrix<T2,SO> >
4816 {
4817  typedef DynamicMatrix< typename MultTrait<T1,T2>::Type, SO > Type;
4819 };
4820 
4821 template< typename T1, bool SO, typename T2, size_t N >
4822 struct MultTrait< DynamicMatrix<T1,SO>, StaticVector<T2,N,false> >
4823 {
4824  typedef DynamicVector< typename MultTrait<T1,T2>::Type, false > Type;
4825 };
4826 
4827 template< typename T1, size_t N, typename T2, bool SO >
4828 struct MultTrait< StaticVector<T1,N,true>, DynamicMatrix<T2,SO> >
4829 {
4830  typedef DynamicVector< typename MultTrait<T1,T2>::Type, true > Type;
4831 };
4832 
4833 template< typename T1, bool SO, typename T2, size_t N >
4834 struct MultTrait< DynamicMatrix<T1,SO>, HybridVector<T2,N,false> >
4835 {
4836  typedef DynamicVector< typename MultTrait<T1,T2>::Type, false > Type;
4837 };
4838 
4839 template< typename T1, size_t N, typename T2, bool SO >
4840 struct MultTrait< HybridVector<T1,N,true>, DynamicMatrix<T2,SO> >
4841 {
4842  typedef DynamicVector< typename MultTrait<T1,T2>::Type, true > Type;
4843 };
4844 
4845 template< typename T1, bool SO, typename T2 >
4846 struct MultTrait< DynamicMatrix<T1,SO>, DynamicVector<T2,false> >
4847 {
4848  typedef DynamicVector< typename MultTrait<T1,T2>::Type, false > Type;
4849 };
4850 
4851 template< typename T1, typename T2, bool SO >
4852 struct MultTrait< DynamicVector<T1,true>, DynamicMatrix<T2,SO> >
4853 {
4854  typedef DynamicVector< typename MultTrait<T1,T2>::Type, true > Type;
4855 };
4856 
4857 template< typename T1, bool SO, typename T2 >
4858 struct MultTrait< DynamicMatrix<T1,SO>, CompressedVector<T2,false> >
4859 {
4860  typedef DynamicVector< typename MultTrait<T1,T2>::Type, false > Type;
4861 };
4862 
4863 template< typename T1, typename T2, bool SO >
4864 struct MultTrait< CompressedVector<T1,true>, DynamicMatrix<T2,SO> >
4865 {
4866  typedef DynamicVector< typename MultTrait<T1,T2>::Type, true > Type;
4867 };
4868 
4869 template< typename T1, bool SO1, typename T2, size_t M, size_t N, bool SO2 >
4870 struct MultTrait< DynamicMatrix<T1,SO1>, StaticMatrix<T2,M,N,SO2> >
4871 {
4872  typedef DynamicMatrix< typename MultTrait<T1,T2>::Type, SO1 > Type;
4873 };
4874 
4875 template< typename T1, size_t M, size_t N, bool SO1, typename T2, bool SO2 >
4876 struct MultTrait< StaticMatrix<T1,M,N,SO1>, DynamicMatrix<T2,SO2> >
4877 {
4878  typedef DynamicMatrix< typename MultTrait<T1,T2>::Type, SO1 > Type;
4879 };
4880 
4881 template< typename T1, bool SO1, typename T2, bool SO2 >
4882 struct MultTrait< DynamicMatrix<T1,SO1>, DynamicMatrix<T2,SO2> >
4883 {
4884  typedef DynamicMatrix< typename MultTrait<T1,T2>::Type, SO1 > Type;
4885 };
4887 //*************************************************************************************************
4888 
4889 
4890 
4891 
4892 //=================================================================================================
4893 //
4894 // DIVTRAIT SPECIALIZATIONS
4895 //
4896 //=================================================================================================
4897 
4898 //*************************************************************************************************
4900 template< typename T1, bool SO, typename T2 >
4901 struct DivTrait< DynamicMatrix<T1,SO>, T2 >
4902 {
4903  typedef DynamicMatrix< typename DivTrait<T1,T2>::Type , SO > Type;
4905 };
4907 //*************************************************************************************************
4908 
4909 
4910 
4911 
4912 //=================================================================================================
4913 //
4914 // MATHTRAIT SPECIALIZATIONS
4915 //
4916 //=================================================================================================
4917 
4918 //*************************************************************************************************
4920 template< typename T1, bool SO, typename T2 >
4921 struct MathTrait< DynamicMatrix<T1,SO>, DynamicMatrix<T2,SO> >
4922 {
4923  typedef DynamicMatrix< typename MathTrait<T1,T2>::HighType, SO > HighType;
4924  typedef DynamicMatrix< typename MathTrait<T1,T2>::LowType , SO > LowType;
4925 };
4927 //*************************************************************************************************
4928 
4929 
4930 
4931 
4932 //=================================================================================================
4933 //
4934 // SUBMATRIXTRAIT SPECIALIZATIONS
4935 //
4936 //=================================================================================================
4937 
4938 //*************************************************************************************************
4940 template< typename T1, bool SO >
4941 struct SubmatrixTrait< DynamicMatrix<T1,SO> >
4942 {
4943  typedef DynamicMatrix<T1,SO> Type;
4944 };
4946 //*************************************************************************************************
4947 
4948 
4949 
4950 
4951 //=================================================================================================
4952 //
4953 // ROWTRAIT SPECIALIZATIONS
4954 //
4955 //=================================================================================================
4956 
4957 //*************************************************************************************************
4959 template< typename T1, bool SO >
4960 struct RowTrait< DynamicMatrix<T1,SO> >
4961 {
4962  typedef DynamicVector<T1,true> Type;
4963 };
4965 //*************************************************************************************************
4966 
4967 
4968 
4969 
4970 //=================================================================================================
4971 //
4972 // COLUMNTRAIT SPECIALIZATIONS
4973 //
4974 //=================================================================================================
4975 
4976 //*************************************************************************************************
4978 template< typename T1, bool SO >
4979 struct ColumnTrait< DynamicMatrix<T1,SO> >
4980 {
4981  typedef DynamicVector<T1,false> Type;
4982 };
4984 //*************************************************************************************************
4985 
4986 } // namespace blaze
4987 
4988 #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:698
size_t n_
The current number of columns of the matrix.
Definition: DynamicMatrix.h:405
Compile time check for numeric types.This type trait tests whether or not the given template paramete...
Definition: IsNumeric.h:98
Constraint on the data type.
Header file for mathematical functions.
void reserve(size_t elements)
Setting the minimum capacity of the matrix.
Definition: DynamicMatrix.h:1486
void reset(DynamicMatrix< Type, SO > &m)
Resetting the given dense matrix.
Definition: DynamicMatrix.h:4579
#define BLAZE_USER_ASSERT(expr, msg)
Run time assertion macro for user checks.In case of an invalid run time expression, the program execution is terminated. The BLAZE_USER_ASSERT macro can be disabled by setting the BLAZE_USER_ASSERT flag to zero or by defining NDEBUG during the compilation.
Definition: Assert.h:117
EnableIf< IsIntegral< T >, Load< T, sizeof(T)> >::Type::Type load(const T *address)
Loads a vector of integral values.
Definition: Load.h:222
Header file for the UNUSED_PARAMETER function template.
const size_t OPENMP_DMATASSIGN_THRESHOLD
OpenMP dense matrix assignment threshold.This threshold specifies when an assignment with a plain den...
Definition: Thresholds.h:536
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:856
Header file for the row trait.
Type *BLAZE_RESTRICT v_
The dynamically allocated matrix elements.
Definition: DynamicMatrix.h:408
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:151
const DMatTransExpr< MT,!SO > trans(const DenseMatrix< MT, SO > &dm)
Calculation of the transpose of the given dense matrix.
Definition: DMatTransExpr.h:751
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:4622
Efficient implementation of a compressed matrix.The CompressedMatrix class template is the represent...
Definition: CompressedMatrix.h:197
void resize(size_t m, size_t n, bool preserve=true)
Changing the size of the matrix.
Definition: DynamicMatrix.h:1410
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:1210
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:1787
Header file for the sparse matrix SMP implementation.
size_t m_
The current number of rows of the sparse matrix.
Definition: CompressedMatrix.h:2528
void storeu(float *address, const sse_float_t &value)
Unaligned store of a vector of &#39;float&#39; values.
Definition: Storeu.h:234
Header file for a safe C++ NULL pointer implementation.
void UNUSED_PARAMETER(const T1 &)
Suppression of unused parameter warnings.
Definition: Unused.h:84
#define BLAZE_CONSTRAINT_MUST_NOT_BE_VOLATILE(T)
Constraint on the data type.In case the given data type is a volatile-qualified type, a compilation error is created.
Definition: Volatile.h:116
DynamicMatrix()
The default constructor for DynamicMatrix.
Definition: DynamicMatrix.h:446
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:1229
Efficient implementation of a dynamic matrix.The DynamicMatrix class template is the representation ...
Definition: DynamicMatrix.h:179
void clear(DynamicMatrix< Type, SO > &m)
Clearing the given dense matrix.
Definition: DynamicMatrix.h:4595
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:195
Base class for sparse matrices.The SparseMatrix class is a base class for all sparse matrix classes...
Definition: Forward.h:104
Constraint on the data type.
size_t capacity_
The current capacity of the pointer array.
Definition: CompressedMatrix.h:2530
~DynamicMatrix()
The destructor for DynamicMatrix.
Definition: DynamicMatrix.h:673
This ResultType
Result type for expression template evaluations.
Definition: DynamicMatrix.h:189
Header file for the SparseMatrix base class.
void deallocate(T *address)
Deallocation of memory.
Definition: Memory.h:114
size_t nonZeros() const
Returns the total number of non-zero elements in the matrix.
Definition: DynamicMatrix.h:1279
size_t adjustColumns(size_t minColumns) const
Adjusting the number columns of the matrix according to its data type Type.
Definition: DynamicMatrix.h:1574
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:121
void stream(float *address, const sse_float_t &value)
Aligned, non-temporal store of a vector of &#39;float&#39; values.
Definition: Stream.h:233
Header file for the DisableIf class template.
ConstIterator cend(size_t i) const
Returns an iterator just past the last element of row/column i.
Definition: DynamicMatrix.h:922
Header file for the multiplication trait.
bool isAligned() const
Returns whether the matrix is properly aligned in memory.
Definition: DynamicMatrix.h:1642
IntrinsicType loadu(size_t i, size_t j) const
Unaligned load of an intrinsic element of the matrix.
Definition: DynamicMatrix.h:1720
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:4558
Type ElementType
Type of the matrix elements.
Definition: DynamicMatrix.h:192
Header file for all forward declarations of the math module.
const Element * ConstIterator
Iterator over constant elements.
Definition: CompressedMatrix.h:2388
#define BLAZE_CONSTRAINT_MUST_NOT_BE_POINTER_TYPE(T)
Constraint on the data type.In case the given data type T is not a pointer type, a compilation error ...
Definition: Pointer.h:116
IntrinsicTrait< Type > IT
Intrinsic trait for the matrix element type.
Definition: DynamicMatrix.h:183
Header file for the dense matrix SMP implementation.
DynamicMatrix< Type, SO > This
Type of this DynamicMatrix instance.
Definition: DynamicMatrix.h:188
Header file for the DenseMatrix base class.
Header file for the DenseIterator class template.
const Type & ReturnType
Return type for expression template evaluations.
Definition: DynamicMatrix.h:194
void assign(Matrix< MT1, SO1 > &lhs, const Matrix< MT2, SO2 > &rhs)
Default implementation of the assignment of a matrix to a matrix.
Definition: Matrix.h:179
Constraint on the data type.
void extend(size_t m, size_t n, bool preserve=true)
Extending the size of the matrix.
Definition: DynamicMatrix.h:1468
size_t rows() const
Returns the current number of rows of the matrix.
Definition: DynamicMatrix.h:1196
#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:1324
Iterator end(size_t i)
Returns an iterator just past the last element of row/column i.
Definition: DynamicMatrix.h:878
const Type & ConstReference
Reference to a constant matrix value.
Definition: CompressedMatrix.h:2386
System settings for streaming (non-temporal stores)
Header file for the EnableIf class template.
DynamicMatrix< Type,!SO > OppositeType
Result type with opposite storage order for expression template evaluations.
Definition: DynamicMatrix.h:190
size_t capacity() const
Returns the maximum capacity of the matrix.
Definition: DynamicMatrix.h:1243
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:91
Header file for the IsNumeric type trait.
size_t nn_
The alignment adjusted number of columns.
Definition: DynamicMatrix.h:406
void store(size_t i, size_t j, const IntrinsicType &value)
Aligned store of an intrinsic element of the matrix.
Definition: DynamicMatrix.h:1753
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:1368
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:4651
void addAssign(Matrix< MT1, SO1 > &lhs, const Matrix< MT2, SO2 > &rhs)
Default implementation of the addition assignment of a matrix to a matrix.
Definition: Matrix.h:209
Header file for the submatrix trait.
Type * data()
Low-level data access to the matrix elements.
Definition: DynamicMatrix.h:737
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:404
Iterator begin(size_t i)
Returns an iterator to the first element of row/column i.
Definition: DynamicMatrix.h:812
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:1624
Header file for the cache size of the target architecture.
void subAssign(Matrix< MT1, SO1 > &lhs, const Matrix< MT2, SO2 > &rhs)
Default implementation of the subtraction assignment of a matrix to matrix.
Definition: Matrix.h:239
#define BLAZE_CONSTRAINT_MUST_NOT_BE_REFERENCE_TYPE(T)
Constraint on the data type.In case the given data type T is not a reference type, a compilation error is created.
Definition: Reference.h:116
Element * Iterator
Iterator over non-constant elements.
Definition: CompressedMatrix.h:2387
Header file for the column trait.
Header file for the isDefault shim.
System settings for the restrict keyword.
Base class for matrices.The Matrix class is a base class for all dense and sparse matrix classes with...
Definition: Forward.h:85
Constraint on the data type.
void swap(DynamicMatrix &m)
Swapping the contents of two matrices.
Definition: DynamicMatrix.h:1555
IntrinsicType load(size_t i, size_t j) const
Aligned load of an intrinsic element of the matrix.
Definition: DynamicMatrix.h:1686
T * allocate(size_t size)
Aligned array allocation.
Definition: Memory.h:83
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:196
bool canSMPAssign() const
Returns whether the matrix can be used in SMP assignments.
Definition: DynamicMatrix.h:1661
size_t n_
The current number of columns of the sparse matrix.
Definition: CompressedMatrix.h:2529
DenseIterator< const Type > ConstIterator
Iterator over constant elements.
Definition: DynamicMatrix.h:199
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:193
size_t capacity_
The maximum capacity of the matrix.
Definition: DynamicMatrix.h:407
This ResultType
Result type for expression template evaluations.
Definition: CompressedMatrix.h:2379
size_t columns(const Matrix< MT, SO > &m)
Returns the current number of columns of the matrix.
Definition: Matrix.h:154
Header file for basic type definitions.
Compile time check for sparse matrix types.This type trait tests whether or not the given template pa...
Definition: IsSparseMatrix.h:103
DenseIterator< Type > Iterator
Iterator over non-constant elements.
Definition: DynamicMatrix.h:198
MatrixAccessProxy< This > Reference
Reference to a non-constant matrix value.
Definition: CompressedMatrix.h:2385
const VT::ElementType min(const SparseVector< VT, TF > &sv)
Returns the smallest element of the sparse vector.
Definition: SparseVector.h:348
boost::true_type TrueType
Type traits base class.The TrueType class is used as base class for type traits and value traits that...
Definition: TrueType.h:61
const size_t cacheSize
Cache size of the target architecture.This setting specifies the available cache size in Byte of the ...
Definition: CacheSize.h:48
Header file for the IsResizable type trait.
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:138
#define BLAZE_INTERNAL_ASSERT(expr, msg)
Run time assertion macro for internal checks.In case of an invalid run time expression, the program execution is terminated. The BLAZE_INTERNAL_ASSERT macro can be disabled by setting the BLAZE_USER_ASSERTION flag to zero or by defining NDEBUG during the compilation.
Definition: Assert.h:101
bool canAlias(const Other *alias) const
Returns whether the matrix can alias with the given address alias.
Definition: DynamicMatrix.h:1604
DynamicMatrix & transpose()
Transposing the matrix.
Definition: DynamicMatrix.h:1517
const Type & ConstReference
Reference to a constant matrix value.
Definition: DynamicMatrix.h:197
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:191
void store(float *address, const sse_float_t &value)
Aligned store of a vector of &#39;float&#39; values.
Definition: Store.h:242
void stream(size_t i, size_t j, const IntrinsicType &value)
Aligned, non-temporal store of an intrinsic element of the matrix.
Definition: DynamicMatrix.h:1820