35 #ifndef _BLAZE_MATH_EXPRESSIONS_SVECSCALARDIVEXPR_H_ 36 #define _BLAZE_MATH_EXPRESSIONS_SVECSCALARDIVEXPR_H_ 100 template<
typename VT
103 class SVecScalarDivExpr
104 :
public VecScalarDivExpr< SparseVector< SVecScalarDivExpr<VT,ST,TF>, TF > >
105 ,
private Computation
135 static constexpr
bool useAssign = RequiresEvaluation_v<VT>;
138 template<
typename VT2 >
140 static constexpr
bool UseAssign_v =
useAssign;
152 template<
typename VT2 >
153 static constexpr
bool UseSMPAssign_v =
154 ( ( !VT2::smpAssignable || !VT::smpAssignable ) &&
useAssign );
344 if( index >=
vector_.size() ) {
347 return (*
this)[index];
376 inline size_t size() const noexcept {
453 template<
typename T >
454 inline bool canAlias(
const T* alias )
const noexcept {
455 return vector_.canAlias( alias );
465 template<
typename T >
466 inline bool isAliased(
const T* alias )
const noexcept {
467 return vector_.isAliased( alias );
491 template<
typename VT2 >
499 assign( ~lhs, rhs.vector_ );
500 (~lhs) /= rhs.scalar_;
519 template<
typename VT2 >
527 assign( ~lhs, rhs.vector_ );
528 (~lhs) /= rhs.scalar_;
547 template<
typename VT2 >
548 friend inline auto addAssign( DenseVector<VT2,TF>& lhs,
const SVecScalarDivExpr& rhs )
549 -> EnableIf_t< UseAssign_v<VT2> >
560 addAssign( ~lhs, tmp );
583 template<
typename VT2 >
584 friend inline auto subAssign( DenseVector<VT2,TF>& lhs,
const SVecScalarDivExpr& rhs )
585 -> EnableIf_t< UseAssign_v<VT2> >
596 subAssign( ~lhs, tmp );
619 template<
typename VT2 >
620 friend inline auto multAssign( DenseVector<VT2,TF>& lhs,
const SVecScalarDivExpr& rhs )
621 -> EnableIf_t< UseAssign_v<VT2> >
632 multAssign( ~lhs, tmp );
663 template<
typename VT2 >
665 -> EnableIf_t< UseSMPAssign_v<VT2> >
699 template<
typename VT2 >
701 -> EnableIf_t< UseSMPAssign_v<VT2> >
735 template<
typename VT2 >
737 -> EnableIf_t< UseSMPAssign_v<VT2> >
785 template<
typename VT
788 struct SVecScalarDivExprHelper
792 using ScalarType = If_t< IsFloatingPoint_v< UnderlyingBuiltin_t<VT> > ||
793 IsFloatingPoint_v< UnderlyingBuiltin_t<ST> >
794 , If_t< IsComplex_v< UnderlyingNumeric_t<VT> > && IsBuiltin_v<ST>
795 , DivTrait_t< UnderlyingBuiltin_t<VT>, ST >
796 , DivTrait_t< UnderlyingNumeric_t<VT>, ST > >
802 using Type = If_t< IsInvertible_v<ScalarType>
803 , SVecScalarMultExpr<VT,ScalarType,TF>
804 , SVecScalarDivExpr<VT,ScalarType,TF> >;
824 template<
typename VT
827 , DisableIf_t< IsZero_v<VT> >* =
nullptr >
828 inline const typename SVecScalarDivExprHelper<VT,ST,TF>::Type
829 svecscalardiv(
const SparseVector<VT,TF>& vec, ST scalar )
833 using ReturnType =
typename SVecScalarDivExprHelper<VT,ST,TF>::Type;
834 using ScalarType = RightOperand_t<ReturnType>;
836 if( IsMultExpr_v<ReturnType> ) {
837 return ReturnType( ~vec, ScalarType(1)/ScalarType(scalar) );
840 return ReturnType( ~vec, scalar );
860 template<
typename VT
863 , EnableIf_t< IsZero_v<VT> >* =
nullptr >
864 inline decltype(
auto)
865 svecscalardiv( const SparseVector<VT,TF>& vec, ST scalar )
871 using ReturnType =
const DivTrait_t< ResultType_t<VT>, ST >;
876 return ReturnType( (~vec).
size() );
905 template<
typename VT
908 , EnableIf_t< IsNumeric_v<ST> >* =
nullptr >
909 inline decltype(
auto) operator/( const
SparseVector<VT,TF>& vec, ST scalar )
915 return svecscalardiv( ~vec, scalar );
941 template<
typename VT
945 , EnableIf_t< IsNumeric_v<ST2> && ( IsInvertible_v<ST1> || IsInvertible_v<ST2> ) >* =
nullptr >
946 inline decltype(
auto) operator*( const SVecScalarDivExpr<VT,ST1,TF>& vec, ST2 scalar )
950 return vec.leftOperand() * ( scalar / vec.rightOperand() );
969 template<
typename ST1
973 , EnableIf_t< IsNumeric_v<ST1> && ( IsInvertible_v<ST1> || IsInvertible_v<ST2> ) >* =
nullptr >
974 inline decltype(
auto) operator*( ST1 scalar, const SVecScalarDivExpr<VT,ST2,TF>& vec )
978 return vec.leftOperand() * ( scalar / vec.rightOperand() );
997 template<
typename VT
1001 , EnableIf_t< IsNumeric_v<ST2> >* =
nullptr >
1002 inline decltype(
auto) operator/( const SVecScalarDivExpr<VT,ST1,TF>& vec, ST2 scalar )
1008 using MultType = MultTrait_t<ST1,ST2>;
1009 using ReturnType =
typename SVecScalarDivExprHelper<VT,MultType,TF>::Type;
1010 using ScalarType = RightOperand_t<ReturnType>;
1012 if( IsMultExpr_v<ReturnType> ) {
1013 return ReturnType( vec.leftOperand(), ScalarType(1)/( vec.rightOperand() * scalar ) );
1016 return ReturnType( vec.leftOperand(), vec.rightOperand() * scalar );
Header file for the UnderlyingNumeric type trait.
Pointer difference type of the Blaze library.
Header file for auxiliary alias declarations.
Constraint on the data type.
ConstIterator(IteratorType vector, RightOperand scalar)
Constructor for the ConstIterator class.
Definition: SVecScalarDivExpr.h:214
size_t size() const noexcept
Returns the current size/dimension of the vector.
Definition: SVecScalarDivExpr.h:376
#define BLAZE_USER_ASSERT(expr, msg)
Run time assertion macro for user checks.In case of an invalid run time expression,...
Definition: Assert.h:117
Header file for basic type definitions.
Header file for the SparseVector base class.
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
static constexpr bool smpAssignable
Compilation switch for the expression template assignment strategy.
Definition: SVecScalarDivExpr.h:181
ResultType_t< VT > RT
Result type of the sparse vector expression.
Definition: SVecScalarDivExpr.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.
typename DivTrait< T1, T2 >::Type DivTrait_t
Auxiliary alias declaration for the DivTrait class template.The DivTrait_t alias declaration provides...
Definition: DivTrait.h:239
size_t index() const
Access to the current index of the sparse element.
Definition: SVecScalarDivExpr.h:266
Header file for the VecScalarDivExpr base class.
Constraint on the data type.
ConstIterator end() const
Returns an iterator just past the last non-zero element of the sparse vector.
Definition: SVecScalarDivExpr.h:366
Header file for the MAYBE_UNUSED function template.
DivTrait_t< RT, ST > ResultType
Result type for expression template evaluations.
Definition: SVecScalarDivExpr.h:162
Header file for the Computation base class.
Header file for the RequiresEvaluation type trait.
IteratorCategory iterator_category
The iterator category.
Definition: SVecScalarDivExpr.h:204
ValueIndexPair< ElementType > Element
Element type of the sparse vector expression.
Definition: SVecScalarDivExpr.h:192
const ConstIterator * operator->() const
Direct access to the sparse vector element at the current iterator position.
Definition: SVecScalarDivExpr.h:246
typename T::ReturnType ReturnType_t
Alias declaration for nested ReturnType type definitions.The ReturnType_t alias declaration provides ...
Definition: Aliases.h:410
typename T::ElementType ElementType_t
Alias declaration for nested ElementType type definitions.The ElementType_t alias declaration provide...
Definition: Aliases.h:170
ST RightOperand
Composite type of the right-hand side scalar value.
Definition: SVecScalarDivExpr.h:176
SVecScalarDivExpr(const VT &vector, ST scalar) noexcept
Constructor for the SVecScalarDivExpr class.
Definition: SVecScalarDivExpr.h:318
DifferenceType operator-(const ConstIterator &rhs) const
Calculating the number of elements between two expression iterators.
Definition: SVecScalarDivExpr.h:299
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
ElementType_t< ResultType > ElementType
Resulting element type.
Definition: SVecScalarDivExpr.h:164
RightOperand scalar_
Right hand side scalar of the multiplication expression.
Definition: SVecScalarDivExpr.h:307
ConstIterator upperBound(size_t index) const
Returns an iterator to the first index greater then the given index.
Definition: SVecScalarDivExpr.h:421
ptrdiff_t DifferenceType
Difference between two iterators.
Definition: SVecScalarDivExpr.h:201
Header file for the ValueIndexPair class.
Header file for the DisableIf class template.
Header file for the IsTemporary type trait class.
Element ValueType
Type of the underlying pointers.
Definition: SVecScalarDivExpr.h:198
Header file for the multiplication trait.
Namespace of the Blaze C++ math library.
Definition: Blaze.h:58
Header file for the If class template.
Header file for the IsFloatingPoint type trait.
IteratorType vector_
Iterator over the elements of the left-hand side sparse vector expression.
Definition: SVecScalarDivExpr.h:306
#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.
Header file for the IsMultExpr type trait class.
Iterator over the elements of the sparse vector/scalar multiplication expression.
Definition: SVecScalarDivExpr.h:187
#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 Element operator *() const
Direct access to the sparse vector element at the current iterator position.
Definition: SVecScalarDivExpr.h:236
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
ValueType * PointerType
Pointer return type.
Definition: SVecScalarDivExpr.h:199
Constraint on the data type.
ReturnType value() const
Access to the current value of the sparse element.
Definition: SVecScalarDivExpr.h:256
ValueType & ReferenceType
Reference return type.
Definition: SVecScalarDivExpr.h:200
bool isAliased(const T *alias) const noexcept
Returns whether the expression is aliased with the given address alias.
Definition: SVecScalarDivExpr.h:466
Header file for the exception macros of the math module.
decltype(std::declval< RN >()/std::declval< ST >()) ExprReturnType
Expression return type for the subscript operator.
Definition: SVecScalarDivExpr.h:124
Constraint on the data type.
If_t< useAssign, const ResultType, const SVecScalarDivExpr & > CompositeType
Data type for composite expression templates.
Definition: SVecScalarDivExpr.h:170
ConstIterator & operator++()
Pre-increment operator.
Definition: SVecScalarDivExpr.h:225
Constraint on the data type.
Header file for the EnableIf class template.
size_t nonZeros() const
Returns the number of non-zero elements in the sparse vector.
Definition: SVecScalarDivExpr.h:386
ConstIterator find(size_t index) const
Searches for a specific vector element.
Definition: SVecScalarDivExpr.h:397
RightOperand scalar_
Right-hand side scalar of the division expression.
Definition: SVecScalarDivExpr.h:474
Header file for the IsNumeric type trait.
static constexpr bool useAssign
Compilation switch for the serial evaluation strategy of the multiplication expression.
Definition: SVecScalarDivExpr.h:135
const If_t< returnExpr, ExprReturnType, ElementType > ReturnType
Return type for expression template evaluations.
Definition: SVecScalarDivExpr.h:167
bool canAlias(const T *alias) const noexcept
Returns whether the expression can alias with the given address alias.
Definition: SVecScalarDivExpr.h:454
ConstIterator begin() const
Returns an iterator to the first non-zero element of the sparse vector.
Definition: SVecScalarDivExpr.h:356
std::forward_iterator_tag IteratorCategory
The iterator category.
Definition: SVecScalarDivExpr.h:197
RightOperand rightOperand() const noexcept
Returns the right-hand side scalar operand.
Definition: SVecScalarDivExpr.h:442
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.
ReturnType_t< VT > RN
Return type of the sparse vector expression.
Definition: SVecScalarDivExpr.h:110
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
Header file for the division trait.
Constraint on the data type.
#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.
If_t< IsExpression_v< VT >, const VT, const VT & > LeftOperand
Composite type of the left-hand side sparse vector expression.
Definition: SVecScalarDivExpr.h:173
#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
ConstIterator_t< RemoveReference_t< LeftOperand > > IteratorType
Iterator type of the sparse vector expression.
Definition: SVecScalarDivExpr.h:195
LeftOperand leftOperand() const noexcept
Returns the left-hand side sparse vector operand.
Definition: SVecScalarDivExpr.h:432
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
Expression object for divisions of a sparse vector by a scalar.The SVecScalarDivExpr class represents...
Definition: Forward.h:156
TransposeType_t< ResultType > TransposeType
Transpose type for expression template evaluations.
Definition: SVecScalarDivExpr.h:163
LeftOperand vector_
Left-hand side sparse vector of the division expression.
Definition: SVecScalarDivExpr.h:473
Header file for the RemoveReference type trait.
Header file for the IsInvertible type trait.
#define BLAZE_CONSTRAINT_MUST_NOT_BE_FLOATING_POINT_TYPE(T)
Constraint on the data type.In case the given data type T is a floating point data type,...
Definition: FloatingPoint.h:81
typename T::ConstIterator ConstIterator_t
Alias declaration for nested ConstIterator type definitions.The ConstIterator_t alias declaration pro...
Definition: Aliases.h:110
ConstIterator lowerBound(size_t index) const
Returns an iterator to the first index not less then the given index.
Definition: SVecScalarDivExpr.h:409
Index-value-pair for sparse vectors and matrices.The ValueIndexPair class represents a single index-v...
Definition: ValueIndexPair.h:73
bool operator==(const ConstIterator &rhs) const
Equality comparison between two ConstIterator objects.
Definition: SVecScalarDivExpr.h:277
Header file for the IsComputation type trait class.
Header file for the IsBuiltin type trait.
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
Base class for sparse vectors.The SparseVector class is a base class for all arbitrarily sized (N-dim...
Definition: Forward.h:146
ReturnType at(size_t index) const
Checked access to the vector elements.
Definition: SVecScalarDivExpr.h:343
static constexpr bool returnExpr
Compilation switch for the selection of the subscript operator return type.
Definition: SVecScalarDivExpr.h:121
bool operator!=(const ConstIterator &rhs) const
Inequality comparison between two ConstIterator objects.
Definition: SVecScalarDivExpr.h:288
Header file for the IsComplex type trait.
#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
ReturnType operator[](size_t index) const
Subscript operator for the direct access to the vector elements.
Definition: SVecScalarDivExpr.h:330
#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
CompositeType_t< VT > CT
Composite type of the sparse vector expression.
Definition: SVecScalarDivExpr.h:111
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
Header file for the IsExpression type trait class.
Header file for the function trace functionality.