35 #ifndef _BLAZE_MATH_EXPRESSIONS_TSMATSVECMULTEXPR_H_
36 #define _BLAZE_MATH_EXPRESSIONS_TSMATSVECMULTEXPR_H_
94 class TSMatSVecMultExpr :
public SparseVector< TSMatSVecMultExpr<MT,VT>, false >
95 ,
private MatVecMultExpr
122 template<
typename T1 >
123 struct UseSMPAssign {
124 enum { value = ( evaluateMatrix || evaluateVector ) };
155 enum { smpAssignable = !evaluateMatrix && MT::smpAssignable &&
156 !evaluateVector && VT::smpAssignable };
194 const VectorIterator vend( x.end() );
195 VectorIterator velem( x.begin() );
197 if(
vec_.size() > 0UL && velem != vend ) {
198 res = A( index, velem->index() ) * velem->value();
200 for( ; velem!=vend; ++velem )
201 res += A( index, velem->index() ) * velem->value();
257 template<
typename T >
259 return (
mat_.isAliased( alias ) ||
vec_.isAliased( alias ) );
269 template<
typename T >
271 return (
mat_.isAliased( alias ) ||
vec_.isAliased( alias ) );
304 template<
typename VT1 >
315 RT x(
serial( rhs.vec_ ) );
316 if( x.nonZeros() == 0UL )
return;
319 LT A(
serial( rhs.mat_ ) );
328 TSMatSVecMultExpr::selectAssignKernel( ~lhs, A, x );
347 template<
typename VT1
350 static inline void selectAssignKernel( VT1& y,
const MT1& A,
const VT2& x )
355 const VectorIterator vend ( x.end() );
356 VectorIterator velem( x.begin() );
358 for( ; velem!=vend; ++velem )
360 const MatrixIterator mend ( A.end ( velem->index() ) );
361 MatrixIterator melem( A.begin( velem->index() ) );
363 for( ; melem!=mend; ++melem ) {
366 y[melem->index()] = melem->value() * velem->value();
368 y[melem->index()] += melem->value() * velem->value();
387 template<
typename VT1 >
397 RT x(
serial( rhs.vec_ ) );
398 if( x.nonZeros() == 0UL )
return;
400 LT A(
serial( rhs.mat_ ) );
407 DynamicVector<ElementType> tmp( (~lhs).
size() );
408 std::vector<byte> indices( (~lhs).
size(), 0 );
409 size_t nonzeros( 0UL );
411 const VectorIterator vend ( x.end() );
412 VectorIterator velem( x.begin() );
414 for( ; velem!=vend; ++velem )
416 const MatrixIterator mend ( A.end ( velem->index() ) );
417 MatrixIterator melem( A.begin( velem->index() ) );
419 for( ; melem!=mend; ++melem ) {
420 if( !indices[melem->index()] ) {
421 indices[melem->index()] = 1;
423 tmp[melem->index()] = melem->value() * velem->value();
426 tmp[melem->index()] += melem->value() * velem->value();
431 (~lhs).reserve( nonzeros );
433 for(
size_t i=0UL; i<(~lhs).
size(); ++i ) {
435 (~lhs).append( i, tmp[i] );
455 template<
typename VT1 >
463 RT x(
serial( rhs.vec_ ) );
464 if( x.nonZeros() == 0UL )
return;
467 LT A(
serial( rhs.mat_ ) );
476 TSMatSVecMultExpr::selectAddAssignKernel( ~lhs, A, x );
495 template<
typename VT1
498 static inline void selectAddAssignKernel( VT1& y,
const MT1& A,
const VT2& x )
503 const VectorIterator vend ( x.end() );
504 VectorIterator velem( x.begin() );
506 for( ; velem!=vend; ++velem )
508 const MatrixIterator mend ( A.end ( velem->index() ) );
509 MatrixIterator melem( A.begin( velem->index() ) );
511 for( ; melem!=mend; ++melem ) {
512 y[melem->index()] += melem->value() * velem->value();
536 template<
typename VT1 >
544 RT x(
serial( rhs.vec_ ) );
545 if( x.nonZeros() == 0UL )
return;
548 LT A(
serial( rhs.mat_ ) );
557 TSMatSVecMultExpr::selectSubAssignKernel( ~lhs, A, x );
576 template<
typename VT1
579 static inline void selectSubAssignKernel( VT1& y,
const MT1& A,
const VT2& x )
584 const VectorIterator vend ( x.end() );
585 VectorIterator velem( x.begin() );
587 for( ; velem!=vend; ++velem )
589 const MatrixIterator mend ( A.end ( velem->index() ) );
590 MatrixIterator melem( A.begin( velem->index() ) );
592 for( ; melem!=mend; ++melem ) {
593 y[melem->index()] -= melem->value() * velem->value();
617 template<
typename VT1 >
628 const ResultType tmp(
serial( rhs ) );
653 template<
typename VT1 >
654 friend inline typename EnableIf< UseSMPAssign<VT1> >::Type
666 if( x.nonZeros() == 0UL )
return;
702 template<
typename VT1 >
703 friend inline typename EnableIf< UseSMPAssign<VT1> >::Type
712 if( x.nonZeros() == 0UL )
return;
748 template<
typename VT1 >
749 friend inline typename EnableIf< UseSMPAssign<VT1> >::Type
758 if( x.nonZeros() == 0UL )
return;
794 template<
typename VT1 >
795 friend inline typename EnableIf< UseSMPAssign<VT1> >::Type
806 const ResultType tmp( rhs );
868 template<
typename T1
870 inline const typename DisableIf< IsMatMatMultExpr<T1>, TSMatSVecMultExpr<T1,T2> >::Type
876 throw std::invalid_argument(
"Matrix and vector sizes do not match" );
893 template<
typename MT,
typename VT >
911 template<
typename MT,
typename VT,
bool AF >
916 typedef typename MultExprTrait< typename SubmatrixExprTrait<const MT,AF>::Type
917 ,
typename SubvectorExprTrait<const VT,AF>::Type >::Type Type;
const size_t SMP_SMATSVECMULT_THRESHOLD
SMP row-major sparse matrix/sparse vector multiplication threshold.This threshold specifies when a ro...
Definition: Thresholds.h:598
Compile time check whether the given type is a computational expression template.This type trait clas...
Definition: IsComputation.h:89
bool canSMPAssign() const
Returns whether the expression can be used in SMP assignments.
Definition: TSMatSVecMultExpr.h:280
MultTrait< MRT, VRT >::Type ResultType
Result type for expression template evaluations.
Definition: TSMatSVecMultExpr.h:132
MT::ResultType MRT
Result type of the left-hand side sparse matrix expression.
Definition: TSMatSVecMultExpr.h:100
BLAZE_ALWAYS_INLINE 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:879
Header file for the Rows type trait.
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:8247
Header file for basic type definitions.
Header file for the SparseVector base class.
#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
Efficient implementation of a compressed matrix.The CompressedMatrix class template is the represent...
Definition: CompressedMatrix.h:209
LeftOperand leftOperand() const
Returns the left-hand side transpose sparse matrix operand.
Definition: TSMatSVecMultExpr.h:236
void reset(const DiagonalProxy< MT > &proxy)
Resetting the represented element to the default initial values.
Definition: DiagonalProxy.h:821
const This & CompositeType
Data type for composite expression templates.
Definition: CompressedMatrix.h:2507
Type ElementType
Type of the sparse matrix elements.
Definition: CompressedMatrix.h:261
SelectType< evaluateMatrix, const MRT, MCT >::Type LT
Type for the assignment of the left-hand side sparse matrix operand.
Definition: TSMatSVecMultExpr.h:147
bool canAlias(const T *alias) const
Returns whether the expression can alias with the given address alias.
Definition: TSMatSVecMultExpr.h:258
const DMatSerialExpr< MT, SO > serial(const DenseMatrix< MT, SO > &dm)
Forces the serial evaluation of the given dense matrix expression dm.
Definition: DMatSerialExpr.h:699
Header file for the Computation base class.
Header file for the RequiresEvaluation type trait.
ReturnType operator[](size_t index) const
Subscript operator for the direct access to the vector elements.
Definition: TSMatSVecMultExpr.h:179
Header file for the implementation of an arbitrarily sized vector.
Base class for sparse matrices.The SparseMatrix class is a base class for all sparse matrix classes...
Definition: Forward.h:107
bool isDefault(const DiagonalProxy< MT > &proxy)
Returns whether the represented element is in default state.
Definition: DiagonalProxy.h:861
const ElementType ReturnType
Return type for expression template evaluations.
Definition: TSMatSVecMultExpr.h:135
Constraint on the data type.
Constraint on the data type.
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:263
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.
Namespace of the Blaze C++ math library.
Definition: Blaze.h:57
Expression object for sparse matrix-sparse vector multiplications.The TSMatSVecMultExpr class represe...
Definition: Forward.h:142
#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
SelectType< evaluateVector, const VRT, VCT >::Type RT
Type for the assignment of the right-hand side sparse vector operand.
Definition: TSMatSVecMultExpr.h:150
const Element * ConstIterator
Iterator over constant elements.
Definition: CompressedMatrix.h:2511
const ResultType CompositeType
Data type for composite expression templates.
Definition: TSMatSVecMultExpr.h:138
Header file for the IsMatMatMultExpr type trait class.
BLAZE_ALWAYS_INLINE 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:635
SelectType< IsExpression< MT >::value, const MT, const MT & >::Type LeftOperand
Composite type of the left-hand side sparse matrix expression.
Definition: TSMatSVecMultExpr.h:141
RightOperand vec_
Right-hand side sparse vector of the multiplication expression.
Definition: TSMatSVecMultExpr.h:288
Base class for N-dimensional dense vectors.The DenseVector class is a base class for all arbitrarily ...
Definition: DenseVector.h:70
TSMatSVecMultExpr< MT, VT > This
Type of this TSMatSVecMultExpr instance.
Definition: TSMatSVecMultExpr.h:131
#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
bool isAliased(const T *alias) const
Returns whether the expression is aliased with the given address alias.
Definition: TSMatSVecMultExpr.h:270
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
#define BLAZE_CONSTRAINT_MUST_FORM_VALID_MATVECMULTEXPR(T1, T2)
Constraint on the data type.In case the given data types T1 and T2 do not form a valid matrix/vector ...
Definition: MatVecMultExpr.h:166
VT::ResultType VRT
Result type of the right-hand side sparse vector expression.
Definition: TSMatSVecMultExpr.h:101
size_t size() const
Returns the current size/dimension of the vector.
Definition: TSMatSVecMultExpr.h:216
Header file for the SelectType class template.
Header file for all forward declarations for expression class templates.
Constraint on the data type.
ResultType::ElementType ElementType
Resulting element type.
Definition: TSMatSVecMultExpr.h:134
Header file for the EnableIf class template.
Header file for the serial shim.
Header file for the byte type.
ResultType::TransposeType TransposeType
Transpose type for expression template evaluations.
Definition: TSMatSVecMultExpr.h:133
Compile time check for resizable data types.This type trait tests whether the given data type is a re...
Definition: IsResizable.h:75
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
SelectType< IsExpression< VT >::value, const VT, const VT & >::Type RightOperand
Composite type of the right-hand side sparse vector expression.
Definition: TSMatSVecMultExpr.h:144
Removal of reference modifiers.The RemoveCV type trait removes any reference modifiers from the given...
Definition: RemoveReference.h:69
LeftOperand mat_
Left-hand side sparse matrix of the multiplication expression.
Definition: TSMatSVecMultExpr.h:287
MT::CompositeType MCT
Composite type of the left-hand side sparse matrix expression.
Definition: TSMatSVecMultExpr.h:102
TSMatSVecMultExpr(const MT &mat, const VT &vec)
Constructor for the TSMatSVecMultExpr class.
Definition: TSMatSVecMultExpr.h:165
Header file for run time assertion macros.
EnableIf< IsDenseMatrix< MT1 > >::Type smpAssign(Matrix< MT1, SO1 > &lhs, const Matrix< MT2, SO2 > &rhs)
Default implementation of the SMP assignment of a matrix to a dense matrix.
Definition: DenseMatrix.h:98
size_t nonZeros() const
Returns an estimation for the number of non-zero elements in the sparse vector.
Definition: TSMatSVecMultExpr.h:226
Base template for the MultTrait class.
Definition: MultTrait.h:150
BLAZE_ALWAYS_INLINE 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:742
VT::CompositeType VCT
Composite type of the right-hand side sparse vector expression.
Definition: TSMatSVecMultExpr.h:103
Header file for the reset shim.
Header file for the isDefault shim.
Header file for the RemoveReference type trait.
RightOperand rightOperand() const
Returns the right-hand side sparse vector operand.
Definition: TSMatSVecMultExpr.h:246
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
Base class for sparse vectors.The SparseVector class is a base class for all arbitrarily sized (N-dim...
Definition: Forward.h:108
#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:2502
BLAZE_ALWAYS_INLINE size_t columns(const Matrix< MT, SO > &matrix)
Returns the current number of columns of the matrix.
Definition: Matrix.h:332
Constraint on the data type.
Header file for the MatVecMultExpr base class.
Header file for the IsResizable type trait.
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.
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
Header file for the IsExpression type trait class.
Header file for the FunctionTrace class.
BLAZE_ALWAYS_INLINE 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:849