35 #ifndef _BLAZE_MATH_EXPRESSIONS_TSVECTSMATMULTEXPR_H_
36 #define _BLAZE_MATH_EXPRESSIONS_TSVECTSMATMULTEXPR_H_
94 class TSVecTSMatMultExpr :
public SparseVector< TSVecTSMatMultExpr<VT,MT>, true >
95 ,
private TVecMatMultExpr
122 template<
typename T1 >
123 struct UseSMPAssign {
124 enum { value = ( evaluateVector || evaluateMatrix ) };
153 enum { smpAssignable = !evaluateVector && VT::smpAssignable &&
154 !evaluateMatrix && MT::smpAssignable };
192 VectorIterator velem( x.begin() );
193 const VectorIterator vend( x.end() );
194 if( velem == vend ) {
199 MatrixIterator melem( A.begin(index) );
200 const MatrixIterator mend( A.end(index) );
201 if( melem == mend ) {
207 if( velem->index() < melem->index() ) {
209 if( velem == vend )
break;
211 else if( melem->index() < velem->index() ) {
213 if( melem == mend )
break;
216 res = velem->value() * melem->value();
223 if( melem != mend && velem != vend )
226 if( velem->index() < melem->index() ) {
228 if( velem == vend )
break;
230 else if( melem->index() < velem->index() ) {
232 if( melem == mend )
break;
235 res += velem->value() * melem->value();
237 if( velem == vend )
break;
239 if( melem == mend )
break;
255 inline ReturnType
at(
size_t index )
const {
256 if( index >=
mat_.columns() ) {
259 return (*
this)[index];
269 return mat_.columns();
279 return mat_.columns();
309 template<
typename T >
311 return (
vec_.isAliased( alias ) ||
mat_.isAliased( alias ) );
321 template<
typename T >
323 return (
vec_.isAliased( alias ) ||
mat_.isAliased( alias ) );
333 return (
size() > SMP_TSVECSMATMULT_THRESHOLD );
356 template<
typename VT1 >
367 LT x(
serial( rhs.vec_ ) );
368 if( x.nonZeros() == 0UL )
return;
371 RT A(
serial( rhs.mat_ ) );
380 TSVecTSMatMultExpr::selectAssignKernel( ~lhs, x, A );
399 template<
typename VT1
402 static inline void selectAssignKernel( VT1& y,
const VT2& x,
const MT1& A )
407 const VectorIterator vend( x.end() );
409 for(
size_t j=0UL; j<A.columns(); ++j )
411 const MatrixIterator mend ( A.end(j) );
412 MatrixIterator melem( A.begin(j) );
414 if( melem == mend )
continue;
416 VectorIterator velem( x.begin() );
419 if( velem->index() < melem->index() ) {
421 if( velem == vend )
break;
423 else if( melem->index() < velem->index() ) {
425 if( melem == mend )
break;
428 y[j] = velem->value() * melem->value();
435 if( velem != vend && melem != mend )
438 if( velem->index() < melem->index() ) {
440 if( velem == vend )
break;
442 else if( melem->index() < velem->index() ) {
444 if( melem == mend )
break;
447 y[j] += velem->value() * melem->value();
449 if( velem == vend )
break;
451 if( melem == mend )
break;
473 template<
typename VT1 >
474 friend inline void assign( SparseVector<VT1,true>& lhs,
const TSVecTSMatMultExpr& rhs )
484 LT x(
serial( rhs.vec_ ) );
485 if( x.nonZeros() == 0UL )
return;
488 RT A(
serial( rhs.mat_ ) );
498 const VectorIterator vend( x.end() );
500 for(
size_t j=0UL; j<A.columns(); ++j )
502 const MatrixIterator mend ( A.end(j) );
503 MatrixIterator melem( A.begin(j) );
505 if( melem == mend )
continue;
507 VectorIterator velem( x.begin() );
512 if( velem->index() < melem->index() ) {
514 if( velem == vend )
break;
516 else if( melem->index() < velem->index() ) {
518 if( melem == mend )
break;
521 accu = velem->value() * melem->value();
528 if( velem != vend && melem != mend )
531 if( velem->index() < melem->index() ) {
533 if( velem == vend )
break;
535 else if( melem->index() < velem->index() ) {
537 if( melem == mend )
break;
540 accu += velem->value() * melem->value();
542 if( velem == vend )
break;
544 if( melem == mend )
break;
550 (~lhs).insert( j, accu );
569 template<
typename VT1 >
570 friend inline void addAssign( DenseVector<VT1,true>& lhs,
const TSVecTSMatMultExpr& rhs )
577 LT x(
serial( rhs.vec_ ) );
578 if( x.nonZeros() == 0UL )
return;
581 RT A(
serial( rhs.mat_ ) );
590 TSVecTSMatMultExpr::selectAddAssignKernel( ~lhs, x, A );
609 template<
typename VT1
612 static inline void selectAddAssignKernel( VT1& y,
const VT2& x,
const MT1& A )
617 const VectorIterator vend( x.end() );
619 for(
size_t j=0UL; j<A.columns(); ++j )
621 const MatrixIterator mend ( A.end(j) );
622 MatrixIterator melem( A.begin(j) );
624 if( melem == mend )
continue;
626 VectorIterator velem( x.begin() );
629 if( velem->index() < melem->index() ) {
631 if( velem == vend )
break;
633 else if( melem->index() < velem->index() ) {
635 if( melem == mend )
break;
638 y[j] += velem->value() * melem->value();
640 if( velem == vend )
break;
642 if( melem == mend )
break;
667 template<
typename VT1 >
668 friend inline void subAssign( DenseVector<VT1,true>& lhs,
const TSVecTSMatMultExpr& rhs )
675 LT x(
serial( rhs.vec_ ) );
676 if( x.nonZeros() == 0UL )
return;
679 RT A(
serial( rhs.mat_ ) );
688 TSVecTSMatMultExpr::selectSubAssignKernel( ~lhs, x, A );
707 template<
typename VT1
710 static inline void selectSubAssignKernel( VT1& y,
const VT2& x,
const MT1& A )
715 const VectorIterator vend( x.end() );
717 for(
size_t j=0UL; j<A.columns(); ++j )
719 const MatrixIterator mend ( A.end(j) );
720 MatrixIterator melem( A.begin(j) );
722 if( melem == mend )
continue;
724 VectorIterator velem( x.begin() );
727 if( velem->index() < melem->index() ) {
729 if( velem == vend )
break;
731 else if( melem->index() < velem->index() ) {
733 if( melem == mend )
break;
736 y[j] -= velem->value() * melem->value();
738 if( velem == vend )
break;
740 if( melem == mend )
break;
765 template<
typename VT1 >
766 friend inline void multAssign( DenseVector<VT1,true>& lhs,
const TSVecTSMatMultExpr& rhs )
776 const ResultType tmp(
serial( rhs ) );
777 multAssign( ~lhs, tmp );
801 template<
typename VT1 >
802 friend inline typename EnableIf< UseSMPAssign<VT1> >::Type
814 if( x.nonZeros() == 0UL )
return;
850 template<
typename VT1 >
851 friend inline typename EnableIf< UseSMPAssign<VT1> >::Type
860 if( x.nonZeros() == 0UL )
return;
896 template<
typename VT1 >
897 friend inline typename EnableIf< UseSMPAssign<VT1> >::Type
906 if( x.nonZeros() == 0UL )
return;
942 template<
typename VT1 >
943 friend inline typename EnableIf< UseSMPAssign<VT1> >::Type
954 const ResultType tmp( rhs );
1017 template<
typename T1
1019 inline const typename DisableIf< Or< IsSymmetric<T2>, IsMatMatMultExpr<T2> >
1020 , TSVecTSMatMultExpr<T1,T2> >::Type
1025 if( (~vec).
size() != (~mat).
rows() ) {
1057 template<
typename T1
1059 inline const typename EnableIf< IsSymmetric<T2>,
typename MultExprTrait<T1,T2>::Type >::Type
1060 operator*(
const SparseVector<T1,true>& vec,
const SparseMatrix<T2,true>& mat )
1066 if( (~vec).
size() != (~mat).
rows() ) {
1070 return (~vec) *
trans( ~mat );
1086 template<
typename VT,
typename MT >
1103 template<
typename VT,
typename MT,
bool AF >
1108 typedef typename MultExprTrait< typename SubvectorExprTrait<const VT,AF>::Type
1109 ,
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
bool canAlias(const T *alias) const
Returns whether the expression can alias with the given address alias.
Definition: TSVecTSMatMultExpr.h:310
Compile time check whether the given type is a computational expression template.This type trait clas...
Definition: IsComputation.h:89
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.
MT::CompositeType MCT
Composite type of the right-hand side sparse matrix expression.
Definition: TSVecTSMatMultExpr.h:103
Header file for the SparseVector base class.
bool canSMPAssign() const
Returns whether the expression can be used in SMP assignments.
Definition: TSVecTSMatMultExpr.h:332
ResultType::TransposeType TransposeType
Transpose type for expression template evaluations.
Definition: TSVecTSMatMultExpr.h:133
Efficient implementation of a compressed matrix.The CompressedMatrix class template is the represent...
Definition: CompressedMatrix.h:207
const ElementType ReturnType
Return type for expression template evaluations.
Definition: TSVecTSMatMultExpr.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
ResultType::ElementType ElementType
Resulting element type.
Definition: TSVecTSMatMultExpr.h:134
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
Header file for the Computation base class.
size_t nonZeros() const
Returns an estimation for the number of non-zero elements in the sparse vector.
Definition: TSVecTSMatMultExpr.h:278
Header file for the RequiresEvaluation type trait.
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.
Constraint on the data type.
Compile time check to query the requirement to evaluate an expression.Via this type trait it is possi...
Definition: RequiresEvaluation.h:90
MT::ResultType MRT
Result type of the right-hand side sparse matrix expression.
Definition: TSVecTSMatMultExpr.h:101
const This & CompositeType
Data type for composite expression templates.
Definition: CompressedMatrix.h:261
TSVecTSMatMultExpr(const VT &vec, const MT &mat)
Constructor for the TSVecTSMatMultExpr class.
Definition: TSVecTSMatMultExpr.h:163
RightOperand mat_
Right-hand side sparse matrix of the multiplication expression.
Definition: TSVecTSMatMultExpr.h:340
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
#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:79
const Element * ConstIterator
Iterator over constant elements.
Definition: CompressedMatrix.h:2592
Expression object for sparse vector-sparse matrix multiplications.The TSVecTSMatMultExpr class repres...
Definition: Forward.h:163
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
Header file for the Columns type trait.
LeftOperand vec_
Left-hand side sparse vector of the multiplication expression.
Definition: TSVecTSMatMultExpr.h:339
Base class for N-dimensional dense vectors.The DenseVector class is a base class for all arbitrarily ...
Definition: DenseVector.h:70
MultTrait< VRT, MRT >::Type ResultType
Result type for expression template evaluations.
Definition: TSVecTSMatMultExpr.h:132
#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
SelectType< evaluateMatrix, const MRT, MCT >::Type RT
Type for the assignment of the right-hand side sparse matrix operand.
Definition: TSVecTSMatMultExpr.h:148
#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
const ResultType CompositeType
Data type for composite expression templates.
Definition: TSVecTSMatMultExpr.h:136
Header file for the SelectType class template.
Header file for all forward declarations for expression class templates.
Constraint on the data type.
TSVecTSMatMultExpr< VT, MT > This
Type of this TSVecTSMatMultExpr instance.
Definition: TSVecTSMatMultExpr.h:131
Header file for the EnableIf class template.
Header file for the serial shim.
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
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 isAliased(const T *alias) const
Returns whether the expression is aliased with the given address alias.
Definition: TSVecTSMatMultExpr.h:322
Header file for the reset shim.
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:142
Header file for the isDefault shim.
Header file for the TVecMatMultExpr base class.
Constraints on the storage order of matrix types.
Header file for the RemoveReference type trait.
SelectType< evaluateVector, const VRT, VCT >::Type LT
Type for the assignment of the left-hand side sparse vector operand.
Definition: TSVecTSMatMultExpr.h:145
#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
LeftOperand leftOperand() const
Returns the left-hand side sparse vector operand.
Definition: TSVecTSMatMultExpr.h:288
VT::CompositeType VCT
Composite type of the left-hand side sparse vector expression.
Definition: TSVecTSMatMultExpr.h:102
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
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
Header file for exception macros.
SelectType< IsExpression< VT >::value, const VT, const VT & >::Type LeftOperand
Composite type of the left-hand side sparse vector expression.
Definition: TSVecTSMatMultExpr.h:139
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.
ReturnType at(size_t index) const
Checked access to the vector elements.
Definition: TSVecTSMatMultExpr.h:255
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
ReturnType operator[](size_t index) const
Subscript operator for the direct access to the vector elements.
Definition: TSVecTSMatMultExpr.h:177
Constraint on the transpose flag of vector types.
Header file for the IsExpression type trait class.
size_t size() const
Returns the current size/dimension of the vector.
Definition: TSVecTSMatMultExpr.h:268
Header file for the FunctionTrace class.
RightOperand rightOperand() const
Returns the right-hand side transpose sparse matrix operand.
Definition: TSVecTSMatMultExpr.h:298
VT::ResultType VRT
Result type of the left-hand side sparse vector expression.
Definition: TSVecTSMatMultExpr.h:100