35 #ifndef _BLAZE_MATH_EXPRESSIONS_TSVECTSMATMULTEXPR_H_ 36 #define _BLAZE_MATH_EXPRESSIONS_TSVECTSMATMULTEXPR_H_ 96 class TSVecTSMatMultExpr
97 :
public TVecMatMultExpr< SparseVector< TSVecTSMatMultExpr<VT,MT>, true > >
124 template<
typename T1 >
192 if( index >=
mat_.columns() ) {
195 return (*
this)[index];
204 inline size_t size() const noexcept {
205 return mat_.columns();
215 return mat_.columns();
245 template<
typename T >
246 inline bool canAlias(
const T* alias )
const noexcept {
247 return (
vec_.isAliased( alias ) ||
mat_.isAliased( alias ) );
257 template<
typename T >
258 inline bool isAliased(
const T* alias )
const noexcept {
259 return (
vec_.isAliased( alias ) ||
mat_.isAliased( alias ) );
269 return (
size() > SMP_TSVECSMATMULT_THRESHOLD );
292 template<
typename VT1 >
304 if( x.nonZeros() == 0UL )
return;
316 TSVecTSMatMultExpr::selectAssignKernel( ~lhs, x, A );
335 template<
typename VT1
338 static inline void selectAssignKernel( VT1& y,
const VT2& x,
const MT1& A )
340 const auto vend( x.end() );
342 for(
size_t j=0UL; j<A.columns(); ++j )
344 const auto mend ( A.end(j) );
345 auto melem( A.begin(j) );
347 if( melem == mend )
continue;
349 auto velem( x.begin() );
352 if( velem->index() < melem->index() ) {
354 if( velem == vend )
break;
356 else if( melem->index() < velem->index() ) {
358 if( melem == mend )
break;
361 y[j] = velem->value() * melem->value();
368 if( velem != vend && melem != mend )
371 if( velem->index() < melem->index() ) {
373 if( velem == vend )
break;
375 else if( melem->index() < velem->index() ) {
377 if( melem == mend )
break;
380 y[j] += velem->value() * melem->value();
382 if( velem == vend )
break;
384 if( melem == mend )
break;
406 template<
typename VT1 >
407 friend inline void assign( SparseVector<VT1,true>& lhs,
const TSVecTSMatMultExpr& rhs )
415 if( x.nonZeros() == 0UL )
return;
428 const auto vend( x.end() );
430 for(
size_t j=0UL; j<A.columns(); ++j )
432 const auto mend ( A.end(j) );
433 auto melem( A.begin(j) );
435 if( melem == mend )
continue;
437 auto velem( x.begin() );
442 if( velem->index() < melem->index() ) {
444 if( velem == vend )
break;
446 else if( melem->index() < velem->index() ) {
448 if( melem == mend )
break;
451 accu = velem->value() * melem->value();
458 if( velem != vend && melem != mend )
461 if( velem->index() < melem->index() ) {
463 if( velem == vend )
break;
465 else if( melem->index() < velem->index() ) {
467 if( melem == mend )
break;
470 accu += velem->value() * melem->value();
472 if( velem == vend )
break;
474 if( melem == mend )
break;
480 (~lhs).insert( j, accu );
499 template<
typename VT1 >
500 friend inline void addAssign( DenseVector<VT1,true>& lhs,
const TSVecTSMatMultExpr& rhs )
508 if( x.nonZeros() == 0UL )
return;
520 TSVecTSMatMultExpr::selectAddAssignKernel( ~lhs, x, A );
539 template<
typename VT1
542 static inline void selectAddAssignKernel( VT1& y,
const VT2& x,
const MT1& A )
544 const auto vend( x.end() );
546 for(
size_t j=0UL; j<A.columns(); ++j )
548 const auto mend ( A.end(j) );
549 auto melem( A.begin(j) );
551 if( melem == mend )
continue;
553 auto velem( x.begin() );
556 if( velem->index() < melem->index() ) {
558 if( velem == vend )
break;
560 else if( melem->index() < velem->index() ) {
562 if( melem == mend )
break;
565 y[j] += velem->value() * melem->value();
567 if( velem == vend )
break;
569 if( melem == mend )
break;
594 template<
typename VT1 >
595 friend inline void subAssign( DenseVector<VT1,true>& lhs,
const TSVecTSMatMultExpr& rhs )
603 if( x.nonZeros() == 0UL )
return;
615 TSVecTSMatMultExpr::selectSubAssignKernel( ~lhs, x, A );
634 template<
typename VT1
637 static inline void selectSubAssignKernel( VT1& y,
const VT2& x,
const MT1& A )
639 const auto vend( x.end() );
641 for(
size_t j=0UL; j<A.columns(); ++j )
643 const auto mend ( A.end(j) );
644 auto melem( A.begin(j) );
646 if( melem == mend )
continue;
648 auto velem( x.begin() );
651 if( velem->index() < melem->index() ) {
653 if( velem == vend )
break;
655 else if( melem->index() < velem->index() ) {
657 if( melem == mend )
break;
660 y[j] -= velem->value() * melem->value();
662 if( velem == vend )
break;
664 if( melem == mend )
break;
689 template<
typename VT1 >
690 friend inline void multAssign( DenseVector<VT1,true>& lhs,
const TSVecTSMatMultExpr& rhs )
701 multAssign( ~lhs, tmp );
725 template<
typename VT1 >
727 -> EnableIf_t< UseSMPAssign_v<VT1> >
738 if( x.nonZeros() == 0UL )
return;
774 template<
typename VT1 >
776 -> EnableIf_t< UseSMPAssign_v<VT1> >
784 if( x.nonZeros() == 0UL )
return;
820 template<
typename VT1 >
822 -> EnableIf_t< UseSMPAssign_v<VT1> >
830 if( x.nonZeros() == 0UL )
return;
866 template<
typename VT1 >
868 -> EnableIf_t< UseSMPAssign_v<VT1> >
925 template<
typename VT
927 , DisableIf_t< IsSymmetric_v<MT> || IsZero_v<MT> || IsZero_v<VT> >* =
nullptr >
928 inline const TSVecTSMatMultExpr<VT,MT>
929 tsvectsmatmult(
const SparseVector<VT,true>& vec,
const SparseMatrix<MT,true>& mat )
935 return TSVecTSMatMultExpr<VT,MT>( ~vec, ~mat );
955 template<
typename VT
957 , EnableIf_t< IsSymmetric_v<MT> &&
958 !( IsIdentity_v<MT> &&
959 IsSame_v< ElementType_t<VT>, ElementType_t<MT> > ) &&
960 !( IsZero_v<MT> || IsZero_v<VT> ) >* =
nullptr >
961 inline decltype(
auto)
962 tsvectsmatmult( const SparseVector<VT,true>& vec, const SparseMatrix<MT,true>& mat )
968 return (~vec) *
trans( ~mat );
988 template<
typename VT
991 IsSame_v< ElementType_t<VT>, ElementType_t<MT> > ) &&
992 !IsZero_v<VT> >* =
nullptr >
994 tsvectsmatmult(
const SparseVector<VT,true>& vec,
const SparseMatrix<MT,true>& mat )
1022 template<
typename VT
1024 , EnableIf_t< IsZero_v<MT> || IsZero_v<VT> >* =
nullptr >
1025 inline decltype(
auto)
1026 tsvectsmatmult( const SparseVector<VT,true>& vec, const SparseMatrix<MT,true>& mat )
1034 using ReturnType =
const MultTrait_t< ResultType_t<VT>, ResultType_t<MT> >;
1039 return ReturnType( (~mat).
columns() );
1076 template<
typename VT
1078 inline decltype(
auto)
1085 if( (~vec).
size() != (~mat).
rows() ) {
1089 return tsvectsmatmult( ~vec, ~mat );
#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
size_t nonZeros() const
Returns an estimation for the number of non-zero elements in the sparse vector.
Definition: TSVecTSMatMultExpr.h:214
Header file for auxiliary alias declarations.
decltype(auto) column(Matrix< MT, SO > &matrix, RCAs... args)
Creating a view on a specific column of the given matrix.
Definition: Column.h:133
Header file for the blaze::checked and blaze::unchecked instances.
const ElementType ReturnType
Return type for expression template evaluations.
Definition: TSVecTSMatMultExpr.h:136
static constexpr bool evaluateMatrix
Compilation switch for the composite type of the right-hand side sparse matrix expression.
Definition: TSVecTSMatMultExpr.h:115
Header file for basic type definitions.
Header file for the SparseVector base class.
typename If< Condition, T1, T2 >::Type If_t
Auxiliary alias template for the If class template.The If_t alias template provides a convenient shor...
Definition: If.h:109
typename T::ResultType ResultType_t
Alias declaration for nested ResultType type definitions.The ResultType_t alias declaration provides ...
Definition: Aliases.h:390
Header file for the serial shim.
If_t< IsExpression_v< VT >, const VT, const VT & > LeftOperand
Composite type of the left-hand side sparse vector expression.
Definition: TSVecTSMatMultExpr.h:140
bool canSMPAssign() const noexcept
Returns whether the expression can be used in SMP assignments.
Definition: TSVecTSMatMultExpr.h:268
void reset(const DiagonalProxy< MT > &proxy)
Resetting the represented element to the default initial values.
Definition: DiagonalProxy.h:595
ResultType_t< MT > MRT
Result type of the right-hand side sparse matrix expression.
Definition: TSVecTSMatMultExpr.h:103
TransposeType_t< ResultType > TransposeType
Transpose type for expression template evaluations.
Definition: TSVecTSMatMultExpr.h:134
constexpr Unchecked unchecked
Global Unchecked instance.The blaze::unchecked instance is an optional token for the creation of view...
Definition: Check.h:138
Constraint on the data type.
Header file for the MAYBE_UNUSED function template.
Header file for the IsIdentity type trait.
Header file for the Computation base class.
Header file for the reset shim.
RightOperand rightOperand() const noexcept
Returns the right-hand side transpose sparse matrix operand.
Definition: TSVecTSMatMultExpr.h:234
Header file for the RequiresEvaluation type trait.
constexpr size_t columns(const Matrix< MT, SO > &matrix) noexcept
Returns the current number of columns of the matrix.
Definition: Matrix.h:514
Base class for sparse matrices.The SparseMatrix class is a base class for all sparse matrix classes....
Definition: Forward.h:145
typename T::ElementType ElementType_t
Alias declaration for nested ElementType type definitions.The ElementType_t alias declaration provide...
Definition: Aliases.h:170
bool isAliased(const T *alias) const noexcept
Returns whether the expression is aliased with the given address alias.
Definition: TSVecTSMatMultExpr.h:258
Constraint on the data type.
typename EnableIf< Condition, T >::Type EnableIf_t
Auxiliary type for the EnableIf class template.The EnableIf_t alias declaration provides a convenient...
Definition: EnableIf.h:138
CompositeType_t< VT > VCT
Composite type of the left-hand side sparse vector expression.
Definition: TSVecTSMatMultExpr.h:104
RightOperand mat_
Right-hand side sparse matrix of the multiplication expression.
Definition: TSVecTSMatMultExpr.h:276
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:58
Header file for the If class template.
#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:61
#define BLAZE_CONSTRAINT_MUST_BE_ZERO_TYPE(T)
Constraint on the data type.In case the given data type T is not a zero vector or matrix type,...
Definition: Zero.h:61
Expression object for sparse vector-sparse matrix multiplications.The TSVecTSMatMultExpr class repres...
Definition: Forward.h:197
#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
LeftOperand vec_
Left-hand side sparse vector of the multiplication expression.
Definition: TSVecTSMatMultExpr.h:275
Base class for N-dimensional dense vectors.The DenseVector class is a base class for all arbitrarily ...
Definition: DenseVector.h:76
constexpr void MAYBE_UNUSED(const Args &...)
Suppression of unused parameter warnings.
Definition: MaybeUnused.h:81
#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
#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:83
If_t< IsExpression_v< MT >, const MT, const MT & > RightOperand
Composite type of the right-hand side sparse matrix expression.
Definition: TSVecTSMatMultExpr.h:143
Header file for the exception macros of the math module.
bool canAlias(const T *alias) const noexcept
Returns whether the expression can alias with the given address alias.
Definition: TSVecTSMatMultExpr.h:246
ResultType_t< VT > VRT
Result type of the left-hand side sparse vector expression.
Definition: TSVecTSMatMultExpr.h:102
Constraint on the data type.
Constraint on the data type.
Header file for the EnableIf class template.
If_t< evaluateVector, const VRT, VCT > LT
Type for the assignment of the left-hand side sparse vector operand.
Definition: TSVecTSMatMultExpr.h:146
typename MultTrait< T1, T2 >::Type MultTrait_t
Auxiliary alias declaration for the MultTrait class template.The MultTrait_t alias declaration provid...
Definition: MultTrait.h:240
#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,...
Definition: Symmetric.h:79
typename T::TransposeType TransposeType_t
Alias declaration for nested TransposeType type definitions.The TransposeType_t alias declaration pro...
Definition: Aliases.h:470
Header file for run time assertion macros.
typename T::CompositeType CompositeType_t
Alias declaration for nested CompositeType type definitions.The CompositeType_t alias declaration pro...
Definition: Aliases.h:90
static constexpr bool smpAssignable
Compilation switch for the expression template assignment strategy.
Definition: TSVecTSMatMultExpr.h:154
const ResultType CompositeType
Data type for composite expression templates.
Definition: TSVecTSMatMultExpr.h:137
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
Header file for the IsZero type trait.
Constraint on the data type.
LeftOperand leftOperand() const noexcept
Returns the left-hand side sparse vector operand.
Definition: TSVecTSMatMultExpr.h:224
#define BLAZE_FUNCTION_TRACE
Function trace macro.This macro can be used to reliably trace function calls. In case function tracin...
Definition: FunctionTrace.h:94
Header file for all forward declarations for expression class templates.
Header file for the isDefault shim.
constexpr size_t size(const Matrix< MT, SO > &matrix) noexcept
Returns the total number of elements of the matrix.
Definition: Matrix.h:530
MultTrait_t< VRT, MRT > ResultType
Result type for expression template evaluations.
Definition: TSVecTSMatMultExpr.h:133
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
Header file for the TVecMatMultExpr base class.
Constraint on the data type.
ElementType_t< ResultType > ElementType
Resulting element type.
Definition: TSVecTSMatMultExpr.h:135
Constraints on the storage order of matrix types.
decltype(auto) serial(const DenseMatrix< MT, SO > &dm)
Forces the serial evaluation of the given dense matrix expression dm.
Definition: DMatSerialExpr.h:808
#define BLAZE_CONSTRAINT_MUST_NOT_REQUIRE_EVALUATION(T)
Constraint on the data type.In case the given data type T requires an intermediate evaluation within ...
Definition: RequiresEvaluation.h:81
constexpr size_t rows(const Matrix< MT, SO > &matrix) noexcept
Returns the current number of rows of the matrix.
Definition: Matrix.h:498
ReturnType operator[](size_t index) const
Subscript operator for the direct access to the vector elements.
Definition: TSVecTSMatMultExpr.h:178
static constexpr bool evaluateVector
Compilation switch for the composite type of the left-hand side sparse vector expression.
Definition: TSVecTSMatMultExpr.h:110
#define BLAZE_CONSTRAINT_MUST_FORM_VALID_TVECMATMULTEXPR(T1, T2)
Constraint on the data type.In case the given data types T1 and T2 do not form a valid vector/matrix ...
Definition: TVecMatMultExpr.h:104
decltype(auto) trans(const DenseMatrix< MT, SO > &dm)
Calculation of the transpose of the given dense matrix.
Definition: DMatTransExpr.h:765
If_t< evaluateMatrix, const MRT, MCT > RT
Type for the assignment of the right-hand side sparse matrix operand.
Definition: TSVecTSMatMultExpr.h:149
Header file for the IsComputation type trait class.
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
size_t size() const noexcept
Returns the current size/dimension of the vector.
Definition: TSVecTSMatMultExpr.h:204
Base class for sparse vectors.The SparseVector class is a base class for all arbitrarily sized (N-dim...
Definition: Forward.h:146
#define BLAZE_CONSTRAINT_MUST_BE_ROW_VECTOR_TYPE(T)
Constraint on the data type.In case the given data type T is not a row dense or sparse vector type (i...
Definition: RowVector.h:61
bool isDefault(const DiagonalProxy< MT > &proxy)
Returns whether the represented element is in default state.
Definition: DiagonalProxy.h:635
TSVecTSMatMultExpr(const VT &vec, const MT &mat) noexcept
Constructor for the TSVecTSMatMultExpr class.
Definition: TSVecTSMatMultExpr.h:164
Constraint on the data type.
#define BLAZE_CONSTRAINT_MUST_NOT_BE_ZERO_TYPE(T)
Constraint on the data type.In case the given data type T is a zero vector or matrix type,...
Definition: Zero.h:81
Header file for the thresholds for matrix/vector and matrix/matrix multiplications.
CompositeType_t< MT > MCT
Composite type of the right-hand side sparse matrix expression.
Definition: TSVecTSMatMultExpr.h:105
#define BLAZE_INTERNAL_ASSERT(expr, msg)
Run time assertion macro for internal checks.In case of an invalid run time expression,...
Definition: Assert.h:101
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:191
#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
ReturnType at(size_t index) const
Checked access to the vector elements.
Definition: TSVecTSMatMultExpr.h:191
Constraint on the transpose flag of vector types.
Header file for the IsExpression type trait class.
Header file for the function trace functionality.