35 #ifndef _BLAZE_MATH_EXPRESSIONS_SMATSMATMULTEXPR_H_
36 #define _BLAZE_MATH_EXPRESSIONS_SMATSMATMULTEXPR_H_
119 template<
typename MT1
121 class SMatSMatMultExpr :
public SparseMatrix< SMatSMatMultExpr<MT1,MT2>, false >
122 ,
private MatMatMultExpr
123 ,
private Computation
150 template<
typename T1,
typename T2,
typename T3 >
151 struct CanExploitSymmetry {
152 enum { value = IsColumnMajorMatrix<T1>::value &&
153 IsSymmetric<T2>::value && IsSymmetric<T3>::value };
165 template<
typename T1,
typename T2,
typename T3 >
166 struct IsEvaluationRequired {
167 enum { value = ( evaluateLeft || evaluateRight ) &&
168 !CanExploitSymmetry<T1,T2,T3>::value };
192 enum { smpAssignable = !evaluateLeft && MT1::smpAssignable &&
193 !evaluateRight && MT2::smpAssignable };
226 if(
lhs_.columns() == 0UL )
243 tmp = element->value() *
rhs_(element->index(),j);
245 for( ; element!=
end; ++element ) {
246 tmp += element->value() *
rhs_(element->index(),j);
257 tmp =
lhs_(i,kbegin) *
rhs_(kbegin,j);
258 for(
size_t k=kbegin+1UL; k<kend; ++k ) {
283 return rhs_.columns();
335 template<
typename T >
337 return (
lhs_.isAliased( alias ) ||
rhs_.isAliased( alias ) );
347 template<
typename T >
349 return (
lhs_.isAliased( alias ) ||
rhs_.isAliased( alias ) );
382 template<
typename MT
392 CT1 A(
serial( rhs.lhs_ ) );
393 CT2 B(
serial( rhs.rhs_ ) );
402 SMatSMatMultExpr::selectAssignKernel( ~lhs, A, B );
420 template<
typename MT3
423 static inline void selectAssignKernel( MT3& C,
const MT4& A,
const MT5& B )
428 for(
size_t i=0UL; i<C.rows(); ++i ) {
429 const LeftIterator lend( A.end(i) );
430 for( LeftIterator lelem=A.begin(i); lelem!=lend; ++lelem ) {
431 const RightIterator rend( B.end( lelem->index() ) );
432 for( RightIterator relem=B.begin( lelem->index() ); relem!=rend; ++relem )
436 C(i,relem->index()) = lelem->value() * relem->value();
439 C(i,relem->index()) += lelem->value() * relem->value();
461 template<
typename MT >
472 CT1 A(
serial( rhs.lhs_ ) );
473 CT2 B(
serial( rhs.rhs_ ) );
483 size_t nonzeros( 0UL );
485 for(
size_t i=0UL; i<(~lhs).
rows(); ++i ) {
486 const LeftIterator lend( A.end(i) );
487 for( LeftIterator lelem=A.begin(i); lelem!=lend; ++lelem ) {
488 nonzeros += B.nonZeros( lelem->index() );
492 if( nonzeros > (~lhs).rows() * (~lhs).
columns() ) {
496 (~lhs).reserve( nonzeros );
501 std::vector<byte> valid ( (~lhs).
columns(), 0 );
502 std::vector<size_t> indices( (~lhs).
columns(), 0UL );
503 size_t minIndex(
inf ), maxIndex( 0UL );
505 for(
size_t i=0UL; i<(~lhs).
rows(); ++i )
507 const LeftIterator lend( A.end(i) );
508 for( LeftIterator lelem=A.begin(i); lelem!=lend; ++lelem )
510 const RightIterator rend( B.end( lelem->index() ) );
511 for( RightIterator relem=B.begin( lelem->index() ); relem!=rend; ++relem )
513 if( !valid[relem->index()] ) {
514 values[relem->index()] = lelem->value() * relem->value();
515 valid [relem->index()] = 1;
516 indices[nonzeros] = relem->index();
518 if( relem->index() < minIndex ) minIndex = relem->index();
519 if( relem->index() > maxIndex ) maxIndex = relem->index();
522 values[relem->index()] += lelem->value() * relem->value();
533 if( ( nonzeros + nonzeros ) < ( maxIndex - minIndex ) )
535 std::sort( indices.begin(), indices.begin() + nonzeros );
537 for(
size_t j=0UL; j<nonzeros; ++j )
539 const size_t index( indices[j] );
541 (~lhs).append( i, index, values[index] );
542 reset( values[index] );
545 reset( valid [index] );
549 for(
size_t j=minIndex; j<=maxIndex; ++j )
552 (~lhs).append( i, j, values[j] );
565 (~lhs).finalize( i );
584 template<
typename MT >
585 friend inline typename DisableIf< CanExploitSymmetry<MT,MT1,MT2> >::Type
598 const ResultType tmp(
serial( rhs ) );
599 (~lhs).reserve( tmp.nonZeros() );
620 template<
typename MT >
621 friend inline typename EnableIf< CanExploitSymmetry<MT,MT1,MT2> >::Type
649 template<
typename MT
651 friend inline typename DisableIf< CanExploitSymmetry<MT,MT1,MT2> >::Type
659 CT1 A(
serial( rhs.lhs_ ) );
660 CT2 B(
serial( rhs.rhs_ ) );
669 SMatSMatMultExpr::selectAddAssignKernel( ~lhs, A, B );
688 template<
typename MT3
691 static inline void selectAddAssignKernel( MT3& C,
const MT4& A,
const MT5& B )
696 for(
size_t i=0UL; i<C.rows(); ++i ) {
697 const LeftIterator lend( A.end(i) );
698 for( LeftIterator lelem=A.begin(i); lelem!=lend; ++lelem ) {
699 const RightIterator rend( B.end( lelem->index() ) );
700 for( RightIterator relem=B.begin( lelem->index() ); relem!=rend; ++relem ) {
701 C(i,relem->index()) += lelem->value() * relem->value();
724 template<
typename MT >
725 friend inline typename EnableIf< CanExploitSymmetry<MT,MT1,MT2> >::Type
757 template<
typename MT
759 friend inline typename DisableIf< CanExploitSymmetry<MT,MT1,MT2> >::Type
767 CT1 A(
serial( rhs.lhs_ ) );
768 CT2 B(
serial( rhs.rhs_ ) );
777 SMatSMatMultExpr::selectSubAssignKernel( ~lhs, A, B );
796 template<
typename MT3
799 static inline void selectSubAssignKernel( MT3& C,
const MT4& A,
const MT5& B )
804 for(
size_t i=0UL; i<C.rows(); ++i ) {
805 const LeftIterator lend( A.end(i) );
806 for( LeftIterator lelem=A.begin(i); lelem!=lend; ++lelem ) {
807 const RightIterator rend( B.end( lelem->index() ) );
808 for( RightIterator relem=B.begin( lelem->index() ); relem!=rend; ++relem ) {
809 C(i,relem->index()) -= lelem->value() * relem->value();
832 template<
typename MT >
833 friend inline typename EnableIf< CanExploitSymmetry<MT,MT1,MT2> >::Type
875 template<
typename MT
877 friend inline typename EnableIf< IsEvaluationRequired<MT,MT1,MT2> >::Type
915 template<
typename MT >
916 friend inline typename EnableIf< CanExploitSymmetry<MT,MT1,MT2> >::Type
947 template<
typename MT
949 friend inline typename EnableIf< IsEvaluationRequired<MT,MT1,MT2> >::Type
987 template<
typename MT >
988 friend inline typename EnableIf< CanExploitSymmetry<MT,MT1,MT2> >::Type
1023 template<
typename MT
1025 friend inline typename EnableIf< IsEvaluationRequired<MT,MT1,MT2> >::Type
1063 template<
typename MT >
1064 friend inline typename EnableIf< CanExploitSymmetry<MT,MT1,MT2> >::Type
1139 template<
typename T1
1141 inline const SMatSMatMultExpr<T1,T2>
1147 throw std::invalid_argument(
"Matrix sizes do not match" );
1164 template<
typename MT1,
typename MT2 >
1182 template<
typename MT1,
typename MT2 >
1184 :
public Columns<MT2>
1200 template<
typename MT1,
typename MT2 >
1202 :
public IsTrue< And< IsLower<MT1>, IsLower<MT2> >::value >
1218 template<
typename MT1,
typename MT2 >
1220 :
public IsTrue< And< IsUniLower<MT1>, IsUniLower<MT2> >::value >
1236 template<
typename MT1,
typename MT2 >
1238 :
public IsTrue< Or< And< IsStrictlyLower<MT1>, IsLower<MT2> >
1239 , And< IsStrictlyLower<MT2>, IsLower<MT1> > >::value >
1255 template<
typename MT1,
typename MT2 >
1257 :
public IsTrue< And< IsUpper<MT1>, IsUpper<MT2> >::value >
1273 template<
typename MT1,
typename MT2 >
1275 :
public IsTrue< And< IsUniUpper<MT1>, IsUniUpper<MT2> >::value >
1291 template<
typename MT1,
typename MT2 >
1293 :
public IsTrue< Or< And< IsStrictlyUpper<MT1>, IsUpper<MT2> >
1294 , And< IsStrictlyUpper<MT2>, IsUpper<MT1> > >::value >
1310 template<
typename MT1,
typename MT2,
typename VT >
1315 typedef typename SelectType< IsSparseMatrix<MT1>::value && IsRowMajorMatrix<MT1>::value &&
1316 IsSparseMatrix<MT2>::value && IsRowMajorMatrix<MT2>::value &&
1317 IsDenseVector<VT>::value && IsColumnVector<VT>::value
1318 ,
typename SMatDVecMultExprTrait< MT1, typename SMatDVecMultExprTrait<MT2,VT>::Type >::Type
1319 , INVALID_TYPE >::Type Type;
1328 template<
typename MT1,
typename MT2,
typename VT >
1333 typedef typename SelectType< IsSparseMatrix<MT1>::value && IsRowMajorMatrix<MT1>::value &&
1334 IsSparseMatrix<MT2>::value && IsRowMajorMatrix<MT2>::value &&
1335 IsSparseVector<VT>::value && IsColumnVector<VT>::value
1336 ,
typename SMatSVecMultExprTrait< MT1, typename SMatSVecMultExprTrait<MT2,VT>::Type >::Type
1337 , INVALID_TYPE >::Type Type;
1346 template<
typename VT,
typename MT1,
typename MT2 >
1351 typedef typename SelectType< IsDenseVector<VT>::value && IsRowVector<VT>::value &&
1352 IsSparseMatrix<MT1>::value && IsRowMajorMatrix<MT1>::value &&
1353 IsSparseMatrix<MT2>::value && IsRowMajorMatrix<MT2>::value
1354 ,
typename TDVecSMatMultExprTrait< typename TDVecSMatMultExprTrait<VT,MT1>::Type, MT2 >::Type
1355 , INVALID_TYPE >::Type Type;
1364 template<
typename VT,
typename MT1,
typename MT2 >
1369 typedef typename SelectType< IsSparseVector<VT>::value && IsRowVector<VT>::value &&
1370 IsSparseMatrix<MT1>::value && IsRowMajorMatrix<MT1>::value &&
1371 IsSparseMatrix<MT2>::value && IsRowMajorMatrix<MT2>::value
1372 ,
typename TSVecSMatMultExprTrait< typename TSVecSMatMultExprTrait<VT,MT1>::Type, MT2 >::Type
1373 , INVALID_TYPE >::Type Type;
1382 template<
typename MT1,
typename MT2,
bool AF >
1387 typedef typename MultExprTrait< typename SubmatrixExprTrait<const MT1,AF>::Type
1388 ,
typename SubmatrixExprTrait<const MT2,AF>::Type >::Type Type;
1397 template<
typename MT1,
typename MT2 >
1402 typedef typename MultExprTrait< typename RowExprTrait<const MT1>::Type, MT2 >::Type Type;
1411 template<
typename MT1,
typename MT2 >
1416 typedef typename MultExprTrait< MT1, typename ColumnExprTrait<const MT2>::Type >::Type Type;
const MT::ElementType max(const DenseMatrix< MT, SO > &dm)
Returns the largest element of the dense matrix.
Definition: DenseMatrix.h:1649
MT2::CompositeType CT2
Composite type of the right-hand side sparse matrix expression.
Definition: SMatSMatMultExpr.h:130
Header file for the SMatDVecMultExprTrait class template.
MT1::CompositeType CT1
Composite type of the left-hand side sparse matrix expression.
Definition: SMatSMatMultExpr.h:129
bool canSMPAssign() const
Returns whether the expression can be used in SMP assignments.
Definition: SMatSMatMultExpr.h:358
RightOperand rhs_
Right-hand side sparse matrix of the multiplication expression.
Definition: SMatSMatMultExpr.h:366
Header file for the Rows type trait.
Header file for the UNUSED_PARAMETER function template.
Header file for the IsUniUpper type trait.
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:8247
Header file for basic type definitions.
ReturnType operator()(size_t i, size_t j) const
2D-access to the matrix elements.
Definition: SMatSMatMultExpr.h:217
bool canAlias(const T *alias) const
Returns whether the expression can alias with the given address alias.
Definition: SMatSMatMultExpr.h:336
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
Header file for the IsSparseMatrix type trait.
Efficient implementation of a compressed matrix.The CompressedMatrix class template is the represent...
Definition: CompressedMatrix.h:209
Header file for the ColumnExprTrait class template.
Header file for the IsColumnMajorMatrix type trait.
void reset(const DiagonalProxy< MT > &proxy)
Resetting the represented element to the default initial values.
Definition: DiagonalProxy.h:821
const This & CompositeType
Data type for composite expression templates.
Definition: CompressedMatrix.h:2507
Header file for the IsRowVector type trait.
Type ElementType
Type of the sparse matrix elements.
Definition: CompressedMatrix.h:261
void UNUSED_PARAMETER(const T1 &)
Suppression of unused parameter warnings.
Definition: Unused.h:81
Header file for the And class template.
Compile time check for lower triangular matrices.This type trait tests whether or not the given templ...
Definition: IsLower.h:90
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:699
Header file for the Computation base class.
Header file for the MatMatMultExpr base class.
Compile time check for upper triangular matrices.This type trait tests whether or not the given templ...
Definition: IsUpper.h:90
Header file for the RequiresEvaluation type trait.
ResultType::ElementType ElementType
Resulting element type.
Definition: SMatSMatMultExpr.h:179
Header file for the TSVecSMatMultExprTrait class template.
Header file for the IsUniLower type trait.
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
bool isDefault(const DiagonalProxy< MT > &proxy)
Returns whether the represented element is in default state.
Definition: DiagonalProxy.h:861
const ElementType ReturnType
Return type for expression template evaluations.
Definition: SMatSMatMultExpr.h:180
Header file for the SparseMatrix base class.
Constraint on the data type.
SelectType< IsExpression< MT2 >::value, const MT2, const MT2 & >::Type RightOperand
Composite type of the right-hand side sparse matrix expression.
Definition: SMatSMatMultExpr.h:187
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
ResultType::TransposeType TransposeType
Transpose type for expression template evaluations.
Definition: SMatSMatMultExpr.h:178
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.
LeftOperand lhs_
Left-hand side sparse matrix of the multiplication expression.
Definition: SMatSMatMultExpr.h:365
Header file for the multiplication trait.
Header file for the IsStrictlyUpper type trait.
Header file for the IsSymmetric type trait.
ResultType::OppositeType OppositeType
Result type with opposite storage order for expression template evaluations.
Definition: SMatSMatMultExpr.h:177
Namespace of the Blaze C++ math library.
Definition: Blaze.h:57
bool isAliased(const T *alias) const
Returns whether the expression is aliased with the given address alias.
Definition: SMatSMatMultExpr.h:348
const Element * ConstIterator
Iterator over constant elements.
Definition: CompressedMatrix.h:2511
Header file for the Or class template.
SelectType< IsExpression< MT1 >::value, const MT1, const MT1 & >::Type LeftOperand
Composite type of the left-hand side sparse matrix expression.
Definition: SMatSMatMultExpr.h:184
size_t nonZeros() const
Returns the number of non-zero elements in the sparse matrix.
Definition: SMatSMatMultExpr.h:292
const MT::ElementType min(const DenseMatrix< MT, SO > &dm)
Returns the smallest element of the dense matrix.
Definition: DenseMatrix.h:1602
SMatSMatMultExpr(const MT1 &lhs, const MT2 &rhs)
Constructor for the SMatSMatMultExpr class.
Definition: SMatSMatMultExpr.h:202
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.
MT1::ResultType RT1
Result type of the left-hand side sparse matrix expression.
Definition: SMatSMatMultExpr.h:127
Numerical infinity for built-in data types.
SMatSMatMultExpr< MT1, MT2 > This
Type of this SMatSMatMultExpr instance.
Definition: SMatSMatMultExpr.h:175
size_t nonZeros(size_t i) const
Returns the number of non-zero elements in the specified row.
Definition: SMatSMatMultExpr.h:303
Header file for the IsLower type trait.
Header file for the SMatSVecMultExprTrait class template.
Constraints on the storage order of matrix types.
size_t rows() const
Returns the current number of rows of the matrix.
Definition: SMatSMatMultExpr.h:272
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 IsStrictlyLower type trait.
Header file for the serial shim.
RightOperand rightOperand() const
Returns the right-hand side sparse matrix operand.
Definition: SMatSMatMultExpr.h:324
#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
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:150
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
const ResultType CompositeType
Data type for composite expression templates.
Definition: SMatSMatMultExpr.h:181
Header file for the reset shim.
Header file for the isDefault shim.
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
LeftOperand leftOperand() const
Returns the left-hand side sparse matrix operand.
Definition: SMatSMatMultExpr.h:314
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.
size_t columns() const
Returns the current number of columns of the matrix.
Definition: SMatSMatMultExpr.h:282
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:937
Header file for the IsComputation type trait class.
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:2502
Header file for the IsTrue value trait.
Header file for the IsUpper type trait.
MT2::ResultType RT2
Result type of the right-hand side sparse matrix expression.
Definition: SMatSMatMultExpr.h:128
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
#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
MultTrait< RT1, RT2 >::Type ResultType
Result type for expression template evaluations.
Definition: SMatSMatMultExpr.h:176