11#ifndef EIGEN_SPARSEPRODUCT_H
12#define EIGEN_SPARSEPRODUCT_H
15#include "./InternalHeaderCheck.h"
30template <
typename Derived>
31template <
typename OtherDerived>
33 const SparseMatrixBase<OtherDerived>& other)
const {
40template <
typename Lhs,
typename Rhs,
int ProductType>
41struct generic_product_impl<Lhs, Rhs, SparseShape, SparseShape, ProductType> {
42 template <
typename Dest>
43 static void evalTo(Dest& dst,
const Lhs& lhs,
const Rhs& rhs) {
44 evalTo(dst, lhs, rhs,
typename evaluator_traits<Dest>::Shape());
48 template <
typename Dest,
typename ActualLhs,
49 std::enable_if_t<std::is_same<typename evaluator_traits<Dest>::Shape, DenseShape>::value,
int> = 0>
50 static void addTo(Dest& dst,
const ActualLhs& lhs,
const Rhs& rhs) {
51 using LhsNested =
typename nested_eval<ActualLhs, Dynamic>::type;
52 using RhsNested =
typename nested_eval<Rhs, Dynamic>::type;
53 LhsNested lhsNested(lhs);
54 RhsNested rhsNested(rhs);
55 internal::sparse_sparse_to_dense_product_selector<remove_all_t<LhsNested>, remove_all_t<RhsNested>, Dest>::run(
56 lhsNested, rhsNested, dst);
60 template <
typename Dest,
61 std::enable_if_t<std::is_same<typename evaluator_traits<Dest>::Shape, DenseShape>::value,
int> = 0>
62 static void subTo(Dest& dst,
const Lhs& lhs,
const Rhs& rhs) {
63 addTo(dst, -lhs, rhs);
68 template <
typename Dest>
69 static void evalTo(Dest& dst,
const Lhs& lhs,
const Rhs& rhs, SparseShape) {
70 using LhsNested =
typename nested_eval<Lhs, Dynamic>::type;
71 using RhsNested =
typename nested_eval<Rhs, Dynamic>::type;
72 LhsNested lhsNested(lhs);
73 RhsNested rhsNested(rhs);
74 internal::conservative_sparse_sparse_product_selector<remove_all_t<LhsNested>, remove_all_t<RhsNested>, Dest>::run(
75 lhsNested, rhsNested, dst);
79 template <
typename Dest>
80 static void evalTo(Dest& dst,
const Lhs& lhs,
const Rhs& rhs, DenseShape) {
87template <
typename Lhs,
typename Rhs,
int ProductType>
88struct generic_product_impl<Lhs, Rhs, SparseShape, SparseTriangularShape, ProductType>
89 :
public generic_product_impl<Lhs, Rhs, SparseShape, SparseShape, ProductType> {};
92template <
typename Lhs,
typename Rhs,
int ProductType>
93struct generic_product_impl<Lhs, Rhs, SparseTriangularShape, SparseShape, ProductType>
94 :
public generic_product_impl<Lhs, Rhs, SparseShape, SparseShape, ProductType> {};
97template <
typename DstXprType,
typename Lhs,
typename Rhs>
99 DstXprType, Product<Lhs, Rhs, AliasFreeProduct>,
100 internal::assign_op<typename DstXprType::Scalar, typename Product<Lhs, Rhs, AliasFreeProduct>::Scalar>,
102 using SrcXprType = Product<Lhs, Rhs, AliasFreeProduct>;
103 static void run(DstXprType& dst,
const SrcXprType& src,
104 const internal::assign_op<typename DstXprType::Scalar, typename SrcXprType::Scalar>&) {
105 Index dstRows = src.rows();
106 Index dstCols = src.cols();
107 if ((dst.rows() != dstRows) || (dst.cols() != dstCols)) dst.resize(dstRows, dstCols);
109 generic_product_impl<Lhs, Rhs>::evalTo(dst, src.lhs(), src.rhs());
114template <
typename DstXprType,
typename Lhs,
typename Rhs>
116 DstXprType, Product<Lhs, Rhs, AliasFreeProduct>,
117 internal::add_assign_op<typename DstXprType::Scalar, typename Product<Lhs, Rhs, AliasFreeProduct>::Scalar>,
119 using SrcXprType = Product<Lhs, Rhs, AliasFreeProduct>;
120 static void run(DstXprType& dst,
const SrcXprType& src,
121 const internal::add_assign_op<typename DstXprType::Scalar, typename SrcXprType::Scalar>&) {
122 generic_product_impl<Lhs, Rhs>::addTo(dst, src.lhs(), src.rhs());
127template <
typename DstXprType,
typename Lhs,
typename Rhs>
129 DstXprType, Product<Lhs, Rhs, AliasFreeProduct>,
130 internal::sub_assign_op<typename DstXprType::Scalar, typename Product<Lhs, Rhs, AliasFreeProduct>::Scalar>,
132 using SrcXprType = Product<Lhs, Rhs, AliasFreeProduct>;
133 static void run(DstXprType& dst,
const SrcXprType& src,
134 const internal::sub_assign_op<typename DstXprType::Scalar, typename SrcXprType::Scalar>&) {
135 generic_product_impl<Lhs, Rhs>::subTo(dst, src.lhs(), src.rhs());
139template <
typename Lhs,
typename Rhs,
int Options>
140struct unary_evaluator<SparseView<Product<Lhs, Rhs, Options> >, IteratorBased>
141 :
public evaluator<typename Product<Lhs, Rhs, DefaultProduct>::PlainObject> {
142 using XprType = SparseView<Product<Lhs, Rhs, Options>>;
143 using PlainObject =
typename XprType::PlainObject;
144 using Base = evaluator<PlainObject>;
146 explicit unary_evaluator(
const XprType& xpr) : m_result(xpr.rows(), xpr.cols()) {
148 internal::construct_at<Base>(
this, m_result);
149 using LhsNested =
typename nested_eval<Lhs, Dynamic>::type;
150 using RhsNested =
typename nested_eval<Rhs, Dynamic>::type;
151 LhsNested lhsNested(xpr.nestedExpression().lhs());
152 RhsNested rhsNested(xpr.nestedExpression().rhs());
154 internal::sparse_sparse_product_with_pruning_selector<remove_all_t<LhsNested>, remove_all_t<RhsNested>,
155 PlainObject>::run(lhsNested, rhsNested, m_result,
156 abs(xpr.reference()) * xpr.epsilon());
160 PlainObject m_result;
166template <
typename Scalar,
int Options_,
typename StorageIndex_>
167template <
typename Lhs,
typename Rhs>
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:203
A versatile sparse matrix representation.
Definition SparseMatrix.h:122
constexpr Derived & derived()
Definition EigenBase.h:50