35 #ifndef _BLAZE_MATH_EXPRESSIONS_SMATTSMATMULTEXPR_H_ 36 #define _BLAZE_MATH_EXPRESSIONS_SMATTSMATMULTEXPR_H_ 95 template<
typename MT1
97 class SMatTSMatMultExpr
98 :
public MatMatMultExpr< SparseMatrix< SMatTSMatMultExpr<MT1,MT2>, IsIdentity_v<MT1> > >
118 template<
typename T1,
typename T2,
typename T3 >
119 static constexpr
bool CanExploitSymmetry_v =
120 ( ( IsRowMajorMatrix_v<T1> && IsSymmetric_v<T3> ) ||
121 ( IsColumnMajorMatrix_v<T1> && IsSymmetric_v<T2> ) );
190 if( i >=
lhs_.rows() ) {
193 if( j >=
rhs_.columns() ) {
205 inline size_t rows() const noexcept {
216 return rhs_.columns();
225 inline constexpr
size_t nonZeros() const noexcept {
236 inline size_t nonZeros(
size_t i )
const noexcept {
268 template<
typename T >
269 inline bool canAlias(
const T* alias )
const noexcept {
270 return (
lhs_.isAliased( alias ) ||
rhs_.isAliased( alias ) );
280 template<
typename T >
281 inline bool isAliased(
const T* alias )
const noexcept {
282 return (
lhs_.isAliased( alias ) ||
rhs_.isAliased( alias ) );
292 return (
rows() *
columns() >= SMP_SMATTSMATMULT_THRESHOLD );
315 template<
typename MT >
327 assign( ~lhs, rhs.lhs_ * tmp );
347 template<
typename MT >
356 assign( ~lhs, rhs.lhs_ *
trans( rhs.rhs_ ) );
374 template<
typename MT >
376 -> DisableIf_t< CanExploitSymmetry_v<MT,MT1,MT2> >
387 const OppositeType_t<MT1> tmp(
serial( rhs.lhs_ ) );
388 assign( ~lhs, tmp * rhs.rhs_ );
408 template<
typename MT >
410 -> EnableIf_t< CanExploitSymmetry_v<MT,MT1,MT2> >
419 assign( ~lhs,
trans( rhs.lhs_ ) * rhs.rhs_ );
437 template<
typename MT >
438 friend inline auto addAssign( DenseMatrix<MT,false>& lhs,
const SMatTSMatMultExpr& rhs )
439 -> DisableIf_t< CanExploitSymmetry_v<MT,MT1,MT2> >
448 const OppositeType_t<MT2> tmp(
serial( rhs.rhs_ ) );
449 addAssign( ~lhs, rhs.lhs_ * tmp );
469 template<
typename MT >
470 friend inline auto addAssign( Matrix<MT,false>& lhs,
const SMatTSMatMultExpr& rhs )
471 -> EnableIf_t< CanExploitSymmetry_v<MT,MT1,MT2> >
478 addAssign( ~lhs, rhs.lhs_ *
trans( rhs.rhs_ ) );
496 template<
typename MT >
497 friend inline auto addAssign( DenseMatrix<MT,true>& lhs,
const SMatTSMatMultExpr& rhs )
498 -> DisableIf_t< CanExploitSymmetry_v<MT,MT1,MT2> >
509 const OppositeType_t<MT1> tmp(
serial( rhs.lhs_ ) );
510 addAssign( ~lhs, tmp * rhs.rhs_ );
530 template<
typename MT >
531 friend inline auto addAssign( Matrix<MT,true>& lhs,
const SMatTSMatMultExpr& rhs )
532 -> EnableIf_t< CanExploitSymmetry_v<MT,MT1,MT2> >
541 addAssign( ~lhs,
trans( rhs.lhs_ ) * rhs.rhs_ );
563 template<
typename MT >
564 friend inline auto subAssign( DenseMatrix<MT,false>& lhs,
const SMatTSMatMultExpr& rhs )
565 -> DisableIf_t< CanExploitSymmetry_v<MT,MT1,MT2> >
574 const OppositeType_t<MT2> tmp(
serial( rhs.rhs_ ) );
575 subAssign( ~lhs, rhs.lhs_ * tmp );
595 template<
typename MT >
596 friend inline auto subAssign( Matrix<MT,false>& lhs,
const SMatTSMatMultExpr& rhs )
597 -> EnableIf_t< CanExploitSymmetry_v<MT,MT1,MT2> >
604 subAssign( ~lhs, rhs.lhs_ *
trans( rhs.rhs_ ) );
622 template<
typename MT >
623 friend inline auto subAssign( DenseMatrix<MT,true>& lhs,
const SMatTSMatMultExpr& rhs )
624 -> DisableIf_t< CanExploitSymmetry_v<MT,MT1,MT2> >
635 const OppositeType_t<MT1> tmp(
serial( rhs.lhs_ ) );
636 subAssign( ~lhs, tmp * rhs.rhs_ );
656 template<
typename MT >
657 friend inline auto subAssign( Matrix<MT,true>& lhs,
const SMatTSMatMultExpr& rhs )
658 -> EnableIf_t< CanExploitSymmetry_v<MT,MT1,MT2> >
667 subAssign( ~lhs,
trans( rhs.lhs_ ) * rhs.rhs_ );
689 template<
typename MT
691 friend inline void schurAssign( DenseMatrix<MT,SO>& lhs,
const SMatTSMatMultExpr& rhs )
702 schurAssign( ~lhs, tmp );
734 template<
typename MT >
736 -> DisableIf_t< CanExploitSymmetry_v<MT,MT1,MT2> >
745 const OppositeType_t<MT2> tmp( rhs.rhs_ );
766 template<
typename MT >
768 -> EnableIf_t< CanExploitSymmetry_v<MT,MT1,MT2> >
795 template<
typename MT >
797 -> DisableIf_t< CanExploitSymmetry_v<MT,MT1,MT2> >
808 const OppositeType_t<MT1> tmp( rhs.lhs_ );
829 template<
typename MT >
831 -> EnableIf_t< CanExploitSymmetry_v<MT,MT1,MT2> >
860 template<
typename MT >
862 -> DisableIf_t< CanExploitSymmetry_v<MT,MT1,MT2> >
871 const OppositeType_t<MT2> tmp( rhs.rhs_ );
892 template<
typename MT >
894 -> DisableIf_t< CanExploitSymmetry_v<MT,MT1,MT2> >
905 const OppositeType_t<MT1> tmp( rhs.lhs_ );
926 template<
typename MT >
928 -> EnableIf_t< CanExploitSymmetry_v<MT,MT1,MT2> >
955 template<
typename MT >
957 -> EnableIf_t< CanExploitSymmetry_v<MT,MT1,MT2> >
990 template<
typename MT >
992 -> DisableIf_t< CanExploitSymmetry_v<MT,MT1,MT2> >
1001 const OppositeType_t<MT2> tmp( rhs.rhs_ );
1022 template<
typename MT >
1024 -> DisableIf_t< CanExploitSymmetry_v<MT,MT1,MT2> >
1035 const OppositeType_t<MT1> tmp( rhs.lhs_ );
1056 template<
typename MT >
1058 -> EnableIf_t< CanExploitSymmetry_v<MT,MT1,MT2> >
1085 template<
typename MT >
1087 -> EnableIf_t< CanExploitSymmetry_v<MT,MT1,MT2> >
1118 template<
typename MT
1184 template<
typename MT1
1186 ,
DisableIf_t< ( ( IsIdentity_v<MT1> || IsIdentity_v<MT2> ) &&
1187 IsSame_v< ElementType_t<MT1>, ElementType_t<MT2> > ) ||
1188 ( IsIdentity_v<MT1> && IsIdentity_v<MT2> ) ||
1189 ( IsZero_v<MT1> || IsZero_v<MT2> ) >* =
nullptr >
1190 inline const SMatTSMatMultExpr<MT1,MT2>
1191 smattsmatmult(
const SparseMatrix<MT1,false>& lhs,
const SparseMatrix<MT2,true>& rhs )
1197 return SMatTSMatMultExpr<MT1,MT2>( ~lhs, ~rhs );
1217 template<
typename MT1
1219 , EnableIf_t< !IsIdentity_v<MT1> && IsIdentity_v<MT2> &&
1220 IsSame_v< ElementType_t<MT1>, ElementType_t<MT2> > >* =
nullptr >
1222 smattsmatmult(
const SparseMatrix<MT1,false>& lhs,
const SparseMatrix<MT2,true>& rhs )
1250 template<
typename MT1
1252 , EnableIf_t< IsIdentity_v<MT1> && !IsIdentity_v<MT2> &&
1253 IsSame_v< ElementType_t<MT1>, ElementType_t<MT2> > >* =
nullptr >
1255 smattsmatmult(
const SparseMatrix<MT1,false>& lhs,
const SparseMatrix<MT2,true>& rhs )
1282 template<
typename MT1
1284 , EnableIf_t< IsIdentity_v<MT1> && IsIdentity_v<MT2> >* =
nullptr >
1285 inline decltype(
auto)
1286 smattsmatmult( const SparseMatrix<MT1,false>& lhs, const SparseMatrix<MT2,true>& rhs )
1294 using ReturnType =
const MultTrait_t< ResultType_t<MT1>, ResultType_t<MT2> >;
1299 return ReturnType( (~lhs).
rows() );
1319 template<
typename MT1
1321 , EnableIf_t< IsZero_v<MT1> || IsZero_v<MT2> >* =
nullptr >
1322 inline decltype(
auto)
1323 smattsmatmult( const SparseMatrix<MT1,false>& lhs, const SparseMatrix<MT2,true>& rhs )
1329 using ReturnType =
const MultTrait_t< ResultType_t<MT1>, ResultType_t<MT2> >;
1334 return ReturnType( (~lhs).
rows(), (~rhs).
columns() );
1370 template<
typename MT1
1372 inline decltype(
auto)
1381 return smattsmatmult( ~lhs, ~rhs );
Constraint on the data type.
#define BLAZE_THROW_INVALID_ARGUMENT(MESSAGE)
Macro for the emission of a std::invalid_argument exception.This macro encapsulates the default way o...
Definition: Exception.h:235
Header file for auxiliary alias declarations.
decltype(auto) column(Matrix< MT, SO > &matrix, RCAs... args)
Creating a view on a specific column of the given matrix.
Definition: Column.h:133
Headerfile for the generic min algorithm.
Header file for the blaze::checked and blaze::unchecked instances.
#define BLAZE_CONSTRAINT_MUST_BE_IDENTITY_MATRIX_TYPE(T)
Constraint on the data type.In case the given data type T is not an identity matrix type,...
Definition: Identity.h:60
const ElementType ReturnType
Return type for expression template evaluations.
Definition: SMatTSMatMultExpr.h:137
Header file for basic type definitions.
size_t columns() const noexcept
Returns the current number of columns of the matrix.
Definition: SMatTSMatMultExpr.h:215
typename If< Condition, T1, T2 >::Type If_t
Auxiliary alias template for the If class template.The If_t alias template provides a convenient shor...
Definition: If.h:109
typename T::ResultType ResultType_t
Alias declaration for nested ResultType type definitions.The ResultType_t alias declaration provides ...
Definition: Aliases.h:390
Header file for the serial shim.
#define BLAZE_CONSTRAINT_MUST_BE_MATRIX_WITH_STORAGE_ORDER(T, SO)
Constraint on the data type.In case the given data type T is not a dense or sparse matrix type and in...
Definition: StorageOrder.h:63
Header file for the IsColumnMajorMatrix type trait.
const ResultType CompositeType
Data type for composite expression templates.
Definition: SMatTSMatMultExpr.h:138
constexpr Unchecked unchecked
Global Unchecked instance.The blaze::unchecked instance is an optional token for the creation of view...
Definition: Check.h:138
Constraint on the data type.
Header file for the MAYBE_UNUSED function template.
Header file for the IsIdentity type trait.
Header file for the Computation base class.
Header file for the MatMatMultExpr base class.
RightOperand rightOperand() const noexcept
Returns the right-hand side transpose sparse matrix operand.
Definition: SMatTSMatMultExpr.h:257
Constraints on the storage order of matrix types.
Header file for the RequiresEvaluation type trait.
OppositeType_t< ResultType > OppositeType
Result type with opposite storage order for expression template evaluations.
Definition: SMatTSMatMultExpr.h:134
constexpr size_t columns(const Matrix< MT, SO > &matrix) noexcept
Returns the current number of columns of the matrix.
Definition: Matrix.h:514
Base class for sparse matrices.The SparseMatrix class is a base class for all sparse matrix classes....
Definition: Forward.h:145
typename T::ElementType ElementType_t
Alias declaration for nested ElementType type definitions.The ElementType_t alias declaration provide...
Definition: Aliases.h:170
Header file for the SparseMatrix base class.
ElementType_t< ResultType > ElementType
Resulting element type.
Definition: SMatTSMatMultExpr.h:136
Constraint on the data type.
typename EnableIf< Condition, T >::Type EnableIf_t
Auxiliary type for the EnableIf class template.The EnableIf_t alias declaration provides a convenient...
Definition: EnableIf.h:138
Expression object for sparse matrix-transpose sparse matrix multiplications.The SMatTSMatMultExpr cla...
Definition: Forward.h:142
ReturnType operator()(size_t i, size_t j) const
2D-access to the matrix elements.
Definition: SMatTSMatMultExpr.h:173
Header file for the DisableIf class template.
LeftOperand leftOperand() const noexcept
Returns the left-hand side sparse matrix operand.
Definition: SMatTSMatMultExpr.h:247
Header file for the multiplication trait.
Header file for the IsSymmetric type trait.
Namespace of the Blaze C++ math library.
Definition: Blaze.h:58
Header file for the If class template.
#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: ColumnMajorMatrix.h:61
CompositeType_t< MT1 > CT1
Composite type of the left-hand side sparse matrix expression.
Definition: SMatTSMatMultExpr.h:105
#define BLAZE_CONSTRAINT_MUST_BE_ZERO_TYPE(T)
Constraint on the data type.In case the given data type T is not a zero vector or matrix type,...
Definition: Zero.h:61
bool isAliased(const T *alias) const noexcept
Returns whether the expression is aliased with the given address alias.
Definition: SMatTSMatMultExpr.h:281
#define BLAZE_THROW_OUT_OF_RANGE(MESSAGE)
Macro for the emission of a std::out_of_range exception.This macro encapsulates the default way of Bl...
Definition: Exception.h:331
constexpr size_t nonZeros() const noexcept
Returns the number of non-zero elements in the sparse matrix.
Definition: SMatTSMatMultExpr.h:225
constexpr void MAYBE_UNUSED(const Args &...)
Suppression of unused parameter warnings.
Definition: MaybeUnused.h:81
ResultType_t< MT2 > RT2
Result type of the right-hand side sparse matrix expression.
Definition: SMatTSMatMultExpr.h:104
Header file for the exception macros of the math module.
CompositeType_t< MT2 > CT2
Composite type of the right-hand side sparse matrix expression.
Definition: SMatTSMatMultExpr.h:106
Constraint on the data type.
SMatTSMatMultExpr(const MT1 &lhs, const MT2 &rhs) noexcept
Constructor for the SMatTSMatMultExpr class.
Definition: SMatTSMatMultExpr.h:158
Header file for the EnableIf class template.
size_t rows() const noexcept
Returns the current number of rows of the matrix.
Definition: SMatTSMatMultExpr.h:205
#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:103
TransposeType_t< ResultType > TransposeType
Transpose type for expression template evaluations.
Definition: SMatTSMatMultExpr.h:135
If_t< IsExpression_v< MT1 >, const MT1, const MT1 & > LeftOperand
Composite type of the left-hand side sparse matrix expression.
Definition: SMatTSMatMultExpr.h:141
typename MultTrait< T1, T2 >::Type MultTrait_t
Auxiliary alias declaration for the MultTrait class template.The MultTrait_t alias declaration provid...
Definition: MultTrait.h:240
typename T::OppositeType OppositeType_t
Alias declaration for nested OppositeType type definitions.The OppositeType_t alias declaration provi...
Definition: Aliases.h:270
ResultType_t< MT1 > RT1
Result type of the left-hand side sparse matrix expression.
Definition: SMatTSMatMultExpr.h:103
#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,...
Definition: Symmetric.h:79
#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:61
typename T::TransposeType TransposeType_t
Alias declaration for nested TransposeType type definitions.The TransposeType_t alias declaration pro...
Definition: Aliases.h:470
Header file for run time assertion macros.
typename T::CompositeType CompositeType_t
Alias declaration for nested CompositeType type definitions.The CompositeType_t alias declaration pro...
Definition: Aliases.h:90
auto smpAddAssign(Matrix< MT1, SO1 > &lhs, const Matrix< MT2, SO2 > &rhs) -> EnableIf_t< IsDenseMatrix_v< MT1 > >
Default implementation of the SMP addition assignment of a matrix to a dense matrix.
Definition: DenseMatrix.h:131
decltype(auto) row(Matrix< MT, SO > &, RRAs...)
Creating a view on a specific row of the given matrix.
Definition: Row.h:133
bool canAlias(const T *alias) const noexcept
Returns whether the expression can alias with the given address alias.
Definition: SMatTSMatMultExpr.h:269
ReturnType at(size_t i, size_t j) const
Checked access to the matrix elements.
Definition: SMatTSMatMultExpr.h:189
Header file for the IsZero type trait.
#define BLAZE_FUNCTION_TRACE
Function trace macro.This macro can be used to reliably trace function calls. In case function tracin...
Definition: FunctionTrace.h:94
Header file for all forward declarations for expression class templates.
MultTrait_t< RT1, RT2 > ResultType
Result type for expression template evaluations.
Definition: SMatTSMatMultExpr.h:133
static constexpr bool smpAssignable
Compilation switch for the expression template assignment strategy.
Definition: SMatTSMatMultExpr.h:149
Base class for matrices.The Matrix class is a base class for all dense and sparse matrix classes with...
Definition: Forward.h:114
auto smpAssign(Matrix< MT1, SO1 > &lhs, const Matrix< MT2, SO2 > &rhs) -> EnableIf_t< IsDenseMatrix_v< MT1 > >
Default implementation of the SMP assignment of a matrix to a dense matrix.
Definition: DenseMatrix.h:100
Constraint on the data type.
Constraints on the storage order of matrix types.
decltype(auto) serial(const DenseMatrix< MT, SO > &dm)
Forces the serial evaluation of the given dense matrix expression dm.
Definition: DMatSerialExpr.h:808
#define BLAZE_CONSTRAINT_MUST_NOT_REQUIRE_EVALUATION(T)
Constraint on the data type.In case the given data type T requires an intermediate evaluation within ...
Definition: RequiresEvaluation.h:81
auto smpSchurAssign(Matrix< MT1, SO1 > &lhs, const Matrix< MT2, SO2 > &rhs) -> EnableIf_t< IsDenseMatrix_v< MT1 > >
Default implementation of the SMP Schur product assignment of a matrix to dense matrix.
Definition: DenseMatrix.h:194
constexpr size_t rows(const Matrix< MT, SO > &matrix) noexcept
Returns the current number of rows of the matrix.
Definition: Matrix.h:498
LeftOperand lhs_
Left-hand side sparse matrix of the multiplication expression.
Definition: SMatTSMatMultExpr.h:298
decltype(auto) trans(const DenseMatrix< MT, SO > &dm)
Calculation of the transpose of the given dense matrix.
Definition: DMatTransExpr.h:765
Header file for the IsRowMajorMatrix type trait.
Header file for the IsComputation type trait class.
auto smpSubAssign(Matrix< MT1, SO1 > &lhs, const Matrix< MT2, SO2 > &rhs) -> EnableIf_t< IsDenseMatrix_v< MT1 > >
Default implementation of the SMP subtraction assignment of a matrix to dense matrix.
Definition: DenseMatrix.h:162
size_t nonZeros(size_t i) const noexcept
Returns the number of non-zero elements in the specified row.
Definition: SMatTSMatMultExpr.h:236
Header file for the IntegralConstant class template.
RightOperand rhs_
Right-hand side sparse matrix of the multiplication expression.
Definition: SMatTSMatMultExpr.h:299
bool canSMPAssign() const noexcept
Returns whether the expression can be used in SMP assignments.
Definition: SMatTSMatMultExpr.h:291
If_t< IsExpression_v< MT2 >, const MT2, const MT2 & > RightOperand
Composite type of the right-hand side sparse matrix expression.
Definition: SMatTSMatMultExpr.h:144
typename DisableIf< Condition, T >::Type DisableIf_t
Auxiliary type for the DisableIf class template.The DisableIf_t alias declaration provides a convenie...
Definition: DisableIf.h:138
Constraint on the data type.
#define BLAZE_CONSTRAINT_MUST_NOT_BE_ZERO_TYPE(T)
Constraint on the data type.In case the given data type T is a zero vector or matrix type,...
Definition: Zero.h:81
Header file for the thresholds for matrix/vector and matrix/matrix multiplications.
constexpr bool IsSame_v
Auxiliary variable template for the IsSame type trait.The IsSame_v variable template provides a conve...
Definition: IsSame.h:159
#define BLAZE_INTERNAL_ASSERT(expr, msg)
Run time assertion macro for internal checks.In case of an invalid run time expression,...
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:61
Header file for the IsExpression type trait class.
Header file for the function trace functionality.