35 #ifndef _BLAZE_MATH_EXPRESSIONS_TSVECSMATMULTEXPR_H_
36 #define _BLAZE_MATH_EXPRESSIONS_TSVECSMATMULTEXPR_H_
97 class TSVecSMatMultExpr :
public SparseVector< TSVecSMatMultExpr<VT,MT>, true >
98 ,
private TVecMatMultExpr
125 template<
typename T1 >
126 struct UseSMPAssign {
127 enum { value = ( evaluateVector || evaluateMatrix ) };
156 enum { smpAssignable = !evaluateVector && VT::smpAssignable &&
157 !evaluateMatrix && MT::smpAssignable };
192 const VectorIterator vend( x.end() );
193 VectorIterator velem( x.begin() );
196 if( velem != vend ) {
197 res = velem->value() * A(velem->index(),index);
199 for( ; velem!=vend; ++velem ) {
200 res += velem->value() * A(velem->index(),index);
217 return mat_.columns();
227 return mat_.columns();
257 template<
typename T >
259 return (
vec_.isAliased( alias ) ||
mat_.isAliased( alias ) );
269 template<
typename T >
271 return (
vec_.isAliased( alias ) ||
mat_.isAliased( alias ) );
304 template<
typename VT1 >
315 LT x(
serial( rhs.vec_ ) );
316 if( x.nonZeros() == 0UL )
return;
319 RT A(
serial( rhs.mat_ ) );
328 TSVecSMatMultExpr::selectAssignKernel( ~lhs, x, A );
347 template<
typename VT1
350 static inline void selectAssignKernel( VT1& y,
const VT2& x,
const MT1& A )
355 const VectorIterator vend( x.end() );
356 VectorIterator velem( x.begin() );
358 for( ; velem!=vend; ++velem )
360 const MatrixIterator mend( A.end( velem->index() ) );
361 MatrixIterator melem( A.begin( velem->index() ) );
363 for( ; melem!=mend; ++melem ) {
366 y[melem->index()] = velem->value() * melem->value();
368 y[melem->index()] += velem->value() * melem->value();
387 template<
typename VT1 >
398 LT x(
serial( rhs.vec_ ) );
399 if( x.nonZeros() == 0UL )
return;
402 RT A(
serial( rhs.mat_ ) );
411 DynamicVector<ElementType> tmp( (~lhs).
size() );
412 std::vector<byte> indices( (~lhs).
size(), 0 );
413 size_t nonzeros( 0UL );
415 const VectorIterator vend( x.end() );
416 VectorIterator velem( x.begin() );
418 for( ; velem!=vend; ++velem )
420 const MatrixIterator mend ( A.end ( velem->index() ) );
421 MatrixIterator melem( A.begin( velem->index() ) );
423 for( ; melem!=mend; ++melem ) {
424 if( !indices[melem->index()] ) {
425 indices[melem->index()] = 1;
427 tmp[melem->index()] = velem->value() * melem->value();
430 tmp[melem->index()] += velem->value() * melem->value();
435 (~lhs).reserve( nonzeros );
437 for(
size_t i=0UL; i<(~lhs).
size(); ++i ) {
439 (~lhs).append( i, tmp[i] );
459 template<
typename VT1 >
467 LT x(
serial( rhs.vec_ ) );
468 if( x.nonZeros() == 0UL )
return;
471 RT A(
serial( rhs.mat_ ) );
480 TSVecSMatMultExpr::selectAddAssignKernel( ~lhs, x, A );
499 template<
typename VT1
502 static inline void selectAddAssignKernel( VT1& y,
const VT2& x,
const MT1& A )
507 const VectorIterator vend( x.end() );
508 VectorIterator velem( x.begin() );
510 for( ; velem!=vend; ++velem )
512 const MatrixIterator mend( A.end( velem->index() ) );
513 MatrixIterator melem( A.begin( velem->index() ) );
515 for( ; melem!=mend; ++melem ) {
516 y[melem->index()] += velem->value() * melem->value();
540 template<
typename VT1 >
548 LT x(
serial( rhs.vec_ ) );
549 if( x.nonZeros() == 0UL )
return;
552 RT A(
serial( rhs.mat_ ) );
561 TSVecSMatMultExpr::selectSubAssignKernel( ~lhs, x, A );
580 template<
typename VT1
583 static inline void selectSubAssignKernel( VT1& y,
const VT2& x,
const MT1& A )
588 const VectorIterator vend( x.end() );
589 VectorIterator velem( x.begin() );
591 for( ; velem!=vend; ++velem )
593 const MatrixIterator mend( A.end( velem->index() ) );
594 MatrixIterator melem( A.begin( velem->index() ) );
596 for( ; melem!=mend; ++melem ) {
597 y[melem->index()] -= velem->value() * melem->value();
621 template<
typename VT1 >
632 const ResultType tmp(
serial( rhs ) );
657 template<
typename VT1 >
658 friend inline typename EnableIf< UseSMPAssign<VT1> >::Type
670 if( x.nonZeros() == 0UL )
return;
706 template<
typename VT1 >
707 friend inline typename EnableIf< UseSMPAssign<VT1> >::Type
716 if( x.nonZeros() == 0UL )
return;
752 template<
typename VT1 >
753 friend inline typename EnableIf< UseSMPAssign<VT1> >::Type
762 if( x.nonZeros() == 0UL )
return;
798 template<
typename VT1 >
799 friend inline typename EnableIf< UseSMPAssign<VT1> >::Type
810 const ResultType tmp( rhs );
872 template<
typename T1
874 inline const typename DisableIf< IsMatMatMultExpr<T2>, TSVecSMatMultExpr<T1,T2> >::Type
879 if( (~vec).
size() != (~mat).
rows() )
880 throw std::invalid_argument(
"Vector and matrix sizes do not match" );
908 template<
typename T1
911 inline const typename EnableIf< IsMatMatMultExpr<T2>,
typename MultExprTrait<T1,T2>::Type >::Type
933 template<
typename MT,
typename VT >
951 template<
typename VT,
typename MT,
bool AF >
956 typedef typename MultExprTrait< typename SubvectorExprTrait<const VT,AF>::Type
957 ,
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
VT::CompositeType VCT
Composite type of the left-hand side sparse vector expression.
Definition: TSVecSMatMultExpr.h:105
BLAZE_ALWAYS_INLINE 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:879
size_t nonZeros() const
Returns an estimation for the number of non-zero elements in the sparse vector.
Definition: TSVecSMatMultExpr.h:226
bool canAlias(const T *alias) const
Returns whether the expression can alias with the given address alias.
Definition: TSVecSMatMultExpr.h:258
const ElementType ReturnType
Return type for expression template evaluations.
Definition: TSVecSMatMultExpr.h:138
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:8247
Header file for basic type definitions.
Header file for the SparseVector base class.
Efficient implementation of a compressed matrix.The CompressedMatrix class template is the represent...
Definition: CompressedMatrix.h:209
ResultType::TransposeType TransposeType
Transpose type for expression template evaluations.
Definition: TSVecSMatMultExpr.h:136
void reset(const DiagonalProxy< MT > &proxy)
Resetting the represented element to the default initial values.
Definition: DiagonalProxy.h:821
TSVecSMatMultExpr< VT, MT > This
Type of this TSVecSMatMultExpr instance.
Definition: TSVecSMatMultExpr.h:134
const This & CompositeType
Data type for composite expression templates.
Definition: CompressedMatrix.h:2507
Type ElementType
Type of the sparse matrix elements.
Definition: CompressedMatrix.h:261
BLAZE_ALWAYS_INLINE size_t rows(const Matrix< MT, SO > &matrix)
Returns the current number of rows of the matrix.
Definition: Matrix.h:316
const DMatSerialExpr< MT, SO > serial(const DenseMatrix< MT, SO > &dm)
Forces the serial evaluation of the given dense matrix expression dm.
Definition: DMatSerialExpr.h:699
MT::ResultType MRT
Result type of the right-hand side sparse matrix expression.
Definition: TSVecSMatMultExpr.h:104
Header file for the Computation base class.
RightOperand mat_
Right-hand side sparse matrix of the multiplication expression.
Definition: TSVecSMatMultExpr.h:288
Header file for the RequiresEvaluation type trait.
Header file for the implementation of an arbitrarily sized vector.
Base class for sparse matrices.The SparseMatrix class is a base class for all sparse matrix classes...
Definition: Forward.h:107
bool isDefault(const DiagonalProxy< MT > &proxy)
Returns whether the represented element is in default state.
Definition: DiagonalProxy.h:861
Constraint on the data type.
SelectType< evaluateMatrix, const MRT, MCT >::Type RT
Type for the assignment of the right-hand side sparse matrix operand.
Definition: TSVecSMatMultExpr.h:151
Constraint on the data type.
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:90
const This & CompositeType
Data type for composite expression templates.
Definition: CompressedMatrix.h:263
SelectType< evaluateVector, const VRT, VCT >::Type LT
Type for the assignment of the left-hand side sparse vector operand.
Definition: TSVecSMatMultExpr.h:148
MultTrait< VRT, MRT >::Type ResultType
Result type for expression template evaluations.
Definition: TSVecSMatMultExpr.h:135
SelectType< IsExpression< MT >::value, const MT, const MT & >::Type RightOperand
Composite type of the right-hand side sparse matrix expression.
Definition: TSVecSMatMultExpr.h:145
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.
Namespace of the Blaze C++ math library.
Definition: Blaze.h:57
LeftOperand leftOperand() const
Returns the left-hand side sparse vector operand.
Definition: TSVecSMatMultExpr.h:236
size_t size() const
Returns the current size/dimension of the vector.
Definition: TSVecSMatMultExpr.h:216
const Element * ConstIterator
Iterator over constant elements.
Definition: CompressedMatrix.h:2511
Expression object for sparse vector-sparse matrix multiplications.The TSVecSMatMultExpr class represe...
Definition: Forward.h:148
Header file for the IsMatMatMultExpr type trait class.
BLAZE_ALWAYS_INLINE 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:635
Header file for the Columns type trait.
bool canSMPAssign() const
Returns whether the expression can be used in SMP assignments.
Definition: TSVecSMatMultExpr.h:280
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
Constraints on the storage order of matrix types.
ResultType::ElementType ElementType
Resulting element type.
Definition: TSVecSMatMultExpr.h:137
Header file for the SelectType class template.
Header file for all forward declarations for expression class templates.
Constraint on the data type.
const ResultType CompositeType
Data type for composite expression templates.
Definition: TSVecSMatMultExpr.h:139
Header file for the EnableIf class template.
LeftOperand vec_
Left-hand side sparse vector of the multiplication expression.
Definition: TSVecSMatMultExpr.h:287
Header file for the serial shim.
MT::CompositeType MCT
Composite type of the right-hand side sparse matrix expression.
Definition: TSVecSMatMultExpr.h:106
Header file for the byte type.
VT::ResultType VRT
Result type of the left-hand side sparse vector expression.
Definition: TSVecSMatMultExpr.h:103
Compile time check for resizable data types.This type trait tests whether the given data type is a re...
Definition: IsResizable.h:75
RightOperand rightOperand() const
Returns the right-hand side sparse matrix operand.
Definition: TSVecSMatMultExpr.h:246
EnableIf< IsDenseMatrix< MT1 > >::Type 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
#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:116
#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: StorageOrder.h:81
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.
EnableIf< IsDenseMatrix< MT1 > >::Type 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
Base template for the MultTrait class.
Definition: MultTrait.h:150
BLAZE_ALWAYS_INLINE 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:742
Header file for the reset shim.
Constraint on the data type.
TSVecSMatMultExpr(const VT &vec, const MT &mat)
Constructor for the TSVecSMatMultExpr class.
Definition: TSVecSMatMultExpr.h:166
Header file for the isDefault shim.
Header file for the TVecMatMultExpr base class.
Constraint on the data type.
bool isAliased(const T *alias) const
Returns whether the expression is aliased with the given address alias.
Definition: TSVecSMatMultExpr.h:270
Header file for the RemoveReference type trait.
#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:166
const size_t SMP_TSVECSMATMULT_THRESHOLD
SMP sparse vector/row-major sparse matrix multiplication threshold.This threshold specifies when a sp...
Definition: Thresholds.h:644
Header file for the IsComputation type trait class.
EnableIf< IsDenseMatrix< MT1 > >::Type 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 vectors.The SparseVector class is a base class for all arbitrarily sized (N-dim...
Definition: Forward.h:108
#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
This ResultType
Result type for expression template evaluations.
Definition: CompressedMatrix.h:2502
#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
ReturnType operator[](size_t index) const
Subscript operator for the direct access to the vector elements.
Definition: TSVecSMatMultExpr.h:180
Header file for the IsResizable type trait.
SelectType< IsExpression< VT >::value, const VT, const VT & >::Type LeftOperand
Composite type of the left-hand side sparse vector expression.
Definition: TSVecSMatMultExpr.h:142
EnableIf< IsDenseVector< VT1 > >::Type 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:189
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:79
Header file for the IsExpression type trait class.
Header file for the FunctionTrace class.
BLAZE_ALWAYS_INLINE 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:849