35 #ifndef _BLAZE_MATH_EXPRESSIONS_SVECSCALARMULTEXPR_H_ 36 #define _BLAZE_MATH_EXPRESSIONS_SVECSCALARMULTEXPR_H_ 96 class SVecScalarMultExpr
97 :
public VecScalarMultExpr< SparseVector< SVecScalarMultExpr<VT,ST,TF>, TF > >
128 static constexpr
bool useAssign = RequiresEvaluation_v<VT>;
131 template<
typename VT2 >
133 static constexpr
bool UseAssign_v =
useAssign;
145 template<
typename VT2 >
146 static constexpr
bool UseSMPAssign_v =
337 if( index >=
vector_.size() ) {
340 return (*
this)[index];
369 inline size_t size() const noexcept {
446 template<
typename T >
447 inline bool canAlias(
const T* alias )
const noexcept {
448 return vector_.canAlias( alias );
458 template<
typename T >
459 inline bool isAliased(
const T* alias )
const noexcept {
460 return vector_.isAliased( alias );
484 template<
typename VT2 >
492 assign( ~lhs, rhs.vector_ );
493 (~lhs) *= rhs.scalar_;
512 template<
typename VT2 >
520 assign( ~lhs, rhs.vector_ );
521 (~lhs) *= rhs.scalar_;
540 template<
typename VT2 >
541 friend inline auto addAssign( DenseVector<VT2,TF>& lhs,
const SVecScalarMultExpr& rhs )
542 -> EnableIf_t< UseAssign_v<VT2> >
553 addAssign( ~lhs, tmp );
576 template<
typename VT2 >
577 friend inline auto subAssign( DenseVector<VT2,TF>& lhs,
const SVecScalarMultExpr& rhs )
578 -> EnableIf_t< UseAssign_v<VT2> >
589 subAssign( ~lhs, tmp );
612 template<
typename VT2 >
613 friend inline auto multAssign( DenseVector<VT2,TF>& lhs,
const SVecScalarMultExpr& rhs )
614 -> EnableIf_t< UseAssign_v<VT2> >
625 multAssign( ~lhs, tmp );
656 template<
typename VT2 >
658 -> EnableIf_t< UseSMPAssign_v<VT2> >
692 template<
typename VT2 >
694 -> EnableIf_t< UseSMPAssign_v<VT2> >
728 template<
typename VT2 >
730 -> EnableIf_t< UseSMPAssign_v<VT2> >
788 template<
typename VT
822 template<
typename VT
825 , DisableIf_t< IsZero_v<VT> >* =
nullptr >
826 inline const SVecScalarMultExpr< VT, MultTrait_t< UnderlyingBuiltin_t<VT>, ST >, TF >
827 svecscalarmult(
const SparseVector<VT,TF>& vec, ST scalar )
831 using ScalarType = MultTrait_t< UnderlyingBuiltin_t<VT>, ST >;
832 using ReturnType =
const SVecScalarMultExpr<VT,ScalarType,TF>;
852 template<
typename VT
855 , EnableIf_t< IsZero_v<VT> >* =
nullptr >
856 inline decltype(
auto)
857 svecscalarmult( const SparseVector<VT,TF>& vec, ST scalar )
863 using ReturnType =
const MultTrait_t< ResultType_t<VT>, ST >;
895 template<
typename VT
898 , EnableIf_t< IsNumeric_v<ST> >* =
nullptr >
899 inline decltype(
auto) operator*( const
SparseVector<VT,TF>& vec, ST scalar )
903 return svecscalarmult( ~vec, scalar );
929 template<
typename ST
932 , EnableIf_t< IsNumeric_v<ST> >* =
nullptr >
933 inline decltype(
auto) operator*( ST scalar, const
SparseVector<VT,TF>& vec )
937 return svecscalarmult( ~vec, scalar );
968 template<
typename VT
1005 template<
typename VT
1008 inline decltype(
auto) operator-( const SVecScalarMultExpr<VT,ST,TF>& sv )
1012 using ReturnType =
const SVecScalarMultExpr<VT,ST,TF>;
1013 return ReturnType( sv.leftOperand(), -sv.rightOperand() );
1040 template<
typename VT
1044 , EnableIf_t< IsNumeric_v<ST2> >* =
nullptr >
1045 inline decltype(
auto) operator*( const SVecScalarMultExpr<VT,ST1,TF>& vec, ST2 scalar )
1049 return vec.leftOperand() * ( vec.rightOperand() * scalar );
1068 template<
typename ST1
1072 , EnableIf_t< IsNumeric_v<ST1> >* =
nullptr >
1073 inline decltype(
auto) operator*( ST1 scalar, const SVecScalarMultExpr<VT,ST2,TF>& vec )
1077 return vec.leftOperand() * ( scalar * vec.rightOperand() );
1096 template<
typename VT
1100 , EnableIf_t< IsNumeric_v<ST2> && ( IsInvertible_v<ST1> || IsInvertible_v<ST2> ) >* =
nullptr >
1101 inline decltype(
auto) operator/( const SVecScalarMultExpr<VT,ST1,TF>& vec, ST2 scalar )
1105 return vec.leftOperand() * ( vec.rightOperand() / scalar );
1125 template<
typename VT1
1129 inline decltype(
auto)
1130 operator*( const SVecScalarMultExpr<VT1,ST,TF>& lhs, const DenseVector<VT2,TF>& rhs )
1134 return ( lhs.leftOperand() * (~rhs) ) * lhs.rightOperand();
1154 template<
typename VT1
1158 inline decltype(
auto)
1159 operator*( const DenseVector<VT1,TF>& lhs, const SVecScalarMultExpr<VT2,ST,TF>& rhs )
1163 return ( (~lhs) * rhs.leftOperand() ) * rhs.rightOperand();
1183 template<
typename VT1
1186 inline decltype(
auto)
1187 operator*( const SVecScalarMultExpr<VT1,ST,false>& lhs, const DenseVector<VT2,true>& rhs )
1191 return ( lhs.leftOperand() * (~rhs) ) * lhs.rightOperand();
1211 template<
typename VT1
1214 inline decltype(
auto)
1215 operator*( const DenseVector<VT1,false>& lhs, const SVecScalarMultExpr<VT2,ST,true>& rhs )
1219 return ( (~lhs) * rhs.leftOperand() ) * rhs.rightOperand();
1239 template<
typename VT1
1243 inline decltype(
auto)
1244 operator*( const SVecScalarMultExpr<VT1,ST,TF>& lhs, const SparseVector<VT2,TF>& rhs )
1248 return ( lhs.leftOperand() * (~rhs) ) * lhs.rightOperand();
1268 template<
typename VT1
1272 inline decltype(
auto)
1273 operator*( const SparseVector<VT1,TF>& lhs, const SVecScalarMultExpr<VT2,ST,TF>& rhs )
1277 return ( (~lhs) * rhs.leftOperand() ) * rhs.rightOperand();
1297 template<
typename VT1
1302 inline decltype(
auto)
1303 operator*( const SVecScalarMultExpr<VT1,ST1,TF>& lhs, const SVecScalarMultExpr<VT2,ST2,TF>& rhs )
1307 return ( lhs.leftOperand() * rhs.leftOperand() ) * ( lhs.rightOperand() * rhs.rightOperand() );
1327 template<
typename VT1
1330 inline decltype(
auto)
1331 operator*( const SVecScalarMultExpr<VT1,ST,false>& lhs, const SparseVector<VT2,true>& rhs )
1335 return ( lhs.leftOperand() * (~rhs) ) * lhs.rightOperand();
1355 template<
typename VT1
1358 inline decltype(
auto)
1359 operator*( const SparseVector<VT1,false>& lhs, const SVecScalarMultExpr<VT2,ST,true>& rhs )
1363 return ( (~lhs) * rhs.leftOperand() ) * rhs.rightOperand();
1383 template<
typename VT1
1387 inline decltype(
auto)
1388 operator*( const SVecScalarMultExpr<VT1,ST1,false>& lhs, const SVecScalarMultExpr<VT2,ST2,true>& rhs )
1392 return ( lhs.leftOperand() * rhs.leftOperand() ) * ( lhs.rightOperand() * rhs.rightOperand() );
1412 template<
typename MT
1416 inline decltype(
auto)
1417 operator*( const DenseMatrix<MT,SO>& mat, const SVecScalarMultExpr<VT,ST,false>& vec )
1421 return ( (~mat) * vec.leftOperand() ) * vec.rightOperand();
1441 template<
typename VT
1445 inline decltype(
auto)
1446 operator*( const SVecScalarMultExpr<VT,ST,true>& vec, const DenseMatrix<MT,SO>& mat )
1450 return ( vec.leftOperand() * (~mat) ) * vec.rightOperand();
1470 template<
typename MT
1474 inline decltype(
auto)
1475 operator*( const SparseMatrix<MT,SO>& mat, const SVecScalarMultExpr<VT,ST,false>& vec )
1479 return ( (~mat) * vec.leftOperand() ) * vec.rightOperand();
1499 template<
typename VT
1503 inline decltype(
auto)
1504 operator*( const SVecScalarMultExpr<VT,ST,true>& vec, const SparseMatrix<MT,SO>& mat )
1508 return ( vec.leftOperand() * (~mat) ) * vec.rightOperand();
RightOperand rightOperand() const noexcept
Returns the right-hand side scalar operand.
Definition: SVecScalarMultExpr.h:435
Pointer difference type of the Blaze library.
ElementType_t< ResultType > ElementType
Resulting element type.
Definition: SVecScalarMultExpr.h:157
size_t nonZeros() const
Returns the number of non-zero elements in the sparse vector.
Definition: SVecScalarMultExpr.h:379
bool operator==(const ConstIterator &rhs) const
Equality comparison between two ConstIterator objects.
Definition: SVecScalarMultExpr.h:270
Header file for auxiliary alias declarations.
Constraint on the data type.
Header file for basic type definitions.
Header file for the SparseVector base class.
bool operator!=(const ConstIterator &rhs) const
Inequality comparison between two ConstIterator objects.
Definition: SVecScalarMultExpr.h:281
typename If< Condition, T1, T2 >::Type If_t
Auxiliary alias declaration for the If class template.The If_t alias declaration provides a convenien...
Definition: If.h:109
ConstIterator_t< RemoveReference_t< LeftOperand > > IteratorType
Iterator type of the sparse vector expression.
Definition: SVecScalarMultExpr.h:188
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.
IteratorCategory iterator_category
The iterator category.
Definition: SVecScalarMultExpr.h:197
DifferenceType operator-(const ConstIterator &rhs) const
Calculating the number of elements between two expression iterators.
Definition: SVecScalarMultExpr.h:292
ConstIterator begin() const
Returns an iterator to the first non-zero element of the sparse vector.
Definition: SVecScalarMultExpr.h:349
static constexpr bool smpAssignable
Compilation flag for SMP assignments.
Definition: CompressedMatrix.h:3113
Constraint on the data type.
Iterator over the elements of the sparse vector/scalar multiplication expression. ...
Definition: SVecScalarMultExpr.h:180
MultTrait_t< RT, ST > ResultType
Result type for expression template evaluations.
Definition: SVecScalarMultExpr.h:155
Header file for the Computation base class.
Header file for the RequiresEvaluation type trait.
constexpr void UNUSED_PARAMETER(const Args &...)
Suppression of unused parameter warnings.
Definition: Unused.h:81
ValueType & ReferenceType
Reference return type.
Definition: SVecScalarMultExpr.h:193
typename T::ReturnType ReturnType_t
Alias declaration for nested ReturnType type definitions.The ReturnType_t alias declaration provides ...
Definition: Aliases.h:410
Header file for the VecScalarMultExpr base class.
ValueIndexPair< ElementType > Element
Element type of the sparse vector expression.
Definition: SVecScalarMultExpr.h:185
std::forward_iterator_tag IteratorCategory
The iterator category.
Definition: SVecScalarMultExpr.h:190
ConstIterator & operator++()
Pre-increment operator.
Definition: SVecScalarMultExpr.h:218
typename T::ElementType ElementType_t
Alias declaration for nested ElementType type definitions.The ElementType_t alias declaration provide...
Definition: Aliases.h:170
ReturnType_t< VT > RN
Return type of the sparse vector expression.
Definition: SVecScalarMultExpr.h:103
auto length(const DenseVector< VT, TF > &dv) -> decltype(sqrt(sqrLength(~dv)))
Calculation of the length (magnitude) of the dense vector .
Definition: DenseVector.h:606
const Element operator*() const
Direct access to the sparse vector element at the current iterator position.
Definition: SVecScalarMultExpr.h:229
RightOperand scalar_
Right-hand side scalar of the multiplication expression.
Definition: SVecScalarMultExpr.h:467
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
Header file for the ValueIndexPair class.
Header file for the DisableIf class template.
Header file for the IsTemporary type trait class.
Header file for the multiplication trait.
Namespace of the Blaze C++ math library.
Definition: Blaze.h:58
Header file for the If class template.
Element ValueType
Type of the underlying pointers.
Definition: SVecScalarMultExpr.h:191
#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
RightOperand scalar_
Right-hand side scalar of the multiplication expression.
Definition: SVecScalarMultExpr.h:300
Header file for the UnderlyingBuiltin type trait.
Type ElementType
Type of the compressed matrix elements.
Definition: CompressedMatrix.h:3080
#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
decltype(auto) normalize(const DenseVector< VT, TF > &vec)
Normalization of the dense vector ( ).
Definition: DVecScalarMultExpr.h:1148
bool isAliased(const T *alias) const noexcept
Returns whether the expression is aliased with the given address alias.
Definition: SVecScalarMultExpr.h:459
const Element * ConstIterator
Iterator over constant elements.
Definition: CompressedMatrix.h:3086
Base class for N-dimensional dense vectors.The DenseVector class is a base class for all arbitrarily ...
Definition: DenseVector.h:76
#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
#define BLAZE_CONSTRAINT_MUST_BE_SPARSE_VECTOR_TYPE(T)
Constraint on the data type.In case the given data type T is not a sparse, N-dimensional vector type...
Definition: SparseVector.h:61
static constexpr bool useAssign
Compilation switch for the serial evaluation strategy of the multiplication expression.
Definition: SVecScalarMultExpr.h:128
Constraint on the data type.
const If_t< returnExpr, ExprReturnType, ElementType > ReturnType
Return type for expression template evaluations.
Definition: SVecScalarMultExpr.h:160
ResultType_t< VT > RT
Result type of the sparse vector expression.
Definition: SVecScalarMultExpr.h:102
Header file for the exception macros of the math module.
static constexpr bool smpAssignable
Compilation switch for the expression template assignment strategy.
Definition: SVecScalarMultExpr.h:174
ValueType * PointerType
Pointer return type.
Definition: SVecScalarMultExpr.h:192
If_t< IsExpression_v< VT >, const VT, const VT &> LeftOperand
Composite type of the left-hand side sparse vector expression.
Definition: SVecScalarMultExpr.h:166
ReturnType operator[](size_t index) const
Subscript operator for the direct access to the vector elements.
Definition: SVecScalarMultExpr.h:323
Constraint on the data type.
Header file for all forward declarations for expression class templates.
Constraint on the data type.
const ConstIterator * operator->() const
Direct access to the sparse vector element at the current iterator position.
Definition: SVecScalarMultExpr.h:239
typename UnderlyingBuiltin< T >::Type UnderlyingBuiltin_t
Auxiliary alias declaration for the UnderlyingBuiltin type trait.The UnderlyingBuiltin_t alias declar...
Definition: UnderlyingBuiltin.h:133
Header file for the EnableIf class template.
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
Header file for the IsNumeric type trait.
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
If_t< useAssign, const ResultType, const SVecScalarMultExpr &> CompositeType
Data type for composite expression templates.
Definition: SVecScalarMultExpr.h:163
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
IteratorType vector_
Iterator over the elements of the left-hand side sparse vector expression.
Definition: SVecScalarMultExpr.h:299
ConstIterator lowerBound(size_t index) const
Returns an iterator to the first index not less then the given index.
Definition: SVecScalarMultExpr.h:402
ConstIterator end() const
Returns an iterator just past the last non-zero element of the sparse vector.
Definition: SVecScalarMultExpr.h:359
bool canAlias(const T *alias) const noexcept
Returns whether the expression can alias with the given address alias.
Definition: SVecScalarMultExpr.h:447
Constraint on the data type.
size_t size() const noexcept
Returns the current size/dimension of the vector.
Definition: SVecScalarMultExpr.h:369
#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
constexpr size_t size(const Matrix< MT, SO > &matrix) noexcept
Returns the total number of elements of the matrix.
Definition: Matrix.h:530
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
Header file for the RemoveReference type trait.
Header file for the IsInvertible type trait.
static constexpr bool returnExpr
Compilation switch for the selection of the subscript operator return type.
Definition: SVecScalarMultExpr.h:114
ConstIterator find(size_t index) const
Searches for a specific vector element.
Definition: SVecScalarMultExpr.h:390
typename T::ConstIterator ConstIterator_t
Alias declaration for nested ConstIterator type definitions.The ConstIterator_t alias declaration pro...
Definition: Aliases.h:110
const Type & ReturnType
Return type for expression template evaluations.
Definition: CompressedMatrix.h:3081
Index-value-pair for sparse vectors and matrices.The ValueIndexPair class represents a single index-v...
Definition: ValueIndexPair.h:73
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
Expression object for sparse vector-scalar multiplications.The SVecScalarMultExpr class represents th...
Definition: Forward.h:148
Base class for sparse vectors.The SparseVector class is a base class for all arbitrarily sized (N-dim...
Definition: Forward.h:138
size_t index() const
Access to the current index of the sparse element.
Definition: SVecScalarMultExpr.h:259
SVecScalarMultExpr(const VT &vector, ST scalar) noexcept
Constructor for the SVecScalarMultExpr class.
Definition: SVecScalarMultExpr.h:311
ConstIterator upperBound(size_t index) const
Returns an iterator to the first index greater then the given index.
Definition: SVecScalarMultExpr.h:414
TransposeType_t< ResultType > TransposeType
Transpose type for expression template evaluations.
Definition: SVecScalarMultExpr.h:156
ptrdiff_t DifferenceType
Difference between two iterators.
Definition: SVecScalarMultExpr.h:194
LeftOperand vector_
Left-hand side sparse vector of the multiplication expression.
Definition: SVecScalarMultExpr.h:466
CompositeType_t< VT > CT
Composite type of the sparse vector expression.
Definition: SVecScalarMultExpr.h:104
ReturnType at(size_t index) const
Checked access to the vector elements.
Definition: SVecScalarMultExpr.h:336
ReturnType value() const
Access to the current value of the sparse element.
Definition: SVecScalarMultExpr.h:249
#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_CONSTRAINT_MUST_BE_VECTOR_WITH_TRANSPOSE_FLAG(T, TF)
Constraint on the data type.In case the given data type T is not a dense or sparse vector type and in...
Definition: TransposeFlag.h:63
#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
decltype(std::declval< RN >() *std::declval< ST >()) ExprReturnType
Expression return type for the subscript operator.
Definition: SVecScalarMultExpr.h:117
LeftOperand leftOperand() const noexcept
Returns the left-hand side sparse vector operand.
Definition: SVecScalarMultExpr.h:425
ST RightOperand
Composite type of the right-hand side scalar value.
Definition: SVecScalarMultExpr.h:169
auto smpMultAssign(Vector< VT1, TF1 > &lhs, const Vector< VT2, TF2 > &rhs) -> EnableIf_t< IsDenseVector_v< VT1 > >
Default implementation of the SMP multiplication assignment of a vector to a dense vector...
Definition: DenseVector.h:191
#define BLAZE_CONSTRAINT_MUST_BE_FLOATING_POINT_TYPE(T)
Constraint on the data type.In case the given data type T is not a floating point data type...
Definition: FloatingPoint.h:61
Header file for the IsExpression type trait class.
Header file for the function trace functionality.
ConstIterator(IteratorType vector, RightOperand scalar)
Constructor for the ConstIterator class.
Definition: SVecScalarMultExpr.h:207