35#ifndef _BLAZE_MATH_EXPRESSIONS_SMATSVECMULTEXPR_H_
36#define _BLAZE_MATH_EXPRESSIONS_SMATSVECMULTEXPR_H_
97 :
public MatVecMultExpr< SparseVector< SMatSVecMultExpr<MT,VT>, false > >
115 static constexpr bool evaluateVector = ( RequiresEvaluation_v<VT> || IsComputation_v<VT> );
124 template<
typename T1 >
198 if( index >=
mat_.rows() ) {
201 return (*
this)[index];
210 inline size_t size() const noexcept {
251 template<
typename T >
252 inline bool canAlias(
const T* alias )
const noexcept {
253 return (
mat_.isAliased( alias ) ||
vec_.isAliased( alias ) );
263 template<
typename T >
264 inline bool isAliased(
const T* alias )
const noexcept {
265 return (
mat_.isAliased( alias ) ||
vec_.isAliased( alias ) );
275 return (
size() > SMP_SMATSVECMULT_THRESHOLD );
297 template<
typename VT1 >
309 if( x.nonZeros() == 0UL )
return;
321 SMatSVecMultExpr::selectAssignKernel( *lhs, A, x );
340 template<
typename VT1
343 static inline void selectAssignKernel( VT1& y,
const MT1& A,
const VT2& x )
345 const auto vend( x.end() );
347 for(
size_t i=0UL; i<y.size(); ++i )
349 const auto mend ( A.end(i) );
350 auto melem( A.begin(i) );
352 if( melem == mend )
continue;
354 auto velem( x.begin() );
357 if( melem->index() < velem->index() ) {
359 if( melem == mend )
break;
361 else if( velem->index() < melem->index() ) {
363 if( velem == vend )
break;
366 y[i] = melem->value() * velem->value();
373 if( melem != mend && velem != vend )
376 if( melem->index() < velem->index() ) {
378 if( melem == mend )
break;
380 else if( velem->index() < melem->index() ) {
382 if( velem == vend )
break;
385 y[i] += melem->value() * velem->value();
387 if( melem == mend )
break;
389 if( velem == vend )
break;
410 template<
typename VT1 >
411 friend inline void assign( SparseVector<VT1,false>& lhs,
const SMatSVecMultExpr& rhs )
418 if( x.nonZeros() == 0UL )
return;
428 const auto vend( x.end() );
430 for(
size_t i=0UL; i<(*lhs).size(); ++i )
432 const auto mend ( A.end(i) );
433 auto melem( A.begin(i) );
435 if( melem == mend )
continue;
437 auto velem( x.begin() );
442 if( melem->index() < velem->index() ) {
444 if( melem == mend )
break;
446 else if( velem->index() < melem->index() ) {
448 if( velem == vend )
break;
451 accu = melem->value() * velem->value();
458 if( melem != mend && velem != vend )
461 if( melem->index() < velem->index() ) {
463 if( melem == mend )
break;
465 else if( velem->index() < melem->index() ) {
467 if( velem == vend )
break;
470 accu += melem->value() * velem->value();
472 if( melem == mend )
break;
474 if( velem == vend )
break;
480 (*lhs).insert( i, accu );
498 template<
typename VT1 >
499 friend inline void addAssign( DenseVector<VT1,false>& lhs,
const SMatSVecMultExpr& rhs )
507 if( x.nonZeros() == 0UL )
return;
519 SMatSVecMultExpr::selectAddAssignKernel( *lhs, A, x );
538 template<
typename VT1
541 static inline void selectAddAssignKernel( VT1& y,
const MT1& A,
const VT2& x )
543 const auto vend( x.end() );
545 for(
size_t i=0UL; i<y.size(); ++i )
547 const auto mend ( A.end(i) );
548 auto melem( A.begin(i) );
550 if( melem == mend )
continue;
552 auto velem( x.begin() );
555 if( melem->index() < velem->index() ) {
557 if( melem == mend )
break;
559 else if( velem->index() < melem->index() ) {
561 if( velem == vend )
break;
564 y[i] += melem->value() * velem->value();
566 if( melem == mend )
break;
568 if( velem == vend )
break;
592 template<
typename VT1 >
593 friend inline void subAssign( DenseVector<VT1,false>& lhs,
const SMatSVecMultExpr& rhs )
601 if( x.nonZeros() == 0UL )
return;
613 SMatSVecMultExpr::selectSubAssignKernel( *lhs, A, x );
632 template<
typename VT1
635 static inline void selectSubAssignKernel( VT1& y,
const MT1& A,
const VT2& x )
637 const auto vend( x.end() );
639 for(
size_t i=0UL; i<y.size(); ++i )
641 const auto mend ( A.end(i) );
642 auto melem( A.begin(i) );
644 if( melem == mend )
continue;
646 auto velem( x.begin() );
649 if( melem->index() < velem->index() ) {
651 if( melem == mend )
break;
653 else if( velem->index() < melem->index() ) {
655 if( velem == vend )
break;
658 y[i] -= melem->value() * velem->value();
660 if( melem == mend )
break;
662 if( velem == vend )
break;
686 template<
typename VT1 >
687 friend inline void multAssign( DenseVector<VT1,false>& lhs,
const SMatSVecMultExpr& rhs )
698 multAssign( *lhs, tmp );
721 template<
typename VT1 >
723 -> EnableIf_t< UseSMPAssign_v<VT1> >
734 if( x.nonZeros() == 0UL )
return;
770 template<
typename VT1 >
772 -> EnableIf_t< UseSMPAssign_v<VT1> >
780 if( x.nonZeros() == 0UL )
return;
816 template<
typename VT1 >
818 -> EnableIf_t< UseSMPAssign_v<VT1> >
826 if( x.nonZeros() == 0UL )
return;
862 template<
typename VT1 >
864 -> EnableIf_t< UseSMPAssign_v<VT1> >
923 , DisableIf_t< IsSymmetric_v<MT> ||
924 ( IsIdentity_v<MT> &&
925 IsSame_v< ElementType_t<MT>, ElementType_t<VT> > ) ||
926 ( IsZero_v<MT> || IsZero_v<VT> ) >* =
nullptr >
927inline const SMatSVecMultExpr<MT,VT>
928 smatsvecmult(
const SparseMatrix<MT,false>& mat,
const SparseVector<VT,false>& vec )
934 return SMatSVecMultExpr<MT,VT>( *mat, *vec );
956 , EnableIf_t< IsSymmetric_v<MT> &&
957 !( IsIdentity_v<MT> &&
958 IsSame_v< ElementType_t<MT>, ElementType_t<VT> > ) &&
959 !( IsZero_v<MT> || IsZero_v<VT> ) >* =
nullptr >
961 smatsvecmult(
const SparseMatrix<MT,false>& mat,
const SparseVector<VT,false>& vec )
967 return trans( *mat ) * (*vec);
990 IsSame_v< ElementType_t<MT>, ElementType_t<VT> > ) &&
991 !IsZero_v<VT> >* =
nullptr >
993 smatsvecmult(
const SparseMatrix<MT,false>& mat,
const SparseVector<VT,false>& vec )
1020template<
typename MT
1022 , EnableIf_t< IsZero_v<MT> || IsZero_v<VT> >* =
nullptr >
1023inline decltype(
auto)
1024 smatsvecmult(
const SparseMatrix<MT,false>& mat,
const SparseVector<VT,false>& vec )
1032 using ReturnType =
const MultTrait_t< ResultType_t<MT>, ResultType_t<VT> >;
1037 return ReturnType( (*mat).rows() );
1074template<
typename MT
1076inline decltype(
auto)
1083 if( (*mat).columns() != (*vec).size() ) {
1087 return smatsvecmult( *mat, *vec );
Header file for auxiliary alias declarations.
typename T::CompositeType CompositeType_t
Alias declaration for nested CompositeType type definitions.
Definition: Aliases.h:110
typename T::ResultType ResultType_t
Alias declaration for nested ResultType type definitions.
Definition: Aliases.h:450
typename T::ElementType ElementType_t
Alias declaration for nested ElementType type definitions.
Definition: Aliases.h:190
typename T::TransposeType TransposeType_t
Alias declaration for nested TransposeType type definitions.
Definition: Aliases.h:550
Header file for run time assertion macros.
Header file for the blaze::checked and blaze::unchecked instances.
Constraint on the transpose flag of vector types.
Header file for the EnableIf class template.
Header file for the function trace functionality.
Header file for the If class template.
Header file for the IsComputation type trait class.
Header file for the isDefault shim.
Header file for the IsExpression type trait class.
Header file for the IsIdentity type trait.
Header file for the IsSymmetric type trait.
Deactivation of problematic macros.
Header file for the MAYBE_UNUSED function template.
Header file for the multiplication trait.
Constraints on the storage order of matrix types.
Constraint on the data type.
Constraint on the data type.
Base class for N-dimensional dense vectors.
Definition: DenseVector.h:77
Expression object for sparse matrix-sparse vector multiplications.
Definition: SMatSVecMultExpr.h:99
If_t< evaluateVector, const VRT, VCT > RT
Type for the assignment of the right-hand side sparse vector operand.
Definition: SMatSVecMultExpr.h:155
CompositeType_t< VT > VCT
Composite type of the right-hand side sparse vector expression.
Definition: SMatSVecMultExpr.h:105
bool canSMPAssign() const noexcept
Returns whether the expression can be used in SMP assignments.
Definition: SMatSVecMultExpr.h:274
ReturnType operator[](size_t index) const
Subscript operator for the direct access to the vector elements.
Definition: SMatSVecMultExpr.h:184
LeftOperand mat_
Left-hand side sparse matrix of the multiplication expression.
Definition: SMatSVecMultExpr.h:281
bool canAlias(const T *alias) const noexcept
Returns whether the expression can alias with the given address alias.
Definition: SMatSVecMultExpr.h:252
size_t nonZeros() const
Returns an estimation for the number of non-zero elements in the sparse vector.
Definition: SMatSVecMultExpr.h:220
TransposeType_t< ResultType > TransposeType
Transpose type for expression template evaluations.
Definition: SMatSVecMultExpr.h:138
const ElementType ReturnType
Return type for expression template evaluations.
Definition: SMatSVecMultExpr.h:140
bool isAliased(const T *alias) const noexcept
Returns whether the expression is aliased with the given address alias.
Definition: SMatSVecMultExpr.h:264
If_t< IsExpression_v< MT >, const MT, const MT & > LeftOperand
Composite type of the left-hand side sparse matrix expression.
Definition: SMatSVecMultExpr.h:146
MultTrait_t< MRT, VRT > ResultType
Result type for expression template evaluations.
Definition: SMatSVecMultExpr.h:137
const ResultType CompositeType
Data type for composite expression templates.
Definition: SMatSVecMultExpr.h:143
ElementType_t< ResultType > ElementType
Resulting element type.
Definition: SMatSVecMultExpr.h:139
size_t size() const noexcept
Returns the current size/dimension of the vector.
Definition: SMatSVecMultExpr.h:210
static constexpr bool evaluateMatrix
Compilation switch for the composite type of the left-hand side sparse matrix expression.
Definition: SMatSVecMultExpr.h:110
RightOperand vec_
Right-hand side sparse vector of the multiplication expression.
Definition: SMatSVecMultExpr.h:282
ReturnType at(size_t index) const
Checked access to the vector elements.
Definition: SMatSVecMultExpr.h:197
LeftOperand leftOperand() const noexcept
Returns the left-hand side sparse matrix operand.
Definition: SMatSVecMultExpr.h:230
CompositeType_t< MT > MCT
Composite type of the left-hand side sparse matrix expression.
Definition: SMatSVecMultExpr.h:104
SMatSVecMultExpr(const MT &mat, const VT &vec) noexcept
Constructor for the SMatSVecMultExpr class.
Definition: SMatSVecMultExpr.h:170
ResultType_t< MT > MRT
Result type of the left-hand side sparse matrix expression.
Definition: SMatSVecMultExpr.h:102
static constexpr bool evaluateVector
Compilation switch for the composite type of the right-hand side sparse vector expression.
Definition: SMatSVecMultExpr.h:115
If_t< IsExpression_v< VT >, const VT, const VT & > RightOperand
Composite type of the right-hand side sparse vector expression.
Definition: SMatSVecMultExpr.h:149
ResultType_t< VT > VRT
Result type of the right-hand side sparse vector expression.
Definition: SMatSVecMultExpr.h:103
static constexpr bool smpAssignable
Compilation switch for the expression template assignment strategy.
Definition: SMatSVecMultExpr.h:160
If_t< evaluateMatrix, const MRT, MCT > LT
Type for the assignment of the left-hand side sparse matrix operand.
Definition: SMatSVecMultExpr.h:152
RightOperand rightOperand() const noexcept
Returns the right-hand side sparse vector operand.
Definition: SMatSVecMultExpr.h:240
Base class for sparse matrices.
Definition: SparseMatrix.h:77
Base class for sparse vectors.
Definition: SparseVector.h:72
Constraint on the data type.
Constraint on the data type.
Constraint on the data type.
Constraint on the data type.
Constraint on the data type.
Header file for the Computation base class.
Header file for the MatVecMultExpr base class.
Header file for the SparseVector base class.
decltype(auto) trans(const DenseMatrix< MT, SO > &dm)
Calculation of the transpose of the given dense matrix.
Definition: DMatTransExpr.h:766
decltype(auto) serial(const DenseMatrix< MT, SO > &dm)
Forces the serial evaluation of the given dense matrix expression dm.
Definition: DMatSerialExpr.h:812
bool isDefault(const DiagonalMatrix< MT, SO, DF > &m)
Returns whether the given diagonal matrix is in default state.
Definition: DiagonalMatrix.h:169
#define BLAZE_CONSTRAINT_MUST_NOT_BE_SYMMETRIC_MATRIX_TYPE(T)
Constraint on the data type.
Definition: Symmetric.h:79
#define BLAZE_CONSTRAINT_MUST_BE_ROW_MAJOR_MATRIX_TYPE(T)
Constraint on the data type.
Definition: RowMajorMatrix.h:61
#define BLAZE_CONSTRAINT_MUST_NOT_REQUIRE_EVALUATION(T)
Constraint on the data type.
Definition: RequiresEvaluation.h:81
#define BLAZE_CONSTRAINT_MUST_NOT_BE_MATMATMULTEXPR_TYPE(T)
Constraint on the data type.
Definition: MatMatMultExpr.h:83
#define BLAZE_CONSTRAINT_MUST_NOT_BE_ZERO_TYPE(T)
Constraint on the data type.
Definition: Zero.h:81
#define BLAZE_CONSTRAINT_MUST_FORM_VALID_MATVECMULTEXPR(T1, T2)
Constraint on the data type.
Definition: MatVecMultExpr.h:104
#define BLAZE_CONSTRAINT_MUST_BE_SPARSE_VECTOR_TYPE(T)
Constraint on the data type.
Definition: SparseVector.h:61
#define BLAZE_CONSTRAINT_MUST_BE_SPARSE_MATRIX_TYPE(T)
Constraint on the data type.
Definition: SparseMatrix.h:61
#define BLAZE_CONSTRAINT_MUST_BE_COLUMN_VECTOR_TYPE(T)
Constraint on the data type.
Definition: ColumnVector.h:61
#define BLAZE_CONSTRAINT_MUST_BE_ZERO_TYPE(T)
Constraint on the data type.
Definition: Zero.h:61
typename MultTrait< T1, T2 >::Type MultTrait_t
Auxiliary alias declaration for the MultTrait class template.
Definition: MultTrait.h:165
constexpr void reset(Matrix< MT, SO > &matrix)
Resetting the given matrix.
Definition: Matrix.h:806
decltype(auto) row(Matrix< MT, SO > &, RRAs...)
Creating a view on a specific row of the given matrix.
Definition: Row.h:137
#define BLAZE_INTERNAL_ASSERT(expr, msg)
Run time assertion macro for internal checks.
Definition: Assert.h:101
auto smpSubAssign(Matrix< MT1, SO1 > &lhs, const Matrix< MT2, SO2 > &rhs) -> EnableIf_t< IsDenseMatrix_v< MT1 > >
Default implementation of the SMP subtraction assignment of a matrix to dense matrix.
Definition: DenseMatrix.h:162
auto smpAssign(Matrix< MT1, SO1 > &lhs, const Matrix< MT2, SO2 > &rhs) -> EnableIf_t< IsDenseMatrix_v< MT1 > >
Default implementation of the SMP assignment of a matrix to a dense matrix.
Definition: DenseMatrix.h:100
auto smpMultAssign(Vector< VT1, TF1 > &lhs, const Vector< VT2, TF2 > &rhs) -> EnableIf_t< IsDenseVector_v< VT1 > >
Default implementation of the SMP multiplication assignment of a vector to a dense vector.
Definition: DenseVector.h:192
auto smpAddAssign(Matrix< MT1, SO1 > &lhs, const Matrix< MT2, SO2 > &rhs) -> EnableIf_t< IsDenseMatrix_v< MT1 > >
Default implementation of the SMP addition assignment of a matrix to a dense matrix.
Definition: DenseMatrix.h:131
typename EnableIf< Condition, T >::Type EnableIf_t
Auxiliary type for the EnableIf class template.
Definition: EnableIf.h:138
constexpr void MAYBE_UNUSED(const Args &...)
Suppression of unused parameter warnings.
Definition: MaybeUnused.h:81
typename If< Condition >::template Type< T1, T2 > If_t
Auxiliary alias template for the If class template.
Definition: If.h:108
#define BLAZE_THROW_OUT_OF_RANGE(MESSAGE)
Macro for the emission of a std::out_of_range exception.
Definition: Exception.h:331
#define BLAZE_THROW_INVALID_ARGUMENT(MESSAGE)
Macro for the emission of a std::invalid_argument exception.
Definition: Exception.h:235
#define BLAZE_FUNCTION_TRACE
Function trace macro.
Definition: FunctionTrace.h:94
constexpr Unchecked unchecked
Global Unchecked instance.
Definition: Check.h:146
Header file for the exception macros of the math module.
Header file for all forward declarations for expression class templates.
Header file for the reset shim.
Header file for the serial shim.
Base class for all compute expression templates.
Definition: Computation.h:68
Base class for all matrix/vector multiplication expression templates.
Definition: MatVecMultExpr.h:69
Header file for the thresholds for matrix/vector and matrix/matrix multiplications.
Header file for the IsZero type trait.
Header file for the RequiresEvaluation type trait.
Header file for basic type definitions.