35#ifndef _BLAZE_MATH_EXPRESSIONS_TSVECTSMATMULTEXPR_H_
36#define _BLAZE_MATH_EXPRESSIONS_TSVECTSMATMULTEXPR_H_
97 :
public TVecMatMultExpr< SparseVector< TSVecTSMatMultExpr<VT,MT>, true > >
124 template<
typename T1 >
196 if( index >=
mat_.columns() ) {
199 return (*
this)[index];
208 inline size_t size() const noexcept {
209 return mat_.columns();
219 return mat_.columns();
249 template<
typename T >
250 inline bool canAlias(
const T* alias )
const noexcept {
251 return (
vec_.isAliased( alias ) ||
mat_.isAliased( alias ) );
261 template<
typename T >
262 inline bool isAliased(
const T* alias )
const noexcept {
263 return (
vec_.isAliased( alias ) ||
mat_.isAliased( alias ) );
273 return (
size() > SMP_TSVECSMATMULT_THRESHOLD );
296 template<
typename VT1 >
308 if( x.nonZeros() == 0UL )
return;
320 TSVecTSMatMultExpr::selectAssignKernel( *lhs, x, A );
339 template<
typename VT1
342 static inline void selectAssignKernel( VT1& y,
const VT2& x,
const MT1& A )
344 const auto vend( x.end() );
346 for(
size_t j=0UL; j<A.columns(); ++j )
348 const auto mend ( A.end(j) );
349 auto melem( A.begin(j) );
351 if( melem == mend )
continue;
353 auto velem( x.begin() );
356 if( velem->index() < melem->index() ) {
358 if( velem == vend )
break;
360 else if( melem->index() < velem->index() ) {
362 if( melem == mend )
break;
365 y[j] = velem->value() * melem->value();
372 if( velem != vend && melem != mend )
375 if( velem->index() < melem->index() ) {
377 if( velem == vend )
break;
379 else if( melem->index() < velem->index() ) {
381 if( melem == mend )
break;
384 y[j] += velem->value() * melem->value();
386 if( velem == vend )
break;
388 if( melem == mend )
break;
410 template<
typename VT1 >
411 friend inline void assign( SparseVector<VT1,true>& lhs,
const TSVecTSMatMultExpr& rhs )
419 if( x.nonZeros() == 0UL )
return;
432 const auto vend( x.end() );
434 for(
size_t j=0UL; j<A.columns(); ++j )
436 const auto mend ( A.end(j) );
437 auto melem( A.begin(j) );
439 if( melem == mend )
continue;
441 auto velem( x.begin() );
446 if( velem->index() < melem->index() ) {
448 if( velem == vend )
break;
450 else if( melem->index() < velem->index() ) {
452 if( melem == mend )
break;
455 accu = velem->value() * melem->value();
462 if( velem != vend && melem != mend )
465 if( velem->index() < melem->index() ) {
467 if( velem == vend )
break;
469 else if( melem->index() < velem->index() ) {
471 if( melem == mend )
break;
474 accu += velem->value() * melem->value();
476 if( velem == vend )
break;
478 if( melem == mend )
break;
484 (*lhs).insert( j, accu );
503 template<
typename VT1 >
504 friend inline void addAssign( DenseVector<VT1,true>& lhs,
const TSVecTSMatMultExpr& rhs )
512 if( x.nonZeros() == 0UL )
return;
524 TSVecTSMatMultExpr::selectAddAssignKernel( *lhs, x, A );
543 template<
typename VT1
546 static inline void selectAddAssignKernel( VT1& y,
const VT2& x,
const MT1& A )
548 const auto vend( x.end() );
550 for(
size_t j=0UL; j<A.columns(); ++j )
552 const auto mend ( A.end(j) );
553 auto melem( A.begin(j) );
555 if( melem == mend )
continue;
557 auto velem( x.begin() );
560 if( velem->index() < melem->index() ) {
562 if( velem == vend )
break;
564 else if( melem->index() < velem->index() ) {
566 if( melem == mend )
break;
569 y[j] += velem->value() * melem->value();
571 if( velem == vend )
break;
573 if( melem == mend )
break;
598 template<
typename VT1 >
599 friend inline void subAssign( DenseVector<VT1,true>& lhs,
const TSVecTSMatMultExpr& rhs )
607 if( x.nonZeros() == 0UL )
return;
619 TSVecTSMatMultExpr::selectSubAssignKernel( *lhs, x, A );
638 template<
typename VT1
641 static inline void selectSubAssignKernel( VT1& y,
const VT2& x,
const MT1& A )
643 const auto vend( x.end() );
645 for(
size_t j=0UL; j<A.columns(); ++j )
647 const auto mend ( A.end(j) );
648 auto melem( A.begin(j) );
650 if( melem == mend )
continue;
652 auto velem( x.begin() );
655 if( velem->index() < melem->index() ) {
657 if( velem == vend )
break;
659 else if( melem->index() < velem->index() ) {
661 if( melem == mend )
break;
664 y[j] -= velem->value() * melem->value();
666 if( velem == vend )
break;
668 if( melem == mend )
break;
693 template<
typename VT1 >
694 friend inline void multAssign( DenseVector<VT1,true>& lhs,
const TSVecTSMatMultExpr& rhs )
705 multAssign( *lhs, tmp );
729 template<
typename VT1 >
731 -> EnableIf_t< UseSMPAssign_v<VT1> >
742 if( x.nonZeros() == 0UL )
return;
778 template<
typename VT1 >
780 -> EnableIf_t< UseSMPAssign_v<VT1> >
788 if( x.nonZeros() == 0UL )
return;
824 template<
typename VT1 >
826 -> EnableIf_t< UseSMPAssign_v<VT1> >
834 if( x.nonZeros() == 0UL )
return;
870 template<
typename VT1 >
872 -> EnableIf_t< UseSMPAssign_v<VT1> >
931 , DisableIf_t< IsSymmetric_v<MT> || IsZero_v<MT> || IsZero_v<VT> >* =
nullptr >
932inline const TSVecTSMatMultExpr<VT,MT>
933 tsvectsmatmult(
const SparseVector<VT,true>& vec,
const SparseMatrix<MT,true>& mat )
939 return TSVecTSMatMultExpr<VT,MT>( *vec, *mat );
961 , EnableIf_t< IsSymmetric_v<MT> &&
962 !( IsIdentity_v<MT> &&
963 IsSame_v< ElementType_t<VT>, ElementType_t<MT> > ) &&
964 !( IsZero_v<MT> || IsZero_v<VT> ) >* =
nullptr >
966 tsvectsmatmult(
const SparseVector<VT,true>& vec,
const SparseMatrix<MT,true>& mat )
972 return (*vec) *
trans( *mat );
995 IsSame_v< ElementType_t<VT>, ElementType_t<MT> > ) &&
996 !IsZero_v<VT> >* =
nullptr >
998 tsvectsmatmult(
const SparseVector<VT,true>& vec,
const SparseMatrix<MT,true>& mat )
1026template<
typename VT
1028 , EnableIf_t< IsZero_v<MT> || IsZero_v<VT> >* =
nullptr >
1029inline decltype(
auto)
1030 tsvectsmatmult(
const SparseVector<VT,true>& vec,
const SparseMatrix<MT,true>& mat )
1038 using ReturnType =
const MultTrait_t< ResultType_t<VT>, ResultType_t<MT> >;
1043 return ReturnType( (*mat).columns() );
1080template<
typename VT
1082inline decltype(
auto)
1089 if( (*vec).size() != (*mat).rows() ) {
1093 return tsvectsmatmult( *vec, *mat );
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.
Constraints on the storage order of matrix 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.
Constraint on the transpose flag of vector types.
Constraint on the data type.
Constraint on the data type.
Base class for N-dimensional dense vectors.
Definition: DenseVector.h:77
Base class for sparse matrices.
Definition: SparseMatrix.h:77
Base class for sparse vectors.
Definition: SparseVector.h:72
Expression object for sparse vector-sparse matrix multiplications.
Definition: TSVecTSMatMultExpr.h:99
TransposeType_t< ResultType > TransposeType
Transpose type for expression template evaluations.
Definition: TSVecTSMatMultExpr.h:138
If_t< IsExpression_v< VT >, const VT, const VT & > LeftOperand
Composite type of the left-hand side sparse vector expression.
Definition: TSVecTSMatMultExpr.h:144
static constexpr bool evaluateVector
Compilation switch for the composite type of the left-hand side sparse vector expression.
Definition: TSVecTSMatMultExpr.h:110
size_t nonZeros() const
Returns an estimation for the number of non-zero elements in the sparse vector.
Definition: TSVecTSMatMultExpr.h:218
LeftOperand leftOperand() const noexcept
Returns the left-hand side sparse vector operand.
Definition: TSVecTSMatMultExpr.h:228
If_t< evaluateMatrix, const MRT, MCT > RT
Type for the assignment of the right-hand side sparse matrix operand.
Definition: TSVecTSMatMultExpr.h:153
static constexpr bool evaluateMatrix
Compilation switch for the composite type of the right-hand side sparse matrix expression.
Definition: TSVecTSMatMultExpr.h:115
const ResultType CompositeType
Data type for composite expression templates.
Definition: TSVecTSMatMultExpr.h:141
RightOperand mat_
Right-hand side sparse matrix of the multiplication expression.
Definition: TSVecTSMatMultExpr.h:280
static constexpr bool smpAssignable
Compilation switch for the expression template assignment strategy.
Definition: TSVecTSMatMultExpr.h:158
CompositeType_t< VT > VCT
Composite type of the left-hand side sparse vector expression.
Definition: TSVecTSMatMultExpr.h:104
CompositeType_t< MT > MCT
Composite type of the right-hand side sparse matrix expression.
Definition: TSVecTSMatMultExpr.h:105
bool canAlias(const T *alias) const noexcept
Returns whether the expression can alias with the given address alias.
Definition: TSVecTSMatMultExpr.h:250
LeftOperand vec_
Left-hand side sparse vector of the multiplication expression.
Definition: TSVecTSMatMultExpr.h:279
RightOperand rightOperand() const noexcept
Returns the right-hand side transpose sparse matrix operand.
Definition: TSVecTSMatMultExpr.h:238
const ElementType ReturnType
Return type for expression template evaluations.
Definition: TSVecTSMatMultExpr.h:140
bool isAliased(const T *alias) const noexcept
Returns whether the expression is aliased with the given address alias.
Definition: TSVecTSMatMultExpr.h:262
If_t< evaluateVector, const VRT, VCT > LT
Type for the assignment of the left-hand side sparse vector operand.
Definition: TSVecTSMatMultExpr.h:150
TSVecTSMatMultExpr(const VT &vec, const MT &mat) noexcept
Constructor for the TSVecTSMatMultExpr class.
Definition: TSVecTSMatMultExpr.h:168
ResultType_t< VT > VRT
Result type of the left-hand side sparse vector expression.
Definition: TSVecTSMatMultExpr.h:102
ReturnType operator[](size_t index) const
Subscript operator for the direct access to the vector elements.
Definition: TSVecTSMatMultExpr.h:182
ElementType_t< ResultType > ElementType
Resulting element type.
Definition: TSVecTSMatMultExpr.h:139
bool canSMPAssign() const noexcept
Returns whether the expression can be used in SMP assignments.
Definition: TSVecTSMatMultExpr.h:272
ResultType_t< MT > MRT
Result type of the right-hand side sparse matrix expression.
Definition: TSVecTSMatMultExpr.h:103
MultTrait_t< VRT, MRT > ResultType
Result type for expression template evaluations.
Definition: TSVecTSMatMultExpr.h:137
ReturnType at(size_t index) const
Checked access to the vector elements.
Definition: TSVecTSMatMultExpr.h:195
size_t size() const noexcept
Returns the current size/dimension of the vector.
Definition: TSVecTSMatMultExpr.h:208
If_t< IsExpression_v< MT >, const MT, const MT & > RightOperand
Composite type of the right-hand side sparse matrix expression.
Definition: TSVecTSMatMultExpr.h:147
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 SparseVector base class.
Header file for the TVecMatMultExpr base class.
decltype(auto) column(Matrix< MT, SO > &matrix, RCAs... args)
Creating a view on a specific column of the given matrix.
Definition: Column.h:137
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_NOT_REQUIRE_EVALUATION(T)
Constraint on the data type.
Definition: RequiresEvaluation.h:81
#define BLAZE_CONSTRAINT_MUST_FORM_VALID_TVECMATMULTEXPR(T1, T2)
Constraint on the data type.
Definition: TVecMatMultExpr.h:104
#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_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_ROW_VECTOR_TYPE(T)
Constraint on the data type.
Definition: RowVector.h:61
#define BLAZE_CONSTRAINT_MUST_BE_COLUMN_MAJOR_MATRIX_TYPE(T)
Constraint on the data type.
Definition: ColumnMajorMatrix.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
#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 vector/matrix multiplication expression templates.
Definition: TVecMatMultExpr.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.