10#ifndef EIGEN_SPARSEPRODUCT_H
11#define EIGEN_SPARSEPRODUCT_H
26template<
typename Derived>
27template<
typename OtherDerived>
28inline const Product<Derived,OtherDerived,AliasFreeProduct>
37template<
typename Lhs,
typename Rhs,
int ProductType>
38struct generic_product_impl<Lhs, Rhs, SparseShape, SparseShape, ProductType>
40 template<
typename Dest>
41 static void evalTo(Dest& dst,
const Lhs& lhs,
const Rhs& rhs)
43 evalTo(dst, lhs, rhs,
typename evaluator_traits<Dest>::Shape());
47 template<
typename Dest,
typename ActualLhs>
48 static void addTo(Dest& dst,
const ActualLhs& lhs,
const Rhs& rhs,
typename enable_if<is_same<
typename evaluator_traits<Dest>::Shape,DenseShape>::value,
int*>::type* = 0)
50 typedef typename nested_eval<ActualLhs,Dynamic>::type LhsNested;
51 typedef typename nested_eval<Rhs,Dynamic>::type RhsNested;
52 LhsNested lhsNested(lhs);
53 RhsNested rhsNested(rhs);
54 internal::sparse_sparse_to_dense_product_selector<typename remove_all<LhsNested>::type,
55 typename remove_all<RhsNested>::type, Dest>::run(lhsNested,rhsNested,dst);
59 template<
typename Dest>
60 static void subTo(Dest& dst,
const Lhs& lhs,
const Rhs& rhs,
typename enable_if<is_same<
typename evaluator_traits<Dest>::Shape,DenseShape>::value,
int*>::type* = 0)
62 addTo(dst, -lhs, rhs);
68 template<
typename Dest>
69 static void evalTo(Dest& dst,
const Lhs& lhs,
const Rhs& rhs, SparseShape)
71 typedef typename nested_eval<Lhs,Dynamic>::type LhsNested;
72 typedef typename nested_eval<Rhs,Dynamic>::type RhsNested;
73 LhsNested lhsNested(lhs);
74 RhsNested rhsNested(rhs);
75 internal::conservative_sparse_sparse_product_selector<typename remove_all<LhsNested>::type,
76 typename remove_all<RhsNested>::type, Dest>::run(lhsNested,rhsNested,dst);
80 template<
typename Dest>
81 static void evalTo(Dest& dst,
const Lhs& lhs,
const Rhs& rhs, DenseShape)
89template<
typename Lhs,
typename Rhs,
int ProductType>
90struct generic_product_impl<Lhs, Rhs, SparseShape, SparseTriangularShape, ProductType>
91 :
public generic_product_impl<Lhs, Rhs, SparseShape, SparseShape, ProductType>
95template<
typename Lhs,
typename Rhs,
int ProductType>
96struct generic_product_impl<Lhs, Rhs, SparseTriangularShape, SparseShape, ProductType>
97 :
public generic_product_impl<Lhs, Rhs, SparseShape, SparseShape, ProductType>
101template<
typename DstXprType,
typename Lhs,
typename Rhs>
102struct Assignment<DstXprType, Product<Lhs,Rhs,AliasFreeProduct>, internal::assign_op<typename DstXprType::Scalar,typename Product<Lhs,Rhs,AliasFreeProduct>::Scalar>, Sparse2Dense>
104 typedef Product<Lhs,Rhs,AliasFreeProduct> SrcXprType;
105 static void run(DstXprType &dst,
const SrcXprType &src,
const internal::assign_op<typename DstXprType::Scalar,typename SrcXprType::Scalar> &)
107 Index dstRows = src.rows();
108 Index dstCols = src.cols();
109 if((dst.rows()!=dstRows) || (dst.cols()!=dstCols))
110 dst.resize(dstRows, dstCols);
112 generic_product_impl<Lhs, Rhs>::evalTo(dst,src.lhs(),src.rhs());
117template<
typename DstXprType,
typename Lhs,
typename Rhs>
118struct Assignment<DstXprType, Product<Lhs,Rhs,AliasFreeProduct>, internal::add_assign_op<typename DstXprType::Scalar,typename Product<Lhs,Rhs,AliasFreeProduct>::Scalar>, Sparse2Dense>
120 typedef Product<Lhs,Rhs,AliasFreeProduct> SrcXprType;
121 static void run(DstXprType &dst,
const SrcXprType &src,
const internal::add_assign_op<typename DstXprType::Scalar,typename SrcXprType::Scalar> &)
123 generic_product_impl<Lhs, Rhs>::addTo(dst,src.lhs(),src.rhs());
128template<
typename DstXprType,
typename Lhs,
typename Rhs>
129struct Assignment<DstXprType, Product<Lhs,Rhs,AliasFreeProduct>, internal::sub_assign_op<typename DstXprType::Scalar,typename Product<Lhs,Rhs,AliasFreeProduct>::Scalar>, Sparse2Dense>
131 typedef Product<Lhs,Rhs,AliasFreeProduct> SrcXprType;
132 static void run(DstXprType &dst,
const SrcXprType &src,
const internal::sub_assign_op<typename DstXprType::Scalar,typename SrcXprType::Scalar> &)
134 generic_product_impl<Lhs, Rhs>::subTo(dst,src.lhs(),src.rhs());
138template<
typename Lhs,
typename Rhs,
int Options>
139struct unary_evaluator<SparseView<Product<Lhs, Rhs, Options> >, IteratorBased>
140 :
public evaluator<typename Product<Lhs, Rhs, DefaultProduct>::PlainObject>
142 typedef SparseView<Product<Lhs, Rhs, Options> > XprType;
143 typedef typename XprType::PlainObject PlainObject;
144 typedef evaluator<PlainObject> Base;
146 explicit unary_evaluator(
const XprType& xpr)
147 : m_result(xpr.rows(), xpr.cols())
150 ::new (
static_cast<Base*
>(
this)) Base(m_result);
151 typedef typename nested_eval<Lhs,
Dynamic>::type LhsNested;
152 typedef typename nested_eval<Rhs,
Dynamic>::type RhsNested;
153 LhsNested lhsNested(xpr.nestedExpression().lhs());
154 RhsNested rhsNested(xpr.nestedExpression().rhs());
156 internal::sparse_sparse_product_with_pruning_selector<typename remove_all<LhsNested>::type,
157 typename remove_all<RhsNested>::type, PlainObject>::run(lhsNested,rhsNested,m_result,
158 abs(xpr.reference())*xpr.epsilon());
162 PlainObject m_result;
168template<typename Scalar,
int _Options, typename _StorageIndex>
169template<typename Lhs, typename Rhs>
170SparseMatrix<Scalar,_Options,_StorageIndex>& SparseMatrix<Scalar,_Options,_StorageIndex>::operator=(const Product<Lhs,Rhs,AliasFreeProduct>& src)
173 SparseMatrix dst(src.rows(),src.cols());
174 internal::generic_product_impl<Lhs, Rhs>::evalTo(dst,src.lhs(),src.rhs());
Expression of the product of two arbitrary matrices or vectors.
Definition: Product.h:75
Base class of any sparse matrices or sparse expressions.
Definition: SparseMatrixBase.h:28
Namespace containing all symbols from the Eigen library.
Definition: Core:141
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:74
const int Dynamic
Definition: Constants.h:22
Derived & derived()
Definition: EigenBase.h:46