10#ifndef EIGEN_SPARSEPRODUCT_H
11#define EIGEN_SPARSEPRODUCT_H
13#include "./InternalHeaderCheck.h"
28template<
typename Derived>
29template<
typename OtherDerived>
30inline const Product<Derived,OtherDerived,AliasFreeProduct>
39template<
typename Lhs,
typename Rhs,
int ProductType>
40struct generic_product_impl<Lhs, Rhs, SparseShape, SparseShape, 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,
typename enable_if<is_same<
typename evaluator_traits<Dest>::Shape,DenseShape>::value,
int*>::type* = 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<typename remove_all<LhsNested>::type,
57 typename remove_all<RhsNested>::type, Dest>::run(lhsNested,rhsNested,dst);
61 template<
typename Dest>
62 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)
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<typename remove_all<LhsNested>::type,
78 typename remove_all<RhsNested>::type, Dest>::run(lhsNested,rhsNested,dst);
82 template<
typename Dest>
83 static void evalTo(Dest& dst,
const Lhs& lhs,
const Rhs& rhs, DenseShape)
91template<
typename Lhs,
typename Rhs,
int ProductType>
92struct generic_product_impl<Lhs, Rhs, SparseShape, SparseTriangularShape, ProductType>
93 :
public generic_product_impl<Lhs, Rhs, SparseShape, SparseShape, ProductType>
97template<
typename Lhs,
typename Rhs,
int ProductType>
98struct generic_product_impl<Lhs, Rhs, SparseTriangularShape, SparseShape, ProductType>
99 :
public generic_product_impl<Lhs, Rhs, SparseShape, SparseShape, ProductType>
103template<
typename DstXprType,
typename Lhs,
typename Rhs>
104struct 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());
119template<
typename DstXprType,
typename Lhs,
typename Rhs>
120struct 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());
130template<
typename DstXprType,
typename Lhs,
typename Rhs>
131struct 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());
140template<
typename Lhs,
typename Rhs,
int Options>
141struct 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)
149 : m_result(xpr.rows(), xpr.cols())
152 ::new (
static_cast<Base*
>(
this)) Base(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<typename remove_all<LhsNested>::type,
159 typename remove_all<RhsNested>::type, PlainObject>::run(lhsNested,rhsNested,m_result,
160 abs(xpr.reference())*xpr.epsilon());
164 PlainObject m_result;
170template<typename Scalar,
int Options_, typename StorageIndex_>
171template<typename Lhs, typename Rhs>
172SparseMatrix<Scalar,Options_,StorageIndex_>& SparseMatrix<Scalar,Options_,StorageIndex_>::operator=(const Product<Lhs,Rhs,AliasFreeProduct>& src)
175 SparseMatrix dst(src.rows(),src.cols());
176 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:77
Base class of any sparse matrices or sparse expressions.
Definition: SparseMatrixBase.h:30
Namespace containing all symbols from the Eigen library.
Definition: B01_Experimental.dox:1
const Eigen::CwiseUnaryOp< Eigen::internal::scalar_abs_op< typename Derived::Scalar >, const Derived > abs(const Eigen::ArrayBase< Derived > &x)
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:59
const int Dynamic
Definition: Constants.h:24
Derived & derived()
Definition: EigenBase.h:48