35 #ifndef _BLAZE_MATH_EXPRESSIONS_SMATSVECMULTEXPR_H_
36 #define _BLAZE_MATH_EXPRESSIONS_SMATSVECMULTEXPR_H_
98 class SMatSVecMultExpr :
public SparseVector< SMatSVecMultExpr<MT,VT>, false >
99 ,
private MatVecMultExpr
100 ,
private Computation
126 template<
typename T1 >
127 struct UseSMPAssign {
128 enum :
bool { value = ( evaluateMatrix || evaluateVector ) };
159 enum :
bool { smpAssignable = !evaluateMatrix && MT::smpAssignable &&
160 !evaluateVector && VT::smpAssignable };
196 inline ReturnType
at(
size_t index )
const {
197 if( index >=
mat_.rows() ) {
200 return (*
this)[index];
209 inline size_t size() const noexcept {
250 template<
typename T >
251 inline bool canAlias(
const T* alias )
const noexcept {
252 return (
mat_.isAliased( alias ) ||
vec_.isAliased( alias ) );
262 template<
typename T >
263 inline bool isAliased(
const T* alias )
const noexcept {
264 return (
mat_.isAliased( alias ) ||
vec_.isAliased( alias ) );
274 return (
size() > SMP_SMATSVECMULT_THRESHOLD );
296 template<
typename VT1 >
307 RT x(
serial( rhs.vec_ ) );
308 if( x.nonZeros() == 0UL )
return;
311 LT A(
serial( rhs.mat_ ) );
320 SMatSVecMultExpr::selectAssignKernel( ~lhs, A, x );
339 template<
typename VT1
342 static inline void selectAssignKernel( VT1& y,
const MT1& A,
const VT2& x )
347 const VectorIterator vend( x.end() );
349 for(
size_t i=0UL; i<y.size(); ++i )
351 const MatrixIterator mend ( A.end(i) );
352 MatrixIterator melem( A.begin(i) );
354 if( melem == mend )
continue;
356 VectorIterator velem( x.begin() );
359 if( melem->index() < velem->index() ) {
361 if( melem == mend )
break;
363 else if( velem->index() < melem->index() ) {
365 if( velem == vend )
break;
368 y[i] = melem->value() * velem->value();
375 if( melem != mend && velem != vend )
378 if( melem->index() < velem->index() ) {
380 if( melem == mend )
break;
382 else if( velem->index() < melem->index() ) {
384 if( velem == vend )
break;
387 y[i] += melem->value() * velem->value();
389 if( melem == mend )
break;
391 if( velem == vend )
break;
412 template<
typename VT1 >
413 friend inline void assign( SparseVector<VT1,false>& lhs,
const SMatSVecMultExpr& rhs )
419 typedef ConstIterator_< RemoveReference_<LT> > MatrixIterator;
420 typedef ConstIterator_< RemoveReference_<RT> > VectorIterator;
423 if( x.nonZeros() == 0UL )
return;
433 const VectorIterator vend( x.end() );
435 for(
size_t i=0UL; i<(~lhs).
size(); ++i )
437 const MatrixIterator mend ( A.end(i) );
438 MatrixIterator melem( A.begin(i) );
440 if( melem == mend )
continue;
442 VectorIterator velem( x.begin() );
447 if( melem->index() < velem->index() ) {
449 if( melem == mend )
break;
451 else if( velem->index() < melem->index() ) {
453 if( velem == vend )
break;
456 accu = melem->value() * velem->value();
463 if( melem != mend && velem != vend )
466 if( melem->index() < velem->index() ) {
468 if( melem == mend )
break;
470 else if( velem->index() < melem->index() ) {
472 if( velem == vend )
break;
475 accu += melem->value() * velem->value();
477 if( melem == mend )
break;
479 if( velem == vend )
break;
485 (~lhs).insert( i, accu );
503 template<
typename VT1 >
504 friend inline void addAssign( DenseVector<VT1,false>& lhs,
const SMatSVecMultExpr& rhs )
511 RT x(
serial( rhs.vec_ ) );
512 if( x.nonZeros() == 0UL )
return;
515 LT A(
serial( rhs.mat_ ) );
524 SMatSVecMultExpr::selectAddAssignKernel( ~lhs, A, x );
543 template<
typename VT1
546 static inline void selectAddAssignKernel( VT1& y,
const MT1& A,
const VT2& x )
548 typedef ConstIterator_< RemoveReference_<LT> > MatrixIterator;
549 typedef ConstIterator_< RemoveReference_<RT> > VectorIterator;
551 const VectorIterator vend( x.end() );
553 for(
size_t i=0UL; i<y.size(); ++i )
555 const MatrixIterator mend ( A.end(i) );
556 MatrixIterator melem( A.begin(i) );
558 if( melem == mend )
continue;
560 VectorIterator velem( x.begin() );
563 if( melem->index() < velem->index() ) {
565 if( melem == mend )
break;
567 else if( velem->index() < melem->index() ) {
569 if( velem == vend )
break;
572 y[i] += melem->value() * velem->value();
574 if( melem == mend )
break;
576 if( velem == vend )
break;
600 template<
typename VT1 >
601 friend inline void subAssign( DenseVector<VT1,false>& lhs,
const SMatSVecMultExpr& rhs )
608 RT x(
serial( rhs.vec_ ) );
609 if( x.nonZeros() == 0UL )
return;
612 LT A(
serial( rhs.mat_ ) );
621 SMatSVecMultExpr::selectSubAssignKernel( ~lhs, A, x );
640 template<
typename VT1
643 static inline void selectSubAssignKernel( VT1& y,
const MT1& A,
const VT2& x )
645 typedef ConstIterator_< RemoveReference_<LT> > MatrixIterator;
646 typedef ConstIterator_< RemoveReference_<RT> > VectorIterator;
648 const VectorIterator vend( x.end() );
650 for(
size_t i=0UL; i<y.size(); ++i )
652 const MatrixIterator mend ( A.end(i) );
653 MatrixIterator melem( A.begin(i) );
655 if( melem == mend )
continue;
657 VectorIterator velem( x.begin() );
660 if( melem->index() < velem->index() ) {
662 if( melem == mend )
break;
664 else if( velem->index() < melem->index() ) {
666 if( velem == vend )
break;
669 y[i] -= melem->value() * velem->value();
671 if( melem == mend )
break;
673 if( velem == vend )
break;
697 template<
typename VT1 >
698 friend inline void multAssign( DenseVector<VT1,false>& lhs,
const SMatSVecMultExpr& rhs )
708 const ResultType tmp(
serial( rhs ) );
709 multAssign( ~lhs, tmp );
732 template<
typename VT1 >
733 friend inline EnableIf_< UseSMPAssign<VT1> >
745 if( x.nonZeros() == 0UL )
return;
781 template<
typename VT1 >
782 friend inline EnableIf_< UseSMPAssign<VT1> >
791 if( x.nonZeros() == 0UL )
return;
827 template<
typename VT1 >
828 friend inline EnableIf_< UseSMPAssign<VT1> >
837 if( x.nonZeros() == 0UL )
return;
873 template<
typename VT1 >
874 friend inline EnableIf_< UseSMPAssign<VT1> >
885 const ResultType tmp( rhs );
948 template<
typename T1
950 inline const DisableIf_< Or< IsSymmetric<T1>, IsMatMatMultExpr<T1> >, SMatSVecMultExpr<T1,T2> >
987 template<
typename T1
989 inline const EnableIf_< IsSymmetric<T1>, MultExprTrait_<T1,T2> >
990 operator*(
const SparseMatrix<T1,false>& mat,
const SparseVector<T2,false>& vec )
1000 return trans( ~mat ) * (~vec);
1020 template<
typename T1
1023 inline const EnableIf_< IsMatMatMultExpr<T1>, MultExprTrait_<T1,T2> >
1024 operator*(
const SparseMatrix<T1,SO>& mat,
const SparseVector<T2,false>& vec )
1030 return (~mat).leftOperand() * ( (~mat).
rightOperand() * vec );
1046 template<
typename MT,
typename VT >
1063 template<
typename MT,
typename VT,
bool AF >
1068 using Type = MultExprTrait_< SubmatrixExprTrait_<const MT,AF>
1069 , SubvectorExprTrait_<const VT,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
ReturnType at(size_t index) const
Checked access to the vector elements.
Definition: SMatSVecMultExpr.h:196
Header file for auxiliary alias declarations.
Compile time check whether the given type is a computational expression template.This type trait clas...
Definition: IsComputation.h:72
CompositeType_< VT > VCT
Composite type of the right-hand side sparse vector expression.
Definition: SMatSVecMultExpr.h:107
IfTrue_< evaluateVector, const VRT, VCT > RT
Type for the assignment of the right-hand side sparse vector operand.
Definition: SMatSVecMultExpr.h:154
LeftOperand mat_
Left-hand side sparse matrix of the multiplication expression.
Definition: SMatSVecMultExpr.h:280
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:7800
Header file for basic type definitions.
Header file for the SparseVector base class.
CompositeType_< MT > MCT
Composite type of the left-hand side sparse matrix expression.
Definition: SMatSVecMultExpr.h:106
#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:61
EnableIf_< IsDenseMatrix< MT1 > > 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
const ElementType ReturnType
Return type for expression template evaluations.
Definition: SMatSVecMultExpr.h:139
Header file for the serial shim.
void reset(const DiagonalProxy< MT > &proxy)
Resetting the represented element to the default initial values.
Definition: DiagonalProxy.h:533
EnableIf_< IsDenseVector< VT1 > > 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:193
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
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.
Constraints on the storage order of matrix types.
Header file for the RequiresEvaluation type trait.
typename T::ResultType ResultType_
Alias declaration for nested ResultType type definitions.The ResultType_ alias declaration provides a...
Definition: Aliases.h:323
EnableIf_< IsDenseMatrix< MT1 > > 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 matrices.The SparseMatrix class is a base class for all sparse matrix classes...
Definition: Forward.h:109
bool isDefault(const DiagonalProxy< MT > &proxy)
Returns whether the represented element is in default state.
Definition: DiagonalProxy.h:573
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
Constraint on the transpose flag of vector types.
Constraint on the data type.
size_t nonZeros() const
Returns an estimation for the number of non-zero elements in the sparse vector.
Definition: SMatSVecMultExpr.h:219
Header file for the MultExprTrait class template.
Compile time check to query the requirement to evaluate an expression.Via this type trait it is possi...
Definition: RequiresEvaluation.h:72
typename T::CompositeType CompositeType_
Alias declaration for nested CompositeType type definitions.The CompositeType_ alias declaration prov...
Definition: Aliases.h:83
Header file for the DisableIf class template.
Header file for the multiplication trait.
Header file for the IsSymmetric type trait.
Namespace of the Blaze C++ math library.
Definition: Blaze.h:57
Expression object for sparse matrix-sparse vector multiplications.The SMatSVecMultExpr class represen...
Definition: Forward.h:101
Header file for the If class template.
EnableIf_< IsDenseMatrix< MT1 > > 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
ElementType_< ResultType > ElementType
Resulting element type.
Definition: SMatSVecMultExpr.h:138
bool isAliased(const T *alias) const noexcept
Returns whether the expression is aliased with the given address alias.
Definition: SMatSVecMultExpr.h:263
Header file for the Or class template.
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 exception.This macro encapsulates the default way of Bl...
Definition: Exception.h:331
IfTrue_< evaluateMatrix, const MRT, MCT > LT
Type for the assignment of the left-hand side sparse matrix operand.
Definition: SMatSVecMultExpr.h:151
LeftOperand leftOperand() const noexcept
Returns the left-hand side sparse matrix operand.
Definition: SMatSVecMultExpr.h:229
typename T::ElementType ElementType_
Alias declaration for nested ElementType type definitions.The ElementType_ alias declaration provides...
Definition: Aliases.h:163
ResultType_< VT > VRT
Result type of the right-hand side sparse vector expression.
Definition: SMatSVecMultExpr.h:105
RightOperand rightOperand() const noexcept
Returns the right-hand side sparse vector operand.
Definition: SMatSVecMultExpr.h:239
Base class for N-dimensional dense vectors.The DenseVector class is a base class for all arbitrarily ...
Definition: DenseVector.h:70
TransposeType_< ResultType > TransposeType
Transpose type for expression template evaluations.
Definition: SMatSVecMultExpr.h:137
#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
BLAZE_ALWAYS_INLINE size_t columns(const Matrix< MT, SO > &matrix) noexcept
Returns the current number of columns of the matrix.
Definition: Matrix.h:330
ReturnType operator[](size_t index) const
Subscript operator for the direct access to the vector elements.
Definition: SMatSVecMultExpr.h:183
#define BLAZE_CONSTRAINT_MUST_NOT_BE_MATMATMULTEXPR_TYPE(T)
Constraint on the data type.In case the given data type T is a matrix/matrix multiplication expressio...
Definition: MatMatMultExpr.h:89
#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:60
#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:110
Header file for the exception macros of the math module.
Header file for all forward declarations for expression class templates.
Constraint on the data type.
SMatSVecMultExpr< MT, VT > This
Type of this SMatSVecMultExpr instance.
Definition: SMatSVecMultExpr.h:135
If_< IsExpression< VT >, const VT, const VT & > RightOperand
Composite type of the right-hand side sparse vector expression.
Definition: SMatSVecMultExpr.h:148
Header file for the EnableIf class template.
DisableIf_< Or< IsComputation< MT >, IsTransExpr< MT > >, RowExprTrait_< MT > > row(Matrix< MT, SO > &matrix, size_t index)
Creating a view on a specific row of the given matrix.
Definition: Row.h:126
RightOperand vec_
Right-hand side sparse vector of the multiplication expression.
Definition: SMatSVecMultExpr.h:281
#define BLAZE_CONSTRAINT_MUST_NOT_BE_SYMMETRIC_MATRIX_TYPE(T)
Constraint on the data type.In case the given data type T is a symmetric matrix type, a compilation error is created.
Definition: Symmetric.h:79
#define BLAZE_CONSTRAINT_MUST_BE_ROW_MAJOR_MATRIX_TYPE(T)
Constraint on the data type.In case the given data type T is not a row-major dense or sparse matrix t...
Definition: RowMajorMatrix.h:61
Header file for run time assertion macros.
ResultType_< MT > MRT
Result type of the left-hand side sparse matrix expression.
Definition: SMatSVecMultExpr.h:104
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.
Header file for the isDefault shim.
Constraint on the data type.
bool canSMPAssign() const noexcept
Returns whether the expression can be used in SMP assignments.
Definition: SMatSVecMultExpr.h:273
const ResultType CompositeType
Data type for composite expression templates.
Definition: SMatSVecMultExpr.h:142
Header file for the RemoveReference type trait.
bool canAlias(const T *alias) const noexcept
Returns whether the expression can alias with the given address alias.
Definition: SMatSVecMultExpr.h:251
typename T::ConstIterator ConstIterator_
Alias declaration for nested ConstIterator type definitions.The ConstIterator_ alias declaration prov...
Definition: Aliases.h:103
const DMatTransExpr< MT,!SO > trans(const DenseMatrix< MT, SO > &dm)
Calculation of the transpose of the given dense matrix.
Definition: DMatTransExpr.h:950
Header file for the IsComputation type trait class.
If_< IsExpression< MT >, const MT, const MT & > LeftOperand
Composite type of the left-hand side sparse matrix expression.
Definition: SMatSVecMultExpr.h:145
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.
Constraint on the data type.
typename T::TransposeType TransposeType_
Alias declaration for nested TransposeType type definitions.The TransposeType_ alias declaration prov...
Definition: Aliases.h:403
SMatSVecMultExpr(const MT &mat, const VT &vec) noexcept
Constructor for the SMatSVecMultExpr class.
Definition: SMatSVecMultExpr.h:169
Header file for the MatVecMultExpr base class.
Constraint on the data type.
MultTrait_< MRT, VRT > ResultType
Result type for expression template evaluations.
Definition: SMatSVecMultExpr.h:136
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:61
Header file for the IsExpression type trait class.
Header file for the FunctionTrace class.
size_t size() const noexcept
Returns the current size/dimension of the vector.
Definition: SMatSVecMultExpr.h:209