35 #ifndef _BLAZE_MATH_EXPRESSIONS_TSMATTSMATMULTEXPR_H_
36 #define _BLAZE_MATH_EXPRESSIONS_TSMATTSMATMULTEXPR_H_
113 template<
typename MT1
115 class TSMatTSMatMultExpr :
public SparseMatrix< TSMatTSMatMultExpr<MT1,MT2>, true >
116 ,
private MatMatMultExpr
117 ,
private Computation
144 template<
typename T1,
typename T2,
typename T3 >
145 struct CanExploitSymmetry {
146 enum { value = IsRowMajorMatrix<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( B.end(j) );
230 ConstIterator element( B.begin(j) );
237 tmp =
lhs_(i,element->index()) * element->value();
239 for( ; element!=
end; ++element )
240 tmp +=
lhs_(i,element->index()) * element->value();
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 TSMatTSMatMultExpr::selectAssignKernel( ~lhs, A, B );
409 template<
typename MT3
412 static inline void selectAssignKernel( MT3& C,
const MT4& A,
const MT5& B )
417 for(
size_t j=0UL; j<C.columns(); ++j ) {
418 const RightIterator rend( B.end(j) );
419 for( RightIterator relem=B.begin(j); relem!=rend; ++relem ) {
420 const LeftIterator lend( A.end( relem->index() ) );
421 for( LeftIterator lelem=A.begin( relem->index() ); lelem!=lend; ++lelem )
425 C(lelem->index(),j) = lelem->value() * relem->value();
428 C(lelem->index(),j) += lelem->value() * relem->value();
450 template<
typename MT >
451 friend inline typename DisableIf< CanExploitSymmetry<MT,MT1,MT2> >::Type
465 (~lhs).reserve( tmp.nonZeros() );
484 template<
typename MT >
506 size_t nonzeros( 0UL );
508 for(
size_t j=0UL; j<(~lhs).
columns(); ++j ) {
509 const RightIterator rend( B.end(j) );
510 for( RightIterator relem=B.begin(j); relem!=rend; ++relem ) {
511 nonzeros += A.nonZeros( relem->index() );
515 if( nonzeros > (~lhs).rows() * (~lhs).
columns() ) {
519 (~lhs).reserve( nonzeros );
524 std::vector<byte> valid ( (~lhs).
rows(), 0 );
525 std::vector<size_t> indices( (~lhs).
rows(), 0UL );
526 size_t minIndex(
inf ), maxIndex( 0UL );
528 for(
size_t j=0UL; j<(~lhs).
columns(); ++j )
530 const RightIterator rend( B.end(j) );
531 for( RightIterator relem=B.begin(j); relem!=rend; ++relem )
533 const LeftIterator lend( A.end( relem->index() ) );
534 for( LeftIterator lelem=A.begin( relem->index() ); lelem!=lend; ++lelem )
536 if( !valid[lelem->index()] ) {
537 values[lelem->index()] = lelem->value() * relem->value();
538 valid [lelem->index()] = 1;
539 indices[nonzeros] = lelem->index();
541 if( lelem->index() < minIndex ) minIndex = lelem->index();
542 if( lelem->index() > maxIndex ) maxIndex = lelem->index();
545 values[lelem->index()] += lelem->value() * relem->value();
556 if( ( nonzeros + nonzeros ) < ( maxIndex - minIndex ) )
558 std::sort( indices.begin(), indices.begin() + nonzeros );
560 for(
size_t i=0UL; i<nonzeros; ++i )
562 const size_t index( indices[i] );
564 (~lhs).append( index, j, values[index] );
565 reset( values[index] );
568 reset( valid [index] );
572 for(
size_t i=minIndex; i<=maxIndex; ++i )
575 (~lhs).append( i, j, values[i] );
588 (~lhs).finalize( j );
609 template<
typename MT >
610 friend inline typename EnableIf< CanExploitSymmetry<MT,MT1,MT2> >::Type
638 template<
typename MT
640 friend inline typename DisableIf< CanExploitSymmetry<MT,MT1,MT2> >::Type
658 TSMatTSMatMultExpr::selectAddAssignKernel( ~lhs, A, B );
677 template<
typename MT3
680 static inline void selectAddAssignKernel( MT3& C,
const MT4& A,
const MT5& B )
685 for(
size_t j=0UL; j<C.columns(); ++j ) {
686 const RightIterator rend( B.end(j) );
687 for( RightIterator relem=B.begin(j); relem!=rend; ++relem ) {
688 const LeftIterator lend( A.end( relem->index() ) );
689 for( LeftIterator lelem=A.begin( relem->index() ); lelem!=lend; ++lelem ) {
690 C(lelem->index(),j) += lelem->value() * relem->value();
713 template<
typename MT >
714 friend inline typename EnableIf< CanExploitSymmetry<MT,MT1,MT2> >::Type
746 template<
typename MT
748 friend inline typename DisableIf< CanExploitSymmetry<MT,MT1,MT2> >::Type
769 TSMatTSMatMultExpr::selectSubAssignKernel( ~lhs, A, B );
788 template<
typename MT3
791 static inline void selectSubAssignKernel( MT3& C,
const MT4& A,
const MT5& B )
796 for(
size_t j=0UL; j<C.columns(); ++j ) {
797 const RightIterator rend( B.end(j) );
798 for( RightIterator relem=B.begin(j); relem!=rend; ++relem ) {
799 const LeftIterator lend( A.end( relem->index() ) );
800 for( LeftIterator lelem=A.begin( relem->index() ); lelem!=lend; ++lelem ) {
801 C(lelem->index(),j) -= lelem->value() * relem->value();
825 template<
typename MT >
826 friend inline typename EnableIf< CanExploitSymmetry<MT,MT1,MT2> >::Type
869 template<
typename MT
871 friend inline typename EnableIf< IsEvaluationRequired<MT,MT1,MT2> >::Type
909 template<
typename MT >
910 friend inline typename EnableIf< CanExploitSymmetry<MT,MT1,MT2> >::Type
941 template<
typename MT
943 friend inline typename EnableIf< IsEvaluationRequired<MT,MT1,MT2> >::Type
982 template<
typename MT >
983 friend inline typename EnableIf< CanExploitSymmetry<MT,MT1,MT2> >::Type
1018 template<
typename MT
1020 friend inline typename EnableIf< IsEvaluationRequired<MT,MT1,MT2> >::Type
1059 template<
typename MT >
1060 friend inline typename EnableIf< CanExploitSymmetry<MT,MT1,MT2> >::Type
1135 template<
typename T1
1137 inline const TSMatTSMatMultExpr<T1,T2>
1143 throw std::invalid_argument(
"Matrix sizes do not match" );
1160 template<
typename MT1,
typename MT2 >
1178 template<
typename MT1,
typename MT2 >
1180 :
public Columns<MT2>
1196 template<
typename MT1,
typename MT2 >
1198 :
public IsTrue< IsLower<MT1>::value && IsLower<MT2>::value >
1214 template<
typename MT1,
typename MT2 >
1216 :
public IsTrue< IsUpper<MT1>::value && IsUpper<MT2>::value >
1232 template<
typename MT1,
typename MT2,
typename VT >
1237 typedef typename SelectType< IsSparseMatrix<MT1>::value && IsColumnMajorMatrix<MT1>::value &&
1238 IsSparseMatrix<MT2>::value && IsColumnMajorMatrix<MT2>::value &&
1239 IsDenseVector<VT>::value && IsColumnVector<VT>::value
1240 ,
typename TSMatDVecMultExprTrait< MT1, typename TSMatDVecMultExprTrait<MT2,VT>::Type >::Type
1241 , INVALID_TYPE >::Type Type;
1250 template<
typename MT1,
typename MT2,
typename VT >
1255 typedef typename SelectType< IsSparseMatrix<MT1>::value && IsColumnMajorMatrix<MT1>::value &&
1256 IsSparseMatrix<MT2>::value && IsColumnMajorMatrix<MT2>::value &&
1257 IsSparseVector<VT>::value && IsColumnVector<VT>::value
1258 ,
typename TSMatDVecMultExprTrait< MT1, typename TSMatDVecMultExprTrait<MT2,VT>::Type >::Type
1259 , INVALID_TYPE >::Type Type;
1268 template<
typename VT,
typename MT1,
typename MT2 >
1273 typedef typename SelectType< IsDenseVector<VT>::value && IsRowVector<VT>::value &&
1274 IsSparseMatrix<MT1>::value && IsColumnMajorMatrix<MT1>::value &&
1275 IsSparseMatrix<MT2>::value && IsColumnMajorMatrix<MT2>::value
1276 ,
typename TDVecTSMatMultExprTrait< typename TDVecTSMatMultExprTrait<VT,MT1>::Type, MT2 >::Type
1277 , INVALID_TYPE >::Type Type;
1286 template<
typename VT,
typename MT1,
typename MT2 >
1291 typedef typename SelectType< IsSparseVector<VT>::value && IsRowVector<VT>::value &&
1292 IsSparseMatrix<MT1>::value && IsColumnMajorMatrix<MT1>::value &&
1293 IsSparseMatrix<MT2>::value && IsColumnMajorMatrix<MT2>::value
1294 ,
typename TSVecTSMatMultExprTrait< typename TSVecTSMatMultExprTrait<VT,MT1>::Type, MT2 >::Type
1295 , INVALID_TYPE >::Type Type;
1304 template<
typename MT1,
typename MT2,
bool AF >
1309 typedef typename MultExprTrait< typename SubmatrixExprTrait<const MT1,AF>::Type
1310 ,
typename SubmatrixExprTrait<const MT2,AF>::Type >::Type Type;
1319 template<
typename MT1,
typename MT2 >
1324 typedef typename MultExprTrait< typename RowExprTrait<const MT1>::Type, MT2 >::Type Type;
1333 template<
typename MT1,
typename MT2 >
1338 typedef typename MultExprTrait< MT1, typename ColumnExprTrait<const MT2>::Type >::Type Type;
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
MT2::CompositeType CT2
Composite type of the right-hand side sparse matrix expression.
Definition: TSMatTSMatMultExpr.h:124
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
bool canSMPAssign() const
Returns whether the expression can be used in SMP assignments.
Definition: TSMatTSMatMultExpr.h:346
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.
ResultType::TransposeType TransposeType
Transpose type for expression template evaluations.
Definition: TSMatTSMatMultExpr.h:172
const ElementType ReturnType
Return type for expression template evaluations.
Definition: TSMatTSMatMultExpr.h:174
Header file for the IsColumnMajorMatrix type trait.
MT1::ResultType RT1
Result type of the left-hand side sparse matrix expression.
Definition: TSMatTSMatMultExpr.h:121
Header file for the TSVecTSMatMultExprTrait class template.
const This & CompositeType
Data type for composite expression templates.
Definition: CompressedMatrix.h:2478
Header file for the IsRowVector type trait.
Type ElementType
Type of the sparse matrix elements.
Definition: CompressedMatrix.h:257
ReturnType operator()(size_t i, size_t j) const
2D-access to the matrix elements.
Definition: TSMatTSMatMultExpr.h:211
void UNUSED_PARAMETER(const T1 &)
Suppression of unused parameter warnings.
Definition: Unused.h:81
LeftOperand leftOperand() const
Returns the left-hand side transpose sparse matrix operand.
Definition: TSMatTSMatMultExpr.h:302
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
TSMatTSMatMultExpr(const MT1 &lhs, const MT2 &rhs)
Constructor for the TSMatTSMatMultExpr class.
Definition: TSMatTSMatMultExpr.h:196
bool canAlias(const T *alias) const
Returns whether the expression can alias with the given address alias.
Definition: TSMatTSMatMultExpr.h:324
Header file for the Computation base class.
Header file for the MatMatMultExpr base class.
Header file for the RequiresEvaluation type trait.
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
RightOperand rightOperand() const
Returns the right-hand side transpose sparse matrix operand.
Definition: TSMatTSMatMultExpr.h:312
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
RightOperand rhs_
Right-hand side sparse matrix of the multiplication expression.
Definition: TSMatTSMatMultExpr.h:354
size_t columns() const
Returns the current number of columns of the matrix.
Definition: TSMatTSMatMultExpr.h:270
size_t nonZeros(size_t i) const
Returns the number of non-zero elements in the specified row.
Definition: TSMatTSMatMultExpr.h:291
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.
LeftOperand lhs_
Left-hand side sparse matrix of the multiplication expression.
Definition: TSMatTSMatMultExpr.h:353
Header file for the IsSymmetric type trait.
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:2482
MultTrait< RT1, RT2 >::Type ResultType
Result type for expression template evaluations.
Definition: TSMatTSMatMultExpr.h:170
Header file for the TDVecTSMatMultExprTrait class template.
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.
ResultType::OppositeType OppositeType
Result type with opposite storage order for expression template evaluations.
Definition: TSMatTSMatMultExpr.h:171
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
Header file for the IsLower type trait.
Constraints on the storage order of matrix types.
size_t nonZeros() const
Returns the number of non-zero elements in the sparse matrix.
Definition: TSMatTSMatMultExpr.h:280
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.
SelectType< IsExpression< MT1 >::value, const MT1, const MT1 & >::Type LeftOperand
Composite type of the left-hand side sparse matrix expression.
Definition: TSMatTSMatMultExpr.h:178
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
TSMatTSMatMultExpr< MT1, MT2 > This
Type of this TSMatTSMatMultExpr instance.
Definition: TSMatTSMatMultExpr.h:169
size_t rows() const
Returns the current number of rows of the matrix.
Definition: TSMatTSMatMultExpr.h:260
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.
ResultType::ElementType ElementType
Resulting element type.
Definition: TSMatTSMatMultExpr.h:173
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.
MT2::ResultType RT2
Result type of the right-hand side sparse matrix expression.
Definition: TSMatTSMatMultExpr.h:122
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
BLAZE_ALWAYS_INLINE void reset(const NonNumericProxy< MT > &proxy)
Resetting the represented element to the default initial values.
Definition: NonNumericProxy.h:833
const ResultType CompositeType
Data type for composite expression templates.
Definition: TSMatTSMatMultExpr.h:175
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
MT1::CompositeType CT1
Composite type of the left-hand side sparse matrix expression.
Definition: TSMatTSMatMultExpr.h:123
Header file for the IsDenseVector type trait.
bool isAliased(const T *alias) const
Returns whether the expression is aliased with the given address alias.
Definition: TSMatTSMatMultExpr.h:336
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.
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
#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.
SelectType< IsExpression< MT2 >::value, const MT2, const MT2 & >::Type RightOperand
Composite type of the right-hand side sparse matrix expression.
Definition: TSMatTSMatMultExpr.h:181
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