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 {
38template <
typename Derived>
39template <
typename OtherDerived>
40Derived& SparseMatrixBase<Derived>::operator*=(
const SparseMatrixBase<OtherDerived>& other) {
47template <
typename Lhs,
typename Rhs,
int ProductType>
48struct generic_product_impl<Lhs, Rhs, SparseShape, SparseShape, ProductType> {
49 template <
typename Dest>
50 static void evalTo(Dest& dst,
const Lhs& lhs,
const Rhs& rhs) {
51 evalTo(dst, lhs, rhs,
typename evaluator_traits<Dest>::Shape());
55 template <
typename Dest,
typename ActualLhs,
56 std::enable_if_t<std::is_same<typename evaluator_traits<Dest>::Shape, DenseShape>::value,
int> = 0>
57 static void addTo(Dest& dst,
const ActualLhs& lhs,
const Rhs& rhs) {
58 using LhsNested =
typename nested_eval<ActualLhs, Dynamic>::type;
59 using RhsNested =
typename nested_eval<Rhs, Dynamic>::type;
60 LhsNested lhsNested(lhs);
61 RhsNested rhsNested(rhs);
62 internal::sparse_sparse_to_dense_product_selector<remove_all_t<LhsNested>, remove_all_t<RhsNested>, Dest>::run(
63 lhsNested, rhsNested, dst);
67 template <
typename Dest,
68 std::enable_if_t<std::is_same<typename evaluator_traits<Dest>::Shape, DenseShape>::value,
int> = 0>
69 static void subTo(Dest& dst,
const Lhs& lhs,
const Rhs& rhs) {
70 addTo(dst, -lhs, rhs);
75 template <
typename Dest>
76 static void evalTo(Dest& dst,
const Lhs& lhs,
const Rhs& rhs, SparseShape) {
77 using LhsNested =
typename nested_eval<Lhs, Dynamic>::type;
78 using RhsNested =
typename nested_eval<Rhs, Dynamic>::type;
79 LhsNested lhsNested(lhs);
80 RhsNested rhsNested(rhs);
81 internal::conservative_sparse_sparse_product_selector<remove_all_t<LhsNested>, remove_all_t<RhsNested>, Dest>::run(
82 lhsNested, rhsNested, dst);
86 template <
typename Dest>
87 static void evalTo(Dest& dst,
const Lhs& lhs,
const Rhs& rhs, DenseShape) {
94template <
typename Lhs,
typename Rhs,
int ProductType>
95struct generic_product_impl<Lhs, Rhs, SparseShape, SparseTriangularShape, ProductType>
96 :
public generic_product_impl<Lhs, Rhs, SparseShape, SparseShape, ProductType> {};
99template <
typename Lhs,
typename Rhs,
int ProductType>
100struct generic_product_impl<Lhs, Rhs, SparseTriangularShape, SparseShape, ProductType>
101 :
public generic_product_impl<Lhs, Rhs, SparseShape, SparseShape, ProductType> {};
104template <
typename DstXprType,
typename Lhs,
typename Rhs>
106 DstXprType, Product<Lhs, Rhs, AliasFreeProduct>,
107 internal::assign_op<typename DstXprType::Scalar, typename Product<Lhs, Rhs, AliasFreeProduct>::Scalar>,
109 using SrcXprType = Product<Lhs, Rhs, AliasFreeProduct>;
110 static void run(DstXprType& dst,
const SrcXprType& src,
111 const internal::assign_op<typename DstXprType::Scalar, typename SrcXprType::Scalar>&) {
112 Index dstRows = src.rows();
113 Index dstCols = src.cols();
114 if ((dst.rows() != dstRows) || (dst.cols() != dstCols)) dst.resize(dstRows, dstCols);
116 generic_product_impl<Lhs, Rhs>::evalTo(dst, src.lhs(), src.rhs());
121template <
typename DstXprType,
typename Lhs,
typename Rhs>
123 DstXprType, Product<Lhs, Rhs, AliasFreeProduct>,
124 internal::add_assign_op<typename DstXprType::Scalar, typename Product<Lhs, Rhs, AliasFreeProduct>::Scalar>,
126 using SrcXprType = Product<Lhs, Rhs, AliasFreeProduct>;
127 static void run(DstXprType& dst,
const SrcXprType& src,
128 const internal::add_assign_op<typename DstXprType::Scalar, typename SrcXprType::Scalar>&) {
129 generic_product_impl<Lhs, Rhs>::addTo(dst, src.lhs(), src.rhs());
134template <
typename DstXprType,
typename Lhs,
typename Rhs>
136 DstXprType, Product<Lhs, Rhs, AliasFreeProduct>,
137 internal::sub_assign_op<typename DstXprType::Scalar, typename Product<Lhs, Rhs, AliasFreeProduct>::Scalar>,
139 using SrcXprType = Product<Lhs, Rhs, AliasFreeProduct>;
140 static void run(DstXprType& dst,
const SrcXprType& src,
141 const internal::sub_assign_op<typename DstXprType::Scalar, typename SrcXprType::Scalar>&) {
142 generic_product_impl<Lhs, Rhs>::subTo(dst, src.lhs(), src.rhs());
146template <
typename Lhs,
typename Rhs,
int Options>
147struct unary_evaluator<SparseView<Product<Lhs, Rhs, Options> >, IteratorBased>
148 :
public evaluator<typename Product<Lhs, Rhs, DefaultProduct>::PlainObject> {
149 using XprType = SparseView<Product<Lhs, Rhs, Options>>;
150 using PlainObject =
typename XprType::PlainObject;
151 using Base = evaluator<PlainObject>;
153 explicit unary_evaluator(
const XprType& xpr) : m_result(xpr.rows(), xpr.cols()) {
154 internal::construct_at<Base>(
this, m_result);
155 using LhsNested =
typename nested_eval<Lhs, Dynamic>::type;
156 using RhsNested =
typename nested_eval<Rhs, Dynamic>::type;
157 LhsNested lhsNested(xpr.nestedExpression().lhs());
158 RhsNested rhsNested(xpr.nestedExpression().rhs());
160 internal::sparse_sparse_product_with_pruning_selector<remove_all_t<LhsNested>, remove_all_t<RhsNested>,
161 PlainObject>::run(lhsNested, rhsNested, m_result,
162 numext::abs(xpr.reference()) *
167 PlainObject m_result;
173template <
typename Scalar,
int Options_,
typename StorageIndex_>
174template <
typename Lhs,
typename Rhs>
178 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:211
A versatile sparse matrix representation.
Definition SparseMatrix.h:121
constexpr Derived & derived()
Definition EigenBase.h:50