35 #ifndef _BLAZE_MATH_EXPRESSIONS_TSMATSVECMULTEXPR_H_
36 #define _BLAZE_MATH_EXPRESSIONS_TSMATSVECMULTEXPR_H_
95 class TSMatSVecMultExpr :
public SparseVector< TSMatSVecMultExpr<MT,VT>, false >
96 ,
private MatVecMultExpr
123 template<
typename T1 >
124 struct UseSMPAssign {
125 enum { value = ( evaluateMatrix || evaluateVector ) };
156 enum { smpAssignable = !evaluateMatrix && MT::smpAssignable &&
157 !evaluateVector && VT::smpAssignable };
195 const VectorIterator vend( x.end() );
196 VectorIterator velem( x.begin() );
198 if(
vec_.size() > 0UL && velem != vend ) {
199 res = A( index, velem->index() ) * velem->value();
201 for( ; velem!=vend; ++velem )
202 res += A( index, velem->index() ) * velem->value();
219 inline ReturnType
at(
size_t index )
const {
220 if( index >=
mat_.rows() ) {
223 return (*
this)[index];
273 template<
typename T >
275 return (
mat_.isAliased( alias ) ||
vec_.isAliased( alias ) );
285 template<
typename T >
287 return (
mat_.isAliased( alias ) ||
vec_.isAliased( alias ) );
297 return (
size() > SMP_SMATSVECMULT_THRESHOLD );
320 template<
typename VT1 >
331 RT x(
serial( rhs.vec_ ) );
332 if( x.nonZeros() == 0UL )
return;
335 LT A(
serial( rhs.mat_ ) );
344 TSMatSVecMultExpr::selectAssignKernel( ~lhs, A, x );
363 template<
typename VT1
366 static inline void selectAssignKernel( VT1& y,
const MT1& A,
const VT2& x )
371 const VectorIterator vend ( x.end() );
372 VectorIterator velem( x.begin() );
374 for( ; velem!=vend; ++velem )
376 const MatrixIterator mend ( A.end ( velem->index() ) );
377 MatrixIterator melem( A.begin( velem->index() ) );
379 for( ; melem!=mend; ++melem ) {
382 y[melem->index()] = melem->value() * velem->value();
384 y[melem->index()] += melem->value() * velem->value();
403 template<
typename VT1 >
404 friend inline void assign( SparseVector<VT1,false>& lhs,
const TSMatSVecMultExpr& rhs )
413 RT x(
serial( rhs.vec_ ) );
414 if( x.nonZeros() == 0UL )
return;
416 LT A(
serial( rhs.mat_ ) );
423 DynamicVector<ElementType> tmp( (~lhs).
size() );
424 std::vector<byte> indices( (~lhs).
size(), 0 );
425 size_t nonzeros( 0UL );
427 const VectorIterator vend ( x.end() );
428 VectorIterator velem( x.begin() );
430 for( ; velem!=vend; ++velem )
432 const MatrixIterator mend ( A.end ( velem->index() ) );
433 MatrixIterator melem( A.begin( velem->index() ) );
435 for( ; melem!=mend; ++melem ) {
436 if( !indices[melem->index()] ) {
437 indices[melem->index()] = 1;
439 tmp[melem->index()] = melem->value() * velem->value();
442 tmp[melem->index()] += melem->value() * velem->value();
447 (~lhs).reserve( nonzeros );
449 for(
size_t i=0UL; i<(~lhs).
size(); ++i ) {
451 (~lhs).append( i, tmp[i] );
471 template<
typename VT1 >
472 friend inline void addAssign( DenseVector<VT1,false>& lhs,
const TSMatSVecMultExpr& rhs )
479 RT x(
serial( rhs.vec_ ) );
480 if( x.nonZeros() == 0UL )
return;
483 LT A(
serial( rhs.mat_ ) );
492 TSMatSVecMultExpr::selectAddAssignKernel( ~lhs, A, x );
511 template<
typename VT1
514 static inline void selectAddAssignKernel( VT1& y,
const MT1& A,
const VT2& x )
519 const VectorIterator vend ( x.end() );
520 VectorIterator velem( x.begin() );
522 for( ; velem!=vend; ++velem )
524 const MatrixIterator mend ( A.end ( velem->index() ) );
525 MatrixIterator melem( A.begin( velem->index() ) );
527 for( ; melem!=mend; ++melem ) {
528 y[melem->index()] += melem->value() * velem->value();
552 template<
typename VT1 >
553 friend inline void subAssign( DenseVector<VT1,false>& lhs,
const TSMatSVecMultExpr& rhs )
560 RT x(
serial( rhs.vec_ ) );
561 if( x.nonZeros() == 0UL )
return;
564 LT A(
serial( rhs.mat_ ) );
573 TSMatSVecMultExpr::selectSubAssignKernel( ~lhs, A, x );
592 template<
typename VT1
595 static inline void selectSubAssignKernel( VT1& y,
const MT1& A,
const VT2& x )
600 const VectorIterator vend ( x.end() );
601 VectorIterator velem( x.begin() );
603 for( ; velem!=vend; ++velem )
605 const MatrixIterator mend ( A.end ( velem->index() ) );
606 MatrixIterator melem( A.begin( velem->index() ) );
608 for( ; melem!=mend; ++melem ) {
609 y[melem->index()] -= melem->value() * velem->value();
633 template<
typename VT1 >
634 friend inline void multAssign( DenseVector<VT1,false>& lhs,
const TSMatSVecMultExpr& rhs )
644 const ResultType tmp(
serial( rhs ) );
645 multAssign( ~lhs, tmp );
669 template<
typename VT1 >
670 friend inline typename EnableIf< UseSMPAssign<VT1> >::Type
682 if( x.nonZeros() == 0UL )
return;
718 template<
typename VT1 >
719 friend inline typename EnableIf< UseSMPAssign<VT1> >::Type
728 if( x.nonZeros() == 0UL )
return;
764 template<
typename VT1 >
765 friend inline typename EnableIf< UseSMPAssign<VT1> >::Type
774 if( x.nonZeros() == 0UL )
return;
810 template<
typename VT1 >
811 friend inline typename EnableIf< UseSMPAssign<VT1> >::Type
822 const ResultType tmp( rhs );
884 template<
typename T1
886 inline const typename DisableIf< IsMatMatMultExpr<T1>, TSMatSVecMultExpr<T1,T2> >::Type
910 template<
typename MT,
typename VT >
927 template<
typename MT,
typename VT,
bool AF >
932 typedef typename MultExprTrait< typename SubmatrixExprTrait<const MT,AF>::Type
933 ,
typename SubvectorExprTrait<const VT,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
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:296
MultTrait< MRT, VRT >::Type ResultType
Result type for expression template evaluations.
Definition: TSMatSVecMultExpr.h:133
MT::ResultType MRT
Result type of the left-hand side sparse matrix expression.
Definition: TSMatSVecMultExpr.h:101
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:7820
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: ColumnVector.h:79
Efficient implementation of a compressed matrix.The CompressedMatrix class template is the represent...
Definition: CompressedMatrix.h:207
LeftOperand leftOperand() const
Returns the left-hand side transpose sparse matrix operand.
Definition: TSMatSVecMultExpr.h:252
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
SelectType< evaluateMatrix, const MRT, MCT >::Type LT
Type for the assignment of the left-hand side sparse matrix operand.
Definition: TSMatSVecMultExpr.h:148
bool canAlias(const T *alias) const
Returns whether the expression can alias with the given address alias.
Definition: TSMatSVecMultExpr.h:274
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.
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:180
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:117
bool isDefault(const DiagonalProxy< MT > &proxy)
Returns whether the represented element is in default state.
Definition: DiagonalProxy.h:547
const ElementType ReturnType
Return type for expression template evaluations.
Definition: TSMatSVecMultExpr.h:136
Constraint on the data type.
Constraint on the transpose flag of vector types.
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: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 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:155
#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: ColumnMajorMatrix.h:79
SelectType< evaluateVector, const VRT, VCT >::Type RT
Type for the assignment of the right-hand side sparse vector operand.
Definition: TSMatSVecMultExpr.h:151
const Element * ConstIterator
Iterator over constant elements.
Definition: CompressedMatrix.h:2592
const ResultType CompositeType
Data type for composite expression templates.
Definition: TSMatSVecMultExpr.h:139
Header file for the IsMatMatMultExpr type trait class.
#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
SelectType< IsExpression< MT >::value, const MT, const MT & >::Type LeftOperand
Composite type of the left-hand side sparse matrix expression.
Definition: TSMatSVecMultExpr.h:142
RightOperand vec_
Right-hand side sparse vector of the multiplication expression.
Definition: TSMatSVecMultExpr.h:304
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:132
#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:286
#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:102
size_t size() const
Returns the current size/dimension of the vector.
Definition: TSMatSVecMultExpr.h:232
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:135
Header file for the EnableIf class template.
Header file for the serial shim.
ReturnType at(size_t index) const
Checked access to the vector elements.
Definition: TSMatSVecMultExpr.h:219
Header file for the byte type.
ResultType::TransposeType TransposeType
Transpose type for expression template evaluations.
Definition: TSMatSVecMultExpr.h:134
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:145
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:303
MT::CompositeType MCT
Composite type of the left-hand side sparse matrix expression.
Definition: TSMatSVecMultExpr.h:103
TSMatSVecMultExpr(const MT &mat, const VT &vec)
Constructor for the TSMatSVecMultExpr class.
Definition: TSMatSVecMultExpr.h:166
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:242
Base template for the MultTrait class.
Definition: MultTrait.h:138
VT::CompositeType VCT
Composite type of the right-hand side sparse vector expression.
Definition: TSMatSVecMultExpr.h:104
Header file for the reset shim.
Header file for the isDefault shim.
Constraints on the storage order of matrix types.
Header file for the RemoveReference type trait.
RightOperand rightOperand() const
Returns the right-hand side sparse vector operand.
Definition: TSMatSVecMultExpr.h:262
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: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
BLAZE_ALWAYS_INLINE size_t columns(const Matrix< MT, SO > &matrix)
Returns the current number of columns of the matrix.
Definition: Matrix.h:324
Constraint on the data type.
Header file for exception macros.
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.