SparseProduct.h
Go to the documentation of this file.
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 
13 namespace Eigen {
14 
26 template<typename Derived>
27 template<typename OtherDerived>
30 {
31  return Product<Derived,OtherDerived,AliasFreeProduct>(derived(), other.derived());
32 }
33 
34 namespace internal {
35 
36 // sparse * sparse
37 template<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, 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);
55  typename remove_all<RhsNested>::type, Dest>::run(lhsNested,rhsNested,dst);
56  }
57 
58  // dense -= sparse * sparse
59  template<typename Dest>
60  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)
61  {
62  addTo(dst, -lhs, rhs);
63  }
64 
65 protected:
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);
76  typename remove_all<RhsNested>::type, Dest>::run(lhsNested,rhsNested,dst);
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
89 template<typename Lhs, typename Rhs, int ProductType>
91  : public generic_product_impl<Lhs, Rhs, SparseShape, SparseShape, ProductType>
92 {};
93 
94 // sparse-triangular * sparse
95 template<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.)
101 template< typename DstXprType, typename Lhs, typename Rhs>
102 struct Assignment<DstXprType, Product<Lhs,Rhs,AliasFreeProduct>, internal::assign_op<typename DstXprType::Scalar,typename Product<Lhs,Rhs,AliasFreeProduct>::Scalar>, Sparse2Dense>
103 {
106  {
107  Index dstRows = src.rows();
108  Index dstCols = src.cols();
109  if((dst.rows()!=dstRows) || (dst.cols()!=dstCols))
110  dst.resize(dstRows, dstCols);
111 
113  }
114 };
115 
116 // dense += sparse-product (can be sparse*sparse, sparse*perm, etc.)
117 template< typename DstXprType, typename Lhs, typename Rhs>
118 struct Assignment<DstXprType, Product<Lhs,Rhs,AliasFreeProduct>, internal::add_assign_op<typename DstXprType::Scalar,typename Product<Lhs,Rhs,AliasFreeProduct>::Scalar>, Sparse2Dense>
119 {
122  {
124  }
125 };
126 
127 // dense -= sparse-product (can be sparse*sparse, sparse*perm, etc.)
128 template< typename DstXprType, typename Lhs, typename Rhs>
129 struct Assignment<DstXprType, Product<Lhs,Rhs,AliasFreeProduct>, internal::sub_assign_op<typename DstXprType::Scalar,typename Product<Lhs,Rhs,AliasFreeProduct>::Scalar>, Sparse2Dense>
130 {
133  {
135  }
136 };
137 
138 template<typename Lhs, typename Rhs, int Options>
140  : public evaluator<typename Product<Lhs, Rhs, DefaultProduct>::PlainObject>
141 {
143  typedef typename XprType::PlainObject PlainObject;
145 
146  explicit unary_evaluator(const XprType& xpr)
147  : m_result(xpr.rows(), xpr.cols())
148  {
149  using std::abs;
150  ::new (static_cast<Base*>(this)) Base(m_result);
151  typedef typename nested_eval<Lhs,Dynamic>::type LhsNested;
152  typedef typename nested_eval<Rhs,Dynamic>::type RhsNested;
153  LhsNested lhsNested(xpr.nestedExpression().lhs());
154  RhsNested rhsNested(xpr.nestedExpression().rhs());
155 
157  typename remove_all<RhsNested>::type, PlainObject>::run(lhsNested,rhsNested,m_result,
158  abs(xpr.reference())*xpr.epsilon());
159  }
160 
161 protected:
163 };
164 
165 } // end namespace internal
166 
167 // sparse matrix = sparse-product (can be sparse*sparse, sparse*perm, etc.)
168 template<typename Scalar, int _Options, typename _StorageIndex>
169 template<typename Lhs, typename Rhs>
171 {
172  // std::cout << "in Assignment : " << DstOptions << "\n";
173  SparseMatrix dst(src.rows(),src.cols());
175  this->swap(dst);
176  return *this;
177 }
178 
179 } // end namespace Eigen
180 
181 #endif // EIGEN_SPARSEPRODUCT_H
Eigen::internal::Lhs
@ Lhs
Definition: TensorContractionMapper.h:19
Eigen::internal::Assignment< DstXprType, Product< Lhs, Rhs, AliasFreeProduct >, internal::add_assign_op< typename DstXprType::Scalar, typename Product< Lhs, Rhs, AliasFreeProduct >::Scalar >, Sparse2Dense >::run
static void run(DstXprType &dst, const SrcXprType &src, const internal::add_assign_op< typename DstXprType::Scalar, typename SrcXprType::Scalar > &)
Definition: SparseProduct.h:121
Eigen::internal::unary_evaluator< SparseView< Product< Lhs, Rhs, Options > >, IteratorBased >::PlainObject
XprType::PlainObject PlainObject
Definition: SparseProduct.h:143
Eigen
Namespace containing all symbols from the Eigen library.
Definition: jet.h:637
Eigen::SparseMatrix
A versatible sparse matrix representation.
Definition: SparseMatrix.h:96
Eigen::internal::Assignment< DstXprType, Product< Lhs, Rhs, AliasFreeProduct >, internal::sub_assign_op< typename DstXprType::Scalar, typename Product< Lhs, Rhs, AliasFreeProduct >::Scalar >, Sparse2Dense >::SrcXprType
Product< Lhs, Rhs, AliasFreeProduct > SrcXprType
Definition: SparseProduct.h:131
Eigen::DenseShape
Definition: Constants.h:528
Eigen::internal::sparse_sparse_product_with_pruning_selector
Definition: SparseSparseProductWithPruning.h:84
Eigen::internal::SparseTriangularShape
Definition: SparseUtil.h:137
Eigen::internal::generic_product_impl< Lhs, Rhs, SparseShape, SparseShape, ProductType >::subTo
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)
Definition: SparseProduct.h:60
Eigen::internal::Assignment< DstXprType, Product< Lhs, Rhs, AliasFreeProduct >, internal::assign_op< typename DstXprType::Scalar, typename Product< Lhs, Rhs, AliasFreeProduct >::Scalar >, Sparse2Dense >::SrcXprType
Product< Lhs, Rhs, AliasFreeProduct > SrcXprType
Definition: SparseProduct.h:104
Eigen::SparseView::nestedExpression
const internal::remove_all< MatrixTypeNested >::type & nestedExpression() const
Definition: SparseView.h:66
type
Definition: pytypes.h:1525
Eigen::internal::generic_product_impl< Lhs, Rhs, SparseShape, SparseShape, ProductType >::evalTo
static void evalTo(Dest &dst, const Lhs &lhs, const Rhs &rhs, DenseShape)
Definition: SparseProduct.h:81
rows
int rows
Definition: Tutorial_commainit_02.cpp:1
Eigen::internal::unary_evaluator< SparseView< Product< Lhs, Rhs, Options > >, IteratorBased >::unary_evaluator
unary_evaluator(const XprType &xpr)
Definition: SparseProduct.h:146
Eigen::internal::Assignment< DstXprType, Product< Lhs, Rhs, AliasFreeProduct >, internal::add_assign_op< typename DstXprType::Scalar, typename Product< Lhs, Rhs, AliasFreeProduct >::Scalar >, Sparse2Dense >::SrcXprType
Product< Lhs, Rhs, AliasFreeProduct > SrcXprType
Definition: SparseProduct.h:120
Eigen::internal::generic_product_impl
Definition: ProductEvaluators.h:86
Eigen::internal::generic_product_impl< Lhs, Rhs, SparseShape, SparseShape, ProductType >::evalTo
static void evalTo(Dest &dst, const Lhs &lhs, const Rhs &rhs, SparseShape)
Definition: SparseProduct.h:69
Eigen::internal::true_type
Definition: Meta.h:96
Eigen::internal::sparse_sparse_to_dense_product_selector
Definition: ConservativeSparseSparseProduct.h:304
Eigen::internal::Sparse2Dense
Definition: SparseAssign.h:62
Eigen::internal::unary_evaluator< SparseView< Product< Lhs, Rhs, Options > >, IteratorBased >::XprType
SparseView< Product< Lhs, Rhs, Options > > XprType
Definition: SparseProduct.h:142
Eigen::SparseShape
Definition: Constants.h:537
Eigen::internal::Assignment< DstXprType, Product< Lhs, Rhs, AliasFreeProduct >, internal::assign_op< typename DstXprType::Scalar, typename Product< Lhs, Rhs, AliasFreeProduct >::Scalar >, Sparse2Dense >::run
static void run(DstXprType &dst, const SrcXprType &src, const internal::assign_op< typename DstXprType::Scalar, typename SrcXprType::Scalar > &)
Definition: SparseProduct.h:105
Eigen::SparseCompressedBase< SparseMatrix< _Scalar, _Options, _StorageIndex > >::operator=
Derived & operator=(const Derived &other)
Eigen::internal::unary_evaluator< SparseView< Product< Lhs, Rhs, Options > >, IteratorBased >::Base
evaluator< PlainObject > Base
Definition: SparseProduct.h:144
Eigen::internal::IteratorBased
Definition: Constants.h:545
Eigen::internal::evaluator_traits_base::Shape
storage_kind_to_shape< typename traits< T >::StorageKind >::Shape Shape
Definition: CoreEvaluators.h:74
Eigen::Product
Expression of the product of two arbitrary matrices or vectors.
Definition: Product.h:71
gtsam.examples.DogLegOptimizerExample.run
def run(args)
Definition: DogLegOptimizerExample.py:21
Eigen::Product::cols
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR Index cols() const EIGEN_NOEXCEPT
Definition: Product.h:104
Eigen::Triplet< double >
Eigen::internal::evaluator
Definition: CoreEvaluators.h:90
Eigen::Product::lhs
EIGEN_DEVICE_FUNC const EIGEN_STRONG_INLINE LhsNestedCleaned & lhs() const
Definition: Product.h:107
Eigen::internal::conservative_sparse_sparse_product_selector
Definition: ConservativeSparseSparseProduct.h:131
Eigen::SparseView::reference
Scalar reference() const
Definition: SparseView.h:68
Eigen::Product::rows
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR Index rows() const EIGEN_NOEXCEPT
Definition: Product.h:102
Eigen::internal::assign_op
Definition: AssignmentFunctors.h:21
Eigen::SparseMatrixBase::operator*
const Product< Derived, OtherDerived > operator*(const DiagonalBase< OtherDerived > &other) const
Definition: SparseMatrixBase.h:302
Eigen::internal::Rhs
@ Rhs
Definition: TensorContractionMapper.h:18
Eigen::Product::rhs
EIGEN_DEVICE_FUNC const EIGEN_STRONG_INLINE RhsNestedCleaned & rhs() const
Definition: Product.h:109
Eigen::internal::sub_assign_op
Definition: AssignmentFunctors.h:67
Product
ProductLieGroup< Point2, Pose2 > Product
Definition: testLie.cpp:33
Eigen::internal::unary_evaluator
Definition: CoreEvaluators.h:65
Eigen::AliasFreeProduct
@ AliasFreeProduct
Definition: Constants.h:500
Eigen::internal::Assignment
Definition: AssignEvaluator.h:824
Eigen::SparseView
Expression of a dense or sparse matrix with zero or too small values removed.
Definition: ForwardDeclarations.h:124
Eigen::SparseMatrixBase
Base class of any sparse matrices or sparse expressions.
Definition: ForwardDeclarations.h:301
Eigen::internal::is_same
Definition: Meta.h:148
Eigen::internal::unary_evaluator< SparseView< Product< Lhs, Rhs, Options > >, IteratorBased >::m_result
PlainObject m_result
Definition: SparseProduct.h:162
abs
#define abs(x)
Definition: datatypes.h:17
Eigen::internal::add_assign_op
Definition: AssignmentFunctors.h:46
internal
Definition: BandTriangularSolver.h:13
Eigen::internal::generic_product_impl< Lhs, Rhs, SparseShape, SparseShape, ProductType >::evalTo
static void evalTo(Dest &dst, const Lhs &lhs, const Rhs &rhs)
Definition: SparseProduct.h:41
Eigen::internal::enable_if
Definition: Meta.h:273
cols
int cols
Definition: Tutorial_commainit_02.cpp:1
swap
int EIGEN_BLAS_FUNC() swap(int *n, RealScalar *px, int *incx, RealScalar *py, int *incy)
Definition: level1_impl.h:130
Eigen::internal::generic_product_impl< Lhs, Rhs, SparseShape, SparseShape, ProductType >::addTo
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)
Definition: SparseProduct.h:48
Eigen::internal::Assignment< DstXprType, Product< Lhs, Rhs, AliasFreeProduct >, internal::sub_assign_op< typename DstXprType::Scalar, typename Product< Lhs, Rhs, AliasFreeProduct >::Scalar >, Sparse2Dense >::run
static void run(DstXprType &dst, const SrcXprType &src, const internal::sub_assign_op< typename DstXprType::Scalar, typename SrcXprType::Scalar > &)
Definition: SparseProduct.h:132
Eigen::SparseView::epsilon
RealScalar epsilon() const
Definition: SparseView.h:69
test_callbacks.value
value
Definition: test_callbacks.py:160
pybind_wrapper_test_script.other
other
Definition: pybind_wrapper_test_script.py:42
Eigen::Index
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:74


gtsam
Author(s):
autogenerated on Sun Dec 22 2024 04:13:47