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-2010 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 
15 template<typename Lhs, typename Rhs>
17 {
19  enum {
24  };
25 
26  typedef typename internal::conditional<TransposeLhs,
29 
30  typedef typename internal::conditional<TransposeRhs,
31  SparseMatrix<Scalar,0>,
33 
35 };
36 
37 namespace internal {
38 template<typename LhsNested, typename RhsNested>
40 {
41  typedef MatrixXpr XprKind;
42  // clean the nested types:
45  typedef typename _LhsNested::Scalar Scalar;
48 
49  enum {
50  LhsCoeffReadCost = _LhsNested::CoeffReadCost,
51  RhsCoeffReadCost = _RhsNested::CoeffReadCost,
52  LhsFlags = _LhsNested::Flags,
53  RhsFlags = _RhsNested::Flags,
54 
55  RowsAtCompileTime = _LhsNested::RowsAtCompileTime,
56  ColsAtCompileTime = _RhsNested::ColsAtCompileTime,
57  MaxRowsAtCompileTime = _LhsNested::MaxRowsAtCompileTime,
58  MaxColsAtCompileTime = _RhsNested::MaxColsAtCompileTime,
59 
60  InnerSize = EIGEN_SIZE_MIN_PREFER_FIXED(_LhsNested::ColsAtCompileTime, _RhsNested::RowsAtCompileTime),
61 
62  EvalToRowMajor = (RhsFlags & LhsFlags & RowMajorBit),
63 
64  RemovedBits = ~(EvalToRowMajor ? 0 : RowMajorBit),
65 
66  Flags = (int(LhsFlags | RhsFlags) & HereditaryBits & RemovedBits)
69 
70  CoeffReadCost = Dynamic
71  };
72 
73  typedef Sparse StorageKind;
74 };
75 
76 } // end namespace internal
77 
78 template<typename LhsNested, typename RhsNested>
80  public SparseMatrixBase<SparseSparseProduct<LhsNested, RhsNested> >
81 {
82  public:
83 
86 
87  private:
88 
89  typedef typename internal::traits<SparseSparseProduct>::_LhsNested _LhsNested;
90  typedef typename internal::traits<SparseSparseProduct>::_RhsNested _RhsNested;
91 
92  public:
93 
94  template<typename Lhs, typename Rhs>
95  EIGEN_STRONG_INLINE SparseSparseProduct(const Lhs& lhs, const Rhs& rhs)
96  : m_lhs(lhs), m_rhs(rhs), m_tolerance(0), m_conservative(true)
97  {
98  init();
99  }
100 
101  template<typename Lhs, typename Rhs>
102  EIGEN_STRONG_INLINE SparseSparseProduct(const Lhs& lhs, const Rhs& rhs, const RealScalar& tolerance)
103  : m_lhs(lhs), m_rhs(rhs), m_tolerance(tolerance), m_conservative(false)
104  {
105  init();
106  }
107 
108  SparseSparseProduct pruned(const Scalar& reference = 0, const RealScalar& epsilon = NumTraits<RealScalar>::dummy_precision()) const
109  {
110  using std::abs;
111  return SparseSparseProduct(m_lhs,m_rhs,abs(reference)*epsilon);
112  }
113 
114  template<typename Dest>
115  void evalTo(Dest& result) const
116  {
117  if(m_conservative)
119  else
121  }
122 
123  EIGEN_STRONG_INLINE Index rows() const { return m_lhs.rows(); }
124  EIGEN_STRONG_INLINE Index cols() const { return m_rhs.cols(); }
125 
126  EIGEN_STRONG_INLINE const _LhsNested& lhs() const { return m_lhs; }
127  EIGEN_STRONG_INLINE const _RhsNested& rhs() const { return m_rhs; }
128 
129  protected:
130  void init()
131  {
132  eigen_assert(m_lhs.cols() == m_rhs.rows());
133 
134  enum {
135  ProductIsValid = _LhsNested::ColsAtCompileTime==Dynamic
136  || _RhsNested::RowsAtCompileTime==Dynamic
137  || int(_LhsNested::ColsAtCompileTime)==int(_RhsNested::RowsAtCompileTime),
138  AreVectors = _LhsNested::IsVectorAtCompileTime && _RhsNested::IsVectorAtCompileTime,
140  };
141  // note to the lost user:
142  // * for a dot product use: v1.dot(v2)
143  // * for a coeff-wise product use: v1.cwise()*v2
144  EIGEN_STATIC_ASSERT(ProductIsValid || !(AreVectors && SameSizes),
145  INVALID_VECTOR_VECTOR_PRODUCT__IF_YOU_WANTED_A_DOT_OR_COEFF_WISE_PRODUCT_YOU_MUST_USE_THE_EXPLICIT_FUNCTIONS)
146  EIGEN_STATIC_ASSERT(ProductIsValid || !(SameSizes && !AreVectors),
147  INVALID_MATRIX_PRODUCT__IF_YOU_WANTED_A_COEFF_WISE_PRODUCT_YOU_MUST_USE_THE_EXPLICIT_FUNCTION)
148  EIGEN_STATIC_ASSERT(ProductIsValid || SameSizes, INVALID_MATRIX_PRODUCT)
149  }
150 
155 };
156 
157 // sparse = sparse * sparse
158 template<typename Derived>
159 template<typename Lhs, typename Rhs>
161 {
162  product.evalTo(derived());
163  return derived();
164 }
165 
177 template<typename Derived>
178 template<typename OtherDerived>
181 {
182  return typename SparseSparseProductReturnType<Derived,OtherDerived>::Type(derived(), other.derived());
183 }
184 
185 } // end namespace Eigen
186 
187 #endif // EIGEN_SPARSEPRODUCT_H
SparseMatrixBase< SparseSparseProduct > Base
Definition: SparseProduct.h:84
double epsilon
#define EIGEN_STRONG_INLINE
EIGEN_STRONG_INLINE Index cols() const
A versatible sparse matrix representation.
Definition: SparseMatrix.h:85
void evalTo(Dest &result) const
EIGEN_STRONG_INLINE SparseSparseProduct(const Lhs &lhs, const Rhs &rhs, const RealScalar &tolerance)
Definition: LDLT.h:16
Holds information about the various numeric (i.e. scalar) types allowed by Eigen. ...
Definition: NumTraits.h:88
#define EIGEN_STATIC_ASSERT(CONDITION, MSG)
Definition: StaticAssert.h:111
EIGEN_STRONG_INLINE const _RhsNested & rhs() const
promote_index_type< typename traits< _LhsNested >::Index, typename traits< _RhsNested >::Index >::type Index
Definition: SparseProduct.h:47
#define EIGEN_SIZE_MIN_PREFER_FIXED(a, b)
EIGEN_STRONG_INLINE const _LhsNested & lhs() const
const unsigned int RowMajorBit
Definition: Constants.h:53
EIGEN_STRONG_INLINE const CwiseUnaryOp< internal::scalar_abs_op< Scalar >, const Derived > abs() const
Derived & operator=(const EigenBase< OtherDerived > &other)
const unsigned int HereditaryBits
Definition: Constants.h:152
Base class of any sparse matrices or sparse expressions.
internal::traits< SparseSparseProduct >::_RhsNested _RhsNested
Definition: SparseProduct.h:90
SparseSparseProduct< LhsNested, RhsNested > Type
Definition: SparseProduct.h:34
internal::traits< SparseSparseProduct >::_LhsNested _LhsNested
Definition: SparseProduct.h:89
const ScalarMultipleReturnType operator*(const Scalar &scalar) const
const unsigned int EvalBeforeAssigningBit
Definition: Constants.h:63
internal::traits< Derived >::Index Index
Definition: EigenBase.h:31
SparseSparseProduct pruned(const Scalar &reference=0, const RealScalar &epsilon=NumTraits< RealScalar >::dummy_precision()) const
internal::conditional< TransposeLhs, SparseMatrix< Scalar, 0 >, typename internal::nested< Lhs, Rhs::RowsAtCompileTime >::type >::type LhsNested
Definition: SparseProduct.h:28
#define EIGEN_DENSE_PUBLIC_INTERFACE(Derived)
internal::traits< Lhs >::Scalar Scalar
Definition: SparseProduct.h:18
#define EIGEN_PREDICATE_SAME_MATRIX_SIZE(TYPE0, TYPE1)
Definition: StaticAssert.h:158
const Derived & derived() const
EIGEN_STRONG_INLINE Index rows() const
internal::conditional< TransposeRhs, SparseMatrix< Scalar, 0 >, typename internal::nested< Rhs, Lhs::RowsAtCompileTime >::type >::type RhsNested
Definition: SparseProduct.h:32
const int Dynamic
Definition: Constants.h:21
const unsigned int EvalBeforeNestingBit
Definition: Constants.h:58
#define eigen_assert(x)


tuw_aruco
Author(s): Lukas Pfeifhofer
autogenerated on Mon Jun 10 2019 15:40:59