35 #ifndef _BLAZE_MATH_EXPRESSIONS_SVECSVECADDEXPR_H_
36 #define _BLAZE_MATH_EXPRESSIONS_SVECSVECADDEXPR_H_
89 template<
typename VT1
92 class SVecSVecAddExpr :
public SparseVector< SVecSVecAddExpr<VT1,VT2,TF>, TF >
93 ,
private VecVecAddExpr
126 template<
typename VT >
127 struct UseSMPAssign {
128 enum :
bool { value = VT::smpAssignable };
155 enum :
bool { smpAssignable =
false };
188 inline ReturnType
at(
size_t index )
const {
189 if( index >=
lhs_.size() ) {
192 return (*
this)[index];
201 inline size_t size() const noexcept {
242 template<
typename T >
243 inline bool canAlias(
const T* alias )
const noexcept {
244 return (
lhs_.canAlias( alias ) ||
rhs_.canAlias( alias ) );
254 template<
typename T >
255 inline bool isAliased(
const T* alias )
const noexcept {
256 return (
lhs_.isAliased( alias ) ||
rhs_.isAliased( alias ) );
279 template<
typename VT >
290 CT1 x(
serial( rhs.lhs_ ) );
291 CT2 y(
serial( rhs.rhs_ ) );
297 const LeftIterator lend( x.end() );
298 const RightIterator rend( y.end() );
300 for( LeftIterator l=x.begin(); l!=lend; ++l ) {
301 (~lhs)[l->index()] = l->value();
304 for( RightIterator r=y.begin(); r!=rend; ++r ) {
306 (~lhs)[r->index()] = r->value();
308 (~lhs)[r->index()] += r->value();
327 template<
typename VT >
338 CT1 x(
serial( rhs.lhs_ ) );
339 CT2 y(
serial( rhs.rhs_ ) );
345 const LeftIterator lend( x.end() );
346 const RightIterator rend( y.end() );
348 for( LeftIterator l=x.begin(); l!=lend; ++l ) {
349 (~lhs)[l->index()] = l->value();
352 for( RightIterator r=y.begin(); r!=rend; ++r ) {
353 (~lhs)[r->index()] += r->value();
371 template<
typename VT >
372 friend inline void assign( SparseVector<VT,TF>& lhs,
const SVecSVecAddExpr& rhs )
378 typedef ConstIterator_< RemoveReference_<CT1> > LeftIterator;
379 typedef ConstIterator_< RemoveReference_<CT2> > RightIterator;
381 CT1 x(
serial( rhs.lhs_ ) );
382 CT2 y(
serial( rhs.rhs_ ) );
388 const LeftIterator lend( x.end() );
389 const RightIterator rend( y.end() );
391 LeftIterator l( x.begin() );
392 RightIterator r( y.begin() );
394 while( l != lend && r != rend )
396 if( l->index() < r->index() ) {
397 (~lhs).append( l->index(), l->value() );
400 else if( l->index() > r->index() ) {
401 (~lhs).append( r->index(), r->value() );
405 (~lhs).append( l->index(), l->value() + r->value() );
412 (~lhs).append( l->index(), l->value() );
417 (~lhs).append( r->index(), r->value() );
436 template<
typename VT >
437 friend inline void addAssign( DenseVector<VT,TF>& lhs,
const SVecSVecAddExpr& rhs )
443 addAssign( ~lhs, rhs.lhs_ );
444 addAssign( ~lhs, rhs.rhs_ );
465 template<
typename VT >
466 friend inline void subAssign( DenseVector<VT,TF>& lhs,
const SVecSVecAddExpr& rhs )
472 subAssign( ~lhs, rhs.lhs_ );
473 subAssign( ~lhs, rhs.rhs_ );
494 template<
typename VT >
495 friend inline void multAssign( DenseVector<VT,TF>& lhs,
const SVecSVecAddExpr& rhs )
505 const ResultType tmp(
serial( rhs ) );
506 multAssign( ~lhs, tmp );
537 template<
typename VT >
538 friend inline EnableIf_< UseSMPAssign<VT> >
569 template<
typename VT >
570 friend inline EnableIf_< UseSMPAssign<VT> >
602 template<
typename VT >
603 friend inline EnableIf_< UseSMPAssign<VT> >
614 const ResultType tmp( rhs );
669 template<
typename T1
672 inline const SVecSVecAddExpr<T1,T2,TF>
677 if( (~lhs).
size() != (~rhs).
size() ) {
696 template<
typename VT1,
typename VT2,
bool TF >
697 struct Size< SVecSVecAddExpr<VT1,VT2,TF> >
698 :
public Max< Size<VT1>, Size<VT2> >
714 template<
typename VT1,
typename VT2,
bool TF,
bool AF >
715 struct SubvectorExprTrait< SVecSVecAddExpr<VT1,VT2,TF>, AF >
719 using Type = AddExprTrait_< SubvectorExprTrait_<const VT1,AF>
720 , SubvectorExprTrait_<const VT2,AF> >;
size_t nonZeros() const
Returns the number of non-zero elements in the sparse vector.
Definition: SVecSVecAddExpr.h:211
#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.
Header file for the Max class template.
Header file for mathematical functions.
Compile time check whether the given type is a temporary vector or matrix type.This type trait class ...
Definition: IsTemporary.h:70
Header file for basic type definitions.
Header file for the SparseVector base class.
LeftOperand lhs_
Left-hand side sparse vector of the addition expression.
Definition: SVecSVecAddExpr.h:262
EnableIf_< IsDenseMatrix< MT1 > > smpSubAssign(Matrix< MT1, SO1 > &lhs, const Matrix< MT2, SO2 > &rhs)
Default implementation of the SMP subtraction assignment of a matrix to dense matrix.
Definition: DenseMatrix.h:160
Header file for the serial shim.
BLAZE_ALWAYS_INLINE size_t size(const Vector< VT, TF > &vector) noexcept
Returns the current size/dimension of the vector.
Definition: Vector.h:258
const IfTrue_< returnExpr, ExprReturnType, ElementType > ReturnType
Return type for expression template evaluations.
Definition: SVecSVecAddExpr.h:141
ReturnType operator[](size_t index) const
Subscript operator for the direct access to the vector elements.
Definition: SVecSVecAddExpr.h:175
const DenseIterator< Type, AF > operator+(const DenseIterator< Type, AF > &it, ptrdiff_t inc) noexcept
Addition between a DenseIterator and an integral value.
Definition: DenseIterator.h:699
EnableIf_< IsDenseVector< VT1 > > smpMultAssign(Vector< VT1, TF1 > &lhs, const Vector< VT2, TF2 > &rhs)
Default implementation of the SMP multiplication assignment of a vector to a dense vector...
Definition: DenseVector.h:193
typename DisableIf< Condition, T >::Type DisableIf_
Auxiliary type for the DisableIf class template.The DisableIf_ alias declaration provides a convenien...
Definition: DisableIf.h:223
const ElementType_< MT > min(const DenseMatrix< MT, SO > &dm)
Returns the smallest element of the dense matrix.
Definition: DenseMatrix.h:1669
Header file for the AddExprTrait class template.
const DMatSerialExpr< MT, SO > serial(const DenseMatrix< MT, SO > &dm)
Forces the serial evaluation of the given dense matrix expression dm.
Definition: DMatSerialExpr.h:723
Header file for the Computation base class.
typename T::ResultType ResultType_
Alias declaration for nested ResultType type definitions.The ResultType_ alias declaration provides a...
Definition: Aliases.h:323
EnableIf_< IsDenseMatrix< MT1 > > smpAddAssign(Matrix< MT1, SO1 > &lhs, const Matrix< MT2, SO2 > &rhs)
Default implementation of the SMP addition assignment of a matrix to a dense matrix.
Definition: DenseMatrix.h:129
bool isDefault(const DiagonalProxy< MT > &proxy)
Returns whether the represented element is in default state.
Definition: DiagonalProxy.h:573
Constraint on the data type.
typename IfTrue< Condition, T1, T2 >::Type IfTrue_
Auxiliary alias declaration for the IfTrue class template.The IfTrue_ alias declaration provides a co...
Definition: If.h:109
AddExprTrait_< RN1, RN2 > ExprReturnType
Expression return type for the subscript operator.
Definition: SVecSVecAddExpr.h:116
typename T::ReturnType ReturnType_
Alias declaration for nested ReturnType type definitions.The ReturnType_ alias declaration provides a...
Definition: Aliases.h:343
CompositeType_< VT2 > CT2
Composite type of the right-hand side sparse vector expression.
Definition: SVecSVecAddExpr.h:103
Expression object for sparse vector-sparse vector additions.The SVecSVecAddExpr class represents the ...
Definition: Forward.h:120
If_< IsExpression< VT2 >, const VT2, const VT2 & > RightOperand
Composite type of the right-hand side sparse vector expression.
Definition: SVecSVecAddExpr.h:150
typename T::CompositeType CompositeType_
Alias declaration for nested CompositeType type definitions.The CompositeType_ alias declaration prov...
Definition: Aliases.h:83
ReturnType at(size_t index) const
Checked access to the vector elements.
Definition: SVecSVecAddExpr.h:188
Header file for the DisableIf class template.
Header file for the IsTemporary type trait class.
typename AddExprTrait< T1, T2 >::Type AddExprTrait_
Auxiliary alias declaration for the AddExprTrait class template.The AddExprTrait_ alias declaration p...
Definition: AddExprTrait.h:219
Namespace of the Blaze C++ math library.
Definition: Blaze.h:57
Header file for the If class template.
Header file for the VecVecAddExpr base class.
#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
#define BLAZE_CONSTRAINT_MUST_FORM_VALID_VECVECADDEXPR(T1, T2)
Constraint on the data type.In case the given data types T1 and T2 do not form a valid vector/vector ...
Definition: VecVecAddExpr.h:109
TransposeType_< ResultType > TransposeType
Transpose type for expression template evaluations.
Definition: SVecSVecAddExpr.h:137
typename T::ElementType ElementType_
Alias declaration for nested ElementType type definitions.The ElementType_ alias declaration provides...
Definition: Aliases.h:163
CompositeType_< VT1 > CT1
Composite type of the left-hand side sparse vector expression.
Definition: SVecSVecAddExpr.h:102
ReturnType_< VT1 > RN1
Return type of the left-hand side sparse vector expression.
Definition: SVecSVecAddExpr.h:100
Base class for N-dimensional dense vectors.The DenseVector class is a base class for all arbitrarily ...
Definition: DenseVector.h:70
If_< IsExpression< VT1 >, const VT1, const VT1 & > LeftOperand
Composite type of the left-hand side sparse vector expression.
Definition: SVecSVecAddExpr.h:147
#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
ResultType_< VT1 > RT1
Result type of the left-hand side sparse vector expression.
Definition: SVecSVecAddExpr.h:98
AddTrait_< RT1, RT2 > ResultType
Result type for expression template evaluations.
Definition: SVecSVecAddExpr.h:136
Constraint on the data type.
#define BLAZE_CONSTRAINT_MUST_BE_REFERENCE_TYPE(T)
Constraint on the data type.In case the given data type T is not a reference type, a compilation error is created.
Definition: Reference.h:60
Header file for the exception macros of the math module.
Header file for all forward declarations for expression class templates.
Constraint on the data type.
ElementType_< ResultType > ElementType
Resulting element type.
Definition: SVecSVecAddExpr.h:138
Header file for the EnableIf class template.
Constraint on the data type.
ResultType_< VT2 > RT2
Result type of the right-hand side sparse vector expression.
Definition: SVecSVecAddExpr.h:99
Header file for run time assertion macros.
RightOperand rightOperand() const noexcept
Returns the right-hand side sparse vector operand.
Definition: SVecSVecAddExpr.h:231
Header file for the addition trait.
size_t size() const noexcept
Returns the current size/dimension of the vector.
Definition: SVecSVecAddExpr.h:201
typename If< T1, T2, T3 >::Type If_
Auxiliary alias declaration for the If class template.The If_ alias declaration provides a convenient...
Definition: If.h:160
SVecSVecAddExpr(const VT1 &lhs, const VT2 &rhs) noexcept
Constructor for the SVecSVecAddExpr class.
Definition: SVecSVecAddExpr.h:161
bool canAlias(const T *alias) const noexcept
Returns whether the expression can alias with the given address alias.
Definition: SVecSVecAddExpr.h:243
ReturnType_< VT2 > RN2
Return type of the right-hand side sparse vector expression.
Definition: SVecSVecAddExpr.h:101
Header file for the isDefault shim.
Header file for the RemoveReference type trait.
typename EnableIf< Condition, T >::Type EnableIf_
Auxiliary alias declaration for the EnableIf class template.The EnableIf_ alias declaration provides ...
Definition: EnableIf.h:223
RightOperand rhs_
Right-hand side sparse vector of the addition expression.
Definition: SVecSVecAddExpr.h:263
typename T::ConstIterator ConstIterator_
Alias declaration for nested ConstIterator type definitions.The ConstIterator_ alias declaration prov...
Definition: Aliases.h:103
Header file for the IsComputation type trait class.
Base class for sparse vectors.The SparseVector class is a base class for all arbitrarily sized (N-dim...
Definition: Forward.h:110
#define BLAZE_FUNCTION_TRACE
Function trace macro.This macro can be used to reliably trace function calls. In case function tracin...
Definition: FunctionTrace.h:157
LeftOperand leftOperand() const noexcept
Returns the left-hand side sparse vector operand.
Definition: SVecSVecAddExpr.h:221
Header file for the SubvectorExprTrait class template.
typename T::TransposeType TransposeType_
Alias declaration for nested TransposeType type definitions.The TransposeType_ alias declaration prov...
Definition: Aliases.h:403
Header file for the IsResizable type trait.
Header file for the Size type trait.
#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
const ResultType CompositeType
Data type for composite expression templates.
Definition: SVecSVecAddExpr.h:144
typename AddTrait< T1, T2 >::Type AddTrait_
Auxiliary alias declaration for the AddTrait class template.The AddTrait_ alias declaration provides ...
Definition: AddTrait.h:245
#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
Header file for the IsExpression type trait class.
Header file for the FunctionTrace class.
SVecSVecAddExpr< VT1, VT2, TF > This
Type of this SVecSVecAddExpr instance.
Definition: SVecSVecAddExpr.h:135
bool isAliased(const T *alias) const noexcept
Returns whether the expression is aliased with the given address alias.
Definition: SVecSVecAddExpr.h:255