35 #ifndef _BLAZE_MATH_EXPRESSIONS_SVECSVECMULTEXPR_H_
36 #define _BLAZE_MATH_EXPRESSIONS_SVECSVECMULTEXPR_H_
86 template<
typename VT1
89 class SVecSVecMultExpr :
public SparseVector< SVecSVecMultExpr<VT1,VT2,TF>, TF >
90 ,
private VecVecMultExpr
138 enum :
bool { smpAssignable =
false };
171 inline ReturnType
at(
size_t index )
const {
172 if( index >=
lhs_.size() ) {
175 return (*
this)[index];
184 inline size_t size() const noexcept {
225 template<
typename T >
226 inline bool canAlias(
const T* alias )
const noexcept {
227 return (
lhs_.canAlias( alias ) ||
rhs_.canAlias( alias ) );
237 template<
typename T >
238 inline bool isAliased(
const T* alias )
const noexcept {
239 return (
lhs_.isAliased( alias ) ||
rhs_.isAliased( alias ) );
261 template<
typename VT >
271 CT1 x(
serial( rhs.lhs_ ) );
272 CT2 y(
serial( rhs.rhs_ ) );
278 const LeftIterator lend( x.end() );
279 const RightIterator rend( y.end() );
281 LeftIterator l( x.begin() );
282 RightIterator r( y.begin() );
284 for( ; l!=lend; ++l ) {
285 while( r!=rend && r->index() < l->index() ) ++r;
287 if( l->index() == r->index() ) {
288 (~lhs)[l->index()] = l->value() * r->value();
308 template<
typename VT >
318 CT1 x(
serial( rhs.lhs_ ) );
319 CT2 y(
serial( rhs.rhs_ ) );
325 const LeftIterator lend( x.end() );
326 const RightIterator rend( y.end() );
328 LeftIterator l( x.begin() );
329 RightIterator r( y.begin() );
331 for( ; l!=lend; ++l ) {
332 while( r!=rend && r->index() < l->index() ) ++r;
334 if( l->index() == r->index() ) {
335 (~lhs).append( l->index(), l->value() * r->value() );
355 template<
typename VT >
356 friend inline void addAssign( DenseVector<VT,TF>& lhs,
const SVecSVecMultExpr& rhs )
362 typedef ConstIterator_< RemoveReference_<CT1> > LeftIterator;
363 typedef ConstIterator_< RemoveReference_<CT2> > RightIterator;
365 CT1 x(
serial( rhs.lhs_ ) );
366 CT2 y(
serial( rhs.rhs_ ) );
372 const LeftIterator lend( x.end() );
373 const RightIterator rend( y.end() );
375 LeftIterator l( x.begin() );
376 RightIterator r( y.begin() );
378 for( ; l!=lend; ++l ) {
379 while( r!=rend && r->index() < l->index() ) ++r;
381 if( l->index() == r->index() ) {
382 (~lhs)[l->index()] += l->value() * r->value();
406 template<
typename VT >
407 friend inline void subAssign( DenseVector<VT,TF>& lhs,
const SVecSVecMultExpr& rhs )
413 typedef ConstIterator_< RemoveReference_<CT1> > LeftIterator;
414 typedef ConstIterator_< RemoveReference_<CT2> > RightIterator;
416 CT1 x(
serial( rhs.lhs_ ) );
417 CT2 y(
serial( rhs.rhs_ ) );
423 const LeftIterator lend( x.end() );
424 const RightIterator rend( y.end() );
426 LeftIterator l( x.begin() );
427 RightIterator r( y.begin() );
429 for( ; l!=lend; ++l ) {
430 while( r!=rend && r->index() < l->index() ) ++r;
432 if( l->index() == r->index() ) {
433 (~lhs)[l->index()] -= l->value() * r->value();
457 template<
typename VT >
458 friend inline void multAssign( DenseVector<VT,TF>& lhs,
const SVecSVecMultExpr& rhs )
464 typedef ConstIterator_< RemoveReference_<CT1> > LeftIterator;
465 typedef ConstIterator_< RemoveReference_<CT2> > RightIterator;
467 CT1 x(
serial( rhs.lhs_ ) );
468 CT2 y(
serial( rhs.rhs_ ) );
474 const LeftIterator lend( x.end() );
475 const RightIterator rend( y.end() );
477 LeftIterator l( x.begin() );
478 RightIterator r( y.begin() );
482 for( ; l!=lend; ++l ) {
483 while( r!=rend && r->index() < l->index() ) ++r;
485 if( l->index() == r->index() ) {
486 for( ; i<r->index(); ++i )
488 (~lhs)[l->index()] *= l->value() * r->value();
494 for( ; i<rhs.size(); ++i )
512 template<
typename VT >
513 friend inline void multAssign( SparseVector<VT,TF>& lhs,
const SVecSVecMultExpr& rhs )
519 typedef ConstIterator_<VT> Iterator1;
520 typedef ConstIterator_< RemoveReference_<CT1> > Iterator2;
521 typedef ConstIterator_< RemoveReference_<CT2> > Iterator3;
523 CT1 x(
serial( rhs.lhs_ ) );
524 CT2 y(
serial( rhs.rhs_ ) );
530 VT tmp( rhs.size(), rhs.nonZeros() );
532 const Iterator1 end1( (~lhs).
end() );
533 const Iterator2 end2( x.end() );
534 const Iterator3 end3( y.end() );
536 Iterator1 i1( (~lhs).
begin() );
537 Iterator2 i2( x.begin() );
538 Iterator3 i3( y.begin() );
540 for( ; i1!=end1; ++i1 ) {
541 while( i2!=end2 && i2->index() < i1->index() ) ++i2;
542 if( i2==end2 )
break;
543 while( i3!=end3 && i3->index() < i1->index() ) ++i3;
544 if( i3==end3 )
break;
545 if( i1->index() == i2->index() && i1->index() == i3->index() ) {
546 tmp.append( i1->index(), i1->value() * i2->value() * i3->value() );
603 template<
typename T1
606 inline const SVecSVecMultExpr<T1,T2,TF>
611 if( (~lhs).
size() != (~rhs).
size() ) {
630 template<
typename VT1,
typename VT2,
bool TF >
631 struct Size< SVecSVecMultExpr<VT1,VT2,TF> >
632 :
public Max< Size<VT1>, Size<VT2> >
648 template<
typename VT1,
typename VT2,
bool TF,
bool AF >
649 struct SubvectorExprTrait< SVecSVecMultExpr<VT1,VT2,TF>, AF >
653 using Type = MultExprTrait_< SubvectorExprTrait_<const VT1,AF>
654 , SubvectorExprTrait_<const VT2,AF> >;
#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
SVecSVecMultExpr(const VT1 &lhs, const VT2 &rhs) noexcept
Constructor for the SVecSVecMultExpr class.
Definition: SVecSVecMultExpr.h:144
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
const DMatDMatMultExpr< T1, T2 > operator*(const DenseMatrix< T1, false > &lhs, const DenseMatrix< T2, false > &rhs)
Multiplication operator for the multiplication of two row-major dense matrices ( ).
Definition: DMatDMatMultExpr.h:7800
Header file for basic type definitions.
Header file for the SparseVector base class.
ReturnType at(size_t index) const
Checked access to the vector elements.
Definition: SVecSVecMultExpr.h:171
ResultType_< VT1 > RT1
Result type of the left-hand side sparse vector expression.
Definition: SVecSVecMultExpr.h:95
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
BLAZE_ALWAYS_INLINE MT::Iterator begin(Matrix< MT, SO > &matrix, size_t i)
Returns an iterator to the first element of row/column i.
Definition: Matrix.h:188
void reset(const DiagonalProxy< MT > &proxy)
Resetting the represented element to the default initial values.
Definition: DiagonalProxy.h:533
CompositeType_< VT2 > CT2
Composite type of the right-hand side sparse vector expression.
Definition: SVecSVecMultExpr.h:100
const ElementType_< MT > min(const DenseMatrix< MT, SO > &dm)
Returns the smallest element of the dense matrix.
Definition: DenseMatrix.h:1669
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
ReturnType_< VT1 > RN1
Return type of the left-hand side sparse vector expression.
Definition: SVecSVecMultExpr.h:97
typename MultTrait< T1, T2 >::Type MultTrait_
Auxiliary alias declaration for the MultTrait class template.The MultTrait_ alias declaration provide...
Definition: MultTrait.h:245
Header file for the Computation base class.
ElementType_< ResultType > ElementType
Resulting element type.
Definition: SVecSVecMultExpr.h:121
typename T::ResultType ResultType_
Alias declaration for nested ResultType type definitions.The ResultType_ alias declaration provides a...
Definition: Aliases.h:323
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
typename T::ReturnType ReturnType_
Alias declaration for nested ReturnType type definitions.The ReturnType_ alias declaration provides a...
Definition: Aliases.h:343
SVecSVecMultExpr< VT1, VT2, TF > This
Type of this SVecSVecMultExpr instance.
Definition: SVecSVecMultExpr.h:118
typename MultExprTrait< T1, T2 >::Type MultExprTrait_
Auxiliary alias declaration for the MultExprTrait class template.The MultExprTrait_ alias declaration...
Definition: MultExprTrait.h:344
Header file for the MultExprTrait class template.
typename T::CompositeType CompositeType_
Alias declaration for nested CompositeType type definitions.The CompositeType_ alias declaration prov...
Definition: Aliases.h:83
LeftOperand leftOperand() const noexcept
Returns the left-hand side sparse vector operand.
Definition: SVecSVecMultExpr.h:204
bool isAliased(const T *alias) const noexcept
Returns whether the expression is aliased with the given address alias.
Definition: SVecSVecMultExpr.h:238
Header file for the IsTemporary type trait class.
Header file for the multiplication trait.
Namespace of the Blaze C++ math library.
Definition: Blaze.h:57
Header file for the If class template.
size_t size() const noexcept
Returns the current size/dimension of the vector.
Definition: SVecSVecMultExpr.h:184
TransposeType_< ResultType > TransposeType
Transpose type for expression template evaluations.
Definition: SVecSVecMultExpr.h:120
ReturnType operator[](size_t index) const
Subscript operator for the direct access to the vector elements.
Definition: SVecSVecMultExpr.h:158
#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
typename T::ElementType ElementType_
Alias declaration for nested ElementType type definitions.The ElementType_ alias declaration provides...
Definition: Aliases.h:163
If_< IsExpression< VT2 >, const VT2, const VT2 & > RightOperand
Composite type of the right-hand side sparse vector expression.
Definition: SVecSVecMultExpr.h:133
Base class for N-dimensional dense vectors.The DenseVector class is a base class for all arbitrarily ...
Definition: DenseVector.h:70
MultTrait_< RT1, RT2 > ResultType
Result type for expression template evaluations.
Definition: SVecSVecMultExpr.h:119
#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
ReturnType_< VT2 > RN2
Return type of the right-hand side sparse vector expression.
Definition: SVecSVecMultExpr.h:98
const ResultType CompositeType
Data type for composite expression templates.
Definition: SVecSVecMultExpr.h:127
Constraint on the data type.
RightOperand rhs_
Right-hand side sparse vector of the multiplication expression.
Definition: SVecSVecMultExpr.h:246
Header file for the exception macros of the math module.
Header file for the VecVecMultExpr base class.
BLAZE_ALWAYS_INLINE MT::Iterator end(Matrix< MT, SO > &matrix, size_t i)
Returns an iterator just past the last element of row/column i.
Definition: Matrix.h:254
Header file for all forward declarations for expression class templates.
Constraint on the data type.
RightOperand rightOperand() const noexcept
Returns the right-hand side sparse vector operand.
Definition: SVecSVecMultExpr.h:214
MultExprTrait_< RN1, RN2 > ExprReturnType
Expression return type for the subscript operator.
Definition: SVecSVecMultExpr.h:113
size_t nonZeros() const
Returns the number of non-zero elements in the sparse vector.
Definition: SVecSVecMultExpr.h:194
Expression object for sparse vector-sparse vector multiplications.The SVecSVecMultExpr class represen...
Definition: Forward.h:122
Header file for run time assertion macros.
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
Header file for the reset shim.
void swap(DiagonalMatrix< MT, SO, DF > &a, DiagonalMatrix< MT, SO, DF > &b) noexcept
Swapping the contents of two matrices.
Definition: DiagonalMatrix.h:258
Header file for the RemoveReference type trait.
const IfTrue_< returnExpr, ExprReturnType, ElementType > ReturnType
Return type for expression template evaluations.
Definition: SVecSVecMultExpr.h:124
LeftOperand lhs_
Left-hand side sparse vector of the multiplication expression.
Definition: SVecSVecMultExpr.h:245
If_< IsExpression< VT1 >, const VT1, const VT1 & > LeftOperand
Composite type of the left-hand side sparse vector expression.
Definition: SVecSVecMultExpr.h:130
typename T::ConstIterator ConstIterator_
Alias declaration for nested ConstIterator type definitions.The ConstIterator_ alias declaration prov...
Definition: Aliases.h:103
Constraint on the data type.
#define BLAZE_CONSTRAINT_MUST_FORM_VALID_VECVECMULTEXPR(T1, T2)
Constraint on the data type.In case the given data types T1 and T2 do not form a valid vector/vector ...
Definition: VecVecMultExpr.h:109
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
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 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
#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
CompositeType_< VT1 > CT1
Composite type of the left-hand side sparse vector expression.
Definition: SVecSVecMultExpr.h:99
bool canAlias(const T *alias) const noexcept
Returns whether the expression can alias with the given address alias.
Definition: SVecSVecMultExpr.h:226
ResultType_< VT2 > RT2
Result type of the right-hand side sparse vector expression.
Definition: SVecSVecMultExpr.h:96
Header file for the IsExpression type trait class.
Header file for the FunctionTrace class.