35 #ifndef _BLAZE_MATH_EXPRESSIONS_SMATSCALARMULTEXPR_H_ 36 #define _BLAZE_MATH_EXPRESSIONS_SMATSCALARMULTEXPR_H_ 96 class SMatScalarMultExpr
97 :
public MatScalarMultExpr< SparseMatrix< SMatScalarMultExpr<MT,ST,SO>, SO > >
128 static constexpr
bool useAssign = RequiresEvaluation_v<MT>;
131 template<
typename MT2 >
133 static constexpr
bool UseAssign_v =
useAssign;
145 template<
typename MT2 >
146 static constexpr
bool UseSMPAssign_v =
147 ( ( !MT2::smpAssignable || !MT::smpAssignable ) &&
useAssign );
378 inline size_t rows() const noexcept {
479 template<
typename T >
480 inline bool canAlias(
const T* alias )
const noexcept {
481 return matrix_.canAlias( alias );
491 template<
typename T >
492 inline bool isAliased(
const T* alias )
const noexcept {
493 return matrix_.isAliased( alias );
517 template<
typename MT2
527 assign( ~lhs, rhs.matrix_ );
528 (~lhs) *= rhs.scalar_;
547 template<
typename MT2
557 assign( ~lhs, rhs.matrix_ );
558 (~lhs) *= rhs.scalar_;
577 template<
typename MT2
579 friend inline auto addAssign( DenseMatrix<MT2,SO2>& lhs,
const SMatScalarMultExpr& rhs )
580 -> EnableIf_t< UseAssign_v<MT2> >
591 addAssign( ~lhs, tmp );
614 template<
typename MT2
616 friend inline auto subAssign( DenseMatrix<MT2,SO2>& lhs,
const SMatScalarMultExpr& rhs )
617 -> EnableIf_t< UseAssign_v<MT2> >
628 subAssign( ~lhs, tmp );
651 template<
typename MT2
653 friend inline auto schurAssign( DenseMatrix<MT2,SO2>& lhs,
const SMatScalarMultExpr& rhs )
654 -> EnableIf_t< UseAssign_v<MT2> >
665 schurAssign( ~lhs, tmp );
704 template<
typename MT2
707 -> EnableIf_t< UseSMPAssign_v<MT2> >
741 template<
typename MT2
744 -> EnableIf_t< UseSMPAssign_v<MT2> >
778 template<
typename MT2
781 -> EnableIf_t< UseSMPAssign_v<MT2> >
847 template<
typename MT
855 return ReturnType( ~sm, ScalarType(-1) );
881 template<
typename MT
884 , DisableIf_t< IsZero_v<MT> >* =
nullptr >
885 inline const SMatScalarMultExpr< MT, MultTrait_t< UnderlyingBuiltin_t<MT>, ST >, SO >
886 smatscalarmult(
const SparseMatrix<MT,SO>& mat, ST scalar )
890 using ScalarType = MultTrait_t< UnderlyingBuiltin_t<MT>, ST >;
891 using ReturnType =
const SMatScalarMultExpr<MT,ScalarType,SO>;
892 return ReturnType( ~mat, scalar );
911 template<
typename MT
914 , EnableIf_t< IsZero_v<MT> >* =
nullptr >
915 inline decltype(
auto)
916 smatscalarmult( const SparseMatrix<MT,SO>& mat, ST scalar )
922 using ReturnType =
const MultTrait_t< ResultType_t<MT>, ST >;
927 return ReturnType( (~mat).
rows(), (~mat).
columns() );
954 template<
typename MT
957 , EnableIf_t< IsNumeric_v<ST> >* =
nullptr >
958 inline decltype(
auto) operator*( const
SparseMatrix<MT,SO>& mat, ST scalar )
962 return smatscalarmult( ~mat, scalar );
988 template<
typename ST
991 , EnableIf_t< IsNumeric_v<ST> >* =
nullptr >
992 inline decltype(
auto) operator*( ST scalar, const
SparseMatrix<MT,SO>& mat )
996 return smatscalarmult( ~mat, scalar );
1021 template<
typename MT
1024 inline decltype(
auto) operator-( const SMatScalarMultExpr<MT,ST,SO>& sm )
1028 using ReturnType =
const SMatScalarMultExpr<MT,ST,SO>;
1029 return ReturnType( sm.leftOperand(), -sm.rightOperand() );
1056 template<
typename MT
1060 , EnableIf_t< IsNumeric_v<ST2> >* =
nullptr >
1061 inline decltype(
auto) operator*( const SMatScalarMultExpr<MT,ST1,SO>& mat, ST2 scalar )
1065 return mat.leftOperand() * ( mat.rightOperand() * scalar );
1084 template<
typename ST1
1088 , EnableIf_t< IsNumeric_v<ST1> >* =
nullptr >
1089 inline decltype(
auto) operator*( ST1 scalar, const SMatScalarMultExpr<MT,ST2,SO>& mat )
1093 return mat.leftOperand() * ( scalar * mat.rightOperand() );
1112 template<
typename MT
1116 , EnableIf_t< IsNumeric_v<ST2> && ( IsInvertible_v<ST1> || IsInvertible_v<ST2> ) >* =
nullptr >
1117 inline decltype(
auto) operator/( const SMatScalarMultExpr<MT,ST1,SO>& mat, ST2 scalar )
1121 return mat.leftOperand() * ( mat.rightOperand() / scalar );
1141 template<
typename MT
1145 inline decltype(
auto)
1146 operator*( const SMatScalarMultExpr<MT,ST,SO>& mat, const DenseVector<VT,false>& vec )
1150 return ( mat.leftOperand() * (~vec) ) * mat.rightOperand();
1170 template<
typename VT
1174 inline decltype(
auto)
1175 operator*( const DenseVector<VT,true>& vec, const SMatScalarMultExpr<MT,ST,SO>& mat )
1179 return ( (~vec) * mat.leftOperand() ) * mat.rightOperand();
1201 template<
typename MT
1206 inline decltype(
auto)
1207 operator*( const SMatScalarMultExpr<MT,ST1,SO>& mat, const DVecScalarMultExpr<VT,ST2,false>& vec )
1211 return ( mat.leftOperand() * vec.leftOperand() ) * ( mat.rightOperand() * vec.rightOperand() );
1233 template<
typename VT
1238 inline decltype(
auto)
1239 operator*( const DVecScalarMultExpr<VT,ST1,true>& vec, const SMatScalarMultExpr<MT,ST2,SO>& mat )
1243 return ( vec.leftOperand() * mat.leftOperand() ) * ( vec.rightOperand() * mat.rightOperand() );
1263 template<
typename MT
1267 inline decltype(
auto)
1268 operator*( const SMatScalarMultExpr<MT,ST,SO>& mat, const SparseVector<VT,false>& vec )
1272 return ( mat.leftOperand() * (~vec) ) * mat.rightOperand();
1292 template<
typename VT
1296 inline decltype(
auto)
1297 operator*( const SparseVector<VT,true>& vec, const SMatScalarMultExpr<MT,ST,SO>& mat )
1301 return ( (~vec) * mat.leftOperand() ) * mat.rightOperand();
1323 template<
typename MT
1328 inline decltype(
auto)
1329 operator*( const SMatScalarMultExpr<MT,ST1,SO>& mat, const SVecScalarMultExpr<VT,ST2,false>& vec )
1333 return ( mat.leftOperand() * vec.leftOperand() ) * ( mat.rightOperand() * vec.rightOperand() );
1355 template<
typename VT
1360 inline decltype(
auto)
1361 operator*( const SVecScalarMultExpr<VT,ST1,true>& vec, const SMatScalarMultExpr<MT,ST2,SO>& mat )
1365 return ( vec.leftOperand() * mat.leftOperand() ) * ( vec.rightOperand() * mat.rightOperand() );
1385 template<
typename MT1
1390 inline decltype(
auto)
1391 operator*( const SMatScalarMultExpr<MT1,ST,SO1>& lhs, const DenseMatrix<MT2,SO2>& rhs )
1395 return ( lhs.leftOperand() * (~rhs) ) * lhs.rightOperand();
1415 template<
typename MT1
1420 inline decltype(
auto)
1421 operator*( const DenseMatrix<MT1,SO1>& lhs, const SMatScalarMultExpr<MT2,ST,SO2>& rhs )
1425 return ( (~lhs) * rhs.leftOperand() ) * rhs.rightOperand();
1445 template<
typename MT1
1450 inline decltype(
auto)
1451 operator*( const SMatScalarMultExpr<MT1,ST,SO1>& lhs, const SparseMatrix<MT2,SO2>& rhs )
1455 return ( lhs.leftOperand() * (~rhs) ) * lhs.rightOperand();
1475 template<
typename MT1
1480 inline decltype(
auto)
1481 operator*( const SparseMatrix<MT1,SO1>& lhs, const SMatScalarMultExpr<MT2,ST,SO2>& rhs )
1485 return ( (~lhs) * rhs.leftOperand() ) * rhs.rightOperand();
1505 template<
typename MT1
1511 inline decltype(
auto)
1512 operator*( const SMatScalarMultExpr<MT1,ST1,SO1>& lhs, const SMatScalarMultExpr<MT2,ST2,SO2>& rhs )
1516 return ( lhs.leftOperand() * rhs.leftOperand() ) * ( lhs.rightOperand() * rhs.rightOperand() );
ConstIterator begin(size_t i) const
Returns an iterator to the first non-zero element of row i.
Definition: SMatScalarMultExpr.h:357
Pointer difference type of the Blaze library.
Header file for auxiliary alias declarations.
static constexpr bool smpAssignable
Compilation switch for the expression template assignment strategy.
Definition: SMatScalarMultExpr.h:303
static constexpr bool useAssign
Compilation switch for the serial evaluation strategy of the multiplication expression.
Definition: SMatScalarMultExpr.h:128
Constraint on the data type.
std::forward_iterator_tag IteratorCategory
The iterator category.
Definition: SMatScalarMultExpr.h:186
ValueIndexPair< ElementType > Element
Element type of the sparse matrix expression.
Definition: SMatScalarMultExpr.h:181
RightOperand rightOperand() const noexcept
Returns the right-hand side scalar operand.
Definition: SMatScalarMultExpr.h:468
Header file for basic type definitions.
size_t nonZeros(size_t i) const
Returns the number of non-zero elements in the specified row.
Definition: SMatScalarMultExpr.h:409
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
ReturnType value() const
Access to the current value of the sparse element.
Definition: SMatScalarMultExpr.h:245
RightOperand scalar_
Right-hand side scalar of the multiplication expression.
Definition: SMatScalarMultExpr.h:500
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
RightOperand scalar_
Right-hand side scalar of the multiplication expression.
Definition: SMatScalarMultExpr.h:296
ValueType * PointerType
Pointer return type.
Definition: SMatScalarMultExpr.h:188
TransposeType_t< ResultType > TransposeType
Transpose type for expression template evaluations.
Definition: SMatScalarMultExpr.h:157
const Element operator *() const
Direct access to the sparse matrix element at the current iterator position.
Definition: SMatScalarMultExpr.h:225
LeftOperand leftOperand() const noexcept
Returns the left-hand side sparse matrix operand.
Definition: SMatScalarMultExpr.h:458
Constraint on the data type.
If_t< IsExpression_v< MT >, const MT, const MT & > LeftOperand
Composite data type of the sparse matrix expression.
Definition: SMatScalarMultExpr.h:167
decltype(std::declval< RN >() *std::declval< ST >()) ExprReturnType
Expression return type for the subscript operator.
Definition: SMatScalarMultExpr.h:117
Header file for the MAYBE_UNUSED function template.
ElementType_t< ResultType > ElementType
Resulting element type.
Definition: SMatScalarMultExpr.h:158
Header file for the Computation base class.
Element ValueType
Type of the underlying pointers.
Definition: SMatScalarMultExpr.h:187
Header file for the RequiresEvaluation type trait.
LeftOperand matrix_
Left-hand side sparse matrix of the multiplication expression.
Definition: SMatScalarMultExpr.h:499
ReturnType at(size_t i, size_t j) const
Checked access to the matrix elements.
Definition: SMatScalarMultExpr.h:340
typename T::ReturnType ReturnType_t
Alias declaration for nested ReturnType type definitions.The ReturnType_t alias declaration provides ...
Definition: Aliases.h:410
DifferenceType operator-(const ConstIterator &rhs) const
Calculating the number of elements between two expression iterators.
Definition: SMatScalarMultExpr.h:288
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 dense matrices.The DenseMatrix class is a base class for all dense matrix classes....
Definition: DenseMatrix.h:81
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.
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
ConstIterator upperBound(size_t i, size_t j) const
Returns an iterator to the first index greater then the given index.
Definition: SMatScalarMultExpr.h:447
Header file for the ValueIndexPair class.
Header file for the DisableIf class template.
SMatScalarMultExpr(const MT &matrix, ST scalar) noexcept
Constructor for the SMatScalarMultExpr class.
Definition: SMatScalarMultExpr.h:312
Header file for the IsTemporary type trait class.
Header file for the multiplication trait.
static constexpr bool returnExpr
Compilation switch for the selection of the subscript operator return type.
Definition: SMatScalarMultExpr.h:114
Namespace of the Blaze C++ math library.
Definition: Blaze.h:58
Header file for the If class template.
ConstIterator & operator++()
Pre-increment operator.
Definition: SMatScalarMultExpr.h:214
#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
Header file for the UnderlyingBuiltin type trait.
ST RightOperand
Composite type of the right-hand side scalar value.
Definition: SMatScalarMultExpr.h:170
#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
const ConstIterator * operator->() const
Direct access to the sparse matrix element at the current iterator position.
Definition: SMatScalarMultExpr.h:235
bool canAlias(const T *alias) const noexcept
Returns whether the expression can alias with the given address alias.
Definition: SMatScalarMultExpr.h:480
#define BLAZE_CONSTRAINT_MUST_BE_SAME_TYPE(A, B)
Data type constraint.In case the two types A and B are not the same (ignoring all cv-qualifiers of bo...
Definition: SameType.h:71
size_t columns() const noexcept
Returns the current number of columns of the matrix.
Definition: SMatScalarMultExpr.h:388
constexpr void MAYBE_UNUSED(const Args &...)
Suppression of unused parameter warnings.
Definition: MaybeUnused.h:81
MultTrait_t< RT, ST > ResultType
Result type for expression template evaluations.
Definition: SMatScalarMultExpr.h:155
Constraints on the storage order of matrix types.
Header file for the exception macros of the math module.
ValueType & ReferenceType
Reference return type.
Definition: SMatScalarMultExpr.h:189
ConstIterator lowerBound(size_t i, size_t j) const
Returns an iterator to the first index not less then the given index.
Definition: SMatScalarMultExpr.h:434
Constraint on the data type.
const If_t< returnExpr, ExprReturnType, ElementType > ReturnType
Return type for expression template evaluations.
Definition: SMatScalarMultExpr.h:161
Expression object for sparse matrix-scalar multiplications.The SMatScalarMult class represents the co...
Definition: Forward.h:128
bool isAliased(const T *alias) const noexcept
Returns whether the expression is aliased with the given address alias.
Definition: SMatScalarMultExpr.h:492
Header file for the EnableIf class template.
ConstIterator end(size_t i) const
Returns an iterator just past the last non-zero element of row i.
Definition: SMatScalarMultExpr.h:368
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
Header file for the IsNumeric type trait.
ConstIterator_t< RemoveReference_t< LeftOperand > > IteratorType
Iterator type of the sparse matrix expression.
Definition: SMatScalarMultExpr.h:184
Header file for the MatScalarMultExpr base class.
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
ConstIterator(IteratorType matrix, RightOperand scalar)
Constructor for the ConstIterator class.
Definition: SMatScalarMultExpr.h:203
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
typename UnderlyingBuiltin< T >::Type UnderlyingBuiltin_t
Auxiliary alias declaration for the UnderlyingBuiltin type trait.The UnderlyingBuiltin_t alias declar...
Definition: UnderlyingBuiltin.h:116
bool operator!=(const ConstIterator &rhs) const
Inequality comparison between two ConstIterator objects.
Definition: SMatScalarMultExpr.h:277
#define BLAZE_CONSTRAINT_MUST_BE_NUMERIC_TYPE(T)
Constraint on the data type.In case the given data type T is not a numeric (integral or floating poin...
Definition: Numeric.h:61
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
size_t nonZeros() const
Returns the number of non-zero elements in the sparse matrix.
Definition: SMatScalarMultExpr.h:398
Header file for all forward declarations for expression class templates.
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
Iterator over the elements of the sparse matrix/scalar multiplication expression.
Definition: SMatScalarMultExpr.h:176
Header file for the RemoveReference type trait.
Header file for the IsInvertible type trait.
IteratorCategory iterator_category
The iterator category.
Definition: SMatScalarMultExpr.h:193
OppositeType_t< ResultType > OppositeType
Result type with opposite storage order for expression template evaluations.
Definition: SMatScalarMultExpr.h:156
typename T::ConstIterator ConstIterator_t
Alias declaration for nested ConstIterator type definitions.The ConstIterator_t alias declaration pro...
Definition: Aliases.h:110
IteratorType matrix_
Iterator over the elements of the left-hand side sparse matrix expression.
Definition: SMatScalarMultExpr.h:295
ResultType_t< MT > RT
Result type of the sparse matrix expression.
Definition: SMatScalarMultExpr.h:102
Index-value-pair for sparse vectors and matrices.The ValueIndexPair class represents a single index-v...
Definition: ValueIndexPair.h:73
ptrdiff_t DifferenceType
Difference between two iterators.
Definition: SMatScalarMultExpr.h:190
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
ReturnType_t< MT > RN
Return type of the sparse matrix expression.
Definition: SMatScalarMultExpr.h:103
size_t rows() const noexcept
Returns the current number of rows of the matrix.
Definition: SMatScalarMultExpr.h:378
If_t< useAssign, const ResultType, const SMatScalarMultExpr & > CompositeType
Data type for composite expression templates.
Definition: SMatScalarMultExpr.h:164
ConstIterator find(size_t i, size_t j) const
Searches for a specific matrix element.
Definition: SMatScalarMultExpr.h:421
ReturnType operator()(size_t i, size_t j) const
2D-access to the matrix elements.
Definition: SMatScalarMultExpr.h:325
size_t index() const
Access to the current index of the sparse element.
Definition: SMatScalarMultExpr.h:255
#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
#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
bool operator==(const ConstIterator &rhs) const
Equality comparison between two ConstIterator objects.
Definition: SMatScalarMultExpr.h:266
#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
CompositeType_t< MT > CT
Composite type of the sparse matrix expression.
Definition: SMatScalarMultExpr.h:104
Header file for the IsExpression type trait class.
Header file for the function trace functionality.