10 #ifndef EIGEN_SPARSEPRODUCT_H
11 #define EIGEN_SPARSEPRODUCT_H
28 template<
typename Derived>
29 template<
typename OtherDerived>
30 inline const Product<Derived,OtherDerived,AliasFreeProduct>
39 template<
typename Lhs,
typename Rhs,
int ProductType>
42 template<
typename Dest>
43 static void evalTo(Dest& dst,
const Lhs& lhs,
const Rhs& rhs)
45 evalTo(dst, lhs, rhs,
typename evaluator_traits<Dest>::Shape());
49 template<
typename Dest,
typename ActualLhs>
50 static void addTo(Dest& dst,
const ActualLhs& lhs,
const Rhs& rhs, std::enable_if_t<is_same<
typename evaluator_traits<Dest>::Shape,DenseShape>::value,
int*>* = 0)
52 typedef typename nested_eval<ActualLhs,Dynamic>::type LhsNested;
53 typedef typename nested_eval<Rhs,Dynamic>::type RhsNested;
54 LhsNested lhsNested(lhs);
55 RhsNested rhsNested(rhs);
56 internal::sparse_sparse_to_dense_product_selector<remove_all_t<LhsNested>,
57 remove_all_t<RhsNested>, Dest>::run(lhsNested,rhsNested,dst);
61 template<
typename Dest>
62 static void subTo(Dest& dst,
const Lhs& lhs,
const Rhs& rhs, std::enable_if_t<is_same<
typename evaluator_traits<Dest>::Shape,DenseShape>::value,
int*>* = 0)
64 addTo(dst, -lhs, rhs);
70 template<
typename Dest>
71 static void evalTo(Dest& dst,
const Lhs& lhs,
const Rhs& rhs, SparseShape)
73 typedef typename nested_eval<Lhs,Dynamic>::type LhsNested;
74 typedef typename nested_eval<Rhs,Dynamic>::type RhsNested;
75 LhsNested lhsNested(lhs);
76 RhsNested rhsNested(rhs);
77 internal::conservative_sparse_sparse_product_selector<remove_all_t<LhsNested>,
78 remove_all_t<RhsNested>, Dest>::run(lhsNested,rhsNested,dst);
82 template<
typename Dest>
83 static void evalTo(Dest& dst,
const Lhs& lhs,
const Rhs& rhs, DenseShape)
91 template<
typename Lhs,
typename Rhs,
int ProductType>
92 struct generic_product_impl<Lhs, Rhs, SparseShape, SparseTriangularShape, ProductType>
93 :
public generic_product_impl<Lhs, Rhs, SparseShape, SparseShape, ProductType>
97 template<
typename Lhs,
typename Rhs,
int ProductType>
98 struct generic_product_impl<Lhs, Rhs, SparseTriangularShape, SparseShape, ProductType>
99 :
public generic_product_impl<Lhs, Rhs, SparseShape, SparseShape, ProductType>
103 template<
typename DstXprType,
typename Lhs,
typename Rhs>
104 struct Assignment<DstXprType, Product<Lhs,Rhs,
AliasFreeProduct>,
internal::assign_op<typename DstXprType::Scalar,typename Product<Lhs,Rhs,AliasFreeProduct>::Scalar>, Sparse2Dense>
106 typedef Product<Lhs,Rhs,AliasFreeProduct> SrcXprType;
107 static void run(DstXprType &dst,
const SrcXprType &src,
const internal::assign_op<typename DstXprType::Scalar,typename SrcXprType::Scalar> &)
109 Index dstRows = src.rows();
110 Index dstCols = src.cols();
111 if((dst.rows()!=dstRows) || (dst.cols()!=dstCols))
112 dst.resize(dstRows, dstCols);
114 generic_product_impl<Lhs, Rhs>::evalTo(dst,src.lhs(),src.rhs());
119 template<
typename DstXprType,
typename Lhs,
typename Rhs>
120 struct Assignment<DstXprType, Product<Lhs,Rhs,
AliasFreeProduct>,
internal::add_assign_op<typename DstXprType::Scalar,typename Product<Lhs,Rhs,AliasFreeProduct>::Scalar>, Sparse2Dense>
122 typedef Product<Lhs,Rhs,AliasFreeProduct> SrcXprType;
123 static void run(DstXprType &dst,
const SrcXprType &src,
const internal::add_assign_op<typename DstXprType::Scalar,typename SrcXprType::Scalar> &)
125 generic_product_impl<Lhs, Rhs>::addTo(dst,src.lhs(),src.rhs());
130 template<
typename DstXprType,
typename Lhs,
typename Rhs>
131 struct Assignment<DstXprType, Product<Lhs,Rhs,
AliasFreeProduct>,
internal::sub_assign_op<typename DstXprType::Scalar,typename Product<Lhs,Rhs,AliasFreeProduct>::Scalar>, Sparse2Dense>
133 typedef Product<Lhs,Rhs,AliasFreeProduct> SrcXprType;
134 static void run(DstXprType &dst,
const SrcXprType &src,
const internal::sub_assign_op<typename DstXprType::Scalar,typename SrcXprType::Scalar> &)
136 generic_product_impl<Lhs, Rhs>::subTo(dst,src.lhs(),src.rhs());
140 template<
typename Lhs,
typename Rhs,
int Options>
141 struct unary_evaluator<SparseView<Product<Lhs, Rhs, Options> >, IteratorBased>
142 :
public evaluator<typename Product<Lhs, Rhs, DefaultProduct>::PlainObject>
144 typedef SparseView<Product<Lhs, Rhs, Options> > XprType;
145 typedef typename XprType::PlainObject PlainObject;
146 typedef evaluator<PlainObject> Base;
148 explicit unary_evaluator(
const XprType& xpr)
152 internal::construct_at<Base>(
this, m_result);
153 typedef typename nested_eval<Lhs,Dynamic>::type LhsNested;
154 typedef typename nested_eval<Rhs,Dynamic>::type RhsNested;
155 LhsNested lhsNested(xpr.nestedExpression().lhs());
156 RhsNested rhsNested(xpr.nestedExpression().rhs());
158 internal::sparse_sparse_product_with_pruning_selector<remove_all_t<LhsNested>,
159 remove_all_t<RhsNested>, PlainObject>::run(lhsNested,rhsNested,m_result,
160 abs(xpr.reference())*xpr.epsilon());
164 PlainObject m_result;
170 template<
typename Scalar,
int Options_,
typename StorageIndex_>
171 template<
typename Lhs,
typename Rhs>
175 SparseMatrix dst(src.rows(),src.cols());
176 internal::generic_product_impl<Lhs, Rhs>::evalTo(dst,src.lhs(),src.rhs());
const AbsReturnType abs() const
Expression of the product of two arbitrary matrices or vectors.
SparseMatrix< Scalar_, Options_, StorageIndex_ > & operator=(const SparseMatrix< Scalar_, Options_, StorageIndex_ > &other)
Base class of any sparse matrices or sparse expressions.
const Product< Derived, OtherDerived > operator*(const DiagonalBase< OtherDerived > &other) const
void swap(scoped_array< T > &a, scoped_array< T > &b)
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
const Eigen::CwiseUnaryOp< Eigen::internal::scalar_abs_op< typename Derived::Scalar >, const Derived > abs(const Eigen::ArrayBase< Derived > &x)