35 #ifndef _BLAZE_MATH_EXPRESSIONS_SMATSMATMULTEXPR_H_
36 #define _BLAZE_MATH_EXPRESSIONS_SMATSMATMULTEXPR_H_
113 template<
typename MT1
115 class SMatSMatMultExpr :
public SparseMatrix< SMatSMatMultExpr<MT1,MT2>, false >
116 ,
private MatMatMultExpr
117 ,
private Computation
144 template<
typename T1,
typename T2,
typename T3 >
145 struct CanExploitSymmetry {
146 enum { value = IsColumnMajorMatrix<T1>::value &&
147 IsSymmetric<T2>::value && IsSymmetric<T3>::value };
159 template<
typename T1,
typename T2,
typename T3 >
160 struct IsEvaluationRequired {
161 enum { value = ( evaluateLeft || evaluateRight ) &&
162 !CanExploitSymmetry<T1,T2,T3>::value };
186 enum { smpAssignable = !evaluateLeft && MT1::smpAssignable &&
187 !evaluateRight && MT2::smpAssignable };
220 if(
lhs_.columns() == 0UL )
229 const ConstIterator
end( A.end(i) );
230 ConstIterator element( A.begin(i) );
237 tmp = element->value() *
rhs_(element->index(),j);
239 for( ; element!=
end; ++element )
240 tmp += element->value() *
rhs_(element->index(),j);
246 for(
size_t k=1UL; k<
lhs_.columns(); ++k ) {
271 return rhs_.columns();
323 template<
typename T >
325 return (
lhs_.isAliased( alias ) ||
rhs_.isAliased( alias ) );
335 template<
typename T >
337 return (
lhs_.isAliased( alias ) ||
rhs_.isAliased( alias ) );
370 template<
typename MT
390 SMatSMatMultExpr::selectAssignKernel( ~lhs, A, B );
408 template<
typename MT3
411 static inline void selectAssignKernel( MT3& C,
const MT4& A,
const MT5& B )
416 for(
size_t i=0UL; i<C.rows(); ++i ) {
417 const LeftIterator lend( A.end(i) );
418 for( LeftIterator lelem=A.begin(i); lelem!=lend; ++lelem ) {
419 const RightIterator rend( B.end( lelem->index() ) );
420 for( RightIterator relem=B.begin( lelem->index() ); relem!=rend; ++relem )
424 C(i,relem->index()) = lelem->value() * relem->value();
427 C(i,relem->index()) += lelem->value() * relem->value();
449 template<
typename MT >
471 size_t nonzeros( 0UL );
473 for(
size_t i=0UL; i<(~lhs).
rows(); ++i ) {
474 const LeftIterator lend( A.end(i) );
475 for( LeftIterator lelem=A.begin(i); lelem!=lend; ++lelem ) {
476 nonzeros += B.nonZeros( lelem->index() );
480 if( nonzeros > (~lhs).rows() * (~lhs).
columns() ) {
484 (~lhs).reserve( nonzeros );
489 std::vector<byte> valid ( (~lhs).
columns(), 0 );
490 std::vector<size_t> indices( (~lhs).
columns(), 0UL );
491 size_t minIndex(
inf ), maxIndex( 0UL );
493 for(
size_t i=0UL; i<(~lhs).
rows(); ++i )
495 const LeftIterator lend( A.end(i) );
496 for( LeftIterator lelem=A.begin(i); lelem!=lend; ++lelem )
498 const RightIterator rend( B.end( lelem->index() ) );
499 for( RightIterator relem=B.begin( lelem->index() ); relem!=rend; ++relem )
501 if( !valid[relem->index()] ) {
502 values[relem->index()] = lelem->value() * relem->value();
503 valid [relem->index()] = 1;
504 indices[nonzeros] = relem->index();
506 if( relem->index() < minIndex ) minIndex = relem->index();
507 if( relem->index() > maxIndex ) maxIndex = relem->index();
510 values[relem->index()] += lelem->value() * relem->value();
521 if( ( nonzeros + nonzeros ) < ( maxIndex - minIndex ) )
523 std::sort( indices.begin(), indices.begin() + nonzeros );
525 for(
size_t j=0UL; j<nonzeros; ++j )
527 const size_t index( indices[j] );
529 (~lhs).append( i, index, values[index] );
530 reset( values[index] );
533 reset( valid [index] );
537 for(
size_t j=minIndex; j<=maxIndex; ++j )
540 (~lhs).append( i, j, values[j] );
553 (~lhs).finalize( i );
572 template<
typename MT >
573 friend inline typename DisableIf< CanExploitSymmetry<MT,MT1,MT2> >::Type
587 (~lhs).reserve( tmp.nonZeros() );
608 template<
typename MT >
609 friend inline typename EnableIf< CanExploitSymmetry<MT,MT1,MT2> >::Type
637 template<
typename MT
639 friend inline typename DisableIf< CanExploitSymmetry<MT,MT1,MT2> >::Type
657 SMatSMatMultExpr::selectAddAssignKernel( ~lhs, A, B );
676 template<
typename MT3
679 static inline void selectAddAssignKernel( MT3& C,
const MT4& A,
const MT5& B )
684 for(
size_t i=0UL; i<C.rows(); ++i ) {
685 const LeftIterator lend( A.end(i) );
686 for( LeftIterator lelem=A.begin(i); lelem!=lend; ++lelem ) {
687 const RightIterator rend( B.end( lelem->index() ) );
688 for( RightIterator relem=B.begin( lelem->index() ); relem!=rend; ++relem ) {
689 C(i,relem->index()) += lelem->value() * relem->value();
712 template<
typename MT >
713 friend inline typename EnableIf< CanExploitSymmetry<MT,MT1,MT2> >::Type
745 template<
typename MT
747 friend inline typename DisableIf< CanExploitSymmetry<MT,MT1,MT2> >::Type
765 SMatSMatMultExpr::selectSubAssignKernel( ~lhs, A, B );
784 template<
typename MT3
787 static inline void selectSubAssignKernel( MT3& C,
const MT4& A,
const MT5& B )
792 for(
size_t i=0UL; i<C.rows(); ++i ) {
793 const LeftIterator lend( A.end(i) );
794 for( LeftIterator lelem=A.begin(i); lelem!=lend; ++lelem ) {
795 const RightIterator rend( B.end( lelem->index() ) );
796 for( RightIterator relem=B.begin( lelem->index() ); relem!=rend; ++relem ) {
797 C(i,relem->index()) -= lelem->value() * relem->value();
820 template<
typename MT >
821 friend inline typename EnableIf< CanExploitSymmetry<MT,MT1,MT2> >::Type
863 template<
typename MT
865 friend inline typename EnableIf< IsEvaluationRequired<MT,MT1,MT2> >::Type
903 template<
typename MT >
904 friend inline typename EnableIf< CanExploitSymmetry<MT,MT1,MT2> >::Type
935 template<
typename MT
937 friend inline typename EnableIf< IsEvaluationRequired<MT,MT1,MT2> >::Type
975 template<
typename MT >
976 friend inline typename EnableIf< CanExploitSymmetry<MT,MT1,MT2> >::Type
1011 template<
typename MT
1013 friend inline typename EnableIf< IsEvaluationRequired<MT,MT1,MT2> >::Type
1051 template<
typename MT >
1052 friend inline typename EnableIf< CanExploitSymmetry<MT,MT1,MT2> >::Type
1127 template<
typename T1
1129 inline const SMatSMatMultExpr<T1,T2>
1135 throw std::invalid_argument(
"Matrix sizes do not match" );
1152 template<
typename MT1,
typename MT2 >
1170 template<
typename MT1,
typename MT2 >
1172 :
public Columns<MT2>
1188 template<
typename MT1,
typename MT2 >
1190 :
public IsTrue< IsLower<MT1>::value && IsLower<MT2>::value >
1206 template<
typename MT1,
typename MT2 >
1208 :
public IsTrue< IsUpper<MT1>::value && IsUpper<MT2>::value >
1224 template<
typename MT1,
typename MT2,
typename VT >
1229 typedef typename SelectType< IsSparseMatrix<MT1>::value && IsRowMajorMatrix<MT1>::value &&
1230 IsSparseMatrix<MT2>::value && IsRowMajorMatrix<MT2>::value &&
1231 IsDenseVector<VT>::value && IsColumnVector<VT>::value
1232 ,
typename SMatDVecMultExprTrait< MT1, typename SMatDVecMultExprTrait<MT2,VT>::Type >::Type
1233 , INVALID_TYPE >::Type Type;
1242 template<
typename MT1,
typename MT2,
typename VT >
1247 typedef typename SelectType< IsSparseMatrix<MT1>::value && IsRowMajorMatrix<MT1>::value &&
1248 IsSparseMatrix<MT2>::value && IsRowMajorMatrix<MT2>::value &&
1249 IsSparseVector<VT>::value && IsColumnVector<VT>::value
1250 ,
typename SMatSVecMultExprTrait< MT1, typename SMatSVecMultExprTrait<MT2,VT>::Type >::Type
1251 , INVALID_TYPE >::Type Type;
1260 template<
typename VT,
typename MT1,
typename MT2 >
1265 typedef typename SelectType< IsDenseVector<VT>::value && IsRowVector<VT>::value &&
1266 IsSparseMatrix<MT1>::value && IsRowMajorMatrix<MT1>::value &&
1267 IsSparseMatrix<MT2>::value && IsRowMajorMatrix<MT2>::value
1268 ,
typename TDVecSMatMultExprTrait< typename TDVecSMatMultExprTrait<VT,MT1>::Type, MT2 >::Type
1269 , INVALID_TYPE >::Type Type;
1278 template<
typename VT,
typename MT1,
typename MT2 >
1283 typedef typename SelectType< IsSparseVector<VT>::value && IsRowVector<VT>::value &&
1284 IsSparseMatrix<MT1>::value && IsRowMajorMatrix<MT1>::value &&
1285 IsSparseMatrix<MT2>::value && IsRowMajorMatrix<MT2>::value
1286 ,
typename TSVecSMatMultExprTrait< typename TSVecSMatMultExprTrait<VT,MT1>::Type, MT2 >::Type
1287 , INVALID_TYPE >::Type Type;
1296 template<
typename MT1,
typename MT2,
bool AF >
1301 typedef typename MultExprTrait< typename SubmatrixExprTrait<const MT1,AF>::Type
1302 ,
typename SubmatrixExprTrait<const MT2,AF>::Type >::Type Type;
1311 template<
typename MT1,
typename MT2 >
1316 typedef typename MultExprTrait< typename RowExprTrait<const MT1>::Type, MT2 >::Type Type;
1325 template<
typename MT1,
typename MT2 >
1330 typedef typename MultExprTrait< MT1, typename ColumnExprTrait<const MT2>::Type >::Type Type;
Header file for the SMatDVecMultExprTrait class template.
Header file for the Rows type trait.
Header file for the UNUSED_PARAMETER function template.
const DMatDMatMultExpr< T1, T2 > operator*(const DenseMatrix< T1, false > &lhs, const DenseMatrix< T2, false > &rhs)
Multiplication operator for the multiplication of two row-major dense matrices ( ).
Definition: DMatDMatMultExpr.h:4838
BLAZE_ALWAYS_INLINE MT::Iterator end(Matrix< MT, SO > &matrix, size_t i)
Returns an iterator just past the last element of row/column i.
Definition: Matrix.h:258
MultTrait< RT1, RT2 >::Type ResultType
Result type for expression template evaluations.
Definition: SMatSMatMultExpr.h:170
Header file for the IsSparseMatrix type trait.
Efficient implementation of a compressed matrix.The CompressedMatrix class template is the represent...
Definition: CompressedMatrix.h:205
Header file for the ColumnExprTrait class template.
bool canSMPAssign() const
Returns whether the expression can be used in SMP assignments.
Definition: SMatSMatMultExpr.h:346
Header file for the IsColumnMajorMatrix type trait.
ResultType::ElementType ElementType
Resulting element type.
Definition: SMatSMatMultExpr.h:173
const This & CompositeType
Data type for composite expression templates.
Definition: CompressedMatrix.h:2478
RightOperand rightOperand() const
Returns the right-hand side sparse matrix operand.
Definition: SMatSMatMultExpr.h:312
Header file for the IsRowVector type trait.
Type ElementType
Type of the sparse matrix elements.
Definition: CompressedMatrix.h:257
void UNUSED_PARAMETER(const T1 &)
Suppression of unused parameter warnings.
Definition: Unused.h:81
Header file for the TDVecSMatMultExprTrait class template.
const DMatSerialExpr< MT, SO > serial(const DenseMatrix< MT, SO > &dm)
Forces the serial evaluation of the given dense matrix expression dm.
Definition: DMatSerialExpr.h:695
Header file for the Computation base class.
Header file for the MatMatMultExpr base class.
Header file for the RequiresEvaluation type trait.
Header file for the TSVecSMatMultExprTrait class template.
size_t nonZeros() const
Returns the number of non-zero elements in the sparse matrix.
Definition: SMatSMatMultExpr.h:280
MT1::CompositeType CT1
Composite type of the left-hand side sparse matrix expression.
Definition: SMatSMatMultExpr.h:123
Header file for the implementation of an arbitrarily sized vector.
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:107
ResultType::OppositeType OppositeType
Result type with opposite storage order for expression template evaluations.
Definition: SMatSMatMultExpr.h:171
MT1::ResultType RT1
Result type of the left-hand side sparse matrix expression.
Definition: SMatSMatMultExpr.h:121
Header file for the SparseMatrix base class.
ResultType::TransposeType TransposeType
Transpose type for expression template evaluations.
Definition: SMatSMatMultExpr.h:172
Constraint on the data type.
Header file for the MultExprTrait class template.
Compile time check to query the requirement to evaluate an expression.Via this type trait it is possi...
Definition: RequiresEvaluation.h:90
const ElementType ReturnType
Return type for expression template evaluations.
Definition: SMatSMatMultExpr.h:174
Compile time type selection.The SelectType class template selects one of the two given types T1 and T...
Definition: SelectType.h:59
Header file for the DisableIf class template.
size_t rows() const
Returns the current number of rows of the matrix.
Definition: SMatSMatMultExpr.h:260
size_t columns() const
Returns the current number of columns of the matrix.
Definition: SMatSMatMultExpr.h:270
Header file for the multiplication trait.
Header file for the IsSymmetric type trait.
RightOperand rhs_
Right-hand side sparse matrix of the multiplication expression.
Definition: SMatSMatMultExpr.h:354
SMatSMatMultExpr< MT1, MT2 > This
Type of this SMatSMatMultExpr instance.
Definition: SMatSMatMultExpr.h:169
SelectType< IsExpression< MT1 >::value, const MT1, const MT1 & >::Type LeftOperand
Composite type of the left-hand side sparse matrix expression.
Definition: SMatSMatMultExpr.h:178
const Element * ConstIterator
Iterator over constant elements.
Definition: CompressedMatrix.h:2482
BLAZE_ALWAYS_INLINE 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:635
Header file for the Columns type trait.
Numerical infinity for built-in data types.
bool canAlias(const T *alias) const
Returns whether the expression can alias with the given address alias.
Definition: SMatSMatMultExpr.h:324
Header file for the IsLower type trait.
LeftOperand leftOperand() const
Returns the left-hand side sparse matrix operand.
Definition: SMatSMatMultExpr.h:302
Header file for the SMatSVecMultExprTrait class template.
SMatSMatMultExpr(const MT1 &lhs, const MT2 &rhs)
Constructor for the SMatSMatMultExpr class.
Definition: SMatSMatMultExpr.h:196
bool isAliased(const T *alias) const
Returns whether the expression is aliased with the given address alias.
Definition: SMatSMatMultExpr.h:336
Constraints on the storage order of matrix types.
const size_t SMP_SMATSMATMULT_THRESHOLD
SMP row-major sparse matrix/row-major sparse matrix multiplication threshold.This threshold specifies...
Definition: Thresholds.h:1110
Header file for the SelectType class template.
Header file for the RowExprTrait class template.
Header file for all forward declarations for expression class templates.
Header file for the EnableIf class template.
Header file for the serial shim.
#define BLAZE_CONSTRAINT_MUST_FORM_VALID_MATMATMULTEXPR(T1, T2)
Constraint on the data type.In case the given data types T1 and T2 do not form a valid matrix/matrix ...
Definition: MatMatMultExpr.h:165
Header file for the byte type.
Compile time check for resizable data types.This type trait tests whether the given data type is a re...
Definition: IsResizable.h:75
size_t nonZeros(size_t i) const
Returns the number of non-zero elements in the specified row.
Definition: SMatSMatMultExpr.h:291
EnableIf< IsDenseMatrix< MT1 > >::Type smpSubAssign(Matrix< MT1, SO1 > &lhs, const Matrix< MT2, SO2 > &rhs)
Default implementation of the SMP subtraction assignment of a matrix to dense matrix.
Definition: DenseMatrix.h:160
Header file for the IsSparseVector type trait.
#define BLAZE_CONSTRAINT_MUST_NOT_BE_SYMMETRIC_MATRIX_TYPE(T)
Constraint on the data type.In case the given data type T is a symmetric matrix type, a compilation error is created.
Definition: Symmetric.h:116
Header file for the SubmatrixExprTrait class template.
#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
Removal of reference modifiers.The RemoveCV type trait removes any reference modifiers from the given...
Definition: RemoveReference.h:69
Expression object for sparse matrix-sparse matrix multiplications.The SMatSMatMultExpr class represen...
Definition: Forward.h:97
Header file for run time assertion macros.
EnableIf< IsDenseMatrix< MT1 > >::Type smpAssign(Matrix< MT1, SO1 > &lhs, const Matrix< MT2, SO2 > &rhs)
Default implementation of the SMP assignment of a matrix to a dense matrix.
Definition: DenseMatrix.h:98
Utility type for generic codes.
Base template for the MultTrait class.
Definition: MultTrait.h:142
BLAZE_ALWAYS_INLINE 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:742
Header file for the reset shim.
Header file for the isDefault shim.
BLAZE_ALWAYS_INLINE bool isDefault(const NonNumericProxy< MT > &proxy)
Returns whether the represented element is in default state.
Definition: NonNumericProxy.h:874
Constraint on the data type.
const Infinity inf
Global Infinity instance.The blaze::inf instance can be used wherever a built-in data type is expecte...
Definition: Infinity.h:1098
ReturnType operator()(size_t i, size_t j) const
2D-access to the matrix elements.
Definition: SMatSMatMultExpr.h:211
BLAZE_ALWAYS_INLINE void reset(const NonNumericProxy< MT > &proxy)
Resetting the represented element to the default initial values.
Definition: NonNumericProxy.h:833
Header file for the RemoveReference type trait.
Substitution Failure Is Not An Error (SFINAE) class.The DisableIf class template is an auxiliary tool...
Definition: DisableIf.h:184
Header file for the IsDenseVector type trait.
LeftOperand lhs_
Left-hand side sparse matrix of the multiplication expression.
Definition: SMatSMatMultExpr.h:353
SelectType< IsExpression< MT2 >::value, const MT2, const MT2 & >::Type RightOperand
Composite type of the right-hand side sparse matrix expression.
Definition: SMatSMatMultExpr.h:181
Header file for the IsRowMajorMatrix type trait.
const DMatTransExpr< MT,!SO > trans(const DenseMatrix< MT, SO > &dm)
Calculation of the transpose of the given dense matrix.
Definition: DMatTransExpr.h:932
Header file for the IsComputation type trait class.
MT2::ResultType RT2
Result type of the right-hand side sparse matrix expression.
Definition: SMatSMatMultExpr.h:122
EnableIf< IsDenseMatrix< MT1 > >::Type smpAddAssign(Matrix< 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:129
#define BLAZE_FUNCTION_TRACE
Function trace macro.This macro can be used to reliably trace function calls. In case function tracin...
Definition: FunctionTrace.h:157
This ResultType
Result type for expression template evaluations.
Definition: CompressedMatrix.h:2473
Header file for the IsTrue value trait.
Header file for basic type definitions.
Header file for the IsUpper type trait.
Header file for the IsColumnVector type trait.
Constraint on the data type.
Header file for the IsResizable type trait.
Header file for the thresholds for matrix/vector and matrix/matrix multiplications.
#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
const ResultType CompositeType
Data type for composite expression templates.
Definition: SMatSMatMultExpr.h:175
#define BLAZE_CONSTRAINT_MUST_BE_SPARSE_MATRIX_TYPE(T)
Constraint on the data type.In case the given data type T is not a sparse, N-dimensional matrix type...
Definition: SparseMatrix.h:79
Header file for the IsExpression type trait class.
Header file for the FunctionTrace class.
BLAZE_ALWAYS_INLINE 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:849
MT2::CompositeType CT2
Composite type of the right-hand side sparse matrix expression.
Definition: SMatSMatMultExpr.h:124