35 #ifndef _BLAZE_MATH_EXPRESSIONS_TSVECDMATMULTEXPR_H_
36 #define _BLAZE_MATH_EXPRESSIONS_TSVECDMATMULTEXPR_H_
92 class TSVecDMatMultExpr :
public DenseVector< TSVecDMatMultExpr<VT,MT>, true >
93 ,
private TVecMatMultExpr
123 template<
typename T1,
typename T2,
typename T3 >
124 struct UseVectorizedKernel {
125 enum { value = T1::vectorizable && T3::vectorizable &&
126 IsSame<typename T1::ElementType,typename T2::ElementType>::value &&
127 IsSame<typename T1::ElementType,typename T3::ElementType>::value &&
128 IntrinsicTrait<typename T1::ElementType>::addition &&
129 IntrinsicTrait<typename T1::ElementType>::multiplication };
140 template<
typename T1,
typename T2,
typename T3 >
141 struct UseOptimizedKernel {
142 enum { value = !UseVectorizedKernel<T1,T2,T3>::value &&
143 !IsResizable<typename T1::ElementType>::value &&
144 !IsResizable<VET>::value };
154 template<
typename T1,
typename T2,
typename T3 >
155 struct UseDefaultKernel {
156 enum { value = !UseVectorizedKernel<T1,T2,T3>::value &&
157 !UseOptimizedKernel<T1,T2,T3>::value };
187 enum { vectorizable = 0 };
190 enum { smpAssignable = 0 };
222 const ConstIterator end( x.end() );
223 ConstIterator element( x.begin() );
226 if( element != end ) {
227 res = element->value() *
mat_( element->index(), index );
229 for( ; element!=end; ++element )
230 res += element->value() *
mat_( element->index(), index );
246 return mat_.columns();
276 template<
typename T >
278 return vec_.isAliased( alias ) ||
mat_.isAliased( alias );
288 template<
typename T >
290 return vec_.isAliased( alias ) ||
mat_.isAliased( alias );
313 template<
typename VT2 >
322 if( x.nonZeros() == 0UL ) {
337 TSVecDMatMultExpr::selectAssignKernel( ~lhs, x, A );
356 template<
typename VT1
360 selectAssignKernel( VT1& y,
const VT2& x,
const MT1& A )
366 const size_t N( A.columns() );
368 ConstIterator element( x.begin() );
369 const ConstIterator end( x.end() );
371 for(
size_t j=0UL; j<N; ++j ) {
372 y[j] = element->value() * A(element->index(),j);
377 for( ; element!=end; ++element ) {
378 for(
size_t j=0UL; j<N; ++j ) {
379 y[j] += element->value() * A(element->index(),j);
400 template<
typename VT1
403 static inline typename EnableIf< UseOptimizedKernel<VT1,VT2,MT1> >::Type
404 selectAssignKernel( VT1& y,
const VT2& x,
const MT1& A )
410 const size_t N( A.columns() );
412 ConstIterator element( x.begin() );
413 const ConstIterator end( x.end() );
415 const size_t iend( x.nonZeros() & size_t(-4) );
416 BLAZE_INTERNAL_ASSERT( ( x.nonZeros() - ( x.nonZeros() % 4UL ) ) == iend,
"Invalid end calculation" );
420 const size_t i1( element->index() );
421 const VET v1( element->value() );
423 const size_t i2( element->index() );
424 const VET v2( element->value() );
426 const size_t i3( element->index() );
427 const VET v3( element->value() );
429 const size_t i4( element->index() );
430 const VET v4( element->value() );
433 for(
size_t j=0UL; j<N; ++j ) {
434 y[j] = v1 * A(i1,j) + v2 * A(i2,j) + v3 * A(i3,j) + v4 * A(i4,j);
439 const size_t i1( element->index() );
440 const VET v1( element->value() );
443 for(
size_t j=0UL; j<N; ++j ) {
448 for(
size_t i=(iend>3UL)?(4UL):(1UL); (i+4UL)<=iend; i+=4UL )
450 const size_t i1( element->index() );
451 const VET v1( element->value() );
453 const size_t i2( element->index() );
454 const VET v2( element->value() );
456 const size_t i3( element->index() );
457 const VET v3( element->value() );
459 const size_t i4( element->index() );
460 const VET v4( element->value() );
463 for(
size_t j=0UL; j<N; ++j ) {
464 y[j] += v1 * A(i1,j) + v2 * A(i2,j) + v3 * A(i3,j) + v4 * A(i4,j);
467 for( ; element!=end; ++element )
469 const size_t i1( element->index() );
470 const VET v1( element->value() );
472 for(
size_t j=0UL; j<N; ++j ) {
473 y[j] += v1 * A(i1,j);
494 template<
typename VT1
497 static inline typename EnableIf< UseVectorizedKernel<VT1,VT2,MT1> >::Type
498 selectAssignKernel( VT1& y,
const VT2& x,
const MT1& A )
500 typedef IntrinsicTrait<ElementType> IT;
505 const size_t N( A.columns() );
507 ConstIterator element( x.begin() );
508 const ConstIterator end( x.end() );
510 const size_t iend( x.nonZeros() & size_t(-4) );
511 BLAZE_INTERNAL_ASSERT( ( x.nonZeros() - ( x.nonZeros() % 4UL ) ) == iend,
"Invalid end calculation" );
515 const size_t i1( element->index() );
518 const size_t i2( element->index() );
521 const size_t i3( element->index() );
524 const size_t i4( element->index() );
528 for(
size_t j=0UL; j<N; j+=IT::size ) {
529 y.store( j, v1 * A.load(i1,j) + v2 * A.load(i2,j) + v3 * A.load(i3,j) + v4 * A.load(i4,j) );
534 const size_t i1( element->index() );
538 for(
size_t j=0UL; j<N; j+=IT::size ) {
539 y.store( j, v1 * A.load(i1,j) );
543 for(
size_t i=(iend>3UL)?(4UL):(1UL); (i+4UL)<=iend; i+=4UL )
545 const size_t i1( element->index() );
548 const size_t i2( element->index() );
551 const size_t i3( element->index() );
554 const size_t i4( element->index() );
558 for(
size_t j=0UL; j<N; j+=IT::size ) {
559 y.store( j, y.load(j) + v1 * A.load(i1,j) + v2 * A.load(i2,j) + v3 * A.load(i3,j) + v4 * A.load(i4,j) );
562 for( ; element!=end; ++element )
564 const size_t i1( element->index() );
567 for(
size_t j=0UL; j<N; j+=IT::size ) {
568 y.store( j, y.load(j) + v1 * A.load(i1,j) );
588 template<
typename VT2 >
617 template<
typename VT2 >
626 if( x.nonZeros() == 0UL )
return;
638 TSVecDMatMultExpr::selectAddAssignKernel( ~lhs, x, A );
656 template<
typename VT1
660 selectAddAssignKernel( VT1& y,
const VT2& x,
const MT1& A )
666 const size_t N( A.columns() );
668 ConstIterator element( x.begin() );
669 const ConstIterator end( x.end() );
671 for( ; element!=end; ++element ) {
672 for(
size_t j=0UL; j<N; ++j ) {
673 y[j] += element->value() * A(element->index(),j);
694 template<
typename VT1
697 static inline typename EnableIf< UseOptimizedKernel<VT1,VT2,MT1> >::Type
698 selectAddAssignKernel( VT1& y,
const VT2& x,
const MT1& A )
704 const size_t N( A.columns() );
706 ConstIterator element( x.begin() );
707 const ConstIterator end( x.end() );
709 const size_t iend( x.nonZeros() & size_t(-4) );
710 BLAZE_INTERNAL_ASSERT( ( x.nonZeros() - ( x.nonZeros() % 4UL ) ) == iend,
"Invalid end calculation" );
712 for(
size_t i=0UL; (i+4UL)<=iend; i+=4UL )
714 const size_t i1( element->index() );
715 const VET v1( element->value() );
717 const size_t i2( element->index() );
718 const VET v2( element->value() );
720 const size_t i3( element->index() );
721 const VET v3( element->value() );
723 const size_t i4( element->index() );
724 const VET v4( element->value() );
727 for(
size_t j=0UL; j<N; ++j ) {
728 y[j] += v1 * A(i1,j) + v2 * A(i2,j) + v3 * A(i3,j) + v4 * A(i4,j);
731 for( ; element!=end; ++element )
733 const size_t i1( element->index() );
734 const VET v1( element->value() );
736 for(
size_t j=0UL; j<N; ++j ) {
737 y[j] += v1 * A(i1,j);
758 template<
typename VT1
761 static inline typename EnableIf< UseVectorizedKernel<VT1,VT2,MT1> >::Type
762 selectAddAssignKernel( VT1& y,
const VT2& x,
const MT1& A )
764 typedef IntrinsicTrait<ElementType> IT;
769 const size_t N( A.columns() );
771 ConstIterator element( x.begin() );
772 const ConstIterator end( x.end() );
774 const size_t iend( x.nonZeros() & size_t(-4) );
775 BLAZE_INTERNAL_ASSERT( ( x.nonZeros() - ( x.nonZeros() % 4UL ) ) == iend,
"Invalid end calculation" );
777 for(
size_t i=0UL; (i+4UL)<=iend; i+=4UL )
779 const size_t i1( element->index() );
782 const size_t i2( element->index() );
785 const size_t i3( element->index() );
788 const size_t i4( element->index() );
792 for(
size_t j=0UL; j<N; j+=IT::size ) {
793 y.store( j, y.load(j) + v1 * A.load(i1,j) + v2 * A.load(i2,j) + v3 * A.load(i3,j) + v4 * A.load(i4,j) );
796 for( ; element!=end; ++element )
798 const size_t i1( element->index() );
801 for(
size_t j=0UL; j<N; j+=IT::size ) {
802 y.store( j, y.load(j) + v1 * A.load(i1,j) );
825 template<
typename VT2 >
836 if( x.nonZeros() == 0UL )
return;
848 TSVecDMatMultExpr::selectSubAssignKernel( ~lhs, x, A );
866 template<
typename VT1
870 selectSubAssignKernel( VT1& y,
const VT2& x,
const MT1& A )
876 const size_t N( A.columns() );
878 ConstIterator element( x.begin() );
879 const ConstIterator end( x.end() );
881 for( ; element!=end; ++element ) {
882 for(
size_t j=0UL; j<N; ++j ) {
883 y[j] -= element->value() * A(element->index(),j);
904 template<
typename VT1
907 static inline typename EnableIf< UseOptimizedKernel<VT1,VT2,MT1> >::Type
908 selectSubAssignKernel( VT1& y,
const VT2& x,
const MT1& A )
914 const size_t N( A.columns() );
916 ConstIterator element( x.begin() );
917 const ConstIterator end( x.end() );
919 const size_t iend( x.nonZeros() & size_t(-4) );
920 BLAZE_INTERNAL_ASSERT( ( x.nonZeros() - ( x.nonZeros() % 4UL ) ) == iend,
"Invalid end calculation" );
922 for(
size_t i=0UL; (i+4UL)<=iend; i+=4UL )
924 const size_t i1( element->index() );
925 const VET v1( element->value() );
927 const size_t i2( element->index() );
928 const VET v2( element->value() );
930 const size_t i3( element->index() );
931 const VET v3( element->value() );
933 const size_t i4( element->index() );
934 const VET v4( element->value() );
937 for(
size_t j=0UL; j<N; ++j ) {
938 y[j] -= v1 * A(i1,j) + v2 * A(i2,j) + v3 * A(i3,j) + v4 * A(i4,j);
941 for( ; element!=end; ++element )
943 const size_t i1( element->index() );
944 const VET v1( element->value() );
946 for(
size_t j=0UL; j<N; ++j ) {
947 y[j] -= v1 * A(i1,j);
968 template<
typename VT1
971 static inline typename EnableIf< UseVectorizedKernel<VT1,VT2,MT1> >::Type
972 selectSubAssignKernel( VT1& y,
const VT2& x,
const MT1& A )
974 typedef IntrinsicTrait<ElementType> IT;
979 const size_t N( A.columns() );
981 ConstIterator element( x.begin() );
982 const ConstIterator end( x.end() );
984 const size_t iend( x.nonZeros() & size_t(-4) );
985 BLAZE_INTERNAL_ASSERT( ( x.nonZeros() - ( x.nonZeros() % 4UL ) ) == iend,
"Invalid end calculation" );
987 for(
size_t i=0UL; (i+4UL)<=iend; i+=4UL )
989 const size_t i1( element->index() );
992 const size_t i2( element->index() );
995 const size_t i3( element->index() );
998 const size_t i4( element->index() );
1002 for(
size_t j=0UL; j<N; j+=IT::size ) {
1003 y.store( j, y.load(j) - v1 * A.load(i1,j) - v2 * A.load(i2,j) - v3 * A.load(i3,j) - v4 * A.load(i4,j) );
1006 for( ; element!=x.end(); ++element )
1008 const size_t i1( element->index() );
1011 for(
size_t j=0UL; j<N; j+=IT::size ) {
1012 y.store( j, y.load(j) - v1 * A.load(i1,j) );
1035 template<
typename VT2 >
1106 template<
typename T1,
typename T2 >
1107 inline const typename DisableIf< IsMatMatMultExpr<T2>, TSVecDMatMultExpr<T1,T2> >::Type
1112 if( (~vec).size() != (~mat).
rows() )
1113 throw std::invalid_argument(
"Vector and matrix sizes do not match" );
1141 template<
typename T1
1144 inline const typename EnableIf< IsMatMatMultExpr<T2>, MultExprTrait<T1,T2> >::Type::Type
1149 return ( vec * (~mat).leftOperand() ) * (~mat).rightOperand();
1164 template<
typename VT,
typename MT >
1165 struct SubvectorExprTrait< TSVecDMatMultExpr<VT,MT> >
1169 typedef typename MultExprTrait< VT, typename SubmatrixExprTrait<const MT>::Type >::Type Type;
Compile time check whether the given type is a computational expression template.This type trait clas...
Definition: IsComputation.h:89
void reset(DynamicMatrix< Type, SO > &m)
Resetting the given dense matrix.
Definition: DynamicMatrix.h:4512
friend void multAssign(DenseVector< VT2, true > &lhs, const TSVecDMatMultExpr &rhs)
Multiplication assignment of a transpose sparse vector-dense matrix multiplication to a dense vector ...
Definition: TSVecDMatMultExpr.h:1036
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
TSVecDMatMultExpr< VT, MT > This
Type of this TSVecDMatMultExpr instance.
Definition: TSVecDMatMultExpr.h:164
ResultType::TransposeType TransposeType
Transpose type for expression template evaluations.
Definition: TSVecDMatMultExpr.h:166
Expression object for transpose sparse vector-dense matrix multiplications.The TSVecDMatMultExpr clas...
Definition: Forward.h:143
SelectType< evaluateMatrix, const MRT, MCT >::Type RT
Type for the assignment of the right-hand side dense matrix operand.
Definition: TSVecDMatMultExpr.h:182
SelectType< IsExpression< MT >::value, const MT, const MT & >::Type RightOperand
Composite type of the right-hand side sparse matrix expression.
Definition: TSVecDMatMultExpr.h:176
ReturnType operator[](size_t index) const
Subscript operator for the direct access to the vector elements.
Definition: TSVecDMatMultExpr.h:213
Efficient implementation of a compressed matrix.The CompressedMatrix class template is the represent...
Definition: CompressedMatrix.h:196
VT::ResultType VRT
Result type of the left-hand side sparse vector expression.
Definition: TSVecDMatMultExpr.h:98
#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
Header file for the IsSame and IsStrictlySame type traits.
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
VT::CompositeType VCT
Composite type of the left-hand side sparse vector expression.
Definition: TSVecDMatMultExpr.h:102
Header file for the DenseVector base class.
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.
IntrinsicTrait< ElementType >::Type IntrinsicType
Resulting intrinsic element type.
Definition: TSVecDMatMultExpr.h:168
Base class for dense matrices.The DenseMatrix class is a base class for all dense matrix classes...
Definition: DenseMatrix.h:70
const ElementType ReturnType
Return type for expression template evaluations.
Definition: TSVecDMatMultExpr.h:169
Constraint on the data type.
Constraint on the data type.
Header file for the MultExprTrait class template.
size_t size() const
Returns the current size/dimension of the vector.
Definition: TSVecDMatMultExpr.h:245
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.
friend void addAssign(DenseVector< VT2, true > &lhs, const TSVecDMatMultExpr &rhs)
Addition assignment of a transpose sparse vector-dense matrix multiplication to a dense vector ( )...
Definition: TSVecDMatMultExpr.h:618
Header file for the multiplication trait.
MT::CompositeType MCT
Composite type of the right-hand side dense matrix expression.
Definition: TSVecDMatMultExpr.h:103
LeftOperand leftOperand() const
Returns the left-hand side sparse vector operand.
Definition: TSVecDMatMultExpr.h:255
const Element * ConstIterator
Iterator over constant elements.
Definition: CompressedMatrix.h:2379
TSVecDMatMultExpr(const VT &vec, const MT &mat)
Constructor for the TSVecDMatMultExpr class.
Definition: TSVecDMatMultExpr.h:199
Header file for the IsMatMatMultExpr type trait class.
MT::ResultType MRT
Result type of the right-hand side dense matrix expression.
Definition: TSVecDMatMultExpr.h:99
bool isAliased(const T *alias) const
Returns whether the expression is aliased with the given address alias.
Definition: TSVecDMatMultExpr.h:289
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
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
SelectType< IsExpression< VT >::value, const VT, const VT & >::Type LeftOperand
Composite type of the left-hand side sparse vector expression.
Definition: TSVecDMatMultExpr.h:173
Constraints on the storage order of matrix types.
Constraint on the data type.
MRT::ElementType MET
Element type of the right-hand side dense matrix expression.
Definition: TSVecDMatMultExpr.h:101
Type ElementType
Type of the sparse matrix elements.
Definition: CompressedMatrix.h:2373
Header file for the SelectType class template.
Header file for all forward declarations for expression class templates.
MultTrait< VRT, MRT >::Type ResultType
Result type for expression template evaluations.
Definition: TSVecDMatMultExpr.h:165
Constraint on the data type.
Header file for the EnableIf class template.
Header file for the SubmatrixExprTrait class template.
#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
Intrinsic characteristics of data types.The IntrinsicTrait class template provides the intrinsic char...
Definition: IntrinsicTrait.h:648
Header file for run time assertion macros.
Base template for the MultTrait class.
Definition: MultTrait.h:141
const ResultType CompositeType
Data type for composite expression templates.
Definition: TSVecDMatMultExpr.h:170
Substitution Failure Is Not An Error (SFINAE) class.The EnableIf class template is an auxiliary tool ...
Definition: EnableIf.h:184
Header file for the reset shim.
bool canAlias(const T *alias) const
Returns whether the expression can alias with the given address alias.
Definition: TSVecDMatMultExpr.h:277
Compile time check for data types.This type trait tests whether or not the given template parameter i...
Definition: IsBlasCompatible.h:99
SelectType< evaluateVector, const VRT, VCT >::Type LT
Type for the assignment of the left-hand side sparse vector operand.
Definition: TSVecDMatMultExpr.h:179
Header file for the TVecMatMultExpr base class.
Header file for the RemoveReference type trait.
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 mat_
Right-hand side dense matrix of the multiplication expression.
Definition: TSVecDMatMultExpr.h:297
LeftOperand vec_
Left-hand side sparse vector of the multiplication expression.
Definition: TSVecDMatMultExpr.h:296
Header file for the IsComputation type trait class.
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
Header file for basic type definitions.
#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
Header file for the SubvectorExprTrait class template.
VRT::ElementType VET
Element type of the left-hand side sparse vector expression.
Definition: TSVecDMatMultExpr.h:100
friend void subAssign(DenseVector< VT2, true > &lhs, const TSVecDMatMultExpr &rhs)
Subtraction assignment of a transpose sparse vector-dense matrix multiplication to a dense vector ( )...
Definition: TSVecDMatMultExpr.h:826
Header file for the IsResizable type trait.
RightOperand rightOperand() const
Returns the right-hand side dense matrix operand.
Definition: TSVecDMatMultExpr.h:265
size_t rows(const Matrix< MT, SO > &m)
Returns the current number of rows of the matrix.
Definition: Matrix.h:138
#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
ResultType::ElementType ElementType
Resulting element type.
Definition: TSVecDMatMultExpr.h:167
Header file for the IsExpression type trait class.
Header file for the FunctionTrace class.