Eigen  3.2.91
SparseProduct.h
1 // This file is part of Eigen, a lightweight C++ template library
2 // for linear algebra.
3 //
4 // Copyright (C) 2008-2014 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>
28 inline const Product<Derived,OtherDerived>
30 {
31  return Product<Derived,OtherDerived>(derived(), other.derived());
32 }
33 
34 namespace internal {
35 
36 // sparse * sparse
37 template<typename Lhs, typename Rhs, int ProductType>
38 struct generic_product_impl<Lhs, Rhs, SparseShape, SparseShape, ProductType>
39 {
40  template<typename Dest>
41  static void evalTo(Dest& dst, const Lhs& lhs, const Rhs& rhs)
42  {
43  typedef typename nested_eval<Lhs,Dynamic>::type LhsNested;
44  typedef typename nested_eval<Rhs,Dynamic>::type RhsNested;
45  LhsNested lhsNested(lhs);
46  RhsNested rhsNested(rhs);
47  internal::conservative_sparse_sparse_product_selector<typename remove_all<LhsNested>::type,
48  typename remove_all<RhsNested>::type, Dest>::run(lhsNested,rhsNested,dst);
49  }
50 };
51 
52 // sparse * sparse-triangular
53 template<typename Lhs, typename Rhs, int ProductType>
54 struct generic_product_impl<Lhs, Rhs, SparseShape, SparseTriangularShape, ProductType>
55  : public generic_product_impl<Lhs, Rhs, SparseShape, SparseShape, ProductType>
56 {};
57 
58 // sparse-triangular * sparse
59 template<typename Lhs, typename Rhs, int ProductType>
60 struct generic_product_impl<Lhs, Rhs, SparseTriangularShape, SparseShape, ProductType>
61  : public generic_product_impl<Lhs, Rhs, SparseShape, SparseShape, ProductType>
62 {};
63 
64 template<typename Lhs, typename Rhs, int Options>
65 struct evaluator<SparseView<Product<Lhs, Rhs, Options> > >
66  : public evaluator<typename Product<Lhs, Rhs, DefaultProduct>::PlainObject>
67 {
68  typedef SparseView<Product<Lhs, Rhs, Options> > XprType;
69  typedef typename XprType::PlainObject PlainObject;
70  typedef evaluator<PlainObject> Base;
71 
72  explicit evaluator(const XprType& xpr)
73  : m_result(xpr.rows(), xpr.cols())
74  {
75  using std::abs;
76  ::new (static_cast<Base*>(this)) Base(m_result);
77  typedef typename nested_eval<Lhs,Dynamic>::type LhsNested;
78  typedef typename nested_eval<Rhs,Dynamic>::type RhsNested;
79  LhsNested lhsNested(xpr.nestedExpression().lhs());
80  RhsNested rhsNested(xpr.nestedExpression().rhs());
81 
82  internal::sparse_sparse_product_with_pruning_selector<typename remove_all<LhsNested>::type,
83  typename remove_all<RhsNested>::type, PlainObject>::run(lhsNested,rhsNested,m_result,
84  abs(xpr.reference())*xpr.epsilon());
85  }
86 
87 protected:
88  PlainObject m_result;
89 };
90 
91 } // end namespace internal
92 
93 } // end namespace Eigen
94 
95 #endif // EIGEN_SPARSEPRODUCT_H
Expression of the product of two arbitrary matrices or vectors.
Definition: Product.h:107
Definition: LDLT.h:16
Derived & derived()
Definition: EigenBase.h:44
Base class of any sparse matrices or sparse expressions.
Definition: SparseMatrixBase.h:26
const ScalarMultipleReturnType operator*(const Scalar &scalar) const
Definition: SparseMatrixBase.h:57
Definition: Eigen_Colamd.h:54