35 #ifndef _BLAZE_MATH_EXPRESSIONS_TSMATTSMATMULTEXPR_H_
36 #define _BLAZE_MATH_EXPRESSIONS_TSMATTSMATMULTEXPR_H_
119 template<
typename MT1
121 class TSMatTSMatMultExpr :
public SparseMatrix< TSMatTSMatMultExpr<MT1,MT2>, true >
122 ,
private MatMatMultExpr
123 ,
private Computation
150 template<
typename T1,
typename T2,
typename T3 >
151 struct CanExploitSymmetry {
152 enum { value = IsRowMajorMatrix<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 =
lhs_(i,element->index()) * element->value();
245 for( ; element!=
end; ++element ) {
246 tmp +=
lhs_(i,element->index()) * element->value();
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 TSMatTSMatMultExpr::selectAssignKernel( ~lhs, A, B );
421 template<
typename MT3
424 static inline void selectAssignKernel( MT3& C,
const MT4& A,
const MT5& B )
429 for(
size_t j=0UL; j<C.columns(); ++j ) {
430 const RightIterator rend( B.end(j) );
431 for( RightIterator relem=B.begin(j); relem!=rend; ++relem ) {
432 const LeftIterator lend( A.end( relem->index() ) );
433 for( LeftIterator lelem=A.begin( relem->index() ); lelem!=lend; ++lelem )
437 C(lelem->index(),j) = lelem->value() * relem->value();
440 C(lelem->index(),j) += lelem->value() * relem->value();
462 template<
typename MT >
463 friend inline typename DisableIf< CanExploitSymmetry<MT,MT1,MT2> >::Type
476 const ResultType tmp(
serial( rhs ) );
477 (~lhs).reserve( tmp.nonZeros() );
496 template<
typename MT >
507 CT1 A(
serial( rhs.lhs_ ) );
508 CT2 B(
serial( rhs.rhs_ ) );
518 size_t nonzeros( 0UL );
520 for(
size_t j=0UL; j<(~lhs).
columns(); ++j ) {
521 const RightIterator rend( B.end(j) );
522 for( RightIterator relem=B.begin(j); relem!=rend; ++relem ) {
523 nonzeros += A.nonZeros( relem->index() );
527 if( nonzeros > (~lhs).rows() * (~lhs).
columns() ) {
531 (~lhs).reserve( nonzeros );
536 std::vector<byte> valid ( (~lhs).
rows(), 0 );
537 std::vector<size_t> indices( (~lhs).
rows(), 0UL );
538 size_t minIndex(
inf ), maxIndex( 0UL );
540 for(
size_t j=0UL; j<(~lhs).
columns(); ++j )
542 const RightIterator rend( B.end(j) );
543 for( RightIterator relem=B.begin(j); relem!=rend; ++relem )
545 const LeftIterator lend( A.end( relem->index() ) );
546 for( LeftIterator lelem=A.begin( relem->index() ); lelem!=lend; ++lelem )
548 if( !valid[lelem->index()] ) {
549 values[lelem->index()] = lelem->value() * relem->value();
550 valid [lelem->index()] = 1;
551 indices[nonzeros] = lelem->index();
553 if( lelem->index() < minIndex ) minIndex = lelem->index();
554 if( lelem->index() > maxIndex ) maxIndex = lelem->index();
557 values[lelem->index()] += lelem->value() * relem->value();
568 if( ( nonzeros + nonzeros ) < ( maxIndex - minIndex ) )
570 std::sort( indices.begin(), indices.begin() + nonzeros );
572 for(
size_t i=0UL; i<nonzeros; ++i )
574 const size_t index( indices[i] );
576 (~lhs).append( index, j, values[index] );
577 reset( values[index] );
580 reset( valid [index] );
584 for(
size_t i=minIndex; i<=maxIndex; ++i )
587 (~lhs).append( i, j, values[i] );
600 (~lhs).finalize( j );
621 template<
typename MT >
622 friend inline typename EnableIf< CanExploitSymmetry<MT,MT1,MT2> >::Type
650 template<
typename MT
652 friend inline typename DisableIf< CanExploitSymmetry<MT,MT1,MT2> >::Type
660 CT1 A(
serial( rhs.lhs_ ) );
661 CT2 B(
serial( rhs.rhs_ ) );
670 TSMatTSMatMultExpr::selectAddAssignKernel( ~lhs, A, B );
689 template<
typename MT3
692 static inline void selectAddAssignKernel( MT3& C,
const MT4& A,
const MT5& B )
697 for(
size_t j=0UL; j<C.columns(); ++j ) {
698 const RightIterator rend( B.end(j) );
699 for( RightIterator relem=B.begin(j); relem!=rend; ++relem ) {
700 const LeftIterator lend( A.end( relem->index() ) );
701 for( LeftIterator lelem=A.begin( relem->index() ); lelem!=lend; ++lelem ) {
702 C(lelem->index(),j) += lelem->value() * relem->value();
725 template<
typename MT >
726 friend inline typename EnableIf< CanExploitSymmetry<MT,MT1,MT2> >::Type
758 template<
typename MT
760 friend inline typename DisableIf< CanExploitSymmetry<MT,MT1,MT2> >::Type
771 CT1 A(
serial( rhs.lhs_ ) );
772 CT2 B(
serial( rhs.rhs_ ) );
781 TSMatTSMatMultExpr::selectSubAssignKernel( ~lhs, A, B );
800 template<
typename MT3
803 static inline void selectSubAssignKernel( MT3& C,
const MT4& A,
const MT5& B )
808 for(
size_t j=0UL; j<C.columns(); ++j ) {
809 const RightIterator rend( B.end(j) );
810 for( RightIterator relem=B.begin(j); relem!=rend; ++relem ) {
811 const LeftIterator lend( A.end( relem->index() ) );
812 for( LeftIterator lelem=A.begin( relem->index() ); lelem!=lend; ++lelem ) {
813 C(lelem->index(),j) -= lelem->value() * relem->value();
837 template<
typename MT >
838 friend inline typename EnableIf< CanExploitSymmetry<MT,MT1,MT2> >::Type
881 template<
typename MT
883 friend inline typename EnableIf< IsEvaluationRequired<MT,MT1,MT2> >::Type
921 template<
typename MT >
922 friend inline typename EnableIf< CanExploitSymmetry<MT,MT1,MT2> >::Type
953 template<
typename MT
955 friend inline typename EnableIf< IsEvaluationRequired<MT,MT1,MT2> >::Type
994 template<
typename MT >
995 friend inline typename EnableIf< CanExploitSymmetry<MT,MT1,MT2> >::Type
1030 template<
typename MT
1032 friend inline typename EnableIf< IsEvaluationRequired<MT,MT1,MT2> >::Type
1071 template<
typename MT >
1072 friend inline typename EnableIf< CanExploitSymmetry<MT,MT1,MT2> >::Type
1147 template<
typename T1
1149 inline const TSMatTSMatMultExpr<T1,T2>
1155 throw std::invalid_argument(
"Matrix sizes do not match" );
1172 template<
typename MT1,
typename MT2 >
1190 template<
typename MT1,
typename MT2 >
1192 :
public Columns<MT2>
1208 template<
typename MT1,
typename MT2 >
1210 :
public IsTrue< And< IsLower<MT1>, IsLower<MT2> >::value >
1226 template<
typename MT1,
typename MT2 >
1228 :
public IsTrue< And< IsUniLower<MT1>, IsUniLower<MT2> >::value >
1244 template<
typename MT1,
typename MT2 >
1246 :
public IsTrue< Or< And< IsStrictlyLower<MT1>, IsLower<MT2> >
1247 , And< IsStrictlyLower<MT2>, IsLower<MT1> > >::value >
1263 template<
typename MT1,
typename MT2 >
1265 :
public IsTrue< And< IsUpper<MT1>, IsUpper<MT2> >::value >
1281 template<
typename MT1,
typename MT2 >
1283 :
public IsTrue< And< IsUniUpper<MT1>, IsUniUpper<MT2> >::value >
1299 template<
typename MT1,
typename MT2 >
1301 :
public IsTrue< Or< And< IsStrictlyUpper<MT1>, IsUpper<MT2> >
1302 , And< IsStrictlyUpper<MT2>, IsUpper<MT1> > >::value >
1318 template<
typename MT1,
typename MT2,
typename VT >
1323 typedef typename SelectType< IsSparseMatrix<MT1>::value && IsColumnMajorMatrix<MT1>::value &&
1324 IsSparseMatrix<MT2>::value && IsColumnMajorMatrix<MT2>::value &&
1325 IsDenseVector<VT>::value && IsColumnVector<VT>::value
1326 ,
typename TSMatDVecMultExprTrait< MT1, typename TSMatDVecMultExprTrait<MT2,VT>::Type >::Type
1327 , INVALID_TYPE >::Type Type;
1336 template<
typename MT1,
typename MT2,
typename VT >
1341 typedef typename SelectType< IsSparseMatrix<MT1>::value && IsColumnMajorMatrix<MT1>::value &&
1342 IsSparseMatrix<MT2>::value && IsColumnMajorMatrix<MT2>::value &&
1343 IsSparseVector<VT>::value && IsColumnVector<VT>::value
1344 ,
typename TSMatDVecMultExprTrait< MT1, typename TSMatDVecMultExprTrait<MT2,VT>::Type >::Type
1345 , INVALID_TYPE >::Type Type;
1354 template<
typename VT,
typename MT1,
typename MT2 >
1359 typedef typename SelectType< IsDenseVector<VT>::value && IsRowVector<VT>::value &&
1360 IsSparseMatrix<MT1>::value && IsColumnMajorMatrix<MT1>::value &&
1361 IsSparseMatrix<MT2>::value && IsColumnMajorMatrix<MT2>::value
1362 ,
typename TDVecTSMatMultExprTrait< typename TDVecTSMatMultExprTrait<VT,MT1>::Type, MT2 >::Type
1363 , INVALID_TYPE >::Type Type;
1372 template<
typename VT,
typename MT1,
typename MT2 >
1377 typedef typename SelectType< IsSparseVector<VT>::value && IsRowVector<VT>::value &&
1378 IsSparseMatrix<MT1>::value && IsColumnMajorMatrix<MT1>::value &&
1379 IsSparseMatrix<MT2>::value && IsColumnMajorMatrix<MT2>::value
1380 ,
typename TSVecTSMatMultExprTrait< typename TSVecTSMatMultExprTrait<VT,MT1>::Type, MT2 >::Type
1381 , INVALID_TYPE >::Type Type;
1390 template<
typename MT1,
typename MT2,
bool AF >
1395 typedef typename MultExprTrait< typename SubmatrixExprTrait<const MT1,AF>::Type
1396 ,
typename SubmatrixExprTrait<const MT2,AF>::Type >::Type Type;
1405 template<
typename MT1,
typename MT2 >
1410 typedef typename MultExprTrait< typename RowExprTrait<const MT1>::Type, MT2 >::Type Type;
1419 template<
typename MT1,
typename MT2 >
1424 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
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
SelectType< IsExpression< MT2 >::value, const MT2, const MT2 & >::Type RightOperand
Composite type of the right-hand side sparse matrix expression.
Definition: TSMatTSMatMultExpr.h:187
const ElementType ReturnType
Return type for expression template evaluations.
Definition: TSMatTSMatMultExpr.h:180
Header file for basic type definitions.
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
ResultType::TransposeType TransposeType
Transpose type for expression template evaluations.
Definition: TSMatTSMatMultExpr.h:178
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
Header file for the TSVecTSMatMultExprTrait class template.
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
bool canAlias(const T *alias) const
Returns whether the expression can alias with the given address alias.
Definition: TSMatTSMatMultExpr.h:336
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
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.
bool isAliased(const T *alias) const
Returns whether the expression is aliased with the given address alias.
Definition: TSMatTSMatMultExpr.h:348
Header file for the IsUniLower type trait.
LeftOperand leftOperand() const
Returns the left-hand side transpose sparse matrix operand.
Definition: TSMatTSMatMultExpr.h:314
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
Header file for the SparseMatrix base class.
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
size_t rows() const
Returns the current number of rows of the matrix.
Definition: TSMatTSMatMultExpr.h:272
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.
Header file for the multiplication trait.
Header file for the IsStrictlyUpper type trait.
Header file for the IsSymmetric type trait.
Namespace of the Blaze C++ math library.
Definition: Blaze.h:57
const size_t SMP_TSMATTSMATMULT_THRESHOLD
SMP column-major sparse matrix/column-major sparse matrix multiplication threshold.This threshold specifies when a column-major sparse matrix/column-major sparse matrix multiplication can be executed in parallel. In case the number of rows/columns of the target matrix is larger or equal to this threshold, the operation is executed in parallel. If the number of rows/columns is below this threshold the operation is executed single-threaded.
Definition: Thresholds.h:1179
#define BLAZE_CONSTRAINT_MUST_BE_COLUMN_MAJOR_MATRIX_TYPE(T)
Constraint on the data type.In case the given data type T is not a column-major dense or sparse matri...
Definition: StorageOrder.h:161
const Element * ConstIterator
Iterator over constant elements.
Definition: CompressedMatrix.h:2511
Header file for the Or class template.
Header file for the TDVecTSMatMultExprTrait class template.
size_t nonZeros(size_t i) const
Returns the number of non-zero elements in the specified row.
Definition: TSMatTSMatMultExpr.h:303
MT1::CompositeType CT1
Composite type of the left-hand side sparse matrix expression.
Definition: TSMatTSMatMultExpr.h:129
const MT::ElementType min(const DenseMatrix< MT, SO > &dm)
Returns the smallest element of the dense matrix.
Definition: DenseMatrix.h:1602
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.
Header file for the TSMatDVecMultExprTrait class template.
Numerical infinity for built-in data types.
RightOperand rhs_
Right-hand side sparse matrix of the multiplication expression.
Definition: TSMatTSMatMultExpr.h:366
Expression object for transpose sparse matrix-transpose sparse matrix multiplications.The TSMatTSMatMultExpr class represents the compile time expression for multiplications between two column-major sparse matrices.
Definition: Forward.h:145
TSMatTSMatMultExpr(const MT1 &lhs, const MT2 &rhs)
Constructor for the TSMatTSMatMultExpr class.
Definition: TSMatTSMatMultExpr.h:202
Header file for the IsLower type trait.
LeftOperand lhs_
Left-hand side sparse matrix of the multiplication expression.
Definition: TSMatTSMatMultExpr.h:365
MT2::CompositeType CT2
Composite type of the right-hand side sparse matrix expression.
Definition: TSMatTSMatMultExpr.h:130
Constraints on the storage order of matrix types.
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.
#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.
ReturnType operator()(size_t i, size_t j) const
2D-access to the matrix elements.
Definition: TSMatTSMatMultExpr.h:217
RightOperand rightOperand() const
Returns the right-hand side transpose sparse matrix operand.
Definition: TSMatTSMatMultExpr.h:324
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.
Removal of reference modifiers.The RemoveCV type trait removes any reference modifiers from the given...
Definition: RemoveReference.h:69
Header file for run time assertion macros.
ResultType::OppositeType OppositeType
Result type with opposite storage order for expression template evaluations.
Definition: TSMatTSMatMultExpr.h:177
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
Header file for the reset shim.
size_t columns() const
Returns the current number of columns of the matrix.
Definition: TSMatTSMatMultExpr.h:282
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
MultTrait< RT1, RT2 >::Type ResultType
Result type for expression template evaluations.
Definition: TSMatTSMatMultExpr.h:176
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.
TSMatTSMatMultExpr< MT1, MT2 > This
Type of this TSMatTSMatMultExpr instance.
Definition: TSMatTSMatMultExpr.h:175
const ResultType CompositeType
Data type for composite expression templates.
Definition: TSMatTSMatMultExpr.h:181
ResultType::ElementType ElementType
Resulting element type.
Definition: TSMatTSMatMultExpr.h:179
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.
Header file for the IsBuiltin type trait.
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
MT2::ResultType RT2
Result type of the right-hand side sparse matrix expression.
Definition: TSMatTSMatMultExpr.h:128
#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.
size_t nonZeros() const
Returns the number of non-zero elements in the sparse matrix.
Definition: TSMatTSMatMultExpr.h:292
Header file for the IsUpper type trait.
Header file for the IsColumnVector type trait.
Constraint on the data type.
SelectType< IsExpression< MT1 >::value, const MT1, const MT1 & >::Type LeftOperand
Composite type of the left-hand side sparse matrix expression.
Definition: TSMatTSMatMultExpr.h:184
Header file for the IsResizable type trait.
bool canSMPAssign() const
Returns whether the expression can be used in SMP assignments.
Definition: TSMatTSMatMultExpr.h:358
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 TSMatSVecMultExprTrait class template.
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
MT1::ResultType RT1
Result type of the left-hand side sparse matrix expression.
Definition: TSMatTSMatMultExpr.h:127