35 #ifndef _BLAZE_MATH_EXPRESSIONS_SVECSVECSUBEXPR_H_ 36 #define _BLAZE_MATH_EXPRESSIONS_SVECSVECSUBEXPR_H_ 89 template<
typename VT1
93 :
public VecVecSubExpr< SparseVector< SVecSVecSubExpr<VT1,VT2,TF>, TF > >
113 static constexpr
bool returnExpr = ( !IsTemporary_v<RN1> && !IsTemporary_v<RN2> );
126 template<
typename VT >
127 static constexpr
bool UseSMPAssign_v = VT::smpAssignable;
188 if( index >=
lhs_.size() ) {
191 return (*
this)[index];
200 inline size_t size() const noexcept {
241 template<
typename T >
242 inline bool canAlias(
const T* alias )
const noexcept {
243 return (
lhs_.canAlias( alias ) ||
rhs_.canAlias( alias ) );
253 template<
typename T >
254 inline bool isAliased(
const T* alias )
const noexcept {
255 return (
lhs_.isAliased( alias ) ||
rhs_.isAliased( alias ) );
278 template<
typename VT >
293 const auto lend( x.end() );
294 const auto rend( y.end() );
296 for(
auto l=x.begin(); l!=lend; ++l ) {
297 (~lhs)[l->index()] = l->value();
300 for(
auto r=y.begin(); r!=rend; ++r ) {
302 (~lhs)[r->index()] = -r->value();
304 (~lhs)[r->index()] -= r->value();
323 template<
typename VT >
338 const auto lend( x.end() );
339 const auto rend( y.end() );
341 for(
auto l=x.begin(); l!=lend; ++l ) {
342 (~lhs)[l->index()] = l->value();
345 for(
auto r=y.begin(); r!=rend; ++r ) {
346 (~lhs)[r->index()] -= r->value();
364 template<
typename VT >
365 friend inline void assign( SparseVector<VT,TF>& lhs,
const SVecSVecSubExpr& rhs )
379 (~lhs).reserve(
min( x.size(), x.nonZeros() + y.nonZeros() ) );
382 const auto lend( x.end() );
383 const auto rend( y.end() );
388 while( l != lend && r != rend )
390 if( l->index() < r->index() ) {
391 (~lhs).append( l->index(), l->value() );
394 else if( l->index() > r->index() ) {
395 (~lhs).append( r->index(), -r->value() );
399 (~lhs).append( l->index(), l->value() - r->value() );
406 (~lhs).append( l->index(), l->value() );
411 (~lhs).append( r->index(), -r->value() );
430 template<
typename VT >
431 friend inline void addAssign( DenseVector<VT,TF>& lhs,
const SVecSVecSubExpr& rhs )
437 addAssign( ~lhs, rhs.lhs_ );
438 subAssign( ~lhs, rhs.rhs_ );
459 template<
typename VT >
460 friend inline void subAssign( DenseVector<VT,TF>& lhs,
const SVecSVecSubExpr& rhs )
466 subAssign( ~lhs, rhs.lhs_ );
467 addAssign( ~lhs, rhs.rhs_ );
488 template<
typename VT >
489 friend inline void multAssign( DenseVector<VT,TF>& lhs,
const SVecSVecSubExpr& rhs )
500 multAssign( ~lhs, tmp );
531 template<
typename VT >
533 -> EnableIf_t< UseSMPAssign_v<VT> >
564 template<
typename VT >
566 -> EnableIf_t< UseSMPAssign_v<VT> >
597 template<
typename VT >
599 -> EnableIf_t< UseSMPAssign_v<VT> >
652 template<
typename VT1
655 ,
DisableIf_t< ( ( IsZero_v<VT1> || IsZero_v<VT2> ) &&
656 IsSame_v< ElementType_t<VT1>, ElementType_t<VT2> > ) ||
657 ( IsZero_v<VT1> && IsZero_v<VT2> ) >* =
nullptr >
658 inline const SVecSVecSubExpr<VT1,VT2,TF>
659 svecsvecsub(
const SparseVector<VT1,TF>& lhs,
const SparseVector<VT2,TF>& rhs )
665 return SVecSVecSubExpr<VT1,VT2,TF>( ~lhs, ~rhs );
684 template<
typename VT1
687 , EnableIf_t< !IsZero_v<VT1> && IsZero_v<VT2> &&
688 IsSame_v< ElementType_t<VT1>, ElementType_t<VT2> > >* =
nullptr >
690 svecsvecsub(
const SparseVector<VT1,TF>& lhs,
const SparseVector<VT2,TF>& rhs )
717 template<
typename VT1
720 , EnableIf_t< IsZero_v<VT1> && !IsZero_v<VT2> &&
721 IsSame_v< ElementType_t<VT1>, ElementType_t<VT2> > >* =
nullptr >
722 inline decltype(
auto)
723 svecsvecsub( const SparseVector<VT1,TF>& lhs, const SparseVector<VT2,TF>& rhs )
749 template<
typename VT1
752 , EnableIf_t< IsZero_v<VT1> && IsZero_v<VT2> >* =
nullptr >
753 inline decltype(
auto)
754 svecsvecsub( const SparseVector<VT1,TF>& lhs, const SparseVector<VT2,TF>& rhs )
762 using ReturnType =
const SubTrait_t< ResultType_t<VT1>, ResultType_t<VT2> >;
767 return ReturnType( (~lhs).
size() );
797 template<
typename VT1
800 inline decltype(
auto)
805 if( (~lhs).
size() != (~rhs).
size() ) {
809 return svecsvecsub( ~lhs, ~rhs );
#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.
Headerfile for the generic min algorithm.
typename SubTrait< T1, T2 >::Type SubTrait_t
Auxiliary alias declaration for the SubTrait class template.The SubTrait_t alias declaration provides...
Definition: SubTrait.h:238
Header file for the subtraction trait.
Header file for basic type definitions.
Header file for the SparseVector base class.
size_t nonZeros() const
Returns the number of non-zero elements in the sparse vector.
Definition: SVecSVecSubExpr.h:210
SVecSVecSubExpr(const VT1 &lhs, const VT2 &rhs) noexcept
Constructor for the SVecSVecSubExpr class.
Definition: SVecSVecSubExpr.h:160
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.
CompositeType_t< VT1 > CT1
Composite type of the left-hand side sparse vector expression.
Definition: SVecSVecSubExpr.h:102
LeftOperand lhs_
Left-hand side sparse vector of the subtraction expression.
Definition: SVecSVecSubExpr.h:261
Header file for the IsSame and IsStrictlySame type traits.
ReturnType_t< VT2 > RN2
Return type of the right-hand side sparse vector expression.
Definition: SVecSVecSubExpr.h:101
LeftOperand leftOperand() const noexcept
Returns the left-hand side sparse vector operand.
Definition: SVecSVecSubExpr.h:220
bool canAlias(const T *alias) const noexcept
Returns whether the expression can alias with the given address alias.
Definition: SVecSVecSubExpr.h:242
Constraint on the data type.
Header file for the MAYBE_UNUSED function template.
Header file for the Computation base class.
const ResultType CompositeType
Data type for composite expression templates.
Definition: SVecSVecSubExpr.h:143
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
bool isAliased(const T *alias) const noexcept
Returns whether the expression is aliased with the given address alias.
Definition: SVecSVecSubExpr.h:254
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
ReturnType operator[](size_t index) const
Subscript operator for the direct access to the vector elements.
Definition: SVecSVecSubExpr.h:174
Header file for the DisableIf class template.
Header file for the IsTemporary type trait class.
decltype(std::declval< RN1 >() - std::declval< RN2 >()) ExprReturnType
Expression return type for the subscript operator.
Definition: SVecSVecSubExpr.h:116
size_t size() const noexcept
Returns the current size/dimension of the vector.
Definition: SVecSVecSubExpr.h:200
Namespace of the Blaze C++ math library.
Definition: Blaze.h:58
Header file for the If class template.
Expression object for sparse vector-sparse vector subtractions.The SVecSVecSubExpr class represents t...
Definition: Forward.h:164
ReturnType_t< VT1 > RN1
Return type of the left-hand side sparse vector expression.
Definition: SVecSVecSubExpr.h:100
static constexpr bool smpAssignable
Compilation switch for the expression template assignment strategy.
Definition: SVecSVecSubExpr.h:154
#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
decltype(auto) min(const DenseMatrix< MT1, SO1 > &lhs, const DenseMatrix< MT2, SO2 > &rhs)
Computes the componentwise minimum of the dense matrices lhs and rhs.
Definition: DMatDMatMapExpr.h:1162
#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
Base class for N-dimensional dense vectors.The DenseVector class is a base class for all arbitrarily ...
Definition: DenseVector.h:76
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
Constraint on the data type.
Header file for the exception macros of the math module.
ResultType_t< VT2 > RT2
Result type of the right-hand side sparse vector expression.
Definition: SVecSVecSubExpr.h:99
Header file for the VecVecSubExpr base class.
Constraint on the data type.
Constraint on the data type.
If_t< IsExpression_v< VT2 >, const VT2, const VT2 & > RightOperand
Composite type of the right-hand side sparse vector expression.
Definition: SVecSVecSubExpr.h:149
Header file for the EnableIf class template.
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.
RightOperand rightOperand() const noexcept
Returns the right-hand side sparse vector operand.
Definition: SVecSVecSubExpr.h:230
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 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.
Header file for the isDefault shim.
constexpr size_t size(const Matrix< MT, SO > &matrix) noexcept
Returns the total number of elements of the matrix.
Definition: Matrix.h:530
If_t< IsExpression_v< VT1 >, const VT1, const VT1 & > LeftOperand
Composite type of the left-hand side sparse vector expression.
Definition: SVecSVecSubExpr.h:146
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
SubTrait_t< RT1, RT2 > ResultType
Result type for expression template evaluations.
Definition: SVecSVecSubExpr.h:135
CompositeType_t< VT2 > CT2
Composite type of the right-hand side sparse vector expression.
Definition: SVecSVecSubExpr.h:103
Constraint on the data type.
const If_t< returnExpr, ExprReturnType, ElementType > ReturnType
Return type for expression template evaluations.
Definition: SVecSVecSubExpr.h:140
#define BLAZE_CONSTRAINT_MUST_FORM_VALID_VECVECSUBEXPR(T1, T2)
Constraint on the data type.In case the given data types T1 and T2 do not form a valid vector/vector ...
Definition: VecVecSubExpr.h:104
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
RightOperand rhs_
Right-hand side sparse vector of the subtraction expression.
Definition: SVecSVecSubExpr.h:262
static constexpr bool returnExpr
Compilation switch for the selection of the subscript operator return type.
Definition: SVecSVecSubExpr.h:113
Base class for sparse vectors.The SparseVector class is a base class for all arbitrarily sized (N-dim...
Definition: Forward.h:146
bool isDefault(const DiagonalProxy< MT > &proxy)
Returns whether the represented element is in default state.
Definition: DiagonalProxy.h:635
TransposeType_t< ResultType > TransposeType
Transpose type for expression template evaluations.
Definition: SVecSVecSubExpr.h:136
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
ReturnType at(size_t index) const
Checked access to the vector elements.
Definition: SVecSVecSubExpr.h:187
Header file for the IsResizable type trait.
ElementType_t< ResultType > ElementType
Resulting element type.
Definition: SVecSVecSubExpr.h:137
#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
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
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
ResultType_t< VT1 > RT1
Result type of the left-hand side sparse vector expression.
Definition: SVecSVecSubExpr.h:98
Header file for the IsExpression type trait class.
Header file for the function trace functionality.