10#ifndef EIGEN_SPARSEPRODUCT_H
11#define EIGEN_SPARSEPRODUCT_H
14#include "./InternalHeaderCheck.h"
29template <
typename Derived>
30template <
typename OtherDerived>
39template <
typename Lhs,
typename Rhs,
int ProductType>
40struct generic_product_impl<Lhs, Rhs, SparseShape, SparseShape, ProductType> {
41 template <
typename Dest>
42 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,
49 std::enable_if_t<is_same<
typename evaluator_traits<Dest>::Shape, DenseShape>::value,
int*>* = 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<remove_all_t<LhsNested>, remove_all_t<RhsNested>, Dest>::run(
55 lhsNested, rhsNested, dst);
59 template <
typename Dest>
60 static void subTo(Dest& dst,
const Lhs& lhs,
const Rhs& rhs,
61 std::enable_if_t<is_same<
typename evaluator_traits<Dest>::Shape, DenseShape>::value,
int*>* = 0) {
62 addTo(dst, -lhs, rhs);
67 template <
typename Dest>
68 static void evalTo(Dest& dst,
const Lhs& lhs,
const Rhs& rhs, SparseShape) {
69 typedef typename nested_eval<Lhs, Dynamic>::type LhsNested;
70 typedef typename nested_eval<Rhs, Dynamic>::type RhsNested;
71 LhsNested lhsNested(lhs);
72 RhsNested rhsNested(rhs);
73 internal::conservative_sparse_sparse_product_selector<remove_all_t<LhsNested>, remove_all_t<RhsNested>, Dest>::run(
74 lhsNested, rhsNested, dst);
78 template <
typename Dest>
79 static void evalTo(Dest& dst,
const Lhs& lhs,
const Rhs& rhs, DenseShape) {
86template <
typename Lhs,
typename Rhs,
int ProductType>
87struct generic_product_impl<Lhs, Rhs, SparseShape, SparseTriangularShape, ProductType>
88 :
public generic_product_impl<Lhs, Rhs, SparseShape, SparseShape, ProductType> {};
91template <
typename Lhs,
typename Rhs,
int ProductType>
92struct generic_product_impl<Lhs, Rhs, SparseTriangularShape, SparseShape, ProductType>
93 :
public generic_product_impl<Lhs, Rhs, SparseShape, SparseShape, ProductType> {};
96template <
typename DstXprType,
typename Lhs,
typename Rhs>
98 DstXprType, Product<Lhs, Rhs, AliasFreeProduct>,
99 internal::assign_op<typename DstXprType::Scalar, typename Product<Lhs, Rhs, AliasFreeProduct>::Scalar>,
101 typedef Product<Lhs, Rhs, AliasFreeProduct> SrcXprType;
102 static void run(DstXprType& dst,
const SrcXprType& src,
103 const internal::assign_op<typename DstXprType::Scalar, typename SrcXprType::Scalar>&) {
104 Index dstRows = src.rows();
105 Index dstCols = src.cols();
106 if ((dst.rows() != dstRows) || (dst.cols() != dstCols)) dst.resize(dstRows, dstCols);
108 generic_product_impl<Lhs, Rhs>::evalTo(dst, src.lhs(), src.rhs());
113template <
typename DstXprType,
typename Lhs,
typename Rhs>
115 DstXprType, Product<Lhs, Rhs, AliasFreeProduct>,
116 internal::add_assign_op<typename DstXprType::Scalar, typename Product<Lhs, Rhs, AliasFreeProduct>::Scalar>,
118 typedef Product<Lhs, Rhs, AliasFreeProduct> SrcXprType;
119 static void run(DstXprType& dst,
const SrcXprType& src,
120 const internal::add_assign_op<typename DstXprType::Scalar, typename SrcXprType::Scalar>&) {
121 generic_product_impl<Lhs, Rhs>::addTo(dst, src.lhs(), src.rhs());
126template <
typename DstXprType,
typename Lhs,
typename Rhs>
128 DstXprType, Product<Lhs, Rhs, AliasFreeProduct>,
129 internal::sub_assign_op<typename DstXprType::Scalar, typename Product<Lhs, Rhs, AliasFreeProduct>::Scalar>,
131 typedef Product<Lhs, Rhs, AliasFreeProduct> SrcXprType;
132 static void run(DstXprType& dst,
const SrcXprType& src,
133 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> {
141 typedef SparseView<Product<Lhs, Rhs, Options> > XprType;
142 typedef typename XprType::PlainObject PlainObject;
143 typedef evaluator<PlainObject> Base;
145 explicit unary_evaluator(
const XprType& xpr) : m_result(xpr.rows(), xpr.cols()) {
147 internal::construct_at<Base>(
this, m_result);
148 typedef typename nested_eval<Lhs, Dynamic>::type LhsNested;
149 typedef typename nested_eval<Rhs, Dynamic>::type RhsNested;
150 LhsNested lhsNested(xpr.nestedExpression().lhs());
151 RhsNested rhsNested(xpr.nestedExpression().rhs());
153 internal::sparse_sparse_product_with_pruning_selector<remove_all_t<LhsNested>, remove_all_t<RhsNested>,
154 PlainObject>::run(lhsNested, rhsNested, m_result,
155 abs(xpr.reference()) * xpr.epsilon());
159 PlainObject m_result;
165template <
typename Scalar,
int Options_,
typename StorageIndex_>
166template <
typename Lhs,
typename Rhs>
167SparseMatrix<Scalar, Options_, StorageIndex_>& SparseMatrix<Scalar, Options_, StorageIndex_>::operator=(
168 const Product<Lhs, Rhs, AliasFreeProduct>& src) {
170 SparseMatrix dst(src.rows(), src.cols());
171 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:202
Base class of any sparse matrices or sparse expressions.
Definition SparseMatrixBase.h:30
Namespace containing all symbols from the Eigen library.
Definition Core:137
const Eigen::CwiseUnaryOp< Eigen::internal::scalar_abs_op< typename Derived::Scalar >, const Derived > abs(const Eigen::ArrayBase< Derived > &x)
Derived & derived()
Definition EigenBase.h:49