All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DMatTransposer.h
Go to the documentation of this file.
1 //=================================================================================================
33 //=================================================================================================
34 
35 #ifndef _BLAZE_MATH_EXPRESSIONS_DMATTRANSPOSER_H_
36 #define _BLAZE_MATH_EXPRESSIONS_DMATTRANSPOSER_H_
37 
38 
39 //*************************************************************************************************
40 // Includes
41 //*************************************************************************************************
42 
49 #include <blaze/util/Assert.h>
50 #include <blaze/util/EnableIf.h>
51 #include <blaze/util/Types.h>
53 
54 
55 namespace blaze {
56 
57 //=================================================================================================
58 //
59 // CLASS DMATTRANSPOSER
60 //
61 //=================================================================================================
62 
63 //*************************************************************************************************
69 template< typename MT // Type of the dense matrix
70  , bool SO > // Storage order
71 class DMatTransposer : public DenseMatrix< DMatTransposer<MT,SO>, SO >
72 {
73  private:
74  //**Type definitions****************************************************************************
76  //**********************************************************************************************
77 
78  public:
79  //**Type definitions****************************************************************************
81  typedef typename MT::TransposeType ResultType;
82  typedef typename MT::OppositeType OppositeType;
83  typedef typename MT::ResultType TransposeType;
84  typedef typename MT::ElementType ElementType;
85  typedef typename IT::Type IntrinsicType;
86  typedef typename MT::ReturnType ReturnType;
87  typedef const This& CompositeType;
88  typedef typename MT::Reference Reference;
90  //**********************************************************************************************
91 
92  //**Compilation flags***************************************************************************
94 
97  enum { vectorizable = MT::vectorizable };
98  //**********************************************************************************************
99 
100  //**Constructor*********************************************************************************
105  explicit inline DMatTransposer( MT& dm )
106  : dm_( dm ) // The dense matrix operand
107  {}
108  //**********************************************************************************************
109 
110  //**Access operator*****************************************************************************
117  inline Reference operator()( size_t i, size_t j ) {
118  BLAZE_INTERNAL_ASSERT( i < dm_.columns(), "Invalid row access index" );
119  BLAZE_INTERNAL_ASSERT( j < dm_.rows() , "Invalid column access index" );
120  return dm_(j,i);
121  }
122  //**********************************************************************************************
123 
124  //**Low-level data access***********************************************************************
129  inline ElementType* data() {
130  return dm_.data();
131  }
132  //**********************************************************************************************
133 
134  //**Multiplication assignment operator**********************************************************
141  template< typename Other > // Data type of the right-hand side scalar
142  inline typename EnableIf< IsNumeric<Other>, DMatTransposer >::Type& operator*=( Other rhs )
143  {
144  (~dm_) *= rhs;
145  return *this;
146  }
147  //**********************************************************************************************
148 
149  //**Division assignment operator****************************************************************
158  template< typename Other > // Data type of the right-hand side scalar
159  inline typename EnableIf< IsNumeric<Other>, DMatTransposer >::Type& operator/=( Other rhs )
160  {
161  BLAZE_USER_ASSERT( rhs != Other(0), "Division by zero detected" );
162 
163  (~dm_) /= rhs;
164  return *this;
165  }
166  //**********************************************************************************************
167 
168  //**Rows function*******************************************************************************
173  inline size_t rows() const {
174  return dm_.columns();
175  }
176  //**********************************************************************************************
177 
178  //**Columns function****************************************************************************
183  inline size_t columns() const {
184  return dm_.rows();
185  }
186  //**********************************************************************************************
187 
188  //**Spacing function****************************************************************************
193  inline size_t spacing() const {
194  return dm_.spacing();
195  }
196  //**********************************************************************************************
197 
198  //**Reset function******************************************************************************
203  inline void reset() {
204  return dm_.reset();
205  }
206  //**********************************************************************************************
207 
208  //**CanAliased function*************************************************************************
214  template< typename Other > // Data type of the foreign expression
215  inline bool canAlias( const Other* alias ) const
216  {
217  return dm_.canAlias( alias );
218  }
219  //**********************************************************************************************
220 
221  //**IsAliased function**************************************************************************
227  template< typename Other > // Data type of the foreign expression
228  inline bool isAliased( const Other* alias ) const
229  {
230  return dm_.isAliased( alias );
231  }
232  //**********************************************************************************************
233 
234  //**Load function*******************************************************************************
245  inline IntrinsicType load( size_t i, size_t j ) const
246  {
247  return dm_.load( j, i );
248  }
249  //**********************************************************************************************
250 
251  //**Loadu function******************************************************************************
262  inline IntrinsicType loadu( size_t i, size_t j ) const
263  {
264  return dm_.loadu( j, i );
265  }
266  //**********************************************************************************************
267 
268  //**Store function******************************************************************************
280  inline void store( size_t i, size_t j, const IntrinsicType& value )
281  {
282  dm_.store( j, i, value );
283  }
284  //**********************************************************************************************
285 
286  //**Storeu function*****************************************************************************
298  inline void storeu( size_t i, size_t j, const IntrinsicType& value )
299  {
300  dm_.storeu( j, i, value );
301  }
302  //**********************************************************************************************
303 
304  //**Stream function*****************************************************************************
316  inline void stream( size_t i, size_t j, const IntrinsicType& value )
317  {
318  dm_.stream( j, i, value );
319  }
320  //**********************************************************************************************
321 
322  //**Transpose assignment of row-major dense matrices********************************************
333  template< typename MT2 > // Type of the right-hand side dense matrix
334  inline void assign( const DenseMatrix<MT2,SO>& rhs )
335  {
337 
338  BLAZE_INTERNAL_ASSERT( dm_.columns() == (~rhs).rows(), "Invalid number of rows" );
339  BLAZE_INTERNAL_ASSERT( dm_.rows() == (~rhs).columns(), "Invalid number of columns" );
340 
341  const size_t m( rows() );
342  const size_t n( columns() );
343 
344  BLAZE_INTERNAL_ASSERT( ( n - ( n % 2UL ) ) == ( n & size_t(-2) ), "Invalid end calculation" );
345  const size_t end( n & size_t(-2) );
346 
347  for( size_t i=0UL; i<m; ++i ) {
348  for( size_t j=0UL; j<end; j+=2UL ) {
349  dm_(j ,i) = (~rhs)(i,j );
350  dm_(j+1UL,i) = (~rhs)(i,j+1UL);
351  }
352  if( end < n ) {
353  dm_(end,i) = (~rhs)(i,end);
354  }
355  }
356  }
357  //**********************************************************************************************
358 
359  //**Transpose assignment of column-major dense matrices*****************************************
370  template< typename MT2 > // Type of the right-hand side dense matrix
371  inline void assign( const DenseMatrix<MT2,!SO>& rhs )
372  {
374 
375  BLAZE_INTERNAL_ASSERT( dm_.columns() == (~rhs).rows(), "Invalid number of rows" );
376  BLAZE_INTERNAL_ASSERT( dm_.rows() == (~rhs).columns(), "Invalid number of columns" );
377 
378  const size_t m( rows() );
379  const size_t n( columns() );
380  const size_t block( 16UL );
381 
382  for( size_t ii=0UL; ii<m; ii+=block ) {
383  const size_t iend( ( m < ii+block )?( m ):( ii+block ) );
384  for( size_t jj=0UL; jj<n; jj+=block ) {
385  const size_t jend( ( n < jj+block )?( n ):( jj+block ) );
386  for( size_t i=ii; i<iend; ++i ) {
387  for( size_t j=jj; j<jend; ++j ) {
388  dm_(j,i) = (~rhs)(i,j);
389  }
390  }
391  }
392  }
393  }
394  //**********************************************************************************************
395 
396  //**Transpose assignment of row-major sparse matrices*******************************************
407  template< typename MT2 > // Type of the right-hand side sparse matrix
408  inline void assign( const SparseMatrix<MT2,SO>& rhs )
409  {
411 
412  BLAZE_INTERNAL_ASSERT( dm_.columns() == (~rhs).rows(), "Invalid number of rows" );
413  BLAZE_INTERNAL_ASSERT( dm_.rows() == (~rhs).columns(), "Invalid number of columns" );
414 
415  typedef typename MT2::ConstIterator RhsConstIterator;
416 
417  for( size_t i=0UL; i<(~rhs).rows(); ++i )
418  for( RhsConstIterator element=(~rhs).begin(i); element!=(~rhs).end(i); ++element )
419  dm_(element->index(),i) = element->value();
420  }
421  //**********************************************************************************************
422 
423  //**Transpose assignment of column-major sparse matrices****************************************
434  template< typename MT2 > // Type of the right-hand side sparse matrix
435  inline void assign( const SparseMatrix<MT2,!SO>& rhs )
436  {
438 
439  BLAZE_INTERNAL_ASSERT( dm_.columns() == (~rhs).rows(), "Invalid number of rows" );
440  BLAZE_INTERNAL_ASSERT( dm_.rows() == (~rhs).columns(), "Invalid number of columns" );
441 
442  typedef typename MT2::ConstIterator RhsConstIterator;
443 
444  for( size_t j=0UL; j<(~rhs).columns(); ++j )
445  for( RhsConstIterator element=(~rhs).begin(j); element!=(~rhs).end(j); ++element )
446  dm_(j,element->index()) = element->value();
447  }
448  //**********************************************************************************************
449 
450  //**Transpose addition assignment of row-major dense matrices***********************************
461  template< typename MT2 > // Type of the right-hand side dense matrix
462  inline void addAssign( const DenseMatrix<MT2,SO>& rhs )
463  {
465 
466  BLAZE_INTERNAL_ASSERT( dm_.columns() == (~rhs).rows(), "Invalid number of rows" );
467  BLAZE_INTERNAL_ASSERT( dm_.rows() == (~rhs).columns(), "Invalid number of columns" );
468 
469  const size_t m( rows() );
470  const size_t n( columns() );
471 
472  BLAZE_INTERNAL_ASSERT( ( n - ( n % 2UL ) ) == ( n & size_t(-2) ), "Invalid end calculation" );
473  const size_t end( n & size_t(-2) );
474 
475  for( size_t i=0UL; i<m; ++i ) {
476  for( size_t j=0UL; j<end; j+=2UL ) {
477  dm_(j ,i) += (~rhs)(i,j );
478  dm_(j+1UL,i) += (~rhs)(i,j+1UL);
479 
480  }
481  if( end < n ) {
482  dm_(end,i) += (~rhs)(i,end);
483  }
484  }
485  }
486  //**********************************************************************************************
487 
488  //**Transpose addition assignment of column-major dense matrices********************************
499  template< typename MT2 > // Type of the right-hand side dense matrix
500  inline void addAssign( const DenseMatrix<MT2,!SO>& rhs )
501  {
503 
504  BLAZE_INTERNAL_ASSERT( dm_.columns() == (~rhs).rows(), "Invalid number of rows" );
505  BLAZE_INTERNAL_ASSERT( dm_.rows() == (~rhs).columns(), "Invalid number of columns" );
506 
507  const size_t m( rows() );
508  const size_t n( columns() );
509  const size_t block( 16UL );
510 
511  for( size_t ii=0UL; ii<m; ii+=block ) {
512  const size_t iend( ( m < ii+block )?( m ):( ii+block ) );
513  for( size_t jj=0UL; jj<n; jj+=block ) {
514  const size_t jend( ( n < jj+block )?( n ):( jj+block ) );
515  for( size_t i=ii; i<iend; ++i ) {
516  for( size_t j=jj; j<jend; ++j ) {
517  dm_(j,i) += (~rhs)(i,j);
518  }
519  }
520  }
521  }
522  }
523  //**********************************************************************************************
524 
525  //**Transpose addition assignment of row-major sparse matrices**********************************
536  template< typename MT2 > // Type of the right-hand side sparse matrix
537  inline void addAssign( const SparseMatrix<MT2,SO>& rhs )
538  {
540 
541  BLAZE_INTERNAL_ASSERT( dm_.columns() == (~rhs).rows(), "Invalid number of rows" );
542  BLAZE_INTERNAL_ASSERT( dm_.rows() == (~rhs).columns(), "Invalid number of columns" );
543 
544  typedef typename MT2::ConstIterator RhsConstIterator;
545 
546  for( size_t i=0UL; i<(~rhs).rows(); ++i )
547  for( RhsConstIterator element=(~rhs).begin(i); element!=(~rhs).end(i); ++element )
548  dm_(element->index(),i) += element->value();
549  }
550  //**********************************************************************************************
551 
552  //**Transpose addition assignment of column-major sparse matrices*******************************
563  template< typename MT2 > // Type of the right-hand side sparse matrix
564  inline void addAssign( const SparseMatrix<MT2,!SO>& rhs )
565  {
567 
568  BLAZE_INTERNAL_ASSERT( dm_.columns() == (~rhs).rows(), "Invalid number of rows" );
569  BLAZE_INTERNAL_ASSERT( dm_.rows() == (~rhs).columns(), "Invalid number of columns" );
570 
571  typedef typename MT2::ConstIterator RhsConstIterator;
572 
573  for( size_t j=0UL; j<(~rhs).columns(); ++j )
574  for( RhsConstIterator element=(~rhs).begin(j); element!=(~rhs).end(j); ++element )
575  dm_(j,element->index()) += element->value();
576  }
577  //**********************************************************************************************
578 
579  //**Transpose subtraction assignment of row-major dense matrices********************************
590  template< typename MT2 > // Type of the right-hand side dense matrix
591  inline void subAssign( const DenseMatrix<MT2,SO>& rhs )
592  {
594 
595  BLAZE_INTERNAL_ASSERT( dm_.columns() == (~rhs).rows(), "Invalid number of rows" );
596  BLAZE_INTERNAL_ASSERT( dm_.rows() == (~rhs).columns(), "Invalid number of columns" );
597 
598  const size_t m( rows() );
599  const size_t n( columns() );
600 
601  BLAZE_INTERNAL_ASSERT( ( n - ( n % 2UL ) ) == ( n & size_t(-2) ), "Invalid end calculation" );
602  const size_t end( n & size_t(-2) );
603 
604  for( size_t i=0UL; i<m; ++i ) {
605  for( size_t j=0UL; j<end; j+=2UL ) {
606  dm_(j ,i) -= (~rhs)(i,j );
607  dm_(j+1UL,i) -= (~rhs)(i,j+1UL);
608 
609  }
610  if( end < n ) {
611  dm_(end,i) -= (~rhs)(i,end);
612  }
613  }
614  }
615  //**********************************************************************************************
616 
617  //**Transpose subtraction assignment of column-major dense matrices*****************************
628  template< typename MT2 > // Type of the right-hand side dense matrix
629  inline void subAssign( const DenseMatrix<MT2,!SO>& rhs )
630  {
632 
633  BLAZE_INTERNAL_ASSERT( dm_.columns() == (~rhs).rows(), "Invalid number of rows" );
634  BLAZE_INTERNAL_ASSERT( dm_.rows() == (~rhs).columns(), "Invalid number of columns" );
635 
636  const size_t m( rows() );
637  const size_t n( columns() );
638  const size_t block( 16UL );
639 
640  for( size_t ii=0UL; ii<m; ii+=block ) {
641  const size_t iend( ( m < ii+block )?( m ):( ii+block ) );
642  for( size_t jj=0UL; jj<n; jj+=block ) {
643  const size_t jend( ( n < jj+block )?( n ):( jj+block ) );
644  for( size_t i=ii; i<iend; ++i ) {
645  for( size_t j=jj; j<jend; ++j ) {
646  dm_(j,i) -= (~rhs)(i,j);
647  }
648  }
649  }
650  }
651  }
652  //**********************************************************************************************
653 
654  //**Transpose subtraction assignment of row-major sparse matrices*******************************
665  template< typename MT2 > // Type of the right-hand side sparse matrix
666  inline void subAssign( const SparseMatrix<MT2,SO>& rhs )
667  {
669 
670  BLAZE_INTERNAL_ASSERT( dm_.columns() == (~rhs).rows(), "Invalid number of rows" );
671  BLAZE_INTERNAL_ASSERT( dm_.rows() == (~rhs).columns(), "Invalid number of columns" );
672 
673  typedef typename MT2::ConstIterator RhsConstIterator;
674 
675  for( size_t i=0UL; i<(~rhs).rows(); ++i )
676  for( RhsConstIterator element=(~rhs).begin(i); element!=(~rhs).end(i); ++element )
677  dm_(element->index(),i) -= element->value();
678  }
679  //**********************************************************************************************
680 
681  //**Transpose subtraction assignment of column-major dense matrices*****************************
692  template< typename MT2 > // Type of the right-hand side sparse matrix
693  inline void subAssign( const SparseMatrix<MT2,!SO>& rhs )
694  {
696 
697  BLAZE_INTERNAL_ASSERT( dm_.columns() == (~rhs).rows(), "Invalid number of rows" );
698  BLAZE_INTERNAL_ASSERT( dm_.rows() == (~rhs).columns(), "Invalid number of columns" );
699 
700  typedef typename MT2::ConstIterator RhsConstIterator;
701 
702  for( size_t j=0UL; j<(~rhs).columns(); ++j )
703  for( RhsConstIterator element=(~rhs).begin(j); element!=(~rhs).end(j); ++element )
704  dm_(j,element->index()) -= element->value();
705  }
706  //**********************************************************************************************
707 
708  private:
709  //**Member variables****************************************************************************
710  MT& dm_;
711  //**********************************************************************************************
712 
713  //**Compile time checks*************************************************************************
719  //**********************************************************************************************
720 };
721 //*************************************************************************************************
722 
723 
724 
725 
726 //=================================================================================================
727 //
728 // CLASS TEMPLATE SPECIALIZATION FOR ROW-MAJOR MATRICES
729 //
730 //=================================================================================================
731 
732 //*************************************************************************************************
740 template< typename MT > // Type of the dense matrix
741 class DMatTransposer<MT,true> : public DenseMatrix< DMatTransposer<MT,true>, true >
742 {
743  private:
744  //**Type definitions****************************************************************************
746  //**********************************************************************************************
747 
748  public:
749  //**Type definitions****************************************************************************
750  typedef DMatTransposer<MT,true> This;
751  typedef typename MT::TransposeType ResultType;
752  typedef typename MT::OppositeType OppositeType;
753  typedef typename MT::ResultType TransposeType;
754  typedef typename MT::ElementType ElementType;
755  typedef typename IT::Type IntrinsicType;
756  typedef typename MT::ReturnType ReturnType;
757  typedef const This& CompositeType;
758  typedef typename MT::Reference Reference;
759  typedef typename MT::ConstReference ConstReference;
760  //**********************************************************************************************
761 
762  //**Compilation flags***************************************************************************
764 
767  enum { vectorizable = MT::vectorizable };
768  //**********************************************************************************************
769 
770  //**Constructor*********************************************************************************
775  explicit inline DMatTransposer( MT& dm )
776  : dm_( dm ) // The dense matrix operand
777  {}
778  //**********************************************************************************************
779 
780  //**Access operator*****************************************************************************
787  inline Reference operator()( size_t i, size_t j ) {
788  BLAZE_INTERNAL_ASSERT( i < dm_.columns(), "Invalid row access index" );
789  BLAZE_INTERNAL_ASSERT( j < dm_.rows() , "Invalid column access index" );
790  return dm_(j,i);
791  }
792  //**********************************************************************************************
793 
794  //**Low-level data access***********************************************************************
799  inline ElementType* data() {
800  return dm_.data();
801  }
802  //**********************************************************************************************
803 
804  //**Rows function*******************************************************************************
809  inline size_t rows() const {
810  return dm_.columns();
811  }
812  //**********************************************************************************************
813 
814  //**Columns function****************************************************************************
819  inline size_t columns() const {
820  return dm_.rows();
821  }
822  //**********************************************************************************************
823 
824  //**Spacing function****************************************************************************
829  inline size_t spacing() const {
830  return dm_.spacing();
831  }
832  //**********************************************************************************************
833 
834  //**Reset function******************************************************************************
839  inline void reset() {
840  return dm_.reset();
841  }
842  //**********************************************************************************************
843 
844  //**CanAliased function*************************************************************************
850  template< typename Other > // Data type of the foreign expression
851  inline bool canAlias( const Other* alias ) const
852  {
853  return dm_.canAlias( alias );
854  }
855  //**********************************************************************************************
856 
857  //**IsAliased function**************************************************************************
863  template< typename Other > // Data type of the foreign expression
864  inline bool isAliased( const Other* alias ) const
865  {
866  return dm_.isAliased( alias );
867  }
868  //**********************************************************************************************
869 
870  //**Load function*******************************************************************************
881  inline IntrinsicType load( size_t i, size_t j ) const
882  {
883  return dm_.load( j, i );
884  }
885  //**********************************************************************************************
886 
887  //**Loadu function******************************************************************************
898  inline IntrinsicType loadu( size_t i, size_t j ) const
899  {
900  return dm_.loadu( j, i );
901  }
902  //**********************************************************************************************
903 
904  //**Store function******************************************************************************
916  inline void store( size_t i, size_t j, const IntrinsicType& value )
917  {
918  dm_.store( j, i, value );
919  }
920  //**********************************************************************************************
921 
922  //**Storeu function*****************************************************************************
934  inline void storeu( size_t i, size_t j, const IntrinsicType& value )
935  {
936  dm_.storeu( j, i, value );
937  }
938  //**********************************************************************************************
939 
940  //**Stream function*****************************************************************************
952  inline void stream( size_t i, size_t j, const IntrinsicType& value )
953  {
954  dm_.stream( j, i, value );
955  }
956  //**********************************************************************************************
957 
958  //**Transpose assignment of column-major dense matrices*****************************************
969  template< typename MT2 > // Type of the right-hand side dense matrix
970  inline void assign( const DenseMatrix<MT2,true>& rhs )
971  {
973 
974  BLAZE_INTERNAL_ASSERT( dm_.columns() == (~rhs).rows(), "Invalid number of rows" );
975  BLAZE_INTERNAL_ASSERT( dm_.rows() == (~rhs).columns(), "Invalid number of columns" );
976 
977  const size_t m( rows() );
978  const size_t n( columns() );
979 
980  BLAZE_INTERNAL_ASSERT( ( m - ( m % 2UL ) ) == ( m & size_t(-2) ), "Invalid end calculation" );
981  const size_t end( m & size_t(-2) );
982 
983  for( size_t j=0UL; j<n; ++j ) {
984  for( size_t i=0UL; i<end; i+=2UL ) {
985  dm_(j,i ) = (~rhs)(i ,j);
986  dm_(j,i+1UL) = (~rhs)(i+1UL,j);
987  }
988  if( end < m ) {
989  dm_(j,end) = (~rhs)(end,j);
990  }
991  }
992  }
993  //**********************************************************************************************
994 
995  //**Transpose assignment of row-major dense matrices********************************************
1006  template< typename MT2 > // Type of the right-hand side dense matrix
1007  inline void assign( const DenseMatrix<MT2,false>& rhs )
1008  {
1010 
1011  BLAZE_INTERNAL_ASSERT( dm_.columns() == (~rhs).rows(), "Invalid number of rows" );
1012  BLAZE_INTERNAL_ASSERT( dm_.rows() == (~rhs).columns(), "Invalid number of columns" );
1013 
1014  const size_t m( rows() );
1015  const size_t n( columns() );
1016  const size_t block( 16UL );
1017 
1018  for( size_t jj=0UL; jj<n; jj+=block ) {
1019  const size_t jend( ( n < jj+block )?( n ):( jj+block ) );
1020  for( size_t ii=0UL; ii<m; ii+=block ) {
1021  const size_t iend( ( m < ii+block )?( m ):( ii+block ) );
1022  for( size_t j=jj; j<jend; ++j ) {
1023  for( size_t i=ii; i<iend; ++i ) {
1024  dm_(j,i) = (~rhs)(i,j);
1025  }
1026  }
1027  }
1028  }
1029  }
1030  //**********************************************************************************************
1031 
1032  //**Transpose assignment of column-major sparse matrices****************************************
1043  template< typename MT2 > // Type of the right-hand side sparse matrix
1044  inline void assign( const SparseMatrix<MT2,true>& rhs )
1045  {
1047 
1048  BLAZE_INTERNAL_ASSERT( dm_.columns() == (~rhs).rows(), "Invalid number of rows" );
1049  BLAZE_INTERNAL_ASSERT( dm_.rows() == (~rhs).columns(), "Invalid number of columns" );
1050 
1051  typedef typename MT2::ConstIterator RhsConstIterator;
1052 
1053  for( size_t j=0UL; j<(~rhs).columns(); ++j )
1054  for( RhsConstIterator element=(~rhs).begin(j); element!=(~rhs).end(j); ++element )
1055  dm_(j,element->index()) = element->value();
1056  }
1057  //**********************************************************************************************
1058 
1059  //**Transpose assignment of row-major sparse matrices*******************************************
1070  template< typename MT2 > // Type of the right-hand side sparse matrix
1071  inline void assign( const SparseMatrix<MT2,false>& rhs )
1072  {
1074 
1075  BLAZE_INTERNAL_ASSERT( dm_.columns() == (~rhs).rows(), "Invalid number of rows" );
1076  BLAZE_INTERNAL_ASSERT( dm_.rows() == (~rhs).columns(), "Invalid number of columns" );
1077 
1078  typedef typename MT2::ConstIterator RhsConstIterator;
1079 
1080  for( size_t i=0UL; i<(~rhs).rows(); ++i )
1081  for( RhsConstIterator element=(~rhs).begin(i); element!=(~rhs).end(i); ++element )
1082  dm_(element->index(),i) = element->value();
1083  }
1084  //**********************************************************************************************
1085 
1086  //**Transpose addition assignment of column-major dense matrices********************************
1097  template< typename MT2 > // Type of the right-hand side dense matrix
1098  inline void addAssign( const DenseMatrix<MT2,true>& rhs )
1099  {
1101 
1102  BLAZE_INTERNAL_ASSERT( dm_.columns() == (~rhs).rows(), "Invalid number of rows" );
1103  BLAZE_INTERNAL_ASSERT( dm_.rows() == (~rhs).columns(), "Invalid number of columns" );
1104 
1105  const size_t m( rows() );
1106  const size_t n( columns() );
1107 
1108  BLAZE_INTERNAL_ASSERT( ( m - ( m % 2UL ) ) == ( m & size_t(-2) ), "Invalid end calculation" );
1109  const size_t end( m & size_t(-2) );
1110 
1111  for( size_t j=0UL; j<n; ++j ) {
1112  for( size_t i=0UL; i<end; i+=2UL ) {
1113  dm_(j,i ) += (~rhs)(i ,j);
1114  dm_(j,i+1UL) += (~rhs)(i+1UL,j);
1115  }
1116  if( end < m ) {
1117  dm_(j,end) += (~rhs)(end,j);
1118  }
1119  }
1120  }
1121  //**********************************************************************************************
1122 
1123  //**Transpose addition assignment of row-major dense matrices***********************************
1134  template< typename MT2 > // Type of the right-hand side dense matrix
1135  inline void addAssign( const DenseMatrix<MT2,false>& rhs )
1136  {
1138 
1139  BLAZE_INTERNAL_ASSERT( dm_.columns() == (~rhs).rows(), "Invalid number of rows" );
1140  BLAZE_INTERNAL_ASSERT( dm_.rows() == (~rhs).columns(), "Invalid number of columns" );
1141 
1142  const size_t m( rows() );
1143  const size_t n( columns() );
1144  const size_t block( 16UL );
1145 
1146  for( size_t jj=0UL; jj<n; jj+=block ) {
1147  const size_t jend( ( n < jj+block )?( n ):( jj+block ) );
1148  for( size_t ii=0UL; ii<m; ii+=block ) {
1149  const size_t iend( ( m < ii+block )?( m ):( ii+block ) );
1150  for( size_t j=jj; j<jend; ++j ) {
1151  for( size_t i=ii; i<iend; ++i ) {
1152  dm_(j,i) += (~rhs)(i,j);
1153  }
1154  }
1155  }
1156  }
1157  }
1158  //**********************************************************************************************
1159 
1160  //**Transpose addition assignment of column-major sparse matrices*******************************
1171  template< typename MT2 > // Type of the right-hand side sparse matrix
1172  inline void addAssign( const SparseMatrix<MT2,true>& rhs )
1173  {
1175 
1176  BLAZE_INTERNAL_ASSERT( dm_.columns() == (~rhs).rows(), "Invalid number of rows" );
1177  BLAZE_INTERNAL_ASSERT( dm_.rows() == (~rhs).columns(), "Invalid number of columns" );
1178 
1179  typedef typename MT2::ConstIterator RhsConstIterator;
1180 
1181  for( size_t j=0UL; j<(~rhs).columns(); ++j )
1182  for( RhsConstIterator element=(~rhs).begin(j); element!=(~rhs).end(j); ++element )
1183  dm_(j,element->index()) += element->value();
1184  }
1185  //**********************************************************************************************
1186 
1187  //**Transpose addition assignment of row-major sparse matrices**********************************
1198  template< typename MT2 > // Type of the right-hand side sparse matrix
1199  inline void addAssign( const SparseMatrix<MT2,false>& rhs )
1200  {
1202 
1203  BLAZE_INTERNAL_ASSERT( dm_.columns() == (~rhs).rows(), "Invalid number of rows" );
1204  BLAZE_INTERNAL_ASSERT( dm_.rows() == (~rhs).columns(), "Invalid number of columns" );
1205 
1206  typedef typename MT2::ConstIterator RhsConstIterator;
1207 
1208  for( size_t i=0UL; i<(~rhs).rows(); ++i )
1209  for( RhsConstIterator element=(~rhs).begin(i); element!=(~rhs).end(i); ++element )
1210  dm_(element->index(),i) += element->value();
1211  }
1212  //**********************************************************************************************
1213 
1214  //**Transpose subtraction assignment of column-major dense matrices*****************************
1225  template< typename MT2 > // Type of the right-hand side dense matrix
1226  inline void subAssign( const DenseMatrix<MT2,true>& rhs )
1227  {
1229 
1230  BLAZE_INTERNAL_ASSERT( dm_.columns() == (~rhs).rows(), "Invalid number of rows" );
1231  BLAZE_INTERNAL_ASSERT( dm_.rows() == (~rhs).columns(), "Invalid number of columns" );
1232 
1233  const size_t m( rows() );
1234  const size_t n( columns() );
1235 
1236  BLAZE_INTERNAL_ASSERT( ( m - ( m % 2UL ) ) == ( m & size_t(-2) ), "Invalid end calculation" );
1237  const size_t end( m & size_t(-2) );
1238 
1239  for( size_t j=0UL; j<n; ++j ) {
1240  for( size_t i=0UL; i<end; i+=2UL ) {
1241  dm_(j,i ) -= (~rhs)(i ,j);
1242  dm_(j,i+1UL) -= (~rhs)(i+1UL,j);
1243  }
1244  if( end < m ) {
1245  dm_(j,end) -= (~rhs)(end,j);
1246  }
1247  }
1248  }
1249  //**********************************************************************************************
1250 
1251  //**Transpose subtraction assignment of row-major dense matrices********************************
1262  template< typename MT2 > // Type of the right-hand side dense matrix
1263  inline void subAssign( const DenseMatrix<MT2,false>& rhs )
1264  {
1266 
1267  BLAZE_INTERNAL_ASSERT( dm_.columns() == (~rhs).rows(), "Invalid number of rows" );
1268  BLAZE_INTERNAL_ASSERT( dm_.rows() == (~rhs).columns(), "Invalid number of columns" );
1269 
1270  const size_t m( rows() );
1271  const size_t n( columns() );
1272  const size_t block( 16UL );
1273 
1274  for( size_t jj=0UL; jj<n; jj+=block ) {
1275  const size_t jend( ( n < jj+block )?( n ):( jj+block ) );
1276  for( size_t ii=0UL; ii<m; ii+=block ) {
1277  const size_t iend( ( m < ii+block )?( m ):( ii+block ) );
1278  for( size_t j=jj; j<jend; ++j ) {
1279  for( size_t i=ii; i<iend; ++i ) {
1280  dm_(j,i) -= (~rhs)(i,j);
1281  }
1282  }
1283  }
1284  }
1285  }
1286  //**********************************************************************************************
1287 
1288  //**Transpose subtraction assignment of column-major sparse matrices****************************
1299  template< typename MT2 > // Type of the right-hand side sparse matrix
1300  inline void subAssign( const SparseMatrix<MT2,true>& rhs )
1301  {
1303 
1304  BLAZE_INTERNAL_ASSERT( dm_.columns() == (~rhs).rows(), "Invalid number of rows" );
1305  BLAZE_INTERNAL_ASSERT( dm_.rows() == (~rhs).columns(), "Invalid number of columns" );
1306 
1307  typedef typename MT2::ConstIterator RhsConstIterator;
1308 
1309  for( size_t j=0UL; j<(~rhs).columns(); ++j )
1310  for( RhsConstIterator element=(~rhs).begin(j); element!=(~rhs).end(j); ++element )
1311  dm_(j,element->index()) -= element->value();
1312  }
1313  //**********************************************************************************************
1314 
1315  //**Transpose subtraction assignment of row-major dense matrices********************************
1326  template< typename MT2 > // Type of the right-hand side sparse matrix
1327  inline void subAssign( const SparseMatrix<MT2,false>& rhs )
1328  {
1330 
1331  BLAZE_INTERNAL_ASSERT( dm_.columns() == (~rhs).rows(), "Invalid number of rows" );
1332  BLAZE_INTERNAL_ASSERT( dm_.rows() == (~rhs).columns(), "Invalid number of columns" );
1333 
1334  typedef typename MT2::ConstIterator RhsConstIterator;
1335 
1336  for( size_t i=0UL; i<(~rhs).rows(); ++i )
1337  for( RhsConstIterator element=(~rhs).begin(i); element!=(~rhs).end(i); ++element )
1338  dm_(element->index(),i) -= element->value();
1339  }
1340  //**********************************************************************************************
1341 
1342  //**Transpose multiplication assignment of dense matrices***************************************
1343  // No special implementation for the transpose multiplication assignment of dense matrices.
1344  //**********************************************************************************************
1345 
1346  //**Transpose multiplication assignment of sparse matrices**************************************
1347  // No special implementation for the transpose multiplication assignment of sparse matrices.
1348  //**********************************************************************************************
1349 
1350  private:
1351  //**Member variables****************************************************************************
1352  MT& dm_;
1353  //**********************************************************************************************
1354 
1355  //**Compile time checks*************************************************************************
1361  //**********************************************************************************************
1362 };
1364 //*************************************************************************************************
1365 
1366 
1367 
1368 
1369 //=================================================================================================
1370 //
1371 // GLOBAL OPERATORS
1372 //
1373 //=================================================================================================
1374 
1375 //*************************************************************************************************
1383 template< typename MT // Type of the dense matrix
1384  , bool SO > // Storage order
1385 inline void reset( DMatTransposer<MT,SO>& m )
1386 {
1387  m.reset();
1388 }
1390 //*************************************************************************************************
1391 
1392 
1393 
1394 
1395 //=================================================================================================
1396 //
1397 // SUBMATRIXTRAIT SPECIALIZATIONS
1398 //
1399 //=================================================================================================
1400 
1401 //*************************************************************************************************
1403 template< typename MT, bool SO >
1404 struct SubmatrixTrait< DMatTransposer<MT,SO> >
1405 {
1406  typedef typename SubmatrixTrait< typename DMatTransposer<MT,SO>::ResultType >::Type Type;
1407 };
1409 //*************************************************************************************************
1410 
1411 } // namespace blaze
1412 
1413 #endif
void addAssign(const SparseMatrix< MT2, SO > &rhs)
Implementation of the transpose addition assignment of a row-major sparse matrix. ...
Definition: DMatTransposer.h:537
void reset(DynamicMatrix< Type, SO > &m)
Resetting the given dense matrix.
Definition: DynamicMatrix.h:4512
#define BLAZE_USER_ASSERT(expr, msg)
Run time assertion macro for user checks.In case of an invalid run time expression, the program execution is terminated. The BLAZE_USER_ASSERT macro can be disabled by setting the BLAZE_USER_ASSERT flag to zero or by defining NDEBUG during the compilation.
Definition: Assert.h:117
DMatTransposer< MT, SO > This
Type of this DMatTransposer instance.
Definition: DMatTransposer.h:80
Efficient implementation of a compressed matrix.The CompressedMatrix class template is the represent...
Definition: CompressedMatrix.h:196
void stream(size_t i, size_t j, const IntrinsicType &value)
Aligned, non-temporal store of an intrinsic element of the matrix.
Definition: DMatTransposer.h:316
EnableIf< IsNumeric< Other >, DMatTransposer >::Type & operator/=(Other rhs)
Division assignment operator for the division of a matrix by a scalar value ( ).
Definition: DMatTransposer.h:159
#define BLAZE_CONSTRAINT_MUST_BE_DENSE_MATRIX_TYPE(T)
Constraint on the data type.In case the given data type T is not a dense, N-dimensional matrix type...
Definition: DenseMatrix.h:79
Constraint on the data type.
void subAssign(const SparseMatrix< MT2,!SO > &rhs)
Implementation of the transpose subtraction assignment of a column-major sparse matrix.
Definition: DMatTransposer.h:693
size_t rows() const
Returns the current number of rows of the matrix.
Definition: DMatTransposer.h:173
void addAssign(const DenseMatrix< MT2, SO > &rhs)
Implementation of the transpose addition assignment of a row-major dense matrix.
Definition: DMatTransposer.h:462
ElementType * data()
Low-level data access to the matrix elements.
Definition: DMatTransposer.h:129
size_t columns() const
Returns the current number of columns of the matrix.
Definition: DMatTransposer.h:183
MT::ReturnType ReturnType
Return type for expression template evaluations.
Definition: DMatTransposer.h:86
CompressedMatrix< Type, false > OppositeType
Result type with opposite storage order for expression template evaluations.
Definition: CompressedMatrix.h:2371
Header file for the intrinsic trait.
Base class for dense matrices.The DenseMatrix class is a base class for all dense matrix classes...
Definition: DenseMatrix.h:70
Base class for sparse matrices.The SparseMatrix class is a base class for all sparse matrix classes...
Definition: Forward.h:104
const This & CompositeType
Data type for composite expression templates.
Definition: DMatTransposer.h:87
Constraint on the data type.
void subAssign(const DenseMatrix< MT2, SO > &rhs)
Implementation of the transpose subtraction assignment of a row-major dense matrix.
Definition: DMatTransposer.h:591
#define BLAZE_CONSTRAINT_MUST_BE_COLUMN_MAJOR_MATRIX_TYPE(T)
Constraint on the data type.In case the given data type T is not a column-major dense or sparse matri...
Definition: StorageOrder.h:161
Reference operator()(size_t i, size_t j)
2D-access to the matrix elements.
Definition: DMatTransposer.h:117
const Element * ConstIterator
Iterator over constant elements.
Definition: CompressedMatrix.h:2379
bool isAliased(const Other *alias) const
Returns whether the matrix is aliased with the given address alias.
Definition: DMatTransposer.h:228
Header file for the DenseMatrix base class.
EnableIf< IsNumeric< Other >, DMatTransposer >::Type & operator*=(Other rhs)
Multiplication assignment operator for the multiplication between a matrix and a scalar value ( )...
Definition: DMatTransposer.h:142
Expression object for the transposition of a dense matrix.The DMatTransposer class is a wrapper objec...
Definition: DMatTransposer.h:71
MT & dm_
The dense matrix operand.
Definition: DMatTransposer.h:710
IntrinsicType loadu(size_t i, size_t j) const
Unaligned load of an intrinsic element of the matrix.
Definition: DMatTransposer.h:262
IntrinsicType load(size_t i, size_t j) const
Aligned load of an intrinsic element of the matrix.
Definition: DMatTransposer.h:245
CompressedMatrix< Type, false > TransposeType
Transpose type for expression template evaluations.
Definition: CompressedMatrix.h:2372
Constraints on the storage order of matrix types.
MT::TransposeType ResultType
Result type for expression template evaluations.
Definition: DMatTransposer.h:81
void assign(const SparseMatrix< MT2,!SO > &rhs)
Implementation of the transpose assignment of a column-major sparse matrix.
Definition: DMatTransposer.h:435
Type ElementType
Type of the sparse matrix elements.
Definition: CompressedMatrix.h:2373
const Type & ConstReference
Reference to a constant matrix value.
Definition: CompressedMatrix.h:2377
void reset()
Resets the matrix elements.
Definition: DMatTransposer.h:203
Header file for the EnableIf class template.
void assign(const DenseMatrix< MT2,!SO > &rhs)
Implementation of the transpose assignment of a column-major dense matrix.
Definition: DMatTransposer.h:371
size_t spacing() const
Returns the spacing between the beginning of two rows.
Definition: DMatTransposer.h:193
void assign(const DenseMatrix< MT2, SO > &rhs)
Implementation of the transpose assignment of a row-major dense matrix.
Definition: DMatTransposer.h:334
Header file for the IsNumeric type trait.
IntrinsicTrait< typename MT::ElementType > IT
Intrinsic trait for the vector element type.
Definition: DMatTransposer.h:75
void subAssign(const SparseMatrix< MT2, SO > &rhs)
Implementation of the transpose subtraction assignment of a row-major sparse matrix.
Definition: DMatTransposer.h:666
#define BLAZE_CONSTRAINT_MUST_BE_ROW_MAJOR_MATRIX_TYPE(T)
Constraint on the data type.In case the given data type T is not a row-major dense or sparse matrix t...
Definition: StorageOrder.h:81
const Type & ReturnType
Return type for expression template evaluations.
Definition: CompressedMatrix.h:2374
MT::ElementType ElementType
Type of the matrix elements.
Definition: DMatTransposer.h:84
Intrinsic characteristics of data types.The IntrinsicTrait class template provides the intrinsic char...
Definition: IntrinsicTrait.h:648
IT::Type IntrinsicType
Intrinsic type of the matrix elements.
Definition: DMatTransposer.h:85
Header file for run time assertion macros.
void subAssign(const DenseMatrix< MT2,!SO > &rhs)
Implementation of the transpose subtraction assignment of a column-major dense matrix.
Definition: DMatTransposer.h:629
Header file for the submatrix trait.
MT::OppositeType OppositeType
Result type with opposite storage order for expression template evaluations.
Definition: DMatTransposer.h:82
void addAssign(const DenseMatrix< MT2,!SO > &rhs)
Implementation of the transpose addition assignment of a column-major dense matrix.
Definition: DMatTransposer.h:500
Substitution Failure Is Not An Error (SFINAE) class.The EnableIf class template is an auxiliary tool ...
Definition: EnableIf.h:184
bool canAlias(const Other *alias) const
Returns whether the matrix can alias with the given address alias.
Definition: DMatTransposer.h:215
MT::Reference Reference
Reference to a non-constant matrix value.
Definition: DMatTransposer.h:88
MT::ResultType TransposeType
Transpose type for expression template evaluations.
Definition: DMatTransposer.h:83
MT::ConstReference ConstReference
Reference to a constant matrix value.
Definition: DMatTransposer.h:89
void addAssign(const SparseMatrix< MT2,!SO > &rhs)
Implementation of the transpose addition assignment of a column-major sparse matrix.
Definition: DMatTransposer.h:564
#define BLAZE_CONSTRAINT_MUST_NOT_BE_EXPRESSION_TYPE(T)
Constraint on the data type.In case the given data type T is an expression (i.e. a type derived from ...
Definition: Expression.h:118
void assign(const SparseMatrix< MT2, SO > &rhs)
Implementation of the transpose assignment of a row-major sparse matrix.
Definition: DMatTransposer.h:408
This ResultType
Result type for expression template evaluations.
Definition: CompressedMatrix.h:2370
void store(size_t i, size_t j, const IntrinsicType &value)
Aligned store of an intrinsic element of the matrix.
Definition: DMatTransposer.h:280
Header file for basic type definitions.
DMatTransposer(MT &dm)
Constructor for the DMatTransposer class.
Definition: DMatTransposer.h:105
MatrixAccessProxy< This > Reference
Reference to a non-constant matrix value.
Definition: CompressedMatrix.h:2376
#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
void storeu(size_t i, size_t j, const IntrinsicType &value)
Unaligned store of an intrinsic element of the matrix.
Definition: DMatTransposer.h:298