Medial Code Documentation
Loading...
Searching...
No Matches
SparseProduct.h
1// This file is part of Eigen, a lightweight C++ template library
2// for linear algebra.
3//
4// Copyright (C) 2008-2015 Gael Guennebaud <gael.guennebaud@inria.fr>
5//
6// This Source Code Form is subject to the terms of the Mozilla
7// Public License v. 2.0. If a copy of the MPL was not distributed
8// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
9
10#ifndef EIGEN_SPARSEPRODUCT_H
11#define EIGEN_SPARSEPRODUCT_H
12
13namespace Eigen {
14
26template<typename Derived>
27template<typename OtherDerived>
28inline const Product<Derived,OtherDerived,AliasFreeProduct>
33
34namespace internal {
35
36// sparse * sparse
37template<typename Lhs, typename Rhs, int ProductType>
39{
40 template<typename Dest>
41 static void evalTo(Dest& dst, const Lhs& lhs, const Rhs& rhs)
42 {
43 evalTo(dst, lhs, rhs, typename evaluator_traits<Dest>::Shape());
44 }
45
46 // dense += sparse * sparse
47 template<typename Dest,typename ActualLhs>
48 static void addTo(Dest& dst, const ActualLhs& lhs, const Rhs& rhs, int* = typename enable_if<is_same<typename evaluator_traits<Dest>::Shape,DenseShape>::value,int*>::type(0) )
49 {
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);
56 }
57
58 // dense -= sparse * sparse
59 template<typename Dest>
60 static void subTo(Dest& dst, const Lhs& lhs, const Rhs& rhs, int* = typename enable_if<is_same<typename evaluator_traits<Dest>::Shape,DenseShape>::value,int*>::type(0) )
61 {
62 addTo(dst, -lhs, rhs);
63 }
64
65protected:
66
67 // sparse = sparse * sparse
68 template<typename Dest>
69 static void evalTo(Dest& dst, const Lhs& lhs, const Rhs& rhs, SparseShape)
70 {
71 typedef typename nested_eval<Lhs,Dynamic>::type LhsNested;
72 typedef typename nested_eval<Rhs,Dynamic>::type RhsNested;
73 LhsNested lhsNested(lhs);
74 RhsNested rhsNested(rhs);
77 }
78
79 // dense = sparse * sparse
80 template<typename Dest>
81 static void evalTo(Dest& dst, const Lhs& lhs, const Rhs& rhs, DenseShape)
82 {
83 dst.setZero();
84 addTo(dst, lhs, rhs);
85 }
86};
87
88// sparse * sparse-triangular
89template<typename Lhs, typename Rhs, int ProductType>
91 : public generic_product_impl<Lhs, Rhs, SparseShape, SparseShape, ProductType>
92{};
93
94// sparse-triangular * sparse
95template<typename Lhs, typename Rhs, int ProductType>
97 : public generic_product_impl<Lhs, Rhs, SparseShape, SparseShape, ProductType>
98{};
99
100// dense = sparse-product (can be sparse*sparse, sparse*perm, etc.)
101template< typename DstXprType, typename Lhs, typename Rhs>
102struct Assignment<DstXprType, Product<Lhs,Rhs,AliasFreeProduct>, internal::assign_op<typename DstXprType::Scalar>, Sparse2Dense>
103{
105 static void run(DstXprType &dst, const SrcXprType &src, const internal::assign_op<typename DstXprType::Scalar> &)
106 {
108 }
109};
110
111// dense += sparse-product (can be sparse*sparse, sparse*perm, etc.)
112template< typename DstXprType, typename Lhs, typename Rhs>
113struct Assignment<DstXprType, Product<Lhs,Rhs,AliasFreeProduct>, internal::add_assign_op<typename DstXprType::Scalar>, Sparse2Dense>
114{
116 static void run(DstXprType &dst, const SrcXprType &src, const internal::add_assign_op<typename DstXprType::Scalar> &)
117 {
119 }
120};
121
122// dense -= sparse-product (can be sparse*sparse, sparse*perm, etc.)
123template< typename DstXprType, typename Lhs, typename Rhs>
124struct Assignment<DstXprType, Product<Lhs,Rhs,AliasFreeProduct>, internal::sub_assign_op<typename DstXprType::Scalar>, Sparse2Dense>
125{
127 static void run(DstXprType &dst, const SrcXprType &src, const internal::sub_assign_op<typename DstXprType::Scalar> &)
128 {
130 }
131};
132
133template<typename Lhs, typename Rhs, int Options>
134struct evaluator<SparseView<Product<Lhs, Rhs, Options> > >
135 : public evaluator<typename Product<Lhs, Rhs, DefaultProduct>::PlainObject>
136{
138 typedef typename XprType::PlainObject PlainObject;
140
141 explicit evaluator(const XprType& xpr)
142 : m_result(xpr.rows(), xpr.cols())
143 {
144 using std::abs;
145 ::new (static_cast<Base*>(this)) Base(m_result);
146 typedef typename nested_eval<Lhs,Dynamic>::type LhsNested;
147 typedef typename nested_eval<Rhs,Dynamic>::type RhsNested;
148 LhsNested lhsNested(xpr.nestedExpression().lhs());
149 RhsNested rhsNested(xpr.nestedExpression().rhs());
150
153 abs(xpr.reference())*xpr.epsilon());
154 }
155
156protected:
157 PlainObject m_result;
158};
159
160} // end namespace internal
161
162} // end namespace Eigen
163
164#endif // EIGEN_SPARSEPRODUCT_H
Expression of the product of two arbitrary matrices or vectors.
Definition Product.h:111
Pseudo expression representing a solving operation.
Definition Solve.h:63
Base class of any sparse matrices or sparse expressions.
Definition SparseMatrixBase.h:34
Definition SparseView.h:32
Definition Constants.h:511
Definition Constants.h:520
Definition AssignEvaluator.h:684
Definition SparseAssign.h:62
Definition SparseUtil.h:137
Definition AssignmentFunctors.h:42
Definition AssignmentFunctors.h:21
Definition ConservativeSparseSparseProduct.h:129
Definition Meta.h:131
Definition CoreEvaluators.h:82
Definition ProductEvaluators.h:81
Definition Meta.h:39
Definition SparseSparseProductWithPruning.h:83
Definition ConservativeSparseSparseProduct.h:297
Definition AssignmentFunctors.h:63
Definition Meta.h:30