35 #ifndef _BLAZE_MATH_EXPRESSIONS_TSVECTSMATMULTEXPR_H_
36 #define _BLAZE_MATH_EXPRESSIONS_TSVECTSMATMULTEXPR_H_
88 class TSVecTSMatMultExpr :
public SparseVector< TSVecTSMatMultExpr<VT,MT>, true >
89 ,
private TVecMatMultExpr
115 template<
typename T1,
typename T2,
typename T3 >
116 struct UseSMPAssignKernel {
117 enum { value = evaluateVector || evaluateMatrix };
146 enum { smpAssignable = !evaluateMatrix && !evaluateVector };
184 VectorIterator velem( x.begin() );
185 const VectorIterator vend( x.end() );
186 if( velem == vend ) {
191 MatrixIterator melem( A.begin(index) );
192 const MatrixIterator mend( A.end(index) );
193 if( melem == mend ) {
199 if( velem->index() < melem->index() ) {
201 if( velem == vend )
break;
203 else if( melem->index() < velem->index() ) {
205 if( melem == mend )
break;
208 res = velem->value() * melem->value();
215 if( melem != mend && velem != vend )
218 if( velem->index() < melem->index() ) {
220 if( velem == vend )
break;
222 else if( melem->index() < velem->index() ) {
224 if( melem == mend )
break;
227 res += velem->value() * melem->value();
229 if( velem == vend )
break;
231 if( melem == mend )
break;
246 return mat_.columns();
256 return mat_.columns();
286 template<
typename T >
288 return (
vec_.isAliased( alias ) ||
mat_.isAliased( alias ) );
298 template<
typename T >
300 return (
vec_.isAliased( alias ) ||
mat_.isAliased( alias ) );
333 template<
typename VT1 >
345 if( x.nonZeros() == 0UL )
return;
357 TSVecTSMatMultExpr::selectAssignKernel( ~lhs, x, A );
376 template<
typename VT1
380 selectAssignKernel( VT1& y,
const VT2& x,
const MT1& A )
385 const VectorIterator vend( x.end() );
387 for(
size_t j=0UL; j<A.columns(); ++j )
389 const MatrixIterator mend ( A.end(j) );
390 MatrixIterator melem( A.begin(j) );
392 if( melem == mend )
continue;
394 VectorIterator velem( x.begin() );
397 if( velem->index() < melem->index() ) {
399 if( velem == vend )
break;
401 else if( melem->index() < velem->index() ) {
403 if( melem == mend )
break;
406 y[j] = velem->value() * melem->value();
413 if( velem != vend && melem != mend )
416 if( velem->index() < melem->index() ) {
418 if( velem == vend )
break;
420 else if( melem->index() < velem->index() ) {
422 if( melem == mend )
break;
425 y[j] += velem->value() * melem->value();
427 if( velem == vend )
break;
429 if( melem == mend )
break;
452 template<
typename VT1
455 static inline typename EnableIf< UseSMPAssignKernel<VT1,MT1,VT2> >::Type
456 selectAssignKernel( VT1& y,
const VT2& x,
const MT1& A )
476 template<
typename VT1 >
488 if( x.nonZeros() == 0UL )
return;
501 const VectorIterator vend( x.end() );
503 for(
size_t j=0UL; j<A.columns(); ++j )
505 const MatrixIterator mend ( A.end(j) );
506 MatrixIterator melem( A.begin(j) );
508 if( melem == mend )
continue;
510 VectorIterator velem( x.begin() );
515 if( velem->index() < melem->index() ) {
517 if( velem == vend )
break;
519 else if( melem->index() < velem->index() ) {
521 if( melem == mend )
break;
524 accu = velem->value() * melem->value();
531 if( velem != vend && melem != mend )
534 if( velem->index() < melem->index() ) {
536 if( velem == vend )
break;
538 else if( melem->index() < velem->index() ) {
540 if( melem == mend )
break;
543 accu += velem->value() * melem->value();
545 if( velem == vend )
break;
547 if( melem == mend )
break;
553 (~lhs).insert( j, accu );
572 template<
typename VT1 >
581 if( x.nonZeros() == 0UL )
return;
593 TSVecTSMatMultExpr::selectAddAssignKernel( ~lhs, x, A );
612 template<
typename VT1
615 static inline typename DisableIf< UseSMPAssignKernel<VT1,MT1,VT2> >::Type
616 selectAddAssignKernel( VT1& y,
const VT2& x,
const MT1& A )
621 const VectorIterator vend( x.end() );
623 for(
size_t j=0UL; j<A.columns(); ++j )
625 const MatrixIterator mend ( A.end(j) );
626 MatrixIterator melem( A.begin(j) );
628 if( melem == mend )
continue;
630 VectorIterator velem( x.begin() );
633 if( velem->index() < melem->index() ) {
635 if( velem == vend )
break;
637 else if( melem->index() < velem->index() ) {
639 if( melem == mend )
break;
642 y[j] += velem->value() * melem->value();
644 if( velem == vend )
break;
646 if( melem == mend )
break;
668 template<
typename VT1
671 static inline typename EnableIf< UseSMPAssignKernel<VT1,MT1,VT2> >::Type
672 selectAddAssignKernel( VT1& y,
const VT2& x,
const MT1& A )
696 template<
typename VT1 >
705 if( x.nonZeros() == 0UL )
return;
717 TSVecTSMatMultExpr::selectSubAssignKernel( ~lhs, x, A );
736 template<
typename VT1
739 static inline typename DisableIf< UseSMPAssignKernel<VT1,MT1,VT2> >::Type
740 selectSubAssignKernel( VT1& y,
const VT2& x,
const MT1& A )
745 const VectorIterator vend( x.end() );
747 for(
size_t j=0UL; j<A.columns(); ++j )
749 const MatrixIterator mend ( A.end(j) );
750 MatrixIterator melem( A.begin(j) );
752 if( melem == mend )
continue;
754 VectorIterator velem( x.begin() );
757 if( velem->index() < melem->index() ) {
759 if( velem == vend )
break;
761 else if( melem->index() < velem->index() ) {
763 if( melem == mend )
break;
766 y[j] -= velem->value() * melem->value();
768 if( velem == vend )
break;
770 if( melem == mend )
break;
792 template<
typename VT1
795 static inline typename EnableIf< UseSMPAssignKernel<VT1,MT1,VT2> >::Type
796 selectSubAssignKernel( VT1& y,
const VT2& x,
const MT1& A )
820 template<
typename VT1 >
892 template<
typename T1
894 inline const typename DisableIf< IsMatMatMultExpr<T2>, TSVecTSMatMultExpr<T1,T2> >::Type
899 if( (~vec).size() != (~mat).
rows() )
900 throw std::invalid_argument(
"Vector and matrix sizes do not match" );
917 template<
typename VT,
typename MT,
bool AF >
918 struct SubvectorExprTrait< TSVecTSMatMultExpr<VT,MT>, AF >
922 typedef typename MultExprTrait< VT, typename SubmatrixExprTrait<const MT,AF>::Type >::Type Type;
Compile time check whether the given type is a computational expression template.This type trait clas...
Definition: IsComputation.h:89
void reset(DynamicMatrix< Type, SO > &m)
Resetting the given dense matrix.
Definition: DynamicMatrix.h:4579
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:4075
size_t size() const
Returns the current size/dimension of the vector.
Definition: TSVecTSMatMultExpr.h:245
Header file for the SparseVector base class.
void smpSubAssign(DenseMatrix< MT1, SO1 > &lhs, const Matrix< MT2, SO2 > &rhs)
Default implementation of the SMP subtraction assignment of a matrix to dense matrix.
Definition: DenseMatrix.h:151
bool isDefault(const DynamicMatrix< Type, SO > &m)
Returns whether the given dense matrix is in default state.
Definition: DynamicMatrix.h:4622
Efficient implementation of a compressed matrix.The CompressedMatrix class template is the represent...
Definition: CompressedMatrix.h:197
void smpMultAssign(DenseVector< 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:178
const This & CompositeType
Data type for composite expression templates.
Definition: CompressedMatrix.h:2384
Type ElementType
Type of the sparse matrix elements.
Definition: CompressedMatrix.h:249
Header file for the Computation base class.
TSVecTSMatMultExpr< VT, MT > This
Type of this TSVecTSMatMultExpr instance.
Definition: TSVecTSMatMultExpr.h:124
Header file for the RequiresEvaluation type trait.
MT::CompositeType MCT
Composite type of the right-hand side sparse matrix expression.
Definition: TSVecTSMatMultExpr.h:97
LeftOperand leftOperand() const
Returns the left-hand side sparse vector operand.
Definition: TSVecTSMatMultExpr.h:265
TSVecTSMatMultExpr(const VT &vec, const MT &mat)
Constructor for the TSVecTSMatMultExpr class.
Definition: TSVecTSMatMultExpr.h:155
LeftOperand vec_
Left-hand side sparse vector of the multiplication expression.
Definition: TSVecTSMatMultExpr.h:316
Base class for sparse matrices.The SparseMatrix class is a base class for all sparse matrix classes...
Definition: Forward.h:104
Constraint on the data type.
Constraint on the data type.
void smpAddAssign(DenseMatrix< 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:121
Compile time check to query the requirement to evaluate an expression.Via this type trait it is possi...
Definition: RequiresEvaluation.h:90
const This & CompositeType
Data type for composite expression templates.
Definition: CompressedMatrix.h:251
Compile time type selection.The SelectType class template selects one of the two given types T1 and T...
Definition: SelectType.h:59
Header file for the DisableIf class template.
Header file for the multiplication trait.
MCT RT
Type for the assignment of the right-hand side sparse matrix operand.
Definition: TSVecTSMatMultExpr.h:141
Header file for the dense vector SMP implementation.
#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: StorageOrder.h:161
const Element * ConstIterator
Iterator over constant elements.
Definition: CompressedMatrix.h:2388
Expression object for sparse vector-sparse matrix multiplications.The TSVecTSMatMultExpr class repres...
Definition: Forward.h:146
Header file for the IsMatMatMultExpr type trait class.
void assign(Matrix< MT1, SO1 > &lhs, const Matrix< MT2, SO2 > &rhs)
Default implementation of the assignment of a matrix to a matrix.
Definition: Matrix.h:179
Base class for N-dimensional dense vectors.The DenseVector class is a base class for all arbitrarily ...
Definition: DenseVector.h:70
#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:79
Constraint on the data type.
#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:78
size_t nonZeros() const
Returns an estimation for the number of non-zero elements in the sparse vector.
Definition: TSVecTSMatMultExpr.h:255
Constraints on the storage order of matrix types.
MultTrait< VRT, MRT >::Type ResultType
Result type for expression template evaluations.
Definition: TSVecTSMatMultExpr.h:125
void multAssign(Matrix< MT1, SO1 > &lhs, const Matrix< MT2, SO2 > &rhs)
Default implementation of the multiplication assignment of a matrix to a matrix.
Definition: Matrix.h:269
Header file for the SelectType class template.
Header file for all forward declarations for expression class templates.
Constraint on the data type.
SelectType< IsExpression< MT >::value, const MT, const MT & >::Type RightOperand
Composite type of the right-hand side sparse matrix expression.
Definition: TSVecTSMatMultExpr.h:135
void smpAssign(DenseMatrix< MT1, SO1 > &lhs, const Matrix< MT2, SO2 > &rhs)
Default implementation of the SMP assignment of a matrix to a dense matrix.
Definition: DenseMatrix.h:91
const ResultType CompositeType
Data type for composite expression templates.
Definition: TSVecTSMatMultExpr.h:129
ResultType::TransposeType TransposeType
Transpose type for expression template evaluations.
Definition: TSVecTSMatMultExpr.h:126
MT::ResultType MRT
Result type of the right-hand side sparse matrix expression.
Definition: TSVecTSMatMultExpr.h:95
Removal of reference modifiers.The RemoveCV type trait removes any reference modifiers from the given...
Definition: RemoveReference.h:69
Header file for run time assertion macros.
Base template for the MultTrait class.
Definition: MultTrait.h:141
SelectType< evaluateVector, const VRT, VCT >::Type LT
Type for the assignment of the left-hand side sparse vector operand.
Definition: TSVecTSMatMultExpr.h:138
void addAssign(Matrix< MT1, SO1 > &lhs, const Matrix< MT2, SO2 > &rhs)
Default implementation of the addition assignment of a matrix to a matrix.
Definition: Matrix.h:209
VT::CompositeType VCT
Composite type of the left-hand side sparse vector expression.
Definition: TSVecTSMatMultExpr.h:96
Header file for the reset shim.
void subAssign(Matrix< MT1, SO1 > &lhs, const Matrix< MT2, SO2 > &rhs)
Default implementation of the subtraction assignment of a matrix to matrix.
Definition: Matrix.h:239
ResultType::ElementType ElementType
Resulting element type.
Definition: TSVecTSMatMultExpr.h:127
Header file for the isDefault shim.
Header file for the TVecMatMultExpr base class.
const size_t SMP_TSVECSMATMULT_THRESHOLD
SMP sparse vector/row-major sparse matrix multiplication threshold.This threshold represents the syst...
Definition: Thresholds.h:321
Header file for the RemoveReference type trait.
Substitution Failure Is Not An Error (SFINAE) class.The DisableIf class template is an auxiliary tool...
Definition: DisableIf.h:184
bool isAliased(const T *alias) const
Returns whether the expression is aliased with the given address alias.
Definition: TSVecTSMatMultExpr.h:299
Header file for the IsComputation type trait class.
RightOperand mat_
Right-hand side sparse matrix of the multiplication expression.
Definition: TSVecTSMatMultExpr.h:317
VT::ResultType VRT
Result type of the left-hand side sparse vector expression.
Definition: TSVecTSMatMultExpr.h:94
const ElementType ReturnType
Return type for expression template evaluations.
Definition: TSVecTSMatMultExpr.h:128
Header file for the sparse vector SMP implementation.
ReturnType operator[](size_t index) const
Subscript operator for the direct access to the vector elements.
Definition: TSVecTSMatMultExpr.h:169
Base class for sparse vectors.The SparseVector class is a base class for all arbitrarily sized (N-dim...
Definition: Forward.h:105
#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
SelectType< IsExpression< VT >::value, const VT, const VT & >::Type LeftOperand
Composite type of the left-hand side sparse vector expression.
Definition: TSVecTSMatMultExpr.h:132
This ResultType
Result type for expression template evaluations.
Definition: CompressedMatrix.h:2379
bool canAlias(const T *alias) const
Returns whether the expression can alias with the given address alias.
Definition: TSVecTSMatMultExpr.h:287
Header file for basic type definitions.
#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: TransposeFlag.h:81
Header file for the thresholds for matrix/vector and matrix/matrix multiplications.
size_t rows(const Matrix< MT, SO > &m)
Returns the current number of rows of the matrix.
Definition: Matrix.h:138
#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
bool canSMPAssign() const
Returns whether the expression can be used in SMP assignments.
Definition: TSVecTSMatMultExpr.h:309
#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:79
Header file for the IsExpression type trait class.
Header file for the FunctionTrace class.
RightOperand rightOperand() const
Returns the right-hand side transpose sparse matrix operand.
Definition: TSVecTSMatMultExpr.h:275