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 >
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 >
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 )
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 >
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 )
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 >
708 const ResultType tmp(
serial( rhs ) );
709 multAssign( ~lhs, tmp );
732 template<
typename VT1 >
745 if( x.nonZeros() == 0UL )
return;
781 template<
typename VT1 >
791 if( x.nonZeros() == 0UL )
return;
827 template<
typename VT1 >
837 if( x.nonZeros() == 0UL )
return;
873 template<
typename VT1 >
885 const ResultType tmp( rhs );
948 template<
typename T1
987 template<
typename T1
1000 return trans( ~mat ) * (~vec);
1020 template<
typename T1
1030 return (~mat).leftOperand() * ( (~mat).
rightOperand() * vec );
1046 template<
typename MT,
typename VT >
1047 struct Size< SMatSVecMultExpr<MT,VT> > :
public Rows<MT>
1063 template<
typename MT,
typename VT,
bool 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
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
Evaluation of the expression type type of a subvector operation.Via this type trait it is possible to...
Definition: SubvectorExprTrait.h:79
Header file for the Rows type trait.
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.
size_t nonZeros() const
Returns an estimation for the number of non-zero elements in the sparse vector.
Definition: SMatSVecMultExpr.h:219
ReturnType at(size_t index) const
Checked access to the vector elements.
Definition: SMatSVecMultExpr.h:196
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
typename DisableIf< Condition, T >::Type DisableIf_
Auxiliary type for the DisableIf class template.The DisableIf_ alias declaration provides a convenien...
Definition: DisableIf.h:223
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
typename MultTrait< T1, T2 >::Type MultTrait_
Auxiliary alias declaration for the MultTrait class template.The MultTrait_ alias declaration provide...
Definition: MultTrait.h:245
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 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:119
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.
typename MultExprTrait< T1, T2 >::Type MultExprTrait_
Auxiliary alias declaration for the MultExprTrait class template.The MultExprTrait_ alias declaration...
Definition: MultExprTrait.h:344
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:111
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
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
typename SubvectorExprTrait< VT, AF >::Type SubvectorExprTrait_
Auxiliary alias declaration for the SubvectorExprTrait type trait.The SubvectorExprTrait_ alias decla...
Definition: SubvectorExprTrait.h:133
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
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:336
bool canSMPAssign() const noexcept
Returns whether the expression can be used in SMP assignments.
Definition: SMatSVecMultExpr.h:273
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
DisableIf_< Or< IsComputation< MT >, IsTransExpr< MT >, IsDeclExpr< 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:128
#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.
LeftOperand leftOperand() const noexcept
Returns the left-hand side sparse matrix operand.
Definition: SMatSVecMultExpr.h:229
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
size_t size() const noexcept
Returns the current size/dimension of the vector.
Definition: SMatSVecMultExpr.h:209
Header file for the reset shim.
#define BLAZE_FUNCTION_TRACE
Function trace macro.This macro can be used to reliably trace function calls. In case function tracin...
Definition: FunctionTrace.h:93
Header file for the isDefault shim.
Constraint on the data type.
RightOperand rightOperand() const noexcept
Returns the right-hand side sparse vector operand.
Definition: SMatSVecMultExpr.h:239
bool canAlias(const T *alias) const noexcept
Returns whether the expression can alias with the given address alias.
Definition: SMatSVecMultExpr.h:251
const ResultType CompositeType
Data type for composite expression templates.
Definition: SMatSVecMultExpr.h:142
Header file for the RemoveReference type trait.
typename EnableIf< Condition, T >::Type EnableIf_
Auxiliary alias declaration for the EnableIf class template.The EnableIf_ alias declaration provides ...
Definition: EnableIf.h:223
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:733
Header file for the IsComputation type trait class.
Compile time evaluation of the size of a vector.The Size type trait evaluates the size of the given v...
Definition: Size.h:75
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:120
Compile time evaluation of the number of rows of a matrix.The Rows type trait evaluates the number of...
Definition: Rows.h:76
Header file for the SubvectorExprTrait class template.
Compile time check whether the given type is a matrix/matrix multiplication expression template...
Definition: IsMatMatMultExpr.h:73
Constraint on the data type.
bool isDefault(const DiagonalProxy< MT > &proxy)
Returns whether the represented element is in default state.
Definition: DiagonalProxy.h:573
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
const DMatDMatMultExpr< T1, T2, false, false, false, false > 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:7505
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 function trace functionality.