Blaze 3.9
SMatTSMatMultExpr.h
Go to the documentation of this file.
1//=================================================================================================
33//=================================================================================================
34
35#ifndef _BLAZE_MATH_EXPRESSIONS_SMATTSMATMULTEXPR_H_
36#define _BLAZE_MATH_EXPRESSIONS_SMATTSMATMULTEXPR_H_
37
38
39//*************************************************************************************************
40// Includes
41//*************************************************************************************************
42
43#include <blaze/math/Aliases.h>
69#include <blaze/util/Assert.h>
70#include <blaze/util/EnableIf.h>
74#include <blaze/util/mpl/If.h>
75#include <blaze/util/Types.h>
76
77
78namespace blaze {
79
80//=================================================================================================
81//
82// CLASS SMATTSMATMULTEXPR
83//
84//=================================================================================================
85
86//*************************************************************************************************
93template< typename MT1 // Type of the left-hand side sparse matrix
94 , typename MT2 > // Type of the right-hand side sparse matrix
96 : public MatMatMultExpr< SparseMatrix< SMatTSMatMultExpr<MT1,MT2>, IsIdentity_v<MT1> > >
97 , private Computation
98{
99 private:
100 //**Type definitions****************************************************************************
105 //**********************************************************************************************
106
107 //**********************************************************************************************
109
116 template< typename T1, typename T2, typename T3 >
117 static constexpr bool CanExploitSymmetry_v =
118 ( ( IsRowMajorMatrix_v<T1> && IsSymmetric_v<T3> ) ||
119 ( IsColumnMajorMatrix_v<T1> && IsSymmetric_v<T2> ) );
121 //**********************************************************************************************
122
123 public:
124 //**Type definitions****************************************************************************
127
130
135 using ReturnType = const ElementType;
136 using CompositeType = const ResultType;
137
139 using LeftOperand = If_t< IsExpression_v<MT1>, const MT1, const MT1& >;
140
142 using RightOperand = If_t< IsExpression_v<MT2>, const MT2, const MT2& >;
143 //**********************************************************************************************
144
145 //**Compilation flags***************************************************************************
147 static constexpr bool smpAssignable = false;
148 //**********************************************************************************************
149
150 //**Constructor*********************************************************************************
156 inline SMatTSMatMultExpr( const MT1& lhs, const MT2& rhs ) noexcept
157 : lhs_( lhs ) // Left-hand side sparse matrix of the multiplication expression
158 , rhs_( rhs ) // Right-hand side sparse matrix of the multiplication expression
159 {
160 BLAZE_INTERNAL_ASSERT( lhs.columns() == rhs.rows(), "Invalid matrix sizes" );
161 }
162 //**********************************************************************************************
163
164 //**Access operator*****************************************************************************
171 inline ReturnType operator()( size_t i, size_t j ) const {
172 BLAZE_INTERNAL_ASSERT( i < lhs_.rows() , "Invalid row access index" );
173 BLAZE_INTERNAL_ASSERT( j < rhs_.columns(), "Invalid column access index" );
174
175 return row( lhs_, i, unchecked ) * column( rhs_, j, unchecked );
176 }
177 //**********************************************************************************************
178
179 //**At function*********************************************************************************
187 inline ReturnType at( size_t i, size_t j ) const {
188 if( i >= lhs_.rows() ) {
189 BLAZE_THROW_OUT_OF_RANGE( "Invalid row access index" );
190 }
191 if( j >= rhs_.columns() ) {
192 BLAZE_THROW_OUT_OF_RANGE( "Invalid column access index" );
193 }
194 return (*this)(i,j);
195 }
196 //**********************************************************************************************
197
198 //**Rows function*******************************************************************************
203 inline size_t rows() const noexcept {
204 return lhs_.rows();
205 }
206 //**********************************************************************************************
207
208 //**Columns function****************************************************************************
213 inline size_t columns() const noexcept {
214 return rhs_.columns();
215 }
216 //**********************************************************************************************
217
218 //**NonZeros function***************************************************************************
223 constexpr size_t nonZeros() const noexcept {
224 return 0UL;
225 }
226 //**********************************************************************************************
227
228 //**NonZeros function***************************************************************************
234 inline size_t nonZeros( size_t i ) const noexcept {
235 MAYBE_UNUSED( i );
236 return 0UL;
237 }
238 //**********************************************************************************************
239
240 //**Left operand access*************************************************************************
245 inline LeftOperand leftOperand() const noexcept {
246 return lhs_;
247 }
248 //**********************************************************************************************
249
250 //**Right operand access************************************************************************
255 inline RightOperand rightOperand() const noexcept {
256 return rhs_;
257 }
258 //**********************************************************************************************
259
260 //**********************************************************************************************
266 template< typename T >
267 inline bool canAlias( const T* alias ) const noexcept {
268 return ( lhs_.isAliased( alias ) || rhs_.isAliased( alias ) );
269 }
270 //**********************************************************************************************
271
272 //**********************************************************************************************
278 template< typename T >
279 inline bool isAliased( const T* alias ) const noexcept {
280 return ( lhs_.isAliased( alias ) || rhs_.isAliased( alias ) );
281 }
282 //**********************************************************************************************
283
284 //**********************************************************************************************
289 inline bool canSMPAssign() const noexcept {
290 return ( rows() * columns() >= SMP_SMATTSMATMULT_THRESHOLD );
291 }
292 //**********************************************************************************************
293
294 private:
295 //**Member variables****************************************************************************
298 //**********************************************************************************************
299
300 //**Assignment to row-major matrices************************************************************
313 template< typename MT > // Type of the target matrix
314 friend inline auto assign( Matrix<MT,false>& lhs, const SMatTSMatMultExpr& rhs )
316 {
318
319 BLAZE_INTERNAL_ASSERT( (*lhs).rows() == rhs.rows() , "Invalid number of rows" );
320 BLAZE_INTERNAL_ASSERT( (*lhs).columns() == rhs.columns(), "Invalid number of columns" );
321
323
324 const OppositeType_t<MT2> tmp( serial( rhs.rhs_ ) );
325 assign( *lhs, rhs.lhs_ * tmp );
326 }
328 //**********************************************************************************************
329
330 //**Restructuring assignment to row-major matrices**********************************************
345 template< typename MT > // Type of the target matrix
346 friend inline auto assign( Matrix<MT,false>& lhs, const SMatTSMatMultExpr& rhs )
348 {
350
351 BLAZE_INTERNAL_ASSERT( (*lhs).rows() == rhs.rows() , "Invalid number of rows" );
352 BLAZE_INTERNAL_ASSERT( (*lhs).columns() == rhs.columns(), "Invalid number of columns" );
353
354 assign( *lhs, rhs.lhs_ * trans( rhs.rhs_ ) );
355 }
357 //**********************************************************************************************
358
359 //**Assignment to column-major matrices*********************************************************
372 template< typename MT > // Type of the target matrix
373 friend inline auto assign( Matrix<MT,true>& lhs, const SMatTSMatMultExpr& rhs )
374 -> DisableIf_t< CanExploitSymmetry_v<MT,MT1,MT2> >
375 {
377
379
380 BLAZE_INTERNAL_ASSERT( (*lhs).rows() == rhs.rows() , "Invalid number of rows" );
381 BLAZE_INTERNAL_ASSERT( (*lhs).columns() == rhs.columns(), "Invalid number of columns" );
382
384
385 const OppositeType_t<MT1> tmp( serial( rhs.lhs_ ) );
386 assign( *lhs, tmp * rhs.rhs_ );
387 }
389 //**********************************************************************************************
390
391 //**Restructuring assignment to column-major matrices*******************************************
406 template< typename MT > // Type of the target matrix
407 friend inline auto assign( Matrix<MT,true>& lhs, const SMatTSMatMultExpr& rhs )
408 -> EnableIf_t< CanExploitSymmetry_v<MT,MT1,MT2> >
409 {
411
413
414 BLAZE_INTERNAL_ASSERT( (*lhs).rows() == rhs.rows() , "Invalid number of rows" );
415 BLAZE_INTERNAL_ASSERT( (*lhs).columns() == rhs.columns(), "Invalid number of columns" );
416
417 assign( *lhs, trans( rhs.lhs_ ) * rhs.rhs_ );
418 }
420 //**********************************************************************************************
421
422 //**Addition assignment to row-major dense matrices*********************************************
435 template< typename MT > // Type of the target dense matrix
436 friend inline auto addAssign( DenseMatrix<MT,false>& lhs, const SMatTSMatMultExpr& rhs )
437 -> DisableIf_t< CanExploitSymmetry_v<MT,MT1,MT2> >
438 {
440
441 BLAZE_INTERNAL_ASSERT( (*lhs).rows() == rhs.rows() , "Invalid number of rows" );
442 BLAZE_INTERNAL_ASSERT( (*lhs).columns() == rhs.columns(), "Invalid number of columns" );
443
445
446 const OppositeType_t<MT2> tmp( serial( rhs.rhs_ ) );
447 addAssign( *lhs, rhs.lhs_ * tmp );
448 }
450 //**********************************************************************************************
451
452 //**Restructuring addition assignment to row-major matrices*************************************
467 template< typename MT > // Type of the target matrix
468 friend inline auto addAssign( Matrix<MT,false>& lhs, const SMatTSMatMultExpr& rhs )
469 -> EnableIf_t< CanExploitSymmetry_v<MT,MT1,MT2> >
470 {
472
473 BLAZE_INTERNAL_ASSERT( (*lhs).rows() == rhs.rows() , "Invalid number of rows" );
474 BLAZE_INTERNAL_ASSERT( (*lhs).columns() == rhs.columns(), "Invalid number of columns" );
475
476 addAssign( *lhs, rhs.lhs_ * trans( rhs.rhs_ ) );
477 }
479 //**********************************************************************************************
480
481 //**Addition assignment to column-major dense matrices******************************************
494 template< typename MT > // Type of the target dense matrix
495 friend inline auto addAssign( DenseMatrix<MT,true>& lhs, const SMatTSMatMultExpr& rhs )
496 -> DisableIf_t< CanExploitSymmetry_v<MT,MT1,MT2> >
497 {
499
501
502 BLAZE_INTERNAL_ASSERT( (*lhs).rows() == rhs.rows() , "Invalid number of rows" );
503 BLAZE_INTERNAL_ASSERT( (*lhs).columns() == rhs.columns(), "Invalid number of columns" );
504
506
507 const OppositeType_t<MT1> tmp( serial( rhs.lhs_ ) );
508 addAssign( *lhs, tmp * rhs.rhs_ );
509 }
511 //**********************************************************************************************
512
513 //**Restructuring addition assignment to column-major matrices**********************************
528 template< typename MT > // Type of the target matrix
529 friend inline auto addAssign( Matrix<MT,true>& lhs, const SMatTSMatMultExpr& rhs )
530 -> EnableIf_t< CanExploitSymmetry_v<MT,MT1,MT2> >
531 {
533
535
536 BLAZE_INTERNAL_ASSERT( (*lhs).rows() == rhs.rows() , "Invalid number of rows" );
537 BLAZE_INTERNAL_ASSERT( (*lhs).columns() == rhs.columns(), "Invalid number of columns" );
538
539 addAssign( *lhs, trans( rhs.lhs_ ) * rhs.rhs_ );
540 }
542 //**********************************************************************************************
543
544 //**Addition assignment to sparse matrices******************************************************
545 // No special implementation for the addition assignment to sparse matrices.
546 //**********************************************************************************************
547
548 //**Subtraction assignment to row-major dense matrices******************************************
561 template< typename MT > // Type of the target dense matrix
562 friend inline auto subAssign( DenseMatrix<MT,false>& lhs, const SMatTSMatMultExpr& rhs )
563 -> DisableIf_t< CanExploitSymmetry_v<MT,MT1,MT2> >
564 {
566
567 BLAZE_INTERNAL_ASSERT( (*lhs).rows() == rhs.rows() , "Invalid number of rows" );
568 BLAZE_INTERNAL_ASSERT( (*lhs).columns() == rhs.columns(), "Invalid number of columns" );
569
571
572 const OppositeType_t<MT2> tmp( serial( rhs.rhs_ ) );
573 subAssign( *lhs, rhs.lhs_ * tmp );
574 }
576 //**********************************************************************************************
577
578 //**Restructuring subtraction assignment to row-major matrices**********************************
593 template< typename MT > // Type of the target matrix
594 friend inline auto subAssign( Matrix<MT,false>& lhs, const SMatTSMatMultExpr& rhs )
595 -> EnableIf_t< CanExploitSymmetry_v<MT,MT1,MT2> >
596 {
598
599 BLAZE_INTERNAL_ASSERT( (*lhs).rows() == rhs.rows() , "Invalid number of rows" );
600 BLAZE_INTERNAL_ASSERT( (*lhs).columns() == rhs.columns(), "Invalid number of columns" );
601
602 subAssign( *lhs, rhs.lhs_ * trans( rhs.rhs_ ) );
603 }
605 //**********************************************************************************************
606
607 //**Subtraction assignment to column-major dense matrices***************************************
620 template< typename MT > // Type of the target dense matrix
621 friend inline auto subAssign( DenseMatrix<MT,true>& lhs, const SMatTSMatMultExpr& rhs )
622 -> DisableIf_t< CanExploitSymmetry_v<MT,MT1,MT2> >
623 {
625
627
628 BLAZE_INTERNAL_ASSERT( (*lhs).rows() == rhs.rows() , "Invalid number of rows" );
629 BLAZE_INTERNAL_ASSERT( (*lhs).columns() == rhs.columns(), "Invalid number of columns" );
630
632
633 const OppositeType_t<MT1> tmp( serial( rhs.lhs_ ) );
634 subAssign( *lhs, tmp * rhs.rhs_ );
635 }
637 //**********************************************************************************************
638
639 //**Restructuring subtraction assignment to column-major matrices*******************************
654 template< typename MT > // Type of the target matrix
655 friend inline auto subAssign( Matrix<MT,true>& lhs, const SMatTSMatMultExpr& rhs )
656 -> EnableIf_t< CanExploitSymmetry_v<MT,MT1,MT2> >
657 {
659
661
662 BLAZE_INTERNAL_ASSERT( (*lhs).rows() == rhs.rows() , "Invalid number of rows" );
663 BLAZE_INTERNAL_ASSERT( (*lhs).columns() == rhs.columns(), "Invalid number of columns" );
664
665 subAssign( *lhs, trans( rhs.lhs_ ) * rhs.rhs_ );
666 }
668 //**********************************************************************************************
669
670 //**Subtraction assignment to sparse matrices***************************************************
671 // No special implementation for the subtraction assignment to sparse matrices.
672 //**********************************************************************************************
673
674 //**Schur product assignment to row-major dense matrices****************************************
687 template< typename MT // Type of the target dense matrix
688 , bool SO > // Storage order of the target dense matrix
689 friend inline void schurAssign( DenseMatrix<MT,SO>& lhs, const SMatTSMatMultExpr& rhs )
690 {
692
695
696 BLAZE_INTERNAL_ASSERT( (*lhs).rows() == rhs.rows() , "Invalid number of rows" );
697 BLAZE_INTERNAL_ASSERT( (*lhs).columns() == rhs.columns(), "Invalid number of columns" );
698
699 const ResultType tmp( serial( rhs ) );
700 schurAssign( *lhs, tmp );
701 }
703 //**********************************************************************************************
704
705 //**Schur product assignment to sparse matrices*************************************************
706 // No special implementation for the Schur product assignment to sparse matrices.
707 //**********************************************************************************************
708
709 //**Multiplication assignment to dense matrices*************************************************
710 // No special implementation for the multiplication assignment to dense matrices.
711 //**********************************************************************************************
712
713 //**Multiplication assignment to sparse matrices************************************************
714 // No special implementation for the multiplication assignment to sparse matrices.
715 //**********************************************************************************************
716
717 //**SMP assignment to row-major matrices********************************************************
732 template< typename MT > // Type of the target matrix
733 friend inline auto smpAssign( Matrix<MT,false>& lhs, const SMatTSMatMultExpr& rhs )
734 -> DisableIf_t< CanExploitSymmetry_v<MT,MT1,MT2> >
735 {
737
738 BLAZE_INTERNAL_ASSERT( (*lhs).rows() == rhs.rows() , "Invalid number of rows" );
739 BLAZE_INTERNAL_ASSERT( (*lhs).columns() == rhs.columns(), "Invalid number of columns" );
740
742
743 const OppositeType_t<MT2> tmp( rhs.rhs_ );
744 smpAssign( *lhs, rhs.lhs_ * tmp );
745 }
747 //**********************************************************************************************
748
749 //**Restructuring SMP assignment to row-major matrices******************************************
764 template< typename MT > // Type of the target matrix
765 friend inline auto smpAssign( Matrix<MT,false>& lhs, const SMatTSMatMultExpr& rhs )
766 -> EnableIf_t< CanExploitSymmetry_v<MT,MT1,MT2> >
767 {
769
770 BLAZE_INTERNAL_ASSERT( (*lhs).rows() == rhs.rows() , "Invalid number of rows" );
771 BLAZE_INTERNAL_ASSERT( (*lhs).columns() == rhs.columns(), "Invalid number of columns" );
772
773 smpAssign( *lhs, rhs.lhs_ * trans( rhs.rhs_ ) );
774 }
776 //**********************************************************************************************
777
778 //**SMP assignment to column-major matrices*****************************************************
793 template< typename MT > // Type of the target matrix
794 friend inline auto smpAssign( Matrix<MT,true>& lhs, const SMatTSMatMultExpr& rhs )
795 -> DisableIf_t< CanExploitSymmetry_v<MT,MT1,MT2> >
796 {
798
800
801 BLAZE_INTERNAL_ASSERT( (*lhs).rows() == rhs.rows() , "Invalid number of rows" );
802 BLAZE_INTERNAL_ASSERT( (*lhs).columns() == rhs.columns(), "Invalid number of columns" );
803
805
806 const OppositeType_t<MT1> tmp( rhs.lhs_ );
807 smpAssign( *lhs, tmp * rhs.rhs_ );
808 }
810 //**********************************************************************************************
811
812 //**Restructuring SMP assignment to column-major matrices***************************************
827 template< typename MT > // Type of the target matrix
828 friend inline auto smpAssign( Matrix<MT,true>& lhs, const SMatTSMatMultExpr& rhs )
829 -> EnableIf_t< CanExploitSymmetry_v<MT,MT1,MT2> >
830 {
832
834
835 BLAZE_INTERNAL_ASSERT( (*lhs).rows() == rhs.rows() , "Invalid number of rows" );
836 BLAZE_INTERNAL_ASSERT( (*lhs).columns() == rhs.columns(), "Invalid number of columns" );
837
838 smpAssign( *lhs, trans( rhs.lhs_ ) * rhs.rhs_ );
839 }
841 //**********************************************************************************************
842
843 //**SMP addition assignment to row-major dense matrices*****************************************
858 template< typename MT > // Type of the target dense matrix
859 friend inline auto smpAddAssign( DenseMatrix<MT,false>& lhs, const SMatTSMatMultExpr& rhs )
860 -> DisableIf_t< CanExploitSymmetry_v<MT,MT1,MT2> >
861 {
863
864 BLAZE_INTERNAL_ASSERT( (*lhs).rows() == rhs.rows() , "Invalid number of rows" );
865 BLAZE_INTERNAL_ASSERT( (*lhs).columns() == rhs.columns(), "Invalid number of columns" );
866
868
869 const OppositeType_t<MT2> tmp( rhs.rhs_ );
870 smpAddAssign( *lhs, rhs.lhs_ * tmp );
871 }
873 //**********************************************************************************************
874
875 //**SMP addition assignment to column-major dense matrices**************************************
890 template< typename MT > // Type of the target dense matrix
891 friend inline auto smpAddAssign( DenseMatrix<MT,true>& lhs, const SMatTSMatMultExpr& rhs )
892 -> DisableIf_t< CanExploitSymmetry_v<MT,MT1,MT2> >
893 {
895
897
898 BLAZE_INTERNAL_ASSERT( (*lhs).rows() == rhs.rows() , "Invalid number of rows" );
899 BLAZE_INTERNAL_ASSERT( (*lhs).columns() == rhs.columns(), "Invalid number of columns" );
900
902
903 const OppositeType_t<MT1> tmp( rhs.lhs_ );
904 smpAddAssign( *lhs, tmp * rhs.rhs_ );
905 }
907 //**********************************************************************************************
908
909 //**Restructuring SMP addition assignment to row-major matrices*********************************
924 template< typename MT > // Type of the target matrix
925 friend inline auto smpAddAssign( Matrix<MT,false>& lhs, const SMatTSMatMultExpr& rhs )
926 -> EnableIf_t< CanExploitSymmetry_v<MT,MT1,MT2> >
927 {
929
930 BLAZE_INTERNAL_ASSERT( (*lhs).rows() == rhs.rows() , "Invalid number of rows" );
931 BLAZE_INTERNAL_ASSERT( (*lhs).columns() == rhs.columns(), "Invalid number of columns" );
932
933 smpAddAssign( *lhs, rhs.lhs_ * trans( rhs.rhs_ ) );
934 }
936 //**********************************************************************************************
937
938 //**Restructuring SMP addition assignment to column-major matrices******************************
953 template< typename MT > // Type of the target matrix
954 friend inline auto smpAddAssign( Matrix<MT,true>& lhs, const SMatTSMatMultExpr& rhs )
955 -> EnableIf_t< CanExploitSymmetry_v<MT,MT1,MT2> >
956 {
958
960
961 BLAZE_INTERNAL_ASSERT( (*lhs).rows() == rhs.rows() , "Invalid number of rows" );
962 BLAZE_INTERNAL_ASSERT( (*lhs).columns() == rhs.columns(), "Invalid number of columns" );
963
964 smpAddAssign( *lhs, trans( rhs.lhs_ ) * rhs.rhs_ );
965 }
967 //**********************************************************************************************
968
969 //**SMP addition assignment to sparse matrices**************************************************
970 // No special implementation for the SMP addition assignment to sparse matrices.
971 //**********************************************************************************************
972
973 //**SMP subtraction assignment to row-major dense matrices**************************************
988 template< typename MT > // Type of the target dense matrix
989 friend inline auto smpSubAssign( DenseMatrix<MT,false>& lhs, const SMatTSMatMultExpr& rhs )
990 -> DisableIf_t< CanExploitSymmetry_v<MT,MT1,MT2> >
991 {
993
994 BLAZE_INTERNAL_ASSERT( (*lhs).rows() == rhs.rows() , "Invalid number of rows" );
995 BLAZE_INTERNAL_ASSERT( (*lhs).columns() == rhs.columns(), "Invalid number of columns" );
996
998
999 const OppositeType_t<MT2> tmp( rhs.rhs_ );
1000 smpSubAssign( *lhs, rhs.lhs_ * tmp );
1001 }
1003 //**********************************************************************************************
1004
1005 //**SMP subtraction assignment to column-major dense matrices***********************************
1020 template< typename MT > // Type of the target dense matrix
1021 friend inline auto smpSubAssign( DenseMatrix<MT,true>& lhs, const SMatTSMatMultExpr& rhs )
1022 -> DisableIf_t< CanExploitSymmetry_v<MT,MT1,MT2> >
1023 {
1025
1027
1028 BLAZE_INTERNAL_ASSERT( (*lhs).rows() == rhs.rows() , "Invalid number of rows" );
1029 BLAZE_INTERNAL_ASSERT( (*lhs).columns() == rhs.columns(), "Invalid number of columns" );
1030
1032
1033 const OppositeType_t<MT1> tmp( rhs.lhs_ );
1034 smpSubAssign( *lhs, tmp * rhs.rhs_ );
1035 }
1037 //**********************************************************************************************
1038
1039 //**Restructuring SMP subtraction assignment to row-major matrices******************************
1054 template< typename MT > // Type of the target matrix
1055 friend inline auto smpSubAssign( Matrix<MT,false>& lhs, const SMatTSMatMultExpr& rhs )
1056 -> EnableIf_t< CanExploitSymmetry_v<MT,MT1,MT2> >
1057 {
1059
1060 BLAZE_INTERNAL_ASSERT( (*lhs).rows() == rhs.rows() , "Invalid number of rows" );
1061 BLAZE_INTERNAL_ASSERT( (*lhs).columns() == rhs.columns(), "Invalid number of columns" );
1062
1063 smpSubAssign( *lhs, rhs.lhs_ * trans( rhs.rhs_ ) );
1064 }
1066 //**********************************************************************************************
1067
1068 //**Restructuring SMP subtraction assignment to column-major matrices***************************
1083 template< typename MT > // Type of the target matrix
1084 friend inline auto smpSubAssign( Matrix<MT,true>& lhs, const SMatTSMatMultExpr& rhs )
1085 -> EnableIf_t< CanExploitSymmetry_v<MT,MT1,MT2> >
1086 {
1088
1090
1091 BLAZE_INTERNAL_ASSERT( (*lhs).rows() == rhs.rows() , "Invalid number of rows" );
1092 BLAZE_INTERNAL_ASSERT( (*lhs).columns() == rhs.columns(), "Invalid number of columns" );
1093
1094 smpSubAssign( *lhs, trans( rhs.lhs_ ) * rhs.rhs_ );
1095 }
1097 //**********************************************************************************************
1098
1099 //**SMP subtraction assignment to sparse matrices***********************************************
1100 // No special implementation for the SMP subtraction assignment to sparse matrices.
1101 //**********************************************************************************************
1102
1103 //**SMP Schur product assignment to row-major dense matrices************************************
1116 template< typename MT // Type of the target dense matrix
1117 , bool SO > // Storage order of the target dense matrix
1118 friend inline void smpSchurAssign( DenseMatrix<MT,SO>& lhs, const SMatTSMatMultExpr& rhs )
1119 {
1121
1124
1125 BLAZE_INTERNAL_ASSERT( (*lhs).rows() == rhs.rows() , "Invalid number of rows" );
1126 BLAZE_INTERNAL_ASSERT( (*lhs).columns() == rhs.columns(), "Invalid number of columns" );
1127
1128 const ResultType tmp( rhs );
1129 smpSchurAssign( *lhs, tmp );
1130 }
1132 //**********************************************************************************************
1133
1134 //**SMP Schur product assignment to sparse matrices*********************************************
1135 // No special implementation for the SMP Schur product assignment to sparse matrices.
1136 //**********************************************************************************************
1137
1138 //**SMP multiplication assignment to dense matrices*********************************************
1139 // No special implementation for the SMP multiplication assignment to dense matrices.
1140 //**********************************************************************************************
1141
1142 //**SMP multiplication assignment to sparse matrices********************************************
1143 // No special implementation for the SMP multiplication assignment to sparse matrices.
1144 //**********************************************************************************************
1145
1146 //**Compile time checks*************************************************************************
1156 //**********************************************************************************************
1157};
1158//*************************************************************************************************
1159
1160
1161
1162
1163//=================================================================================================
1164//
1165// GLOBAL BINARY ARITHMETIC OPERATORS
1166//
1167//=================================================================================================
1168
1169//*************************************************************************************************
1182template< typename MT1 // Type of the left-hand side sparse matrix
1183 , typename MT2 // Type of the right-hand side sparse matrix
1184 , DisableIf_t< ( ( IsIdentity_v<MT1> || IsIdentity_v<MT2> ) &&
1185 IsSame_v< ElementType_t<MT1>, ElementType_t<MT2> > ) ||
1186 ( IsIdentity_v<MT1> && IsIdentity_v<MT2> ) ||
1187 ( IsZero_v<MT1> || IsZero_v<MT2> ) >* = nullptr >
1188inline const SMatTSMatMultExpr<MT1,MT2>
1189 smattsmatmult( const SparseMatrix<MT1,false>& lhs, const SparseMatrix<MT2,true>& rhs )
1190{
1192
1193 BLAZE_INTERNAL_ASSERT( (*lhs).columns() == (*rhs).rows(), "Invalid matrix sizes" );
1194
1195 return SMatTSMatMultExpr<MT1,MT2>( *lhs, *rhs );
1196}
1198//*************************************************************************************************
1199
1200
1201//*************************************************************************************************
1215template< typename MT1 // Type of the left-hand side sparse matrix
1216 , typename MT2 // Type of the right-hand side sparse matrix
1217 , EnableIf_t< !IsIdentity_v<MT1> && IsIdentity_v<MT2> &&
1218 IsSame_v< ElementType_t<MT1>, ElementType_t<MT2> > >* = nullptr >
1219inline const MT1&
1220 smattsmatmult( const SparseMatrix<MT1,false>& lhs, const SparseMatrix<MT2,true>& rhs )
1221{
1223
1224 MAYBE_UNUSED( rhs );
1225
1226 BLAZE_INTERNAL_ASSERT( (*lhs).columns() == (*rhs).rows(), "Invalid matrix sizes" );
1227
1228 return (*lhs);
1229}
1231//*************************************************************************************************
1232
1233
1234//*************************************************************************************************
1248template< typename MT1 // Type of the left-hand side sparse matrix
1249 , typename MT2 // Type of the right-hand side sparse matrix
1250 , EnableIf_t< IsIdentity_v<MT1> && !IsIdentity_v<MT2> &&
1251 IsSame_v< ElementType_t<MT1>, ElementType_t<MT2> > >* = nullptr >
1252inline const MT2&
1253 smattsmatmult( const SparseMatrix<MT1,false>& lhs, const SparseMatrix<MT2,true>& rhs )
1254{
1256
1257 MAYBE_UNUSED( lhs );
1258
1259 BLAZE_INTERNAL_ASSERT( (*lhs).columns() == (*rhs).rows(), "Invalid matrix sizes" );
1260
1261 return (*rhs);
1262}
1264//*************************************************************************************************
1265
1266
1267//*************************************************************************************************
1280template< typename MT1 // Type of the left-hand side sparse matrix
1281 , typename MT2 // Type of the right-hand side sparse matrix
1282 , EnableIf_t< IsIdentity_v<MT1> && IsIdentity_v<MT2> >* = nullptr >
1283inline decltype(auto)
1284 smattsmatmult( const SparseMatrix<MT1,false>& lhs, const SparseMatrix<MT2,true>& rhs )
1285{
1287
1288 MAYBE_UNUSED( rhs );
1289
1290 BLAZE_INTERNAL_ASSERT( (*lhs).columns() == (*rhs).rows(), "Invalid matrix sizes" );
1291
1292 using ReturnType = const MultTrait_t< ResultType_t<MT1>, ResultType_t<MT2> >;
1293
1296
1297 return ReturnType( (*lhs).rows() );
1298}
1300//*************************************************************************************************
1301
1302
1303//*************************************************************************************************
1317template< typename MT1 // Type of the left-hand side sparse matrix
1318 , typename MT2 // Type of the right-hand side sparse matrix
1319 , EnableIf_t< IsZero_v<MT1> || IsZero_v<MT2> >* = nullptr >
1320inline decltype(auto)
1321 smattsmatmult( const SparseMatrix<MT1,false>& lhs, const SparseMatrix<MT2,true>& rhs )
1322{
1324
1325 BLAZE_INTERNAL_ASSERT( (*lhs).columns() == (*rhs).rows(), "Invalid matrix sizes" );
1326
1327 using ReturnType = const MultTrait_t< ResultType_t<MT1>, ResultType_t<MT2> >;
1328
1329 BLAZE_CONSTRAINT_MUST_BE_MATRIX_WITH_STORAGE_ORDER( ReturnType, !IsZero_v<MT1> );
1331
1332 return ReturnType( (*lhs).rows(), (*rhs).columns() );
1333}
1335//*************************************************************************************************
1336
1337
1338//*************************************************************************************************
1368template< typename MT1 // Type of the left-hand side sparse matrix
1369 , typename MT2 > // Type of the right-hand side sparse matrix
1370inline decltype(auto)
1371 operator*( const SparseMatrix<MT1,false>& lhs, const SparseMatrix<MT2,true>& rhs )
1372{
1374
1375 if( (*lhs).columns() != (*rhs).rows() ) {
1376 BLAZE_THROW_INVALID_ARGUMENT( "Matrix sizes do not match" );
1377 }
1378
1379 return smattsmatmult( *lhs, *rhs );
1380}
1381//*************************************************************************************************
1382
1383} // namespace blaze
1384
1385#endif
Header file for auxiliary alias declarations.
typename T::CompositeType CompositeType_t
Alias declaration for nested CompositeType type definitions.
Definition: Aliases.h:110
typename T::ResultType ResultType_t
Alias declaration for nested ResultType type definitions.
Definition: Aliases.h:450
typename T::ElementType ElementType_t
Alias declaration for nested ElementType type definitions.
Definition: Aliases.h:190
typename T::OppositeType OppositeType_t
Alias declaration for nested OppositeType type definitions.
Definition: Aliases.h:310
typename T::TransposeType TransposeType_t
Alias declaration for nested TransposeType type definitions.
Definition: Aliases.h:550
Header file for run time assertion macros.
Header file for the blaze::checked and blaze::unchecked instances.
Constraints on the storage order of matrix types.
Header file for the EnableIf class template.
Header file for the function trace functionality.
Constraint on the data type.
Header file for the If class template.
Header file for the IntegralConstant class template.
Header file for the IsColumnMajorMatrix type trait.
Header file for the IsExpression type trait class.
Header file for the IsIdentity type trait.
Header file for the IsRowMajorMatrix type trait.
Header file for the IsSymmetric type trait.
Header file for the MAYBE_UNUSED function template.
Header file for the multiplication trait.
Constraints on the storage order of matrix types.
Constraint on the data type.
Constraint on the data type.
Base class for matrices.
Definition: Matrix.h:85
Expression object for sparse matrix-transpose sparse matrix multiplications.
Definition: SMatTSMatMultExpr.h:98
ResultType_t< MT1 > RT1
Result type of the left-hand side sparse matrix expression.
Definition: SMatTSMatMultExpr.h:101
RightOperand rightOperand() const noexcept
Returns the right-hand side transpose sparse matrix operand.
Definition: SMatTSMatMultExpr.h:255
ElementType_t< ResultType > ElementType
Resulting element type.
Definition: SMatTSMatMultExpr.h:134
If_t< IsExpression_v< MT2 >, const MT2, const MT2 & > RightOperand
Composite type of the right-hand side sparse matrix expression.
Definition: SMatTSMatMultExpr.h:142
constexpr size_t nonZeros() const noexcept
Returns the number of non-zero elements in the sparse matrix.
Definition: SMatTSMatMultExpr.h:223
CompositeType_t< MT2 > CT2
Composite type of the right-hand side sparse matrix expression.
Definition: SMatTSMatMultExpr.h:104
size_t nonZeros(size_t i) const noexcept
Returns the number of non-zero elements in the specified row.
Definition: SMatTSMatMultExpr.h:234
CompositeType_t< MT1 > CT1
Composite type of the left-hand side sparse matrix expression.
Definition: SMatTSMatMultExpr.h:103
ReturnType operator()(size_t i, size_t j) const
2D-access to the matrix elements.
Definition: SMatTSMatMultExpr.h:171
OppositeType_t< ResultType > OppositeType
Result type with opposite storage order for expression template evaluations.
Definition: SMatTSMatMultExpr.h:132
bool isAliased(const T *alias) const noexcept
Returns whether the expression is aliased with the given address alias.
Definition: SMatTSMatMultExpr.h:279
RightOperand rhs_
Right-hand side sparse matrix of the multiplication expression.
Definition: SMatTSMatMultExpr.h:297
ReturnType at(size_t i, size_t j) const
Checked access to the matrix elements.
Definition: SMatTSMatMultExpr.h:187
SMatTSMatMultExpr(const MT1 &lhs, const MT2 &rhs) noexcept
Constructor for the SMatTSMatMultExpr class.
Definition: SMatTSMatMultExpr.h:156
size_t columns() const noexcept
Returns the current number of columns of the matrix.
Definition: SMatTSMatMultExpr.h:213
TransposeType_t< ResultType > TransposeType
Transpose type for expression template evaluations.
Definition: SMatTSMatMultExpr.h:133
If_t< IsExpression_v< MT1 >, const MT1, const MT1 & > LeftOperand
Composite type of the left-hand side sparse matrix expression.
Definition: SMatTSMatMultExpr.h:139
MultTrait_t< RT1, RT2 > ResultType
Result type for expression template evaluations.
Definition: SMatTSMatMultExpr.h:131
size_t rows() const noexcept
Returns the current number of rows of the matrix.
Definition: SMatTSMatMultExpr.h:203
LeftOperand lhs_
Left-hand side sparse matrix of the multiplication expression.
Definition: SMatTSMatMultExpr.h:296
const ElementType ReturnType
Return type for expression template evaluations.
Definition: SMatTSMatMultExpr.h:135
bool canSMPAssign() const noexcept
Returns whether the expression can be used in SMP assignments.
Definition: SMatTSMatMultExpr.h:289
ResultType_t< MT2 > RT2
Result type of the right-hand side sparse matrix expression.
Definition: SMatTSMatMultExpr.h:102
static constexpr bool smpAssignable
Compilation switch for the expression template assignment strategy.
Definition: SMatTSMatMultExpr.h:147
bool canAlias(const T *alias) const noexcept
Returns whether the expression can alias with the given address alias.
Definition: SMatTSMatMultExpr.h:267
const ResultType CompositeType
Data type for composite expression templates.
Definition: SMatTSMatMultExpr.h:136
LeftOperand leftOperand() const noexcept
Returns the left-hand side sparse matrix operand.
Definition: SMatTSMatMultExpr.h:245
Base class for sparse matrices.
Definition: SparseMatrix.h:77
Constraint on the data type.
Constraint on the data type.
Constraint on the data type.
Header file for the Computation base class.
Header file for the MatMatMultExpr base class.
Header file for the SparseMatrix base class.
decltype(auto) column(Matrix< MT, SO > &matrix, RCAs... args)
Creating a view on a specific column of the given matrix.
Definition: Column.h:137
decltype(auto) trans(const DenseMatrix< MT, SO > &dm)
Calculation of the transpose of the given dense matrix.
Definition: DMatTransExpr.h:766
decltype(auto) serial(const DenseMatrix< MT, SO > &dm)
Forces the serial evaluation of the given dense matrix expression dm.
Definition: DMatSerialExpr.h:812
#define BLAZE_CONSTRAINT_MUST_NOT_BE_SYMMETRIC_MATRIX_TYPE(T)
Constraint on the data type.
Definition: Symmetric.h:79
#define BLAZE_CONSTRAINT_MUST_BE_ROW_MAJOR_MATRIX_TYPE(T)
Constraint on the data type.
Definition: RowMajorMatrix.h:61
#define BLAZE_CONSTRAINT_MUST_NOT_REQUIRE_EVALUATION(T)
Constraint on the data type.
Definition: RequiresEvaluation.h:81
#define BLAZE_CONSTRAINT_MUST_FORM_VALID_MATMATMULTEXPR(T1, T2)
Constraint on the data type.
Definition: MatMatMultExpr.h:103
#define BLAZE_CONSTRAINT_MUST_NOT_BE_ZERO_TYPE(T)
Constraint on the data type.
Definition: Zero.h:81
#define BLAZE_CONSTRAINT_MUST_BE_SPARSE_MATRIX_TYPE(T)
Constraint on the data type.
Definition: SparseMatrix.h:61
#define BLAZE_CONSTRAINT_MUST_BE_IDENTITY_MATRIX_TYPE(T)
Constraint on the data type.
Definition: Identity.h:60
#define BLAZE_CONSTRAINT_MUST_BE_COLUMN_MAJOR_MATRIX_TYPE(T)
Constraint on the data type.
Definition: ColumnMajorMatrix.h:61
#define BLAZE_CONSTRAINT_MUST_BE_ZERO_TYPE(T)
Constraint on the data type.
Definition: Zero.h:61
#define BLAZE_CONSTRAINT_MUST_BE_MATRIX_WITH_STORAGE_ORDER(T, SO)
Constraint on the data type.
Definition: StorageOrder.h:63
typename MultTrait< T1, T2 >::Type MultTrait_t
Auxiliary alias declaration for the MultTrait class template.
Definition: MultTrait.h:165
decltype(auto) row(Matrix< MT, SO > &, RRAs...)
Creating a view on a specific row of the given matrix.
Definition: Row.h:137
#define BLAZE_INTERNAL_ASSERT(expr, msg)
Run time assertion macro for internal checks.
Definition: Assert.h:101
auto smpSubAssign(Matrix< MT1, SO1 > &lhs, const Matrix< MT2, SO2 > &rhs) -> EnableIf_t< IsDenseMatrix_v< MT1 > >
Default implementation of the SMP subtraction assignment of a matrix to dense matrix.
Definition: DenseMatrix.h:162
auto smpAssign(Matrix< MT1, SO1 > &lhs, const Matrix< MT2, SO2 > &rhs) -> EnableIf_t< IsDenseMatrix_v< MT1 > >
Default implementation of the SMP assignment of a matrix to a dense matrix.
Definition: DenseMatrix.h:100
auto smpSchurAssign(Matrix< MT1, SO1 > &lhs, const Matrix< MT2, SO2 > &rhs) -> EnableIf_t< IsDenseMatrix_v< MT1 > >
Default implementation of the SMP Schur product assignment of a matrix to dense matrix.
Definition: DenseMatrix.h:194
auto smpAddAssign(Matrix< MT1, SO1 > &lhs, const Matrix< MT2, SO2 > &rhs) -> EnableIf_t< IsDenseMatrix_v< MT1 > >
Default implementation of the SMP addition assignment of a matrix to a dense matrix.
Definition: DenseMatrix.h:131
constexpr bool IsSame_v
Auxiliary variable template for the IsSame type trait.
Definition: IsSame.h:159
typename EnableIf< Condition, T >::Type EnableIf_t
Auxiliary type for the EnableIf class template.
Definition: EnableIf.h:138
constexpr void MAYBE_UNUSED(const Args &...)
Suppression of unused parameter warnings.
Definition: MaybeUnused.h:81
typename If< Condition >::template Type< T1, T2 > If_t
Auxiliary alias template for the If class template.
Definition: If.h:108
#define BLAZE_THROW_OUT_OF_RANGE(MESSAGE)
Macro for the emission of a std::out_of_range exception.
Definition: Exception.h:331
#define BLAZE_THROW_INVALID_ARGUMENT(MESSAGE)
Macro for the emission of a std::invalid_argument exception.
Definition: Exception.h:235
typename EnableIf<!Condition, T >::Type DisableIf_t
Auxiliary type for the EnableIf class template.
Definition: EnableIf.h:175
#define BLAZE_FUNCTION_TRACE
Function trace macro.
Definition: FunctionTrace.h:94
constexpr Unchecked unchecked
Global Unchecked instance.
Definition: Check.h:146
Header file for the exception macros of the math module.
Header file for all forward declarations for expression class templates.
Header file for the serial shim.
Base class for all compute expression templates.
Definition: Computation.h:68
Base class for all matrix/matrix multiplication expression templates.
Definition: MatMatMultExpr.h:71
Header file for the thresholds for matrix/vector and matrix/matrix multiplications.
Header file for the IsZero type trait.
Header file for the RequiresEvaluation type trait.
Header file for basic type definitions.
Header file for the generic min algorithm.