35 #ifndef _BLAZE_MATH_EXPRESSIONS_SVECSCALARMULTEXPR_H_ 36 #define _BLAZE_MATH_EXPRESSIONS_SVECSCALARMULTEXPR_H_ 97 class SVecScalarMultExpr
98 :
public VecScalarMultExpr< SparseVector< SVecScalarMultExpr<VT,ST,TF>, TF > >
129 static constexpr
bool useAssign = RequiresEvaluation_v<VT>;
132 template<
typename VT2 >
134 static constexpr
bool UseAssign_v =
useAssign;
146 template<
typename VT2 >
147 static constexpr
bool UseSMPAssign_v =
148 ( ( !VT2::smpAssignable || !VT::smpAssignable ) &&
useAssign );
338 if( index >=
vector_.size() ) {
341 return (*
this)[index];
370 inline size_t size() const noexcept {
447 template<
typename T >
448 inline bool canAlias(
const T* alias )
const noexcept {
449 return vector_.canAlias( alias );
459 template<
typename T >
460 inline bool isAliased(
const T* alias )
const noexcept {
461 return vector_.isAliased( alias );
485 template<
typename VT2 >
493 assign( ~lhs, rhs.vector_ );
494 (~lhs) *= rhs.scalar_;
513 template<
typename VT2 >
521 assign( ~lhs, rhs.vector_ );
522 (~lhs) *= rhs.scalar_;
541 template<
typename VT2 >
542 friend inline auto addAssign( DenseVector<VT2,TF>& lhs,
const SVecScalarMultExpr& rhs )
543 -> EnableIf_t< UseAssign_v<VT2> >
554 addAssign( ~lhs, tmp );
577 template<
typename VT2 >
578 friend inline auto subAssign( DenseVector<VT2,TF>& lhs,
const SVecScalarMultExpr& rhs )
579 -> EnableIf_t< UseAssign_v<VT2> >
590 subAssign( ~lhs, tmp );
613 template<
typename VT2 >
614 friend inline auto multAssign( DenseVector<VT2,TF>& lhs,
const SVecScalarMultExpr& rhs )
615 -> EnableIf_t< UseAssign_v<VT2> >
626 multAssign( ~lhs, tmp );
657 template<
typename VT2 >
659 -> EnableIf_t< UseSMPAssign_v<VT2> >
693 template<
typename VT2 >
695 -> EnableIf_t< UseSMPAssign_v<VT2> >
729 template<
typename VT2 >
731 -> EnableIf_t< UseSMPAssign_v<VT2> >
789 template<
typename VT
797 return ReturnType( ~sv, ScalarType(-1) );
823 template<
typename VT
826 , DisableIf_t< IsZero_v<VT> >* =
nullptr >
827 inline const SVecScalarMultExpr< VT, MultTrait_t< UnderlyingBuiltin_t<VT>, ST >, TF >
828 svecscalarmult(
const SparseVector<VT,TF>& vec, ST scalar )
832 using ScalarType = MultTrait_t< UnderlyingBuiltin_t<VT>, ST >;
833 using ReturnType =
const SVecScalarMultExpr<VT,ScalarType,TF>;
834 return ReturnType( ~vec, scalar );
853 template<
typename VT
856 , EnableIf_t< IsZero_v<VT> >* =
nullptr >
857 inline decltype(
auto)
858 svecscalarmult( const SparseVector<VT,TF>& vec, ST scalar )
864 using ReturnType =
const MultTrait_t< ResultType_t<VT>, ST >;
869 return ReturnType( (~vec).
size() );
896 template<
typename VT
899 , EnableIf_t< IsNumeric_v<ST> >* =
nullptr >
900 inline decltype(
auto) operator*( const
SparseVector<VT,TF>& vec, ST scalar )
904 return svecscalarmult( ~vec, scalar );
930 template<
typename ST
933 , EnableIf_t< IsNumeric_v<ST> >* =
nullptr >
934 inline decltype(
auto) operator*( ST scalar, const
SparseVector<VT,TF>& vec )
938 return svecscalarmult( ~vec, scalar );
969 template<
typename VT
977 const ElementType len (
length( ~vec ) );
978 const ElementType ilen( ( len != ElementType(0) )?( ElementType(1) / len ):( 0 ) );
981 return ReturnType( ~vec, ilen );
1006 template<
typename VT
1009 inline decltype(
auto) operator-( const SVecScalarMultExpr<VT,ST,TF>& sv )
1013 using ReturnType =
const SVecScalarMultExpr<VT,ST,TF>;
1014 return ReturnType( sv.leftOperand(), -sv.rightOperand() );
1041 template<
typename VT
1045 , EnableIf_t< IsNumeric_v<ST2> >* =
nullptr >
1046 inline decltype(
auto) operator*( const SVecScalarMultExpr<VT,ST1,TF>& vec, ST2 scalar )
1050 return vec.leftOperand() * ( vec.rightOperand() * scalar );
1069 template<
typename ST1
1073 , EnableIf_t< IsNumeric_v<ST1> >* =
nullptr >
1074 inline decltype(
auto) operator*( ST1 scalar, const SVecScalarMultExpr<VT,ST2,TF>& vec )
1078 return vec.leftOperand() * ( scalar * vec.rightOperand() );
1097 template<
typename VT
1101 , EnableIf_t< IsNumeric_v<ST2> && ( IsInvertible_v<ST1> || IsInvertible_v<ST2> ) >* =
nullptr >
1102 inline decltype(
auto) operator/( const SVecScalarMultExpr<VT,ST1,TF>& vec, ST2 scalar )
1106 return vec.leftOperand() * ( vec.rightOperand() / scalar );
1126 template<
typename VT1
1130 inline decltype(
auto)
1131 operator*( const SVecScalarMultExpr<VT1,ST,TF>& lhs, const DenseVector<VT2,TF>& rhs )
1135 return ( lhs.leftOperand() * (~rhs) ) * lhs.rightOperand();
1155 template<
typename VT1
1159 inline decltype(
auto)
1160 operator*( const DenseVector<VT1,TF>& lhs, const SVecScalarMultExpr<VT2,ST,TF>& rhs )
1164 return ( (~lhs) * rhs.leftOperand() ) * rhs.rightOperand();
1184 template<
typename VT1
1187 inline decltype(
auto)
1188 operator*( const SVecScalarMultExpr<VT1,ST,false>& lhs, const DenseVector<VT2,true>& rhs )
1192 return ( lhs.leftOperand() * (~rhs) ) * lhs.rightOperand();
1212 template<
typename VT1
1215 inline decltype(
auto)
1216 operator*( const DenseVector<VT1,false>& lhs, const SVecScalarMultExpr<VT2,ST,true>& rhs )
1220 return ( (~lhs) * rhs.leftOperand() ) * rhs.rightOperand();
1240 template<
typename VT1
1244 inline decltype(
auto)
1245 operator*( const SVecScalarMultExpr<VT1,ST,TF>& lhs, const SparseVector<VT2,TF>& rhs )
1249 return ( lhs.leftOperand() * (~rhs) ) * lhs.rightOperand();
1269 template<
typename VT1
1273 inline decltype(
auto)
1274 operator*( const SparseVector<VT1,TF>& lhs, const SVecScalarMultExpr<VT2,ST,TF>& rhs )
1278 return ( (~lhs) * rhs.leftOperand() ) * rhs.rightOperand();
1298 template<
typename VT1
1303 inline decltype(
auto)
1304 operator*( const SVecScalarMultExpr<VT1,ST1,TF>& lhs, const SVecScalarMultExpr<VT2,ST2,TF>& rhs )
1308 return ( lhs.leftOperand() * rhs.leftOperand() ) * ( lhs.rightOperand() * rhs.rightOperand() );
1328 template<
typename VT1
1331 inline decltype(
auto)
1332 operator*( const SVecScalarMultExpr<VT1,ST,false>& lhs, const SparseVector<VT2,true>& rhs )
1336 return ( lhs.leftOperand() * (~rhs) ) * lhs.rightOperand();
1356 template<
typename VT1
1359 inline decltype(
auto)
1360 operator*( const SparseVector<VT1,false>& lhs, const SVecScalarMultExpr<VT2,ST,true>& rhs )
1364 return ( (~lhs) * rhs.leftOperand() ) * rhs.rightOperand();
1384 template<
typename VT1
1388 inline decltype(
auto)
1389 operator*( const SVecScalarMultExpr<VT1,ST1,false>& lhs, const SVecScalarMultExpr<VT2,ST2,true>& rhs )
1393 return ( lhs.leftOperand() * rhs.leftOperand() ) * ( lhs.rightOperand() * rhs.rightOperand() );
1413 template<
typename MT
1417 inline decltype(
auto)
1418 operator*( const DenseMatrix<MT,SO>& mat, const SVecScalarMultExpr<VT,ST,false>& vec )
1422 return ( (~mat) * vec.leftOperand() ) * vec.rightOperand();
1442 template<
typename VT
1446 inline decltype(
auto)
1447 operator*( const SVecScalarMultExpr<VT,ST,true>& vec, const DenseMatrix<MT,SO>& mat )
1451 return ( vec.leftOperand() * (~mat) ) * vec.rightOperand();
1471 template<
typename MT
1475 inline decltype(
auto)
1476 operator*( const SparseMatrix<MT,SO>& mat, const SVecScalarMultExpr<VT,ST,false>& vec )
1480 return ( (~mat) * vec.leftOperand() ) * vec.rightOperand();
1500 template<
typename VT
1504 inline decltype(
auto)
1505 operator*( const SVecScalarMultExpr<VT,ST,true>& vec, const SparseMatrix<MT,SO>& mat )
1509 return ( vec.leftOperand() * (~mat) ) * vec.rightOperand();
RightOperand rightOperand() const noexcept
Returns the right-hand side scalar operand.
Definition: SVecScalarMultExpr.h:436
Pointer difference type of the Blaze library.
ElementType_t< ResultType > ElementType
Resulting element type.
Definition: SVecScalarMultExpr.h:158
size_t nonZeros() const
Returns the number of non-zero elements in the sparse vector.
Definition: SVecScalarMultExpr.h:380
bool operator==(const ConstIterator &rhs) const
Equality comparison between two ConstIterator objects.
Definition: SVecScalarMultExpr.h:271
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:282
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
ConstIterator_t< RemoveReference_t< LeftOperand > > IteratorType
Iterator type of the sparse vector expression.
Definition: SVecScalarMultExpr.h:189
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.
const Element operator *() const
Direct access to the sparse vector element at the current iterator position.
Definition: SVecScalarMultExpr.h:230
IteratorCategory iterator_category
The iterator category.
Definition: SVecScalarMultExpr.h:198
DifferenceType operator-(const ConstIterator &rhs) const
Calculating the number of elements between two expression iterators.
Definition: SVecScalarMultExpr.h:293
ConstIterator begin() const
Returns an iterator to the first non-zero element of the sparse vector.
Definition: SVecScalarMultExpr.h:350
Constraint on the data type.
Header file for the MAYBE_UNUSED function template.
Iterator over the elements of the sparse vector/scalar multiplication expression.
Definition: SVecScalarMultExpr.h:181
MultTrait_t< RT, ST > ResultType
Result type for expression template evaluations.
Definition: SVecScalarMultExpr.h:156
Header file for the Computation base class.
Header file for the RequiresEvaluation type trait.
ValueType & ReferenceType
Reference return type.
Definition: SVecScalarMultExpr.h:194
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:186
std::forward_iterator_tag IteratorCategory
The iterator category.
Definition: SVecScalarMultExpr.h:191
ConstIterator & operator++()
Pre-increment operator.
Definition: SVecScalarMultExpr.h:219
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:104
RightOperand scalar_
Right-hand side scalar of the multiplication expression.
Definition: SVecScalarMultExpr.h:468
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:192
#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:301
Header file for the UnderlyingBuiltin type trait.
#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:1149
bool isAliased(const T *alias) const noexcept
Returns whether the expression is aliased with the given address alias.
Definition: SVecScalarMultExpr.h:460
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
constexpr void MAYBE_UNUSED(const Args &...)
Suppression of unused parameter warnings.
Definition: MaybeUnused.h:81
#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:129
Constraint on the data type.
const If_t< returnExpr, ExprReturnType, ElementType > ReturnType
Return type for expression template evaluations.
Definition: SVecScalarMultExpr.h:161
ResultType_t< VT > RT
Result type of the sparse vector expression.
Definition: SVecScalarMultExpr.h:103
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:175
ValueType * PointerType
Pointer return type.
Definition: SVecScalarMultExpr.h:193
If_t< IsExpression_v< VT >, const VT, const VT & > LeftOperand
Composite type of the left-hand side sparse vector expression.
Definition: SVecScalarMultExpr.h:167
ReturnType operator[](size_t index) const
Subscript operator for the direct access to the vector elements.
Definition: SVecScalarMultExpr.h:324
Constraint on the data type.
Constraint on the data type.
const ConstIterator * operator->() const
Direct access to the sparse vector element at the current iterator position.
Definition: SVecScalarMultExpr.h:240
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.
decltype(auto) length(const DenseVector< VT, TF > &dv)
Calculation of the length (magnitude) of the dense vector .
Definition: DVecNormExpr.h:596
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:164
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:300
ConstIterator lowerBound(size_t index) const
Returns an iterator to the first index not less then the given index.
Definition: SVecScalarMultExpr.h:403
ConstIterator end() const
Returns an iterator just past the last non-zero element of the sparse vector.
Definition: SVecScalarMultExpr.h:360
bool canAlias(const T *alias) const noexcept
Returns whether the expression can alias with the given address alias.
Definition: SVecScalarMultExpr.h:448
typename UnderlyingBuiltin< T >::Type UnderlyingBuiltin_t
Auxiliary alias declaration for the UnderlyingBuiltin type trait.The UnderlyingBuiltin_t alias declar...
Definition: UnderlyingBuiltin.h:116
Constraint on the data type.
size_t size() const noexcept
Returns the current size/dimension of the vector.
Definition: SVecScalarMultExpr.h:370
#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
Header file for all forward declarations for expression class templates.
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:115
ConstIterator find(size_t index) const
Searches for a specific vector element.
Definition: SVecScalarMultExpr.h:391
typename T::ConstIterator ConstIterator_t
Alias declaration for nested ConstIterator type definitions.The ConstIterator_t alias declaration pro...
Definition: Aliases.h:110
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:157
Base class for sparse vectors.The SparseVector class is a base class for all arbitrarily sized (N-dim...
Definition: Forward.h:146
size_t index() const
Access to the current index of the sparse element.
Definition: SVecScalarMultExpr.h:260
SVecScalarMultExpr(const VT &vector, ST scalar) noexcept
Constructor for the SVecScalarMultExpr class.
Definition: SVecScalarMultExpr.h:312
ConstIterator upperBound(size_t index) const
Returns an iterator to the first index greater then the given index.
Definition: SVecScalarMultExpr.h:415
TransposeType_t< ResultType > TransposeType
Transpose type for expression template evaluations.
Definition: SVecScalarMultExpr.h:157
ptrdiff_t DifferenceType
Difference between two iterators.
Definition: SVecScalarMultExpr.h:195
LeftOperand vector_
Left-hand side sparse vector of the multiplication expression.
Definition: SVecScalarMultExpr.h:467
CompositeType_t< VT > CT
Composite type of the sparse vector expression.
Definition: SVecScalarMultExpr.h:105
ReturnType at(size_t index) const
Checked access to the vector elements.
Definition: SVecScalarMultExpr.h:337
ReturnType value() const
Access to the current value of the sparse element.
Definition: SVecScalarMultExpr.h:250
#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,...
Definition: Assert.h:101
decltype(std::declval< RN >() *std::declval< ST >()) ExprReturnType
Expression return type for the subscript operator.
Definition: SVecScalarMultExpr.h:118
LeftOperand leftOperand() const noexcept
Returns the left-hand side sparse vector operand.
Definition: SVecScalarMultExpr.h:426
ST RightOperand
Composite type of the right-hand side scalar value.
Definition: SVecScalarMultExpr.h:170
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:208