35 #ifndef _BLAZE_MATH_EXPRESSIONS_TDMATSVECMULTEXPR_H_
36 #define _BLAZE_MATH_EXPRESSIONS_TDMATSVECMULTEXPR_H_
91 class TDMatSVecMultExpr :
public DenseVector< TDMatSVecMultExpr<MT,VT>, false >
92 ,
private MatVecMultExpr
122 template<
typename T1,
typename T2,
typename T3 >
123 struct UseVectorizedKernel {
124 enum { value = T1::vectorizable && T2::vectorizable &&
125 IsSame<typename T1::ElementType,typename T2::ElementType>::value &&
126 IsSame<typename T1::ElementType,typename T3::ElementType>::value &&
127 IntrinsicTrait<typename T1::ElementType>::addition &&
128 IntrinsicTrait<typename T1::ElementType>::multiplication };
139 template<
typename T1,
typename T2,
typename T3 >
140 struct UseOptimizedKernel {
141 enum { value = !UseVectorizedKernel<T1,T2,T3>::value &&
142 !IsResizable<typename T1::ElementType>::value &&
143 !IsResizable<VET>::value };
153 template<
typename T1,
typename T2,
typename T3 >
154 struct UseDefaultKernel {
155 enum { value = !UseVectorizedKernel<T1,T2,T3>::value &&
156 !UseOptimizedKernel<T1,T2,T3>::value };
186 enum { vectorizable = 0 };
189 enum { smpAssignable = 0 };
221 ConstIterator element( x.begin() );
224 if( element != x.end() ) {
225 res =
mat_( index, element->index() ) * element->value();
227 for( ; element!=x.end(); ++element ) {
228 res +=
mat_( index, element->index() ) * element->value();
275 template<
typename T >
277 return mat_.isAliased( alias ) ||
vec_.isAliased( alias );
287 template<
typename T >
289 return mat_.isAliased( alias ) ||
vec_.isAliased( alias );
312 template<
typename VT1 >
321 if( x.nonZeros() == 0UL ) {
336 TDMatSVecMultExpr::selectAssignKernel( ~lhs, A, x );
355 template<
typename VT1
359 selectAssignKernel( VT1& y,
const MT1& A,
const VT2& x )
365 const size_t M( A.rows() );
367 ConstIterator element( x.begin() );
368 const ConstIterator end( x.end() );
370 for(
size_t i=0UL; i<M; ++i ) {
371 y[i] = A(i,element->index()) * element->value();
376 for( ; element!=end; ++element ) {
377 for(
size_t i=0UL; i<M; ++i ) {
378 y[i] += A(i,element->index()) * element->value();
399 template<
typename VT1
402 static inline typename EnableIf< UseOptimizedKernel<VT1,MT1,VT2> >::Type
403 selectAssignKernel( VT1& y,
const MT1& A,
const VT2& x )
409 const size_t M( A.rows() );
411 ConstIterator element( x.begin() );
412 const ConstIterator end( x.end() );
414 const size_t jend( x.nonZeros() & size_t(-4) );
415 BLAZE_INTERNAL_ASSERT( ( x.nonZeros() - ( x.nonZeros() % 4UL ) ) == jend,
"Invalid end calculation" );
419 const size_t j1( element->index() );
420 const VET v1( element->value() );
422 const size_t j2( element->index() );
423 const VET v2( element->value() );
425 const size_t j3( element->index() );
426 const VET v3( element->value() );
428 const size_t j4( element->index() );
429 const VET v4( element->value() );
432 for(
size_t i=0UL; i<M; ++i ) {
433 y[i] = A(i,j1) * v1 + A(i,j2) * v2 + A(i,j3) * v3 + A(i,j4) * v4;
438 const size_t j1( element->index() );
439 const VET v1( element->value() );
442 for(
size_t i=0UL; i<M; ++i ) {
447 for(
size_t j=(jend>3UL)?(4UL):(1UL); (j+4UL)<=jend; j+=4UL )
449 const size_t j1( element->index() );
450 const VET v1( element->value() );
452 const size_t j2( element->index() );
453 const VET v2( element->value() );
455 const size_t j3( element->index() );
456 const VET v3( element->value() );
458 const size_t j4( element->index() );
459 const VET v4( element->value() );
462 for(
size_t i=0UL; i<M; ++i ) {
463 y[i] += A(i,j1) * v1 + A(i,j2) * v2 + A(i,j3) * v3 + A(i,j4) * v4;
466 for( ; element!=end; ++element )
468 const size_t j1( element->index() );
469 const VET v1( element->value() );
471 for(
size_t i=0UL; i<M; ++i ) {
472 y[i] += A(i,j1) * v1;
493 template<
typename VT1
496 static inline typename EnableIf< UseVectorizedKernel<VT1,MT1,VT2> >::Type
497 selectAssignKernel( VT1& y,
const MT1& A,
const VT2& x )
499 typedef IntrinsicTrait<ElementType> IT;
504 const size_t M( A.rows() );
506 ConstIterator element( x.begin() );
507 const ConstIterator end( x.end() );
509 const size_t jend( x.nonZeros() & size_t(-4) );
510 BLAZE_INTERNAL_ASSERT( ( x.nonZeros() - ( x.nonZeros() % 4UL ) ) == jend,
"Invalid end calculation" );
514 const size_t j1( element->index() );
517 const size_t j2( element->index() );
520 const size_t j3( element->index() );
523 const size_t j4( element->index() );
527 for(
size_t i=0UL; i<M; i+=IT::size ) {
528 y.store( i, A.load(i,j1) * v1 + A.load(i,j2) * v2 + A.load(i,j3) * v3 + A.load(i,j4) * v4 );
533 const size_t j1( element->index() );
537 for(
size_t i=0UL; i<M; i+=IT::size ) {
538 y.store( i, A.load(i,j1) * v1 );
542 for(
size_t j=(jend>3UL)?(4UL):(1UL); (j+4UL)<=jend; j+=4UL )
544 const size_t j1( element->index() );
547 const size_t j2( element->index() );
550 const size_t j3( element->index() );
553 const size_t j4( element->index() );
557 for(
size_t i=0UL; i<M; i+=IT::size ) {
558 y.store( i, y.load(i) + A.load(i,j1) * v1 + A.load(i,j2) * v2 + A.load(i,j3) * v3 + A.load(i,j4) * v4 );
561 for( ; element!=end; ++element )
563 const size_t j1( element->index() );
566 for(
size_t i=0UL; i<M; i+=IT::size ) {
567 y.store( i, y.load(i) + A.load(i,j1) * v1 );
587 template<
typename VT1 >
617 template<
typename VT1 >
628 if( x.nonZeros() == 0UL )
return;
640 TDMatSVecMultExpr::selectAddAssignKernel( ~lhs, A, x );
659 template<
typename VT1
662 static inline typename EnableIf< UseDefaultKernel<VT1,MT1,VT2> >::Type
663 selectAddAssignKernel( VT1& y,
const MT1& A,
const VT2& x )
669 const size_t M( A.rows() );
671 ConstIterator element( x.begin() );
672 const ConstIterator end( x.end() );
674 for( ; element!=end; ++element ) {
675 for(
size_t i=0UL; i<M; ++i ) {
676 y[i] += A(i,element->index()) * element->value();
697 template<
typename VT1
700 static inline typename EnableIf< UseOptimizedKernel<VT1,MT1,VT2> >::Type
701 selectAddAssignKernel( VT1& y,
const MT1& A,
const VT2& x )
707 const size_t M( A.rows() );
709 ConstIterator element( x.begin() );
710 const ConstIterator end( x.end() );
712 const size_t jend( x.nonZeros() & size_t(-4) );
713 BLAZE_INTERNAL_ASSERT( ( x.nonZeros() - ( x.nonZeros() % 4UL ) ) == jend,
"Invalid end calculation" );
715 for(
size_t j=0UL; (j+4UL)<=jend; j+=4UL )
717 const size_t j1( element->index() );
718 const VET v1( element->value() );
720 const size_t j2( element->index() );
721 const VET v2( element->value() );
723 const size_t j3( element->index() );
724 const VET v3( element->value() );
726 const size_t j4( element->index() );
727 const VET v4( element->value() );
730 for(
size_t i=0UL; i<M; ++i ) {
731 y[i] += A(i,j1) * v1 + A(i,j2) * v2 + A(i,j3) * v3 + A(i,j4) * v4;
734 for( ; element!=end; ++element )
736 const size_t j1( element->index() );
737 const VET v1( element->value() );
739 for(
size_t i=0UL; i<M; ++i ) {
740 y[i] += A(i,j1) * v1;
761 template<
typename VT1
764 static inline typename EnableIf< UseVectorizedKernel<VT1,MT1,VT2> >::Type
765 selectAddAssignKernel( VT1& y,
const MT1& A,
const VT2& x )
767 typedef IntrinsicTrait<ElementType> IT;
772 const size_t M( A.rows() );
774 ConstIterator element( x.begin() );
775 const ConstIterator end( x.end() );
777 const size_t jend( x.nonZeros() & size_t(-4) );
778 BLAZE_INTERNAL_ASSERT( ( x.nonZeros() - ( x.nonZeros() % 4UL ) ) == jend,
"Invalid end calculation" );
780 for(
size_t j=0UL; (j+4UL)<=jend; j+=4UL )
782 const size_t j1( element->index() );
785 const size_t j2( element->index() );
788 const size_t j3( element->index() );
791 const size_t j4( element->index() );
795 for(
size_t i=0UL; i<M; i+=IT::size ) {
796 y.store( i, y.load(i) + A.load(i,j1) * v1 + A.load(i,j2) * v2 + A.load(i,j3) * v3 + A.load(i,j4) * v4 );
799 for( ; element!=end; ++element )
801 const size_t j1( element->index() );
804 for(
size_t i=0UL; i<M; i+=IT::size ) {
805 y.store( i, y.load(i) + A.load(i,j1) * v1 );
829 template<
typename VT1 >
840 if( x.nonZeros() == 0UL )
return;
852 TDMatSVecMultExpr::selectSubAssignKernel( ~lhs, A, x );
871 template<
typename VT1
874 static inline typename EnableIf< UseDefaultKernel<VT1,MT1,VT2> >::Type
875 selectSubAssignKernel( VT1& y,
const MT1& A,
const VT2& x )
881 const size_t M( A.rows() );
883 ConstIterator element( x.begin() );
884 const ConstIterator end( x.end() );
886 for( ; element!=end; ++element ) {
887 for(
size_t i=0UL; i<M; ++i ) {
888 y[i] -= A(i,element->index()) * element->value();
909 template<
typename VT1
912 static inline typename EnableIf< UseOptimizedKernel<VT1,MT1,VT2> >::Type
913 selectSubAssignKernel( VT1& y,
const MT1& A,
const VT2& x )
919 const size_t M( A.rows() );
921 ConstIterator element( x.begin() );
922 const ConstIterator end( x.end() );
924 const size_t jend( x.nonZeros() & size_t(-4) );
925 BLAZE_INTERNAL_ASSERT( ( x.nonZeros() - ( x.nonZeros() % 4UL ) ) == jend,
"Invalid end calculation" );
927 for(
size_t j=0UL; (j+4UL)<=jend; j+=4UL )
929 const size_t j1( element->index() );
930 const VET v1( element->value() );
932 const size_t j2( element->index() );
933 const VET v2( element->value() );
935 const size_t j3( element->index() );
936 const VET v3( element->value() );
938 const size_t j4( element->index() );
939 const VET v4( element->value() );
942 for(
size_t i=0UL; i<M; ++i ) {
943 y[i] -= A(i,j1) * v1 + A(i,j2) * v2 + A(i,j3) * v3 + A(i,j4) * v4;
946 for( ; element!=end; ++element )
948 const size_t j1( element->index() );
949 const VET v1( element->value() );
951 for(
size_t i=0UL; i<M; ++i ) {
952 y[i] -= A(i,j1) * v1;
973 template<
typename VT1
976 static inline typename EnableIf< UseVectorizedKernel<VT1,MT1,VT2> >::Type
977 selectSubAssignKernel( VT1& y,
const MT1& A,
const VT2& x )
979 typedef IntrinsicTrait<ElementType> IT;
984 const size_t M( A.rows() );
986 ConstIterator element( x.begin() );
987 const ConstIterator end( x.end() );
989 const size_t jend( x.nonZeros() & size_t(-4) );
990 BLAZE_INTERNAL_ASSERT( ( x.nonZeros() - ( x.nonZeros() % 4UL ) ) == jend,
"Invalid end calculation" );
992 for(
size_t j=0UL; (j+4UL)<=jend; j+=4UL )
994 const size_t j1( element->index() );
997 const size_t j2( element->index() );
1000 const size_t j3( element->index() );
1003 const size_t j4( element->index() );
1007 for(
size_t i=0UL; i<M; i+=IT::size ) {
1008 y.store( i, y.load(i) - A.load(i,j1) * v1 - A.load(i,j2) * v2 - A.load(i,j3) * v3 - A.load(i,j4) * v4 );
1011 for( ; element!=end; ++element )
1013 const size_t j1( element->index() );
1016 for(
size_t i=0UL; i<M; i+=IT::size ) {
1017 y.store( i, y.load(i) - A.load(i,j1) * v1 );
1041 template<
typename VT1 >
1114 template<
typename T1
1116 inline const typename DisableIf< IsMatMatMultExpr<T1>, TDMatSVecMultExpr<T1,T2> >::Type
1121 if( (~mat).
columns() != (~vec).size() )
1122 throw std::invalid_argument(
"Matrix and vector sizes do not match" );
1139 template<
typename MT,
typename VT >
1140 struct SubvectorExprTrait< TDMatSVecMultExpr<MT,VT> >
1144 typedef typename MultExprTrait< typename SubmatrixExprTrait<const MT>::Type, VT >::Type Type;
ResultType::ElementType ElementType
Resulting element type.
Definition: TDMatSVecMultExpr.h:166
Compile time check whether the given type is a computational expression template.This type trait clas...
Definition: IsComputation.h:89
size_t size() const
Returns the current size/dimension of the vector.
Definition: TDMatSVecMultExpr.h:244
void reset(DynamicMatrix< Type, SO > &m)
Resetting the given dense matrix.
Definition: DynamicMatrix.h:4512
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:3703
VT::ResultType VRT
Result type of the right-hand side sparse vector expression.
Definition: TDMatSVecMultExpr.h:98
#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: TransposeFlag.h:159
Efficient implementation of a compressed matrix.The CompressedMatrix class template is the represent...
Definition: CompressedMatrix.h:196
#define BLAZE_CONSTRAINT_MUST_BE_DENSE_MATRIX_TYPE(T)
Constraint on the data type.In case the given data type T is not a dense, N-dimensional matrix type...
Definition: DenseMatrix.h:79
RightOperand vec_
Right-hand side sparse vector of the multiplication expression.
Definition: TDMatSVecMultExpr.h:296
Header file for the IsSame and IsStrictlySame type traits.
VRT::ElementType VET
Element type of the right-hand side sparse vector expression.
Definition: TDMatSVecMultExpr.h:100
const This & CompositeType
Data type for composite expression templates.
Definition: CompressedMatrix.h:2375
Type ElementType
Type of the sparse matrix elements.
Definition: CompressedMatrix.h:248
Header file for the DenseVector base class.
MRT::ElementType MET
Element type of the left-hand side dense matrix expression.
Definition: TDMatSVecMultExpr.h:99
TDMatSVecMultExpr< MT, VT > This
Type of this TDMatSVecMultExpr instance.
Definition: TDMatSVecMultExpr.h:163
MultTrait< MRT, VRT >::Type ResultType
Result type for expression template evaluations.
Definition: TDMatSVecMultExpr.h:164
Header file for the Computation base class.
Type relationship analysis.This class tests if the two data types A and B are equal. For this type comparison, the cv-qualifiers of both data types are ignored. If A and B are the same data type (ignoring the cv-qualifiers), then the value member enumeration is set to 1, the nested type definition Type is TrueType, and the class derives from TrueType. Otherwise value is set to 0, Type is FalseType, and the class derives from FalseType.
Definition: IsSame.h:158
Header file for the RequiresEvaluation type trait.
Base class for dense matrices.The DenseMatrix class is a base class for all dense matrix classes...
Definition: DenseMatrix.h:70
SelectType< IsExpression< VT >::value, const VT, const VT & >::Type RightOperand
Composite type of the right-hand side dense vector expression.
Definition: TDMatSVecMultExpr.h:175
Constraint on the data type.
ReturnType operator[](size_t index) const
Subscript operator for the direct access to the vector elements.
Definition: TDMatSVecMultExpr.h:212
bool isAliased(const T *alias) const
Returns whether the expression is aliased with the given address alias.
Definition: TDMatSVecMultExpr.h:288
Constraint on the data type.
Header file for the MultExprTrait class template.
const This & CompositeType
Data type for composite expression templates.
Definition: CompressedMatrix.h:250
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.
const ElementType ReturnType
Return type for expression template evaluations.
Definition: TDMatSVecMultExpr.h:168
#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:2379
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
LeftOperand mat_
Left-hand side dense matrix of the multiplication expression.
Definition: TDMatSVecMultExpr.h:295
Base class for N-dimensional dense vectors.The DenseVector class is a base class for all arbitrarily ...
Definition: DenseVector.h:70
IntrinsicTrait< ElementType >::Type IntrinsicType
Resulting intrinsic element type.
Definition: TDMatSVecMultExpr.h:167
#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
const ResultType CompositeType
Data type for composite expression templates.
Definition: TDMatSVecMultExpr.h:169
Constraints on the storage order of matrix types.
Constraint on the data type.
TDMatSVecMultExpr(const MT &mat, const VT &vec)
Constructor for the TDMatSVecMultExpr class.
Definition: TDMatSVecMultExpr.h:198
Type ElementType
Type of the sparse matrix elements.
Definition: CompressedMatrix.h:2373
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< evaluateVector, const VRT, typename VT::CompositeType >::Type RT
Type for the assignment of the right-hand side dense matrix operand.
Definition: TDMatSVecMultExpr.h:181
Expression object for transpose dense matrix-sparse vector multiplications.The TDMatSVecMultExpr clas...
Definition: Forward.h:126
Header file for the SubmatrixExprTrait class template.
Removal of reference modifiers.The RemoveCV type trait removes any reference modifiers from the given...
Definition: RemoveReference.h:69
Intrinsic characteristics of data types.The IntrinsicTrait class template provides the intrinsic char...
Definition: IntrinsicTrait.h:648
LeftOperand leftOperand() const
Returns the left-hand side transpose dense matrix operand.
Definition: TDMatSVecMultExpr.h:254
Header file for run time assertion macros.
Base template for the MultTrait class.
Definition: MultTrait.h:141
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
Substitution Failure Is Not An Error (SFINAE) class.The EnableIf class template is an auxiliary tool ...
Definition: EnableIf.h:184
VT::CompositeType VCT
Composite type of the right-hand side sparse vector expression.
Definition: TDMatSVecMultExpr.h:102
Header file for the reset shim.
Compile time check for data types.This type trait tests whether or not the given template parameter i...
Definition: IsBlasCompatible.h:99
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
MT::ResultType MRT
Result type of the left-hand side dense matrix expression.
Definition: TDMatSVecMultExpr.h:97
SelectType< evaluateMatrix, const MRT, MCT >::Type LT
Type for the assignment of the left-hand side dense matrix operand.
Definition: TDMatSVecMultExpr.h:178
Header file for the RemoveReference type trait.
bool canAlias(const T *alias) const
Returns whether the expression can alias with the given address alias.
Definition: TDMatSVecMultExpr.h:276
Header file for all intrinsic functionality.
#define BLAZE_CONSTRAINT_MUST_BE_DENSE_VECTOR_TYPE(T)
Constraint on the data type.In case the given data type T is not a dense, N-dimensional vector type...
Definition: DenseVector.h:79
RightOperand rightOperand() const
Returns the right-hand side sparse vector operand.
Definition: TDMatSVecMultExpr.h:264
Header file for the IsComputation type trait class.
ResultType::TransposeType TransposeType
Transpose type for expression template evaluations.
Definition: TDMatSVecMultExpr.h:165
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
This ResultType
Result type for expression template evaluations.
Definition: CompressedMatrix.h:2370
size_t columns(const Matrix< MT, SO > &m)
Returns the current number of columns of the matrix.
Definition: Matrix.h:154
Header file for basic type definitions.
Header file for the SubvectorExprTrait class template.
Header file for the MatVecMultExpr base class.
SelectType< IsExpression< MT >::value, const MT, const MT & >::Type LeftOperand
Composite type of the left-hand side dense matrix expression.
Definition: TDMatSVecMultExpr.h:172
Header file for the IsResizable type trait.
#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
EnableIf< IsIntegral< T >, Set< T, sizeof(T)> >::Type::Type set(T value)
Sets all values in the vector to the given integral value.
Definition: Set.h:209
MT::CompositeType MCT
Composite type of the left-hand side dense matrix expression.
Definition: TDMatSVecMultExpr.h:101
Header file for the IsExpression type trait class.
Header file for the FunctionTrace class.