35 #ifndef _BLAZE_MATH_EXPRESSIONS_TSMATSVECMULTEXPR_H_
36 #define _BLAZE_MATH_EXPRESSIONS_TSMATSVECMULTEXPR_H_
91 class TSMatSVecMultExpr :
public SparseVector< TSMatSVecMultExpr<MT,VT>, false >
92 ,
private MatVecMultExpr
118 template<
typename T1,
typename T2,
typename T3 >
119 struct UseSMPAssignKernel {
120 enum { value = evaluateMatrix || evaluateVector };
151 enum { smpAssignable = !evaluateMatrix && !evaluateVector };
189 const VectorIterator vend( x.end() );
190 VectorIterator velem( x.begin() );
192 if(
vec_.size() > 0UL && velem != vend ) {
193 res = A( index, velem->index() ) * velem->value();
195 for( ; velem!=vend; ++velem )
196 res += A( index, velem->index() ) * velem->value();
252 template<
typename T >
254 return (
mat_.isAliased( alias ) ||
vec_.isAliased( alias ) );
264 template<
typename T >
266 return (
mat_.isAliased( alias ) ||
vec_.isAliased( alias ) );
299 template<
typename VT1 >
311 if( x.nonZeros() == 0UL )
return;
323 TSMatSVecMultExpr::selectAssignKernel( ~lhs, A, x );
342 template<
typename VT1
346 selectAssignKernel( VT1& y,
const MT1& A,
const VT2& x )
351 const VectorIterator vend ( x.end() );
352 VectorIterator velem( x.begin() );
354 for( ; velem!=vend; ++velem )
356 const MatrixIterator mend ( A.end ( velem->index() ) );
357 MatrixIterator melem( A.begin( velem->index() ) );
359 for( ; melem!=mend; ++melem ) {
362 y[melem->index()] = melem->value() * velem->value();
364 y[melem->index()] += melem->value() * velem->value();
385 template<
typename VT1
388 static inline typename EnableIf< UseSMPAssignKernel<VT1,MT1,VT2> >::Type
389 selectAssignKernel( VT1& y,
const MT1& A,
const VT2& x )
408 template<
typename VT1 >
419 if( x.nonZeros() == 0UL )
return;
428 DynamicVector<ElementType> tmp( (~lhs).
size() );
429 std::vector<bool> indices( (~lhs).
size(),
false );
430 size_t nonzeros( 0UL );
432 const VectorIterator vend ( x.end() );
433 VectorIterator velem( x.begin() );
435 for( ; velem!=vend; ++velem )
437 const MatrixIterator mend ( A.end( velem->index() ) );
438 MatrixIterator melem( A.begin( velem->index() ) );
440 for( ; melem!=mend; ++melem ) {
441 if( !indices[melem->index()] ) {
442 indices[melem->index()] =
true;
444 tmp[melem->index()] = melem->value() * velem->value();
447 tmp[melem->index()] += melem->value() * velem->value();
452 (~lhs).reserve( nonzeros );
454 for(
size_t i=0UL; i<(~lhs).
size(); ++i ) {
456 (~lhs).append( i, tmp[i] );
476 template<
typename VT1 >
485 if( x.nonZeros() == 0UL )
return;
497 TSMatSVecMultExpr::selectAddAssignKernel( ~lhs, A, x );
516 template<
typename VT1
519 static inline typename DisableIf< UseSMPAssignKernel<VT1,MT1,VT2> >::Type
520 selectAddAssignKernel( VT1& y,
const MT1& A,
const VT2& x )
525 const VectorIterator vend ( x.end() );
526 VectorIterator velem( x.begin() );
528 for( ; velem!=vend; ++velem )
530 const MatrixIterator mend ( A.end ( velem->index() ) );
531 MatrixIterator melem( A.begin( velem->index() ) );
533 for( ; melem!=mend; ++melem ) {
534 y[melem->index()] += melem->value() * velem->value();
555 template<
typename VT1
558 static inline typename EnableIf< UseSMPAssignKernel<VT1,MT1,VT2> >::Type
559 selectAddAssignKernel( VT1& y,
const MT1& A,
const VT2& x )
583 template<
typename VT1 >
592 if( x.nonZeros() == 0UL )
return;
604 TSMatSVecMultExpr::selectSubAssignKernel( ~lhs, A, x );
623 template<
typename VT1
626 static inline typename DisableIf< UseSMPAssignKernel<VT1,MT1,VT2> >::Type
627 selectSubAssignKernel( VT1& y,
const MT1& A,
const VT2& x )
632 const VectorIterator vend ( x.end() );
633 VectorIterator velem( x.begin() );
635 for( ; velem!=vend; ++velem )
637 const MatrixIterator mend ( A.end ( velem->index() ) );
638 MatrixIterator melem( A.begin( velem->index() ) );
640 for( ; melem!=mend; ++melem ) {
641 y[melem->index()] -= melem->value() * velem->value();
662 template<
typename VT1
665 static inline typename EnableIf< UseSMPAssignKernel<VT1,MT1,VT2> >::Type
666 selectSubAssignKernel( VT1& y,
const MT1& A,
const VT2& x )
690 template<
typename VT1 >
762 template<
typename T1
764 inline const typename DisableIf< IsMatMatMultExpr<T1>, TSMatSVecMultExpr<T1,T2> >::Type
769 if( (~mat).
columns() != (~vec).size() )
770 throw std::invalid_argument(
"Matrix and vector sizes do not match" );
787 template<
typename MT,
typename VT,
bool AF >
788 struct SubvectorExprTrait< TSMatSVecMultExpr<MT,VT>, AF >
792 typedef typename MultExprTrait< typename SubmatrixExprTrait<const MT,AF>::Type, VT >::Type Type;
VT::CompositeType VCT
Composite type of the right-hand side sparse vector expression.
Definition: TSMatSVecMultExpr.h:100
const size_t SMP_SMATSVECMULT_THRESHOLD
SMP row-major sparse matrix/sparse vector multiplication threshold.This threshold represents the syst...
Definition: Thresholds.h:295
Compile time check whether the given type is a computational expression template.This type trait clas...
Definition: IsComputation.h:89
void reset(DynamicMatrix< Type, SO > &m)
Resetting the given dense matrix.
Definition: DynamicMatrix.h:4579
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:4075
size_t nonZeros() const
Returns an estimation for the number of non-zero elements in the sparse vector.
Definition: TSMatSVecMultExpr.h:221
Header file for the SparseVector base class.
SelectType< IsExpression< MT >::value, const MT, const MT & >::Type LeftOperand
Composite type of the left-hand side sparse matrix expression.
Definition: TSMatSVecMultExpr.h:137
void smpSubAssign(DenseMatrix< MT1, SO1 > &lhs, const Matrix< MT2, SO2 > &rhs)
Default implementation of the SMP subtraction assignment of a matrix to dense matrix.
Definition: DenseMatrix.h:151
#define BLAZE_CONSTRAINT_MUST_BE_COLUMN_VECTOR_TYPE(T)
Constraint on the data type.In case the given data type T is not a column dense or sparse vector type...
Definition: TransposeFlag.h:159
const ResultType CompositeType
Data type for composite expression templates.
Definition: TSMatSVecMultExpr.h:134
bool isDefault(const DynamicMatrix< Type, SO > &m)
Returns whether the given dense matrix is in default state.
Definition: DynamicMatrix.h:4622
Efficient implementation of a compressed matrix.The CompressedMatrix class template is the represent...
Definition: CompressedMatrix.h:197
void smpMultAssign(DenseVector< 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:178
bool isAliased(const T *alias) const
Returns whether the expression is aliased with the given address alias.
Definition: TSMatSVecMultExpr.h:265
const This & CompositeType
Data type for composite expression templates.
Definition: CompressedMatrix.h:2384
Type ElementType
Type of the sparse matrix elements.
Definition: CompressedMatrix.h:249
size_t size() const
Returns the current size/dimension of the vector.
Definition: TSMatSVecMultExpr.h:211
SelectType< evaluateVector, const VRT, VCT >::Type RT
Type for the assignment of the right-hand side sparse vector operand.
Definition: TSMatSVecMultExpr.h:146
Header file for the Computation base class.
MCT LT
Type for the assignment of the left-hand side sparse matrix operand.
Definition: TSMatSVecMultExpr.h:143
Header file for the RequiresEvaluation type trait.
SelectType< IsExpression< VT >::value, const VT, const VT & >::Type RightOperand
Composite type of the right-hand side sparse vector expression.
Definition: TSMatSVecMultExpr.h:140
Base class for sparse matrices.The SparseMatrix class is a base class for all sparse matrix classes...
Definition: Forward.h:104
Constraint on the data type.
MT::ResultType MRT
Result type of the left-hand side sparse matrix expression.
Definition: TSMatSVecMultExpr.h:97
Constraint on the data type.
void smpAddAssign(DenseMatrix< 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:121
Compile time check to query the requirement to evaluate an expression.Via this type trait it is possi...
Definition: RequiresEvaluation.h:90
const This & CompositeType
Data type for composite expression templates.
Definition: CompressedMatrix.h:251
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 multiplication trait.
Header file for the dense vector SMP implementation.
Expression object for sparse matrix-sparse vector multiplications.The TSMatSVecMultExpr class represe...
Definition: Forward.h:138
#define BLAZE_CONSTRAINT_MUST_BE_COLUMN_MAJOR_MATRIX_TYPE(T)
Constraint on the data type.In case the given data type T is not a column-major dense or sparse matri...
Definition: StorageOrder.h:161
const Element * ConstIterator
Iterator over constant elements.
Definition: CompressedMatrix.h:2388
Header file for the IsMatMatMultExpr type trait class.
void assign(Matrix< MT1, SO1 > &lhs, const Matrix< MT2, SO2 > &rhs)
Default implementation of the assignment of a matrix to a matrix.
Definition: Matrix.h:179
ResultType::ElementType ElementType
Resulting element type.
Definition: TSMatSVecMultExpr.h:130
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
Constraint on the data type.
LeftOperand leftOperand() const
Returns the left-hand side transpose sparse matrix operand.
Definition: TSMatSVecMultExpr.h:231
#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
TSMatSVecMultExpr< MT, VT > This
Type of this TSMatSVecMultExpr instance.
Definition: TSMatSVecMultExpr.h:127
LeftOperand mat_
Left-hand side sparse matrix of the multiplication expression.
Definition: TSMatSVecMultExpr.h:282
bool canAlias(const T *alias) const
Returns whether the expression can alias with the given address alias.
Definition: TSMatSVecMultExpr.h:253
void multAssign(Matrix< MT1, SO1 > &lhs, const Matrix< MT2, SO2 > &rhs)
Default implementation of the multiplication assignment of a matrix to a matrix.
Definition: Matrix.h:269
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 complete DynamicVector implementation.
Header file for the EnableIf class template.
void smpAssign(DenseMatrix< MT1, SO1 > &lhs, const Matrix< MT2, SO2 > &rhs)
Default implementation of the SMP assignment of a matrix to a dense matrix.
Definition: DenseMatrix.h:91
Compile time check for resizable data types.This type trait tests whether the given data type is a re...
Definition: IsResizable.h:75
Removal of reference modifiers.The RemoveCV type trait removes any reference modifiers from the given...
Definition: RemoveReference.h:69
Header file for run time assertion macros.
RightOperand vec_
Right-hand side sparse vector of the multiplication expression.
Definition: TSMatSVecMultExpr.h:283
Base template for the MultTrait class.
Definition: MultTrait.h:141
void addAssign(Matrix< MT1, SO1 > &lhs, const Matrix< MT2, SO2 > &rhs)
Default implementation of the addition assignment of a matrix to a matrix.
Definition: Matrix.h:209
Header file for the reset shim.
void subAssign(Matrix< MT1, SO1 > &lhs, const Matrix< MT2, SO2 > &rhs)
Default implementation of the subtraction assignment of a matrix to matrix.
Definition: Matrix.h:239
Header file for the isDefault shim.
ReturnType operator[](size_t index) const
Subscript operator for the direct access to the vector elements.
Definition: TSMatSVecMultExpr.h:174
bool canSMPAssign() const
Returns whether the expression can be used in SMP assignments.
Definition: TSMatSVecMultExpr.h:275
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
const ElementType ReturnType
Return type for expression template evaluations.
Definition: TSMatSVecMultExpr.h:131
VT::ResultType VRT
Result type of the right-hand side sparse vector expression.
Definition: TSMatSVecMultExpr.h:98
Header file for the IsComputation type trait class.
Header file for the sparse vector SMP implementation.
Base class for sparse vectors.The SparseVector class is a base class for all arbitrarily sized (N-dim...
Definition: Forward.h:105
#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:2379
ResultType::TransposeType TransposeType
Transpose type for expression template evaluations.
Definition: TSMatSVecMultExpr.h:129
size_t columns(const Matrix< MT, SO > &m)
Returns the current number of columns of the matrix.
Definition: Matrix.h:154
MultTrait< MRT, VRT >::Type ResultType
Result type for expression template evaluations.
Definition: TSMatSVecMultExpr.h:128
Header file for basic type definitions.
TSMatSVecMultExpr(const MT &mat, const VT &vec)
Constructor for the TSMatSVecMultExpr class.
Definition: TSMatSVecMultExpr.h:160
RightOperand rightOperand() const
Returns the right-hand side sparse vector operand.
Definition: TSMatSVecMultExpr.h:241
Header file for the MatVecMultExpr base class.
Header file for the IsResizable type trait.
Header file for the thresholds for matrix/vector and matrix/matrix multiplications.
#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
#define BLAZE_CONSTRAINT_MUST_BE_SPARSE_MATRIX_TYPE(T)
Constraint on the data type.In case the given data type T is not a sparse, N-dimensional matrix type...
Definition: SparseMatrix.h:79
MT::CompositeType MCT
Composite type of the left-hand side sparse matrix expression.
Definition: TSMatSVecMultExpr.h:99
Header file for the IsExpression type trait class.
Header file for the FunctionTrace class.