35 #ifndef _BLAZE_MATH_EXPRESSIONS_SMATSMATMULTEXPR_H_
36 #define _BLAZE_MATH_EXPRESSIONS_SMATSMATMULTEXPR_H_
120 template<
typename MT1
122 class SMatSMatMultExpr :
public SparseMatrix< SMatSMatMultExpr<MT1,MT2>, false >
123 ,
private MatMatMultExpr
124 ,
private Computation
151 template<
typename T1,
typename T2,
typename T3 >
152 struct CanExploitSymmetry {
153 enum { value = IsColumnMajorMatrix<T1>::value &&
154 IsSymmetric<T2>::value && IsSymmetric<T3>::value };
166 template<
typename T1,
typename T2,
typename T3 >
167 struct IsEvaluationRequired {
168 enum { value = ( evaluateLeft || evaluateRight ) &&
169 !CanExploitSymmetry<T1,T2,T3>::value };
193 enum { smpAssignable = !evaluateLeft && MT1::smpAssignable &&
194 !evaluateRight && MT2::smpAssignable };
227 if(
lhs_.columns() == 0UL )
244 tmp = element->value() *
rhs_(element->index(),j);
246 for( ; element!=
end; ++element ) {
247 tmp += element->value() *
rhs_(element->index(),j);
258 tmp =
lhs_(i,kbegin) *
rhs_(kbegin,j);
259 for(
size_t k=kbegin+1UL; k<kend; ++k ) {
276 inline ReturnType
at(
size_t i,
size_t j )
const {
277 if( i >=
lhs_.rows() ) {
280 if( j >=
rhs_.columns() ) {
303 return rhs_.columns();
355 template<
typename T >
357 return (
lhs_.isAliased( alias ) ||
rhs_.isAliased( alias ) );
367 template<
typename T >
369 return (
lhs_.isAliased( alias ) ||
rhs_.isAliased( alias ) );
379 return (
rows() > SMP_SMATSMATMULT_THRESHOLD );
402 template<
typename MT
412 CT1 A(
serial( rhs.lhs_ ) );
413 CT2 B(
serial( rhs.rhs_ ) );
422 SMatSMatMultExpr::selectAssignKernel( ~lhs, A, B );
440 template<
typename MT3
443 static inline void selectAssignKernel( MT3& C,
const MT4& A,
const MT5& B )
448 for(
size_t i=0UL; i<C.rows(); ++i ) {
449 const LeftIterator lend( A.end(i) );
450 for( LeftIterator lelem=A.begin(i); lelem!=lend; ++lelem ) {
451 const RightIterator rend( B.end( lelem->index() ) );
452 for( RightIterator relem=B.begin( lelem->index() ); relem!=rend; ++relem )
456 C(i,relem->index()) = lelem->value() * relem->value();
459 C(i,relem->index()) += lelem->value() * relem->value();
481 template<
typename MT >
482 friend inline void assign( SparseMatrix<MT,false>& lhs,
const SMatSMatMultExpr& rhs )
492 CT1 A(
serial( rhs.lhs_ ) );
493 CT2 B(
serial( rhs.rhs_ ) );
503 size_t nonzeros( 0UL );
505 for(
size_t i=0UL; i<(~lhs).
rows(); ++i ) {
506 const LeftIterator lend( A.end(i) );
507 for( LeftIterator lelem=A.begin(i); lelem!=lend; ++lelem ) {
508 nonzeros += B.nonZeros( lelem->index() );
512 if( nonzeros > (~lhs).rows() * (~lhs).
columns() ) {
516 (~lhs).reserve( nonzeros );
521 std::vector<byte> valid ( (~lhs).
columns(), 0 );
522 std::vector<size_t> indices( (~lhs).
columns(), 0UL );
523 size_t minIndex(
inf ), maxIndex( 0UL );
525 for(
size_t i=0UL; i<(~lhs).
rows(); ++i )
527 const LeftIterator lend( A.end(i) );
528 for( LeftIterator lelem=A.begin(i); lelem!=lend; ++lelem )
530 const RightIterator rend( B.end( lelem->index() ) );
531 for( RightIterator relem=B.begin( lelem->index() ); relem!=rend; ++relem )
533 if( !valid[relem->index()] ) {
534 values[relem->index()] = lelem->value() * relem->value();
535 valid [relem->index()] = 1;
536 indices[nonzeros] = relem->index();
538 if( relem->index() < minIndex ) minIndex = relem->index();
539 if( relem->index() > maxIndex ) maxIndex = relem->index();
542 values[relem->index()] += lelem->value() * relem->value();
553 if( ( nonzeros + nonzeros ) < ( maxIndex - minIndex ) )
555 std::sort( indices.begin(), indices.begin() + nonzeros );
557 for(
size_t j=0UL; j<nonzeros; ++j )
559 const size_t index( indices[j] );
561 (~lhs).append( i, index, values[index] );
562 reset( values[index] );
565 reset( valid [index] );
569 for(
size_t j=minIndex; j<=maxIndex; ++j )
572 (~lhs).append( i, j, values[j] );
585 (~lhs).finalize( i );
604 template<
typename MT >
605 friend inline typename DisableIf< CanExploitSymmetry<MT,MT1,MT2> >::Type
618 const ResultType tmp(
serial( rhs ) );
619 (~lhs).reserve( tmp.nonZeros() );
640 template<
typename MT >
641 friend inline typename EnableIf< CanExploitSymmetry<MT,MT1,MT2> >::Type
651 assign( ~lhs,
trans( rhs.lhs_ ) *
trans( rhs.rhs_ ) );
669 template<
typename MT
671 friend inline typename DisableIf< CanExploitSymmetry<MT,MT1,MT2> >::Type
679 CT1 A(
serial( rhs.lhs_ ) );
680 CT2 B(
serial( rhs.rhs_ ) );
689 SMatSMatMultExpr::selectAddAssignKernel( ~lhs, A, B );
708 template<
typename MT3
711 static inline void selectAddAssignKernel( MT3& C,
const MT4& A,
const MT5& B )
716 for(
size_t i=0UL; i<C.rows(); ++i ) {
717 const LeftIterator lend( A.end(i) );
718 for( LeftIterator lelem=A.begin(i); lelem!=lend; ++lelem ) {
719 const RightIterator rend( B.end( lelem->index() ) );
720 for( RightIterator relem=B.begin( lelem->index() ); relem!=rend; ++relem ) {
721 C(i,relem->index()) += lelem->value() * relem->value();
744 template<
typename MT >
745 friend inline typename EnableIf< CanExploitSymmetry<MT,MT1,MT2> >::Type
755 addAssign( ~lhs,
trans( rhs.lhs_ ) *
trans( rhs.rhs_ ) );
777 template<
typename MT
779 friend inline typename DisableIf< CanExploitSymmetry<MT,MT1,MT2> >::Type
787 CT1 A(
serial( rhs.lhs_ ) );
788 CT2 B(
serial( rhs.rhs_ ) );
797 SMatSMatMultExpr::selectSubAssignKernel( ~lhs, A, B );
816 template<
typename MT3
819 static inline void selectSubAssignKernel( MT3& C,
const MT4& A,
const MT5& B )
824 for(
size_t i=0UL; i<C.rows(); ++i ) {
825 const LeftIterator lend( A.end(i) );
826 for( LeftIterator lelem=A.begin(i); lelem!=lend; ++lelem ) {
827 const RightIterator rend( B.end( lelem->index() ) );
828 for( RightIterator relem=B.begin( lelem->index() ); relem!=rend; ++relem ) {
829 C(i,relem->index()) -= lelem->value() * relem->value();
852 template<
typename MT >
853 friend inline typename EnableIf< CanExploitSymmetry<MT,MT1,MT2> >::Type
863 subAssign( ~lhs,
trans( rhs.lhs_ ) *
trans( rhs.rhs_ ) );
895 template<
typename MT
897 friend inline typename EnableIf< IsEvaluationRequired<MT,MT1,MT2> >::Type
935 template<
typename MT >
936 friend inline typename EnableIf< CanExploitSymmetry<MT,MT1,MT2> >::Type
967 template<
typename MT
969 friend inline typename EnableIf< IsEvaluationRequired<MT,MT1,MT2> >::Type
1007 template<
typename MT >
1008 friend inline typename EnableIf< CanExploitSymmetry<MT,MT1,MT2> >::Type
1043 template<
typename MT
1045 friend inline typename EnableIf< IsEvaluationRequired<MT,MT1,MT2> >::Type
1083 template<
typename MT >
1084 friend inline typename EnableIf< CanExploitSymmetry<MT,MT1,MT2> >::Type
1159 template<
typename T1
1161 inline const SMatSMatMultExpr<T1,T2>
1185 template<
typename MT1,
typename MT2 >
1202 template<
typename MT1,
typename MT2 >
1219 template<
typename MT1,
typename MT2 >
1221 :
public IsTrue< And< IsLower<MT1>, IsLower<MT2> >::value >
1237 template<
typename MT1,
typename MT2 >
1239 :
public IsTrue< And< IsUniLower<MT1>, IsUniLower<MT2> >::value >
1255 template<
typename MT1,
typename MT2 >
1257 :
public IsTrue< Or< And< IsStrictlyLower<MT1>, IsLower<MT2> >
1258 , And< IsStrictlyLower<MT2>, IsLower<MT1> > >::value >
1274 template<
typename MT1,
typename MT2 >
1276 :
public IsTrue< And< IsUpper<MT1>, IsUpper<MT2> >::value >
1292 template<
typename MT1,
typename MT2 >
1294 :
public IsTrue< And< IsUniUpper<MT1>, IsUniUpper<MT2> >::value >
1310 template<
typename MT1,
typename MT2 >
1312 :
public IsTrue< Or< And< IsStrictlyUpper<MT1>, IsUpper<MT2> >
1313 , And< IsStrictlyUpper<MT2>, IsUpper<MT1> > >::value >
1329 template<
typename MT1,
typename MT2,
typename VT >
1334 typedef typename SelectType< IsSparseMatrix<MT1>::value && IsRowMajorMatrix<MT1>::value &&
1335 IsSparseMatrix<MT2>::value && IsRowMajorMatrix<MT2>::value &&
1336 IsDenseVector<VT>::value && IsColumnVector<VT>::value
1337 ,
typename SMatDVecMultExprTrait< MT1, typename SMatDVecMultExprTrait<MT2,VT>::Type >::Type
1338 , INVALID_TYPE >::Type Type;
1347 template<
typename MT1,
typename MT2,
typename VT >
1352 typedef typename SelectType< IsSparseMatrix<MT1>::value && IsRowMajorMatrix<MT1>::value &&
1353 IsSparseMatrix<MT2>::value && IsRowMajorMatrix<MT2>::value &&
1354 IsSparseVector<VT>::value && IsColumnVector<VT>::value
1355 ,
typename SMatSVecMultExprTrait< MT1, typename SMatSVecMultExprTrait<MT2,VT>::Type >::Type
1356 , INVALID_TYPE >::Type Type;
1365 template<
typename VT,
typename MT1,
typename MT2 >
1370 typedef typename SelectType< IsDenseVector<VT>::value && IsRowVector<VT>::value &&
1371 IsSparseMatrix<MT1>::value && IsRowMajorMatrix<MT1>::value &&
1372 IsSparseMatrix<MT2>::value && IsRowMajorMatrix<MT2>::value
1373 ,
typename TDVecSMatMultExprTrait< typename TDVecSMatMultExprTrait<VT,MT1>::Type, MT2 >::Type
1374 , INVALID_TYPE >::Type Type;
1383 template<
typename VT,
typename MT1,
typename MT2 >
1388 typedef typename SelectType< IsSparseVector<VT>::value && IsRowVector<VT>::value &&
1389 IsSparseMatrix<MT1>::value && IsRowMajorMatrix<MT1>::value &&
1390 IsSparseMatrix<MT2>::value && IsRowMajorMatrix<MT2>::value
1391 ,
typename TSVecSMatMultExprTrait< typename TSVecSMatMultExprTrait<VT,MT1>::Type, MT2 >::Type
1392 , INVALID_TYPE >::Type Type;
1401 template<
typename MT1,
typename MT2,
bool AF >
1406 typedef typename MultExprTrait< typename SubmatrixExprTrait<const MT1,AF>::Type
1407 ,
typename SubmatrixExprTrait<const MT2,AF>::Type >::Type Type;
1416 template<
typename MT1,
typename MT2 >
1421 typedef typename MultExprTrait< typename RowExprTrait<const MT1>::Type, MT2 >::Type Type;
1430 template<
typename MT1,
typename MT2 >
1435 typedef typename MultExprTrait< MT1, typename ColumnExprTrait<const MT2>::Type >::Type Type;
#define BLAZE_THROW_INVALID_ARGUMENT(MESSAGE)
Macro for the emission of a std::invalid_argument exceptionThis macro encapsulates the default way of...
Definition: Exception.h:187
const MT::ElementType max(const DenseMatrix< MT, SO > &dm)
Returns the largest element of the dense matrix.
Definition: DenseMatrix.h:1729
MT2::CompositeType CT2
Composite type of the right-hand side sparse matrix expression.
Definition: SMatSMatMultExpr.h:131
Header file for mathematical functions.
Header file for the SMatDVecMultExprTrait class template.
MT1::CompositeType CT1
Composite type of the left-hand side sparse matrix expression.
Definition: SMatSMatMultExpr.h:130
bool canSMPAssign() const
Returns whether the expression can be used in SMP assignments.
Definition: SMatSMatMultExpr.h:378
RightOperand rhs_
Right-hand side sparse matrix of the multiplication expression.
Definition: SMatSMatMultExpr.h:386
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:7820
Header file for basic type definitions.
ReturnType operator()(size_t i, size_t j) const
2D-access to the matrix elements.
Definition: SMatSMatMultExpr.h:218
bool canAlias(const T *alias) const
Returns whether the expression can alias with the given address alias.
Definition: SMatSMatMultExpr.h:356
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:250
Header file for the IsSparseMatrix type trait.
Efficient implementation of a compressed matrix.The CompressedMatrix class template is the represent...
Definition: CompressedMatrix.h:207
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:507
const This & CompositeType
Data type for composite expression templates.
Definition: CompressedMatrix.h:2588
Header file for the IsRowVector type trait.
Type ElementType
Type of the sparse matrix elements.
Definition: CompressedMatrix.h:259
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:721
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
Constraints on the storage order of matrix types.
Header file for the RequiresEvaluation type trait.
ResultType::ElementType ElementType
Resulting element type.
Definition: SMatSMatMultExpr.h:180
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:117
bool isDefault(const DiagonalProxy< MT > &proxy)
Returns whether the represented element is in default state.
Definition: DiagonalProxy.h:547
const ElementType ReturnType
Return type for expression template evaluations.
Definition: SMatSMatMultExpr.h:181
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:188
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:179
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:385
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:178
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:368
const Element * ConstIterator
Iterator over constant elements.
Definition: CompressedMatrix.h:2592
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:185
size_t nonZeros() const
Returns the number of non-zero elements in the sparse matrix.
Definition: SMatSMatMultExpr.h:312
#define BLAZE_THROW_OUT_OF_RANGE(MESSAGE)
Macro for the emission of a std::out_of_range exceptionThis macro encapsulates the default way of Bla...
Definition: Exception.h:331
const MT::ElementType min(const DenseMatrix< MT, SO > &dm)
Returns the smallest element of the dense matrix.
Definition: DenseMatrix.h:1682
SMatSMatMultExpr(const MT1 &lhs, const MT2 &rhs)
Constructor for the SMatSMatMultExpr class.
Definition: SMatSMatMultExpr.h:203
Header file for the Columns type trait.
MT1::ResultType RT1
Result type of the left-hand side sparse matrix expression.
Definition: SMatSMatMultExpr.h:128
Numerical infinity for built-in data types.
SMatSMatMultExpr< MT1, MT2 > This
Type of this SMatSMatMultExpr instance.
Definition: SMatSMatMultExpr.h:176
size_t nonZeros(size_t i) const
Returns the number of non-zero elements in the specified row.
Definition: SMatSMatMultExpr.h:323
Header file for the IsLower type trait.
Header file for the SMatSVecMultExprTrait class template.
size_t rows() const
Returns the current number of rows of the matrix.
Definition: SMatSMatMultExpr.h:292
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:344
#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
ReturnType at(size_t i, size_t j) const
Checked access to the matrix elements.
Definition: SMatSMatMultExpr.h:276
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: RowMajorMatrix.h:79
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:107
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:138
const ResultType CompositeType
Data type for composite expression templates.
Definition: SMatSMatMultExpr.h:182
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:334
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:302
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:944
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:2583
Header file for the IsTrue value trait.
Header file for the IsUpper type trait.
Header file for exception macros.
MT2::ResultType RT2
Result type of the right-hand side sparse matrix expression.
Definition: SMatSMatMultExpr.h:129
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.
MultTrait< RT1, RT2 >::Type ResultType
Result type for expression template evaluations.
Definition: SMatSMatMultExpr.h:177