35 #ifndef _BLAZE_MATH_EXPRESSIONS_SMATSVECMULTEXPR_H_
36 #define _BLAZE_MATH_EXPRESSIONS_SMATSVECMULTEXPR_H_
97 class SMatSVecMultExpr :
public SparseVector< SMatSVecMultExpr<MT,VT>, false >
98 ,
private MatVecMultExpr
125 template<
typename T1 >
126 struct UseSMPAssign {
127 enum { value = ( evaluateMatrix || evaluateVector ) };
158 enum { smpAssignable = !evaluateMatrix && MT::smpAssignable &&
159 !evaluateVector && VT::smpAssignable };
191 if(
vec_.size() == 0UL )
201 MatrixIterator melem( A.begin(index) );
202 const MatrixIterator mend( A.end(index) );
203 if( melem == mend ) {
207 VectorIterator velem( x.begin() );
208 const VectorIterator vend( x.end() );
209 if( velem == vend ) {
214 if( melem->index() < velem->index() ) {
216 if( melem == mend )
break;
218 else if( velem->index() < melem->index() ) {
220 if( velem == vend )
break;
223 res = melem->value() * velem->value();
230 if( melem != mend && velem != vend )
233 if( melem->index() < velem->index() ) {
235 if( melem == mend )
break;
237 else if( velem->index() < melem->index() ) {
239 if( velem == vend )
break;
242 res += melem->value() * velem->value();
244 if( melem == mend )
break;
246 if( velem == vend )
break;
257 MatrixIterator melem( A.begin(index) );
258 const MatrixIterator mend( A.end(index) );
263 res = melem->value() *
vec_[melem->index()];
265 for( ; melem!=mend; ++melem ) {
266 res += melem->value() *
vec_[melem->index()];
275 VectorIterator velem( x.begin() );
276 const VectorIterator vend( x.end() );
281 res =
mat_(index,velem->index()) * velem->value();
283 for( ; velem!=vend; ++velem ) {
284 res +=
mat_(index,velem->index()) * velem->value();
291 for(
size_t j=1UL; j<
vec_.size(); ++j ) {
307 inline ReturnType
at(
size_t index )
const {
308 if( index >=
mat_.rows() ) {
311 return (*
this)[index];
361 template<
typename T >
363 return (
mat_.isAliased( alias ) ||
vec_.isAliased( alias ) );
373 template<
typename T >
375 return (
mat_.isAliased( alias ) ||
vec_.isAliased( alias ) );
385 return (
size() > SMP_SMATSVECMULT_THRESHOLD );
407 template<
typename VT1 >
418 RT x(
serial( rhs.vec_ ) );
419 if( x.nonZeros() == 0UL )
return;
422 LT A(
serial( rhs.mat_ ) );
431 SMatSVecMultExpr::selectAssignKernel( ~lhs, A, x );
450 template<
typename VT1
453 static inline void selectAssignKernel( VT1& y,
const MT1& A,
const VT2& x )
458 const VectorIterator vend( x.end() );
460 for(
size_t i=0UL; i<y.size(); ++i )
462 const MatrixIterator mend ( A.end(i) );
463 MatrixIterator melem( A.begin(i) );
465 if( melem == mend )
continue;
467 VectorIterator velem( x.begin() );
470 if( melem->index() < velem->index() ) {
472 if( melem == mend )
break;
474 else if( velem->index() < melem->index() ) {
476 if( velem == vend )
break;
479 y[i] = melem->value() * velem->value();
486 if( melem != mend && velem != vend )
489 if( melem->index() < velem->index() ) {
491 if( melem == mend )
break;
493 else if( velem->index() < melem->index() ) {
495 if( velem == vend )
break;
498 y[i] += melem->value() * velem->value();
500 if( melem == mend )
break;
502 if( velem == vend )
break;
523 template<
typename VT1 >
524 friend inline void assign( SparseVector<VT1,false>& lhs,
const SMatSVecMultExpr& rhs )
534 if( x.nonZeros() == 0UL )
return;
544 const VectorIterator vend( x.end() );
546 for(
size_t i=0UL; i<(~lhs).
size(); ++i )
548 const MatrixIterator mend ( A.end(i) );
549 MatrixIterator melem( A.begin(i) );
551 if( melem == mend )
continue;
553 VectorIterator velem( x.begin() );
558 if( melem->index() < velem->index() ) {
560 if( melem == mend )
break;
562 else if( velem->index() < melem->index() ) {
564 if( velem == vend )
break;
567 accu = melem->value() * velem->value();
574 if( melem != mend && velem != vend )
577 if( melem->index() < velem->index() ) {
579 if( melem == mend )
break;
581 else if( velem->index() < melem->index() ) {
583 if( velem == vend )
break;
586 accu += melem->value() * velem->value();
588 if( melem == mend )
break;
590 if( velem == vend )
break;
596 (~lhs).insert( i, accu );
614 template<
typename VT1 >
615 friend inline void addAssign( DenseVector<VT1,false>& lhs,
const SMatSVecMultExpr& rhs )
622 RT x(
serial( rhs.vec_ ) );
623 if( x.nonZeros() == 0UL )
return;
626 LT A(
serial( rhs.mat_ ) );
635 SMatSVecMultExpr::selectAddAssignKernel( ~lhs, A, x );
654 template<
typename VT1
657 static inline void selectAddAssignKernel( VT1& y,
const MT1& A,
const VT2& x )
662 const VectorIterator vend( x.end() );
664 for(
size_t i=0UL; i<y.size(); ++i )
666 const MatrixIterator mend ( A.end(i) );
667 MatrixIterator melem( A.begin(i) );
669 if( melem == mend )
continue;
671 VectorIterator velem( x.begin() );
674 if( melem->index() < velem->index() ) {
676 if( melem == mend )
break;
678 else if( velem->index() < melem->index() ) {
680 if( velem == vend )
break;
683 y[i] += melem->value() * velem->value();
685 if( melem == mend )
break;
687 if( velem == vend )
break;
711 template<
typename VT1 >
712 friend inline void subAssign( DenseVector<VT1,false>& lhs,
const SMatSVecMultExpr& rhs )
722 RT x(
serial( rhs.vec_ ) );
723 if( x.nonZeros() == 0UL )
return;
726 LT A(
serial( rhs.mat_ ) );
735 SMatSVecMultExpr::selectSubAssignKernel( ~lhs, A, x );
754 template<
typename VT1
757 static inline void selectSubAssignKernel( VT1& y,
const MT1& A,
const VT2& x )
762 const VectorIterator vend( x.end() );
764 for(
size_t i=0UL; i<y.size(); ++i )
766 const MatrixIterator mend ( A.end(i) );
767 MatrixIterator melem( A.begin(i) );
769 if( melem == mend )
continue;
771 VectorIterator velem( x.begin() );
774 if( melem->index() < velem->index() ) {
776 if( melem == mend )
break;
778 else if( velem->index() < melem->index() ) {
780 if( velem == vend )
break;
783 y[i] -= melem->value() * velem->value();
785 if( melem == mend )
break;
787 if( velem == vend )
break;
811 template<
typename VT1 >
812 friend inline void multAssign( DenseVector<VT1,false>& lhs,
const SMatSVecMultExpr& rhs )
822 const ResultType tmp(
serial( rhs ) );
823 multAssign( ~lhs, tmp );
846 template<
typename VT1 >
847 friend inline typename EnableIf< UseSMPAssign<VT1> >::Type
859 if( x.nonZeros() == 0UL )
return;
895 template<
typename VT1 >
896 friend inline typename EnableIf< UseSMPAssign<VT1> >::Type
905 if( x.nonZeros() == 0UL )
return;
941 template<
typename VT1 >
942 friend inline typename EnableIf< UseSMPAssign<VT1> >::Type
954 if( x.nonZeros() == 0UL )
return;
990 template<
typename VT1 >
991 friend inline typename EnableIf< UseSMPAssign<VT1> >::Type
1002 const ResultType tmp( rhs );
1065 template<
typename T1
1067 inline const typename DisableIf< Or< IsSymmetric<T1>, IsMatMatMultExpr<T1> >
1068 , SMatSVecMultExpr<T1,T2> >::Type
1105 template<
typename T1
1107 inline const typename EnableIf< IsSymmetric<T1>,
typename MultExprTrait<T1,T2>::Type >::Type
1108 operator*(
const SparseMatrix<T1,false>& mat,
const SparseVector<T2,false>& vec )
1118 return trans( ~mat ) * (~vec);
1138 template<
typename T1
1141 inline const typename EnableIf< IsMatMatMultExpr<T1>,
typename MultExprTrait<T1,T2>::Type >::Type
1142 operator*(
const SparseMatrix<T1,SO>& mat,
const SparseVector<T2,false>& vec )
1148 return (~mat).leftOperand() * ( (~mat).
rightOperand() * vec );
1164 template<
typename MT,
typename VT >
1181 template<
typename MT,
typename VT,
bool AF >
1186 typedef typename MultExprTrait< typename SubmatrixExprTrait<const MT,AF>::Type
1187 ,
typename SubvectorExprTrait<const VT,AF>::Type >::Type Type;
SelectType< IsExpression< VT >::value, const VT, const VT & >::Type RightOperand
Composite type of the right-hand side sparse vector expression.
Definition: SMatSVecMultExpr.h:147
#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
ReturnType at(size_t index) const
Checked access to the vector elements.
Definition: SMatSVecMultExpr.h:307
Compile time check whether the given type is a computational expression template.This type trait clas...
Definition: IsComputation.h:89
LeftOperand mat_
Left-hand side sparse matrix of the multiplication expression.
Definition: SMatSVecMultExpr.h:391
Header file for the Rows type trait.
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.
VT::CompositeType VCT
Composite type of the right-hand side sparse vector expression.
Definition: SMatSVecMultExpr.h:106
ResultType::ElementType ElementType
Resulting element type.
Definition: SMatSVecMultExpr.h:137
#define BLAZE_CONSTRAINT_MUST_BE_COLUMN_VECTOR_TYPE(T)
Constraint on the data type.In case the given data type T is not a column dense or sparse vector type...
Definition: ColumnVector.h:79
const ElementType ReturnType
Return type for expression template evaluations.
Definition: SMatSVecMultExpr.h:138
VT::ResultType VRT
Result type of the right-hand side sparse vector expression.
Definition: SMatSVecMultExpr.h:104
Efficient implementation of a compressed matrix.The CompressedMatrix class template is the represent...
Definition: CompressedMatrix.h:207
MultTrait< MRT, VRT >::Type ResultType
Result type for expression template evaluations.
Definition: SMatSVecMultExpr.h:135
void reset(const DiagonalProxy< MT > &proxy)
Resetting the represented element to the default initial values.
Definition: DiagonalProxy.h:507
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
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
Header file for the Computation base class.
Constraints on the storage order of matrix types.
Header file for the RequiresEvaluation type trait.
bool canAlias(const T *alias) const
Returns whether the expression can alias with the given address alias.
Definition: SMatSVecMultExpr.h:362
SelectType< evaluateVector, const VRT, VCT >::Type RT
Type for the assignment of the right-hand side sparse vector operand.
Definition: SMatSVecMultExpr.h:153
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
size_t size() const
Returns the current size/dimension of the vector.
Definition: SMatSVecMultExpr.h:320
Constraint on the data type.
Constraint on the transpose flag of vector types.
Constraint on the data type.
size_t nonZeros() const
Returns an estimation for the number of non-zero elements in the sparse vector.
Definition: SMatSVecMultExpr.h:330
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< evaluateMatrix, const MRT, MCT >::Type LT
Type for the assignment of the left-hand side sparse matrix operand.
Definition: SMatSVecMultExpr.h:150
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.
Header file for the IsSymmetric type trait.
Namespace of the Blaze C++ math library.
Definition: Blaze.h:57
Expression object for sparse matrix-sparse vector multiplications.The SMatSVecMultExpr class represen...
Definition: Forward.h:109
const Element * ConstIterator
Iterator over constant elements.
Definition: CompressedMatrix.h:2592
Header file for the Or class template.
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
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
ReturnType operator[](size_t index) const
Subscript operator for the direct access to the vector elements.
Definition: SMatSVecMultExpr.h:182
#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:126
#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
RightOperand rightOperand() const
Returns the right-hand side sparse vector operand.
Definition: SMatSVecMultExpr.h:350
#define BLAZE_CONSTRAINT_MUST_FORM_VALID_MATVECMULTEXPR(T1, T2)
Constraint on the data type.In case the given data types T1 and T2 do not form a valid matrix/vector ...
Definition: MatVecMultExpr.h:166
Header file for the SelectType class template.
Header file for all forward declarations for expression class templates.
Constraint on the data type.
SMatSVecMultExpr< MT, VT > This
Type of this SMatSVecMultExpr instance.
Definition: SMatSVecMultExpr.h:134
SMatSVecMultExpr(const MT &mat, const VT &vec)
Constructor for the SMatSVecMultExpr class.
Definition: SMatSVecMultExpr.h:168
Header file for the EnableIf class template.
MT::CompositeType MCT
Composite type of the left-hand side sparse matrix expression.
Definition: SMatSVecMultExpr.h:105
Header file for the serial shim.
ResultType::TransposeType TransposeType
Transpose type for expression template evaluations.
Definition: SMatSVecMultExpr.h:136
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
RightOperand vec_
Right-hand side sparse vector of the multiplication expression.
Definition: SMatSVecMultExpr.h:392
#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
bool canSMPAssign() const
Returns whether the expression can be used in SMP assignments.
Definition: SMatSVecMultExpr.h:384
Header file for the reset shim.
Header file for the isDefault shim.
Constraint on the data type.
const ResultType CompositeType
Data type for composite expression templates.
Definition: SMatSVecMultExpr.h:141
Header file for the RemoveReference type trait.
LeftOperand leftOperand() const
Returns the left-hand side sparse matrix operand.
Definition: SMatSVecMultExpr.h:340
const DMatTransExpr< MT,!SO > trans(const DenseMatrix< MT, SO > &dm)
Calculation of the transpose of the given dense matrix.
Definition: DMatTransExpr.h:944
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
MT::ResultType MRT
Result type of the left-hand side sparse matrix expression.
Definition: SMatSVecMultExpr.h:103
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
BLAZE_ALWAYS_INLINE size_t columns(const Matrix< MT, SO > &matrix)
Returns the current number of columns of the matrix.
Definition: Matrix.h:324
Header file for the SubvectorExprTrait class template.
bool isAliased(const T *alias) const
Returns whether the expression is aliased with the given address alias.
Definition: SMatSVecMultExpr.h:374
Constraint on the data type.
Header file for exception macros.
Header file for the MatVecMultExpr base class.
Constraint on the data type.
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.
SelectType< IsExpression< MT >::value, const MT, const MT & >::Type LeftOperand
Composite type of the left-hand side sparse matrix expression.
Definition: SMatSVecMultExpr.h:144