35 #ifndef _BLAZE_MATH_EXPRESSIONS_SVECSVECSUBEXPR_H_
36 #define _BLAZE_MATH_EXPRESSIONS_SVECSVECSUBEXPR_H_
88 template<
typename VT1
91 class SVecSVecSubExpr :
public SparseVector< SVecSVecSubExpr<VT1,VT2,TF>, TF >
92 ,
private VecVecSubExpr
127 template<
typename VT >
128 struct UseSMPAssign {
129 enum { value = VT::smpAssignable };
156 enum { smpAssignable = 0 };
189 inline ReturnType
at(
size_t index )
const {
190 if( index >=
lhs_.size() ) {
193 return (*
this)[index];
243 template<
typename T >
245 return (
lhs_.canAlias( alias ) ||
rhs_.canAlias( alias ) );
255 template<
typename T >
257 return (
lhs_.isAliased( alias ) ||
rhs_.isAliased( alias ) );
280 template<
typename VT >
291 CT1 x(
serial( rhs.lhs_ ) );
292 CT2 y(
serial( rhs.rhs_ ) );
298 const LeftIterator lend( x.end() );
299 const RightIterator rend( y.end() );
301 for( LeftIterator l=x.begin(); l!=lend; ++l ) {
302 (~lhs)[l->index()] = l->value();
305 for( RightIterator r=y.begin(); r!=rend; ++r ) {
307 (~lhs)[r->index()] = -r->value();
309 (~lhs)[r->index()] -= r->value();
328 template<
typename VT >
339 CT1 x(
serial( rhs.lhs_ ) );
340 CT2 y(
serial( rhs.rhs_ ) );
346 const LeftIterator lend( x.end() );
347 const RightIterator rend( y.end() );
349 for( LeftIterator l=x.begin(); l!=lend; ++l ) {
350 (~lhs)[l->index()] = l->value();
353 for( RightIterator r=y.begin(); r!=rend; ++r ) {
354 (~lhs)[r->index()] -= r->value();
372 template<
typename VT >
373 friend inline void assign( SparseVector<VT,TF>& lhs,
const SVecSVecSubExpr& rhs )
382 CT1 x(
serial( rhs.lhs_ ) );
383 CT2 y(
serial( rhs.rhs_ ) );
389 const LeftIterator lend( x.end() );
390 const RightIterator rend( y.end() );
392 LeftIterator l( x.begin() );
393 RightIterator r( y.begin() );
395 while( l != lend && r != rend )
397 if( l->index() < r->index() ) {
398 (~lhs).append( l->index(), l->value() );
401 else if( l->index() > r->index() ) {
402 (~lhs).append( r->index(), -r->value() );
406 (~lhs).append( l->index(), l->value() - r->value() );
413 (~lhs).append( l->index(), l->value() );
418 (~lhs).append( r->index(), -r->value() );
437 template<
typename VT >
438 friend inline void addAssign( DenseVector<VT,TF>& lhs,
const SVecSVecSubExpr& rhs )
444 addAssign( ~lhs, rhs.lhs_ );
445 subAssign( ~lhs, rhs.rhs_ );
466 template<
typename VT >
467 friend inline void subAssign( DenseVector<VT,TF>& lhs,
const SVecSVecSubExpr& rhs )
473 subAssign( ~lhs, rhs.lhs_ );
474 addAssign( ~lhs, rhs.rhs_ );
495 template<
typename VT >
496 friend inline void multAssign( DenseVector<VT,TF>& lhs,
const SVecSVecSubExpr& rhs )
506 const ResultType tmp(
serial( rhs ) );
507 multAssign( ~lhs, tmp );
538 template<
typename VT >
539 friend inline typename EnableIf< UseSMPAssign<VT> >::Type
571 template<
typename VT >
572 friend inline typename EnableIf< UseSMPAssign<VT> >::Type
604 template<
typename VT >
605 friend inline typename EnableIf< UseSMPAssign<VT> >::Type
616 const ResultType tmp( rhs );
671 template<
typename T1
674 inline const SVecSVecSubExpr<T1,T2,TF>
679 if( (~lhs).
size() != (~rhs).
size() ) {
698 template<
typename VT1,
typename VT2,
bool TF >
699 struct Size< SVecSVecSubExpr<VT1,VT2,TF> >
700 :
public Max< Size<VT1>, Size<VT2> >
716 template<
typename VT1,
typename VT2,
bool TF,
bool AF >
717 struct SubvectorExprTrait< SVecSVecSubExpr<VT1,VT2,TF>, AF >
721 typedef typename SubExprTrait< typename SubvectorExprTrait<const VT1,AF>::Type
722 ,
typename SubvectorExprTrait<const VT2,AF>::Type >::Type Type;
#define BLAZE_THROW_INVALID_ARGUMENT(MESSAGE)
Macro for the emission of a std::invalid_argument exceptionThis macro encapsulates the default way of...
Definition: Exception.h:187
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:87
Header file for the subtraction trait.
Header file for basic type definitions.
Header file for the SparseVector base class.
SelectType< IsExpression< VT2 >::value, const VT2, const VT2 & >::Type RightOperand
Composite type of the right-hand side sparse vector expression.
Definition: SVecSVecSubExpr.h:151
BLAZE_ALWAYS_INLINE size_t size(const Vector< VT, TF > &vector)
Returns the current size/dimension of the vector.
Definition: Vector.h:252
SelectType< IsExpression< VT1 >::value, const VT1, const VT1 & >::Type LeftOperand
Composite type of the left-hand side sparse vector expression.
Definition: SVecSVecSubExpr.h:148
size_t size() const
Returns the current size/dimension of the vector.
Definition: SVecSVecSubExpr.h:202
Efficient implementation of a compressed matrix.The CompressedMatrix class template is the represent...
Definition: CompressedMatrix.h:207
bool canAlias(const T *alias) const
Returns whether the expression can alias with the given address alias.
Definition: SVecSVecSubExpr.h:244
LeftOperand lhs_
Left-hand side sparse vector of the subtraction expression.
Definition: SVecSVecSubExpr.h:263
VT1::ResultType RT1
Result type of the left-hand side sparse vector expression.
Definition: SVecSVecSubExpr.h:97
const ResultType CompositeType
Data type for composite expression templates.
Definition: SVecSVecSubExpr.h:145
VT2::ResultType RT2
Result type of the right-hand side sparse vector expression.
Definition: SVecSVecSubExpr.h:98
const This & CompositeType
Data type for composite expression templates.
Definition: CompressedMatrix.h:2588
Type ElementType
Type of the sparse matrix elements.
Definition: CompressedMatrix.h:259
const DMatSerialExpr< MT, SO > serial(const DenseMatrix< MT, SO > &dm)
Forces the serial evaluation of the given dense matrix expression dm.
Definition: DMatSerialExpr.h:721
Header file for the Computation base class.
VT1::CompositeType CT1
Composite type of the left-hand side sparse vector expression.
Definition: SVecSVecSubExpr.h:101
RightOperand rightOperand() const
Returns the right-hand side sparse vector operand.
Definition: SVecSVecSubExpr.h:232
ReturnType at(size_t index) const
Checked access to the vector elements.
Definition: SVecSVecSubExpr.h:189
bool isDefault(const DiagonalProxy< MT > &proxy)
Returns whether the represented element is in default state.
Definition: DiagonalProxy.h:547
Constraint on the data type.
SubExprTrait< RN1, RN2 >::Type ExprReturnType
Expression return type for the subscript operator.
Definition: SVecSVecSubExpr.h:117
const This & CompositeType
Data type for composite expression templates.
Definition: CompressedMatrix.h:261
Compile time type selection.The SelectType class template selects one of the two given types T1 and T...
Definition: SelectType.h:59
Header file for the DisableIf class template.
Header file for the IsTemporary type trait class.
Namespace of the Blaze C++ math library.
Definition: Blaze.h:57
Expression object for sparse vector-sparse vector subtractions.The SVecSVecSubExpr class represents t...
Definition: Forward.h:133
SubTrait< RT1, RT2 >::Type ResultType
Result type for expression template evaluations.
Definition: SVecSVecSubExpr.h:137
VT2::TransposeType TT2
Transpose type of the right-hand side sparse vector expression.
Definition: SVecSVecSubExpr.h:104
const Element * ConstIterator
Iterator over constant elements.
Definition: CompressedMatrix.h:2592
#define BLAZE_THROW_OUT_OF_RANGE(MESSAGE)
Macro for the emission of a std::out_of_range exceptionThis macro encapsulates the default way of Bla...
Definition: Exception.h:331
const MT::ElementType min(const DenseMatrix< MT, SO > &dm)
Returns the smallest element of the dense matrix.
Definition: DenseMatrix.h:1682
ReturnType operator[](size_t index) const
Subscript operator for the direct access to the vector elements.
Definition: SVecSVecSubExpr.h:176
ResultType::ElementType ElementType
Resulting element type.
Definition: SVecSVecSubExpr.h:139
Base class for N-dimensional dense vectors.The DenseVector class is a base class for all arbitrarily ...
Definition: DenseVector.h:70
#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:79
const DenseIterator< Type, AF > operator-(const DenseIterator< Type, AF > &it, ptrdiff_t inc)
Subtraction between a DenseIterator and an integral value.
Definition: DenseIterator.h:642
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:78
CompressedMatrix< Type, false > TransposeType
Transpose type for expression template evaluations.
Definition: CompressedMatrix.h:2585
Evaluation of the return type of a subtraction expression.Via this type trait it is possible to evalu...
Definition: SubExprTrait.h:104
Header file for the VecVecSubExpr base class.
Header file for the SelectType class template.
Header file for all forward declarations for expression class templates.
Constraint on the data type.
bool isAliased(const T *alias) const
Returns whether the expression is aliased with the given address alias.
Definition: SVecSVecSubExpr.h:256
Header file for the EnableIf class template.
Header file for the serial shim.
EnableIf< IsDenseMatrix< MT1 > >::Type 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
const Type & ReturnType
Return type for expression template evaluations.
Definition: CompressedMatrix.h:2587
Removal of reference modifiers.The RemoveCV type trait removes any reference modifiers from the given...
Definition: RemoveReference.h:69
ResultType::TransposeType TransposeType
Transpose type for expression template evaluations.
Definition: SVecSVecSubExpr.h:138
Header file for run time assertion macros.
VT1::TransposeType TT1
Transpose type of the left-hand side sparse vector expression.
Definition: SVecSVecSubExpr.h:103
Substitution Failure Is Not An Error (SFINAE) class.The EnableIf class template is an auxiliary tool ...
Definition: EnableIf.h:184
Header file for the isDefault shim.
LeftOperand leftOperand() const
Returns the left-hand side sparse vector operand.
Definition: SVecSVecSubExpr.h:222
Header file for the RemoveReference type trait.
Substitution Failure Is Not An Error (SFINAE) class.The DisableIf class template is an auxiliary tool...
Definition: DisableIf.h:184
size_t nonZeros() const
Returns the number of non-zero elements in the sparse vector.
Definition: SVecSVecSubExpr.h:212
Constraint on the data type.
VT1::ReturnType RN1
Return type of the left-hand side sparse vector expression.
Definition: SVecSVecSubExpr.h:99
SVecSVecSubExpr< VT1, VT2, TF > This
Type of this SVecSVecSubExpr instance.
Definition: SVecSVecSubExpr.h:136
#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:165
Header file for the IsComputation type trait class.
EnableIf< IsDenseMatrix< MT1 > >::Type 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
RightOperand rhs_
Right-hand side sparse vector of the subtraction expression.
Definition: SVecSVecSubExpr.h:264
Base class for sparse vectors.The SparseVector class is a base class for all arbitrarily sized (N-dim...
Definition: Forward.h:118
#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
This ResultType
Result type for expression template evaluations.
Definition: CompressedMatrix.h:2583
Header file for the SubvectorExprTrait class template.
Base template for the SubTrait class.
Definition: SubTrait.h:138
Header file for exception macros.
VT2::ReturnType RN2
Return type of the right-hand side sparse vector expression.
Definition: SVecSVecSubExpr.h:100
Header file for the IsResizable type trait.
Header file for the SubExprTrait class template.
EnableIf< IsDenseVector< VT1 > >::Type 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:189
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:81
#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
const SelectType< returnExpr, ExprReturnType, ElementType >::Type ReturnType
Return type for expression template evaluations.
Definition: SVecSVecSubExpr.h:142
Header file for the IsExpression type trait class.
Header file for the FunctionTrace class.
SVecSVecSubExpr(const VT1 &lhs, const VT2 &rhs)
Constructor for the SVecSVecSubExpr class.
Definition: SVecSVecSubExpr.h:162
VT2::CompositeType CT2
Composite type of the right-hand side sparse vector expression.
Definition: SVecSVecSubExpr.h:102