35 #ifndef _BLAZE_MATH_EXPRESSIONS_SVECSVECMULTEXPR_H_
36 #define _BLAZE_MATH_EXPRESSIONS_SVECSVECMULTEXPR_H_
85 template<
typename VT1
88 class SVecSVecMultExpr :
public SparseVector< SVecSVecMultExpr<VT1,VT2,TF>, TF >
89 ,
private VecVecMultExpr
139 enum { smpAssignable = 0 };
172 inline ReturnType
at(
size_t index )
const {
173 if( index >=
lhs_.size() ) {
176 return (*
this)[index];
226 template<
typename T >
228 return (
lhs_.canAlias( alias ) ||
rhs_.canAlias( alias ) );
238 template<
typename T >
240 return (
lhs_.isAliased( alias ) ||
rhs_.isAliased( alias ) );
262 template<
typename VT >
272 CT1 x(
serial( rhs.lhs_ ) );
273 CT2 y(
serial( rhs.rhs_ ) );
279 const LeftIterator lend( x.end() );
280 const RightIterator rend( y.end() );
282 LeftIterator l( x.begin() );
283 RightIterator r( y.begin() );
285 for( ; l!=lend; ++l ) {
286 while( r!=rend && r->index() < l->index() ) ++r;
288 if( l->index() == r->index() ) {
289 (~lhs)[l->index()] = l->value() * r->value();
309 template<
typename VT >
319 CT1 x(
serial( rhs.lhs_ ) );
320 CT2 y(
serial( rhs.rhs_ ) );
326 const LeftIterator lend( x.end() );
327 const RightIterator rend( y.end() );
329 LeftIterator l( x.begin() );
330 RightIterator r( y.begin() );
332 for( ; l!=lend; ++l ) {
333 while( r!=rend && r->index() < l->index() ) ++r;
335 if( l->index() == r->index() ) {
336 (~lhs).append( l->index(), l->value() * r->value() );
356 template<
typename VT >
357 friend inline void addAssign( DenseVector<VT,TF>& lhs,
const SVecSVecMultExpr& rhs )
366 CT1 x(
serial( rhs.lhs_ ) );
367 CT2 y(
serial( rhs.rhs_ ) );
373 const LeftIterator lend( x.end() );
374 const RightIterator rend( y.end() );
376 LeftIterator l( x.begin() );
377 RightIterator r( y.begin() );
379 for( ; l!=lend; ++l ) {
380 while( r!=rend && r->index() < l->index() ) ++r;
382 if( l->index() == r->index() ) {
383 (~lhs)[l->index()] += l->value() * r->value();
407 template<
typename VT >
408 friend inline void subAssign( DenseVector<VT,TF>& lhs,
const SVecSVecMultExpr& rhs )
417 CT1 x(
serial( rhs.lhs_ ) );
418 CT2 y(
serial( rhs.rhs_ ) );
424 const LeftIterator lend( x.end() );
425 const RightIterator rend( y.end() );
427 LeftIterator l( x.begin() );
428 RightIterator r( y.begin() );
430 for( ; l!=lend; ++l ) {
431 while( r!=rend && r->index() < l->index() ) ++r;
433 if( l->index() == r->index() ) {
434 (~lhs)[l->index()] -= l->value() * r->value();
458 template<
typename VT >
459 friend inline void multAssign( DenseVector<VT,TF>& lhs,
const SVecSVecMultExpr& rhs )
468 CT1 x(
serial( rhs.lhs_ ) );
469 CT2 y(
serial( rhs.rhs_ ) );
475 const LeftIterator lend( x.end() );
476 const RightIterator rend( y.end() );
478 LeftIterator l( x.begin() );
479 RightIterator r( y.begin() );
483 for( ; l!=lend; ++l ) {
484 while( r!=rend && r->index() < l->index() ) ++r;
486 if( l->index() == r->index() ) {
487 for( ; i<r->index(); ++i )
489 (~lhs)[l->index()] *= l->value() * r->value();
495 for( ; i<rhs.size(); ++i )
513 template<
typename VT >
514 friend inline void multAssign( SparseVector<VT,TF>& lhs,
const SVecSVecMultExpr& rhs )
524 CT1 x(
serial( rhs.lhs_ ) );
525 CT2 y(
serial( rhs.rhs_ ) );
531 VT tmp( rhs.size(), rhs.nonZeros() );
533 const Iterator1 end1( (~lhs).
end() );
534 const Iterator2 end2( x.end() );
535 const Iterator3 end3( y.end() );
537 Iterator1 i1( (~lhs).
begin() );
538 Iterator2 i2( x.begin() );
539 Iterator3 i3( y.begin() );
541 for( ; i1!=end1; ++i1 ) {
542 while( i2!=end2 && i2->index() < i1->index() ) ++i2;
543 if( i2==end2 )
break;
544 while( i3!=end3 && i3->index() < i1->index() ) ++i3;
545 if( i3==end3 )
break;
546 if( i1->index() == i2->index() && i1->index() == i3->index() ) {
547 tmp.append( i1->index(), i1->value() * i2->value() * i3->value() );
604 template<
typename T1
607 inline const SVecSVecMultExpr<T1,T2,TF>
612 if( (~lhs).
size() != (~rhs).
size() ) {
631 template<
typename VT1,
typename VT2,
bool TF >
632 struct Size< SVecSVecMultExpr<VT1,VT2,TF> >
633 :
public Max< Size<VT1>, Size<VT2> >
649 template<
typename VT1,
typename VT2,
bool TF,
bool AF >
650 struct SubvectorExprTrait< SVecSVecMultExpr<VT1,VT2,TF>, AF >
654 typedef typename MultExprTrait< typename SubvectorExprTrait<const VT1,AF>::Type
655 ,
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
const SelectType< returnExpr, ExprReturnType, ElementType >::Type ReturnType
Return type for expression template evaluations.
Definition: SVecSVecMultExpr.h:125
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
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:7820
Header file for basic type definitions.
Header file for the SparseVector base class.
VT1::TransposeType TT1
Transpose type of the left-hand side sparse vector expression.
Definition: SVecSVecMultExpr.h:100
BLAZE_ALWAYS_INLINE size_t size(const Vector< VT, TF > &vector)
Returns the current size/dimension of the vector.
Definition: Vector.h:252
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:250
LeftOperand leftOperand() const
Returns the left-hand side sparse vector operand.
Definition: SVecSVecMultExpr.h:205
ReturnType at(size_t index) const
Checked access to the vector elements.
Definition: SVecSVecMultExpr.h:172
size_t size() const
Returns the current size/dimension of the vector.
Definition: SVecSVecMultExpr.h:185
ResultType::TransposeType TransposeType
Transpose type for expression template evaluations.
Definition: SVecSVecMultExpr.h:121
Efficient implementation of a compressed matrix.The CompressedMatrix class template is the represent...
Definition: CompressedMatrix.h:207
void reset(const DiagonalProxy< MT > &proxy)
Resetting the represented element to the default initial values.
Definition: DiagonalProxy.h:507
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.
RightOperand rightOperand() const
Returns the right-hand side sparse vector operand.
Definition: SVecSVecMultExpr.h:215
VT2::TransposeType TT2
Transpose type of the right-hand side sparse vector expression.
Definition: SVecSVecMultExpr.h:101
bool canAlias(const T *alias) const
Returns whether the expression can alias with the given address alias.
Definition: SVecSVecMultExpr.h:227
VT2::CompositeType CT2
Composite type of the right-hand side sparse vector expression.
Definition: SVecSVecMultExpr.h:99
Constraint on the data type.
SVecSVecMultExpr< VT1, VT2, TF > This
Type of this SVecSVecMultExpr instance.
Definition: SVecSVecMultExpr.h:119
Header file for the MultExprTrait class template.
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 IsTemporary type trait class.
Header file for the multiplication trait.
Namespace of the Blaze C++ math library.
Definition: Blaze.h:57
ResultType::ElementType ElementType
Resulting element type.
Definition: SVecSVecMultExpr.h:122
const Element * ConstIterator
Iterator over constant elements.
Definition: CompressedMatrix.h:2592
VT1::ResultType RT1
Result type of the left-hand side sparse vector expression.
Definition: SVecSVecMultExpr.h:94
MultTrait< RT1, RT2 >::Type ResultType
Result 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:159
#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
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 ResultType CompositeType
Data type for composite expression templates.
Definition: SVecSVecMultExpr.h:128
Constraint on the data type.
RightOperand rhs_
Right-hand side sparse vector of the multiplication expression.
Definition: SVecSVecMultExpr.h:247
CompressedMatrix< Type, false > TransposeType
Transpose type for expression template evaluations.
Definition: CompressedMatrix.h:2585
VT2::ResultType RT2
Result type of the right-hand side sparse vector expression.
Definition: SVecSVecMultExpr.h:95
MultExprTrait< RN1, RN2 >::Type ExprReturnType
Expression return type for the subscript operator.
Definition: SVecSVecMultExpr.h:114
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:187
Header file for the VecVecMultExpr base class.
Header file for the SelectType class template.
Header file for all forward declarations for expression class templates.
Constraint on the data type.
Header file for the serial shim.
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
size_t nonZeros() const
Returns the number of non-zero elements in the sparse vector.
Definition: SVecSVecMultExpr.h:195
Expression object for sparse vector-sparse vector multiplications.The SVecSVecMultExpr class represen...
Definition: Forward.h:132
Header file for run time assertion macros.
Base template for the MultTrait class.
Definition: MultTrait.h:138
Header file for the reset shim.
VT2::ReturnType RN2
Return type of the right-hand side sparse vector expression.
Definition: SVecSVecMultExpr.h:97
Header file for the RemoveReference type trait.
VT1::ReturnType RN1
Return type of the left-hand side sparse vector expression.
Definition: SVecSVecMultExpr.h:96
void swap(DiagonalMatrix< MT, SO, DF > &a, DiagonalMatrix< MT, SO, DF > &b)
Swapping the contents of two matrices.
Definition: DiagonalMatrix.h:256
LeftOperand lhs_
Left-hand side sparse vector of the multiplication expression.
Definition: SVecSVecMultExpr.h:246
VT1::CompositeType CT1
Composite type of the left-hand side sparse vector expression.
Definition: SVecSVecMultExpr.h:98
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:165
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: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
SelectType< IsExpression< VT1 >::value, const VT1, const VT1 & >::Type LeftOperand
Composite type of the left-hand side sparse vector expression.
Definition: SVecSVecMultExpr.h:131
This ResultType
Result type for expression template evaluations.
Definition: CompressedMatrix.h:2583
bool isAliased(const T *alias) const
Returns whether the expression is aliased with the given address alias.
Definition: SVecSVecMultExpr.h:239
Header file for the SubvectorExprTrait class template.
Header file for exception macros.
Header file for the Size type trait.
Evaluation of the resulting expression type of a multiplication.Via this type trait it is possible to...
Definition: MultExprTrait.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: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
SelectType< IsExpression< VT2 >::value, const VT2, const VT2 & >::Type RightOperand
Composite type of the right-hand side sparse vector expression.
Definition: SVecSVecMultExpr.h:134
SVecSVecMultExpr(const VT1 &lhs, const VT2 &rhs)
Constructor for the SVecSVecMultExpr class.
Definition: SVecSVecMultExpr.h:145
Header file for the IsExpression type trait class.
Header file for the FunctionTrace class.