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);
218 inline ReturnType
at(
size_t index )
const {
219 if( index >=
mat_.columns() ) {
222 return (*
this)[index];
232 return mat_.columns();
242 return mat_.columns();
272 template<
typename T >
274 return (
vec_.isAliased( alias ) ||
mat_.isAliased( alias ) );
284 template<
typename T >
286 return (
vec_.isAliased( alias ) ||
mat_.isAliased( alias ) );
296 return (
size() > SMP_TSVECSMATMULT_THRESHOLD );
319 template<
typename VT1 >
330 LT x(
serial( rhs.vec_ ) );
331 if( x.nonZeros() == 0UL )
return;
334 RT A(
serial( rhs.mat_ ) );
343 TSVecSMatMultExpr::selectAssignKernel( ~lhs, x, A );
362 template<
typename VT1
365 static inline void selectAssignKernel( VT1& y,
const VT2& x,
const MT1& A )
370 const VectorIterator vend( x.end() );
371 VectorIterator velem( x.begin() );
373 for( ; velem!=vend; ++velem )
375 const MatrixIterator mend( A.end( velem->index() ) );
376 MatrixIterator melem( A.begin( velem->index() ) );
378 for( ; melem!=mend; ++melem ) {
381 y[melem->index()] = velem->value() * melem->value();
383 y[melem->index()] += velem->value() * melem->value();
402 template<
typename VT1 >
403 friend inline void assign( SparseVector<VT1,true>& lhs,
const TSVecSMatMultExpr& rhs )
413 LT x(
serial( rhs.vec_ ) );
414 if( x.nonZeros() == 0UL )
return;
417 RT A(
serial( rhs.mat_ ) );
426 DynamicVector<ElementType> tmp( (~lhs).
size() );
427 std::vector<byte> indices( (~lhs).
size(), 0 );
428 size_t nonzeros( 0UL );
430 const VectorIterator vend( x.end() );
431 VectorIterator velem( x.begin() );
433 for( ; velem!=vend; ++velem )
435 const MatrixIterator mend ( A.end ( velem->index() ) );
436 MatrixIterator melem( A.begin( velem->index() ) );
438 for( ; melem!=mend; ++melem ) {
439 if( !indices[melem->index()] ) {
440 indices[melem->index()] = 1;
442 tmp[melem->index()] = velem->value() * melem->value();
445 tmp[melem->index()] += velem->value() * melem->value();
450 (~lhs).reserve( nonzeros );
452 for(
size_t i=0UL; i<(~lhs).
size(); ++i ) {
454 (~lhs).append( i, tmp[i] );
474 template<
typename VT1 >
475 friend inline void addAssign( DenseVector<VT1,true>& lhs,
const TSVecSMatMultExpr& rhs )
482 LT x(
serial( rhs.vec_ ) );
483 if( x.nonZeros() == 0UL )
return;
486 RT A(
serial( rhs.mat_ ) );
495 TSVecSMatMultExpr::selectAddAssignKernel( ~lhs, x, A );
514 template<
typename VT1
517 static inline void selectAddAssignKernel( VT1& y,
const VT2& x,
const MT1& A )
522 const VectorIterator vend( x.end() );
523 VectorIterator velem( x.begin() );
525 for( ; velem!=vend; ++velem )
527 const MatrixIterator mend( A.end( velem->index() ) );
528 MatrixIterator melem( A.begin( velem->index() ) );
530 for( ; melem!=mend; ++melem ) {
531 y[melem->index()] += velem->value() * melem->value();
555 template<
typename VT1 >
556 friend inline void subAssign( DenseVector<VT1,true>& lhs,
const TSVecSMatMultExpr& rhs )
563 LT x(
serial( rhs.vec_ ) );
564 if( x.nonZeros() == 0UL )
return;
567 RT A(
serial( rhs.mat_ ) );
576 TSVecSMatMultExpr::selectSubAssignKernel( ~lhs, x, A );
595 template<
typename VT1
598 static inline void selectSubAssignKernel( VT1& y,
const VT2& x,
const MT1& A )
603 const VectorIterator vend( x.end() );
604 VectorIterator velem( x.begin() );
606 for( ; velem!=vend; ++velem )
608 const MatrixIterator mend( A.end( velem->index() ) );
609 MatrixIterator melem( A.begin( velem->index() ) );
611 for( ; melem!=mend; ++melem ) {
612 y[melem->index()] -= velem->value() * melem->value();
636 template<
typename VT1 >
637 friend inline void multAssign( DenseVector<VT1,true>& lhs,
const TSVecSMatMultExpr& rhs )
647 const ResultType tmp(
serial( rhs ) );
648 multAssign( ~lhs, tmp );
672 template<
typename VT1 >
673 friend inline typename EnableIf< UseSMPAssign<VT1> >::Type
685 if( x.nonZeros() == 0UL )
return;
721 template<
typename VT1 >
722 friend inline typename EnableIf< UseSMPAssign<VT1> >::Type
731 if( x.nonZeros() == 0UL )
return;
767 template<
typename VT1 >
768 friend inline typename EnableIf< UseSMPAssign<VT1> >::Type
777 if( x.nonZeros() == 0UL )
return;
813 template<
typename VT1 >
814 friend inline typename EnableIf< UseSMPAssign<VT1> >::Type
825 const ResultType tmp( rhs );
887 template<
typename T1
889 inline const typename DisableIf< IsMatMatMultExpr<T2>, TSVecSMatMultExpr<T1,T2> >::Type
894 if( (~vec).
size() != (~mat).
rows() ) {
924 template<
typename T1
927 inline const typename EnableIf< IsMatMatMultExpr<T2>,
typename MultExprTrait<T1,T2>::Type >::Type
949 template<
typename VT,
typename MT >
966 template<
typename VT,
typename MT,
bool AF >
971 typedef typename MultExprTrait< typename SubvectorExprTrait<const VT,AF>::Type
972 ,
typename SubmatrixExprTrait<const MT,AF>::Type >::Type Type;
#define BLAZE_THROW_INVALID_ARGUMENT(MESSAGE)
Macro for the emission of a std::invalid_argument exceptionThis macro encapsulates the default way of...
Definition: Exception.h:187
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
size_t nonZeros() const
Returns an estimation for the number of non-zero elements in the sparse vector.
Definition: TSVecSMatMultExpr.h:241
bool canAlias(const T *alias) const
Returns whether the expression can alias with the given address alias.
Definition: TSVecSMatMultExpr.h:273
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:7820
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:207
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:507
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:2588
Type ElementType
Type of the sparse matrix elements.
Definition: CompressedMatrix.h:259
BLAZE_ALWAYS_INLINE size_t rows(const Matrix< MT, SO > &matrix)
Returns the current number of rows of the matrix.
Definition: Matrix.h:308
const DMatSerialExpr< MT, SO > serial(const DenseMatrix< MT, SO > &dm)
Forces the serial evaluation of the given dense matrix expression dm.
Definition: DMatSerialExpr.h:721
MT::ResultType MRT
Result type of the right-hand side sparse matrix expression.
Definition: TSVecSMatMultExpr.h:104
Header file for the Computation base class.
Constraints on the storage order of matrix types.
RightOperand mat_
Right-hand side sparse matrix of the multiplication expression.
Definition: TSVecSMatMultExpr.h:303
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:117
bool isDefault(const DiagonalProxy< MT > &proxy)
Returns whether the represented element is in default state.
Definition: DiagonalProxy.h:547
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:261
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:251
ReturnType at(size_t index) const
Checked access to the vector elements.
Definition: TSVecSMatMultExpr.h:218
size_t size() const
Returns the current size/dimension of the vector.
Definition: TSVecSMatMultExpr.h:231
const Element * ConstIterator
Iterator over constant elements.
Definition: CompressedMatrix.h:2592
Expression object for sparse vector-sparse matrix multiplications.The TSVecSMatMultExpr class represe...
Definition: Forward.h:161
Header file for the IsMatMatMultExpr type trait class.
#define BLAZE_THROW_OUT_OF_RANGE(MESSAGE)
Macro for the emission of a std::out_of_range exceptionThis macro encapsulates the default way of Bla...
Definition: Exception.h:331
Header file for the Columns type trait.
bool canSMPAssign() const
Returns whether the expression can be used in SMP assignments.
Definition: TSVecSMatMultExpr.h:295
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
#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
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:302
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:261
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: RowMajorMatrix.h:79
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:138
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:285
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
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:118
#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:2583
#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:79
ReturnType operator[](size_t index) const
Subscript operator for the direct access to the vector elements.
Definition: TSVecSMatMultExpr.h:180
Header file for exception macros.
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
Constraint on the transpose flag of vector types.
Header file for the IsExpression type trait class.
Header file for the FunctionTrace class.