Solve.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) 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_SOLVE_H
11 #define EIGEN_SOLVE_H
12 
13 namespace Eigen {
14 
15 template<typename Decomposition, typename RhsType, typename StorageKind> class SolveImpl;
16 
29 namespace internal {
30 
31 // this solve_traits class permits to determine the evaluation type with respect to storage kind (Dense vs Sparse)
32 template<typename Decomposition, typename RhsType,typename StorageKind> struct solve_traits;
33 
34 template<typename Decomposition, typename RhsType>
35 struct solve_traits<Decomposition,RhsType,Dense>
36 {
37  typedef typename make_proper_matrix_type<typename RhsType::Scalar,
38  Decomposition::ColsAtCompileTime,
39  RhsType::ColsAtCompileTime,
40  RhsType::PlainObject::Options,
41  Decomposition::MaxColsAtCompileTime,
42  RhsType::MaxColsAtCompileTime>::type PlainObject;
43 };
44 
45 template<typename Decomposition, typename RhsType>
46 struct traits<Solve<Decomposition, RhsType> >
47  : traits<typename solve_traits<Decomposition,RhsType,typename internal::traits<RhsType>::StorageKind>::PlainObject>
48 {
52  enum {
53  Flags = BaseTraits::Flags & RowMajorBit,
54  CoeffReadCost = HugeCost
55  };
56 };
57 
58 }
59 
60 
61 template<typename Decomposition, typename RhsType>
62 class Solve : public SolveImpl<Decomposition,RhsType,typename internal::traits<RhsType>::StorageKind>
63 {
64 public:
67 
68  Solve(const Decomposition &dec, const RhsType &rhs)
69  : m_dec(dec), m_rhs(rhs)
70  {}
71 
74 
75  EIGEN_DEVICE_FUNC const Decomposition& dec() const { return m_dec; }
76  EIGEN_DEVICE_FUNC const RhsType& rhs() const { return m_rhs; }
77 
78 protected:
79  const Decomposition &m_dec;
80  const RhsType &m_rhs;
81 };
82 
83 
84 // Specialization of the Solve expression for dense results
85 template<typename Decomposition, typename RhsType>
86 class SolveImpl<Decomposition,RhsType,Dense>
87  : public MatrixBase<Solve<Decomposition,RhsType> >
88 {
90 
91 public:
92 
95 
96 private:
97 
98  Scalar coeff(Index row, Index col) const;
99  Scalar coeff(Index i) const;
100 };
101 
102 // Generic API dispatcher
103 template<typename Decomposition, typename RhsType, typename StorageKind>
104 class SolveImpl : public internal::generic_xpr_base<Solve<Decomposition,RhsType>, MatrixXpr, StorageKind>::type
105 {
106  public:
108 };
109 
110 namespace internal {
111 
112 // Evaluator of Solve -> eval into a temporary
113 template<typename Decomposition, typename RhsType>
114 struct evaluator<Solve<Decomposition,RhsType> >
115  : public evaluator<typename Solve<Decomposition,RhsType>::PlainObject>
116 {
120 
121  enum { Flags = Base::Flags | EvalBeforeNestingBit };
122 
123  EIGEN_DEVICE_FUNC explicit evaluator(const SolveType& solve)
124  : m_result(solve.rows(), solve.cols())
125  {
126  ::new (static_cast<Base*>(this)) Base(m_result);
127  solve.dec()._solve_impl(solve.rhs(), m_result);
128  }
129 
130 protected:
132 };
133 
134 // Specialization for "dst = dec.solve(rhs)"
135 // NOTE we need to specialize it for Dense2Dense to avoid ambiguous specialization error and a Sparse2Sparse specialization must exist somewhere
136 template<typename DstXprType, typename DecType, typename RhsType, typename Scalar>
137 struct Assignment<DstXprType, Solve<DecType,RhsType>, internal::assign_op<Scalar,Scalar>, Dense2Dense>
138 {
140  static void run(DstXprType &dst, const SrcXprType &src, const internal::assign_op<Scalar,Scalar> &)
141  {
142  Index dstRows = src.rows();
143  Index dstCols = src.cols();
144  if((dst.rows()!=dstRows) || (dst.cols()!=dstCols))
145  dst.resize(dstRows, dstCols);
146 
147  src.dec()._solve_impl(src.rhs(), dst);
148  }
149 };
150 
151 // Specialization for "dst = dec.transpose().solve(rhs)"
152 template<typename DstXprType, typename DecType, typename RhsType, typename Scalar>
153 struct Assignment<DstXprType, Solve<Transpose<const DecType>,RhsType>, internal::assign_op<Scalar,Scalar>, Dense2Dense>
154 {
156  static void run(DstXprType &dst, const SrcXprType &src, const internal::assign_op<Scalar,Scalar> &)
157  {
158  Index dstRows = src.rows();
159  Index dstCols = src.cols();
160  if((dst.rows()!=dstRows) || (dst.cols()!=dstCols))
161  dst.resize(dstRows, dstCols);
162 
163  src.dec().nestedExpression().template _solve_impl_transposed<false>(src.rhs(), dst);
164  }
165 };
166 
167 // Specialization for "dst = dec.adjoint().solve(rhs)"
168 template<typename DstXprType, typename DecType, typename RhsType, typename Scalar>
169 struct Assignment<DstXprType, Solve<CwiseUnaryOp<internal::scalar_conjugate_op<typename DecType::Scalar>, const Transpose<const DecType> >,RhsType>,
170  internal::assign_op<Scalar,Scalar>, Dense2Dense>
171 {
173  static void run(DstXprType &dst, const SrcXprType &src, const internal::assign_op<Scalar,Scalar> &)
174  {
175  Index dstRows = src.rows();
176  Index dstCols = src.cols();
177  if((dst.rows()!=dstRows) || (dst.cols()!=dstCols))
178  dst.resize(dstRows, dstCols);
179 
180  src.dec().nestedExpression().nestedExpression().template _solve_impl_transposed<true>(src.rhs(), dst);
181  }
182 };
183 
184 } // end namespace internal
185 
186 } // end namespace Eigen
187 
188 #endif // EIGEN_SOLVE_H
Eigen::internal::evaluator< Solve< Decomposition, RhsType > >::Base
evaluator< PlainObject > Base
Definition: Solve.h:119
Eigen::internal::evaluator::Base
unary_evaluator< T > Base
Definition: CoreEvaluators.h:92
Eigen::HugeCost
const int HugeCost
Definition: Constants.h:44
Eigen::MatrixXpr
Definition: Constants.h:522
EIGEN_DEVICE_FUNC
#define EIGEN_DEVICE_FUNC
Definition: Macros.h:976
Eigen
Namespace containing all symbols from the Eigen library.
Definition: jet.h:637
col
m col(1)
Eigen::internal::Assignment< DstXprType, Solve< Transpose< const DecType >, RhsType >, internal::assign_op< Scalar, Scalar >, Dense2Dense >::run
static void run(DstXprType &dst, const SrcXprType &src, const internal::assign_op< Scalar, Scalar > &)
Definition: Solve.h:156
Eigen::DenseBase< Solve< Decomposition, RhsType > >::Scalar
internal::traits< Solve< Decomposition, RhsType > >::Scalar Scalar
Definition: DenseBase.h:66
Eigen::internal::Assignment< DstXprType, Solve< DecType, RhsType >, internal::assign_op< Scalar, Scalar >, Dense2Dense >::run
static void run(DstXprType &dst, const SrcXprType &src, const internal::assign_op< Scalar, Scalar > &)
Definition: Solve.h:140
Eigen::Solve::Solve
Solve(const Decomposition &dec, const RhsType &rhs)
Definition: Solve.h:68
Eigen::internal::traits< Solve< Decomposition, RhsType > >::PlainObject
solve_traits< Decomposition, RhsType, typename internal::traits< RhsType >::StorageKind >::PlainObject PlainObject
Definition: Solve.h:49
Eigen::RowMajorBit
const unsigned int RowMajorBit
Definition: Constants.h:66
Eigen::Solve::m_dec
const Decomposition & m_dec
Definition: Solve.h:79
EIGEN_CONSTEXPR
#define EIGEN_CONSTEXPR
Definition: Macros.h:787
Eigen::internal::Dense2Dense
Definition: AssignEvaluator.h:814
type
Definition: pytypes.h:1525
EIGEN_DENSE_PUBLIC_INTERFACE
#define EIGEN_DENSE_PUBLIC_INTERFACE(Derived)
Definition: Macros.h:1283
Eigen::internal::evaluator< Solve< Decomposition, RhsType > >::m_result
PlainObject m_result
Definition: Solve.h:131
Eigen::SolveImpl
Definition: Solve.h:15
Eigen::Solve::dec
const EIGEN_DEVICE_FUNC Decomposition & dec() const
Definition: Solve.h:75
rows
int rows
Definition: Tutorial_commainit_02.cpp:1
Eigen::Solve::rhs
const EIGEN_DEVICE_FUNC RhsType & rhs() const
Definition: Solve.h:76
Eigen::internal::Assignment< DstXprType, Solve< CwiseUnaryOp< internal::scalar_conjugate_op< typename DecType::Scalar >, const Transpose< const DecType > >, RhsType >, internal::assign_op< Scalar, Scalar >, Dense2Dense >::SrcXprType
Solve< CwiseUnaryOp< internal::scalar_conjugate_op< typename DecType::Scalar >, const Transpose< const DecType > >, RhsType > SrcXprType
Definition: Solve.h:172
Eigen::Transpose
Expression of the transpose of a matrix.
Definition: Transpose.h:52
Eigen::Solve::m_rhs
const RhsType & m_rhs
Definition: Solve.h:80
Eigen::SolveImpl::Base
internal::generic_xpr_base< Solve< Decomposition, RhsType >, MatrixXpr, StorageKind >::type Base
Definition: Solve.h:107
Eigen::internal::Assignment< DstXprType, Solve< Transpose< const DecType >, RhsType >, internal::assign_op< Scalar, Scalar >, Dense2Dense >::SrcXprType
Solve< Transpose< const DecType >, RhsType > SrcXprType
Definition: Solve.h:155
Eigen::internal::Assignment< DstXprType, Solve< DecType, RhsType >, internal::assign_op< Scalar, Scalar >, Dense2Dense >::SrcXprType
Solve< DecType, RhsType > SrcXprType
Definition: Solve.h:139
Eigen::internal::generic_xpr_base
Definition: XprHelper.h:501
Eigen::internal::solve_traits
Definition: Solve.h:32
Eigen::internal::traits< Solve< Decomposition, RhsType > >::StorageIndex
promote_index_type< typename Decomposition::StorageIndex, typename RhsType::StorageIndex >::type StorageIndex
Definition: Solve.h:50
Eigen::Solve::rows
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR Index rows() const EIGEN_NOEXCEPT
Definition: Solve.h:72
Eigen::SolveImpl< Decomposition, RhsType, Dense >::Derived
Solve< Decomposition, RhsType > Derived
Definition: Solve.h:89
Eigen::internal::evaluator
Definition: CoreEvaluators.h:90
Eigen::internal::traits< Solve< Decomposition, RhsType > >::BaseTraits
traits< PlainObject > BaseTraits
Definition: Solve.h:51
Eigen::internal::assign_op
Definition: AssignmentFunctors.h:21
Eigen::Solve
Pseudo expression representing a solving operation.
Definition: Solve.h:62
Eigen::internal::evaluator< Solve< Decomposition, RhsType > >::evaluator
EIGEN_DEVICE_FUNC evaluator(const SolveType &solve)
Definition: Solve.h:123
Eigen::internal::traits
Definition: ForwardDeclarations.h:17
Eigen::SolveImpl< Decomposition, RhsType, Dense >::Base
MatrixBase< Solve< Decomposition, RhsType > > Base
Definition: Solve.h:93
Eigen::Solve::StorageIndex
internal::traits< Solve >::StorageIndex StorageIndex
Definition: Solve.h:66
Eigen::CwiseUnaryOp
Generic expression where a coefficient-wise unary operator is applied to an expression.
Definition: CwiseUnaryOp.h:55
row
m row(1)
Eigen::internal::conditional
Definition: Meta.h:109
Eigen::internal::make_proper_matrix_type
Definition: XprHelper.h:257
Eigen::internal::Assignment
Definition: AssignEvaluator.h:824
Eigen::Solve::cols
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR Index cols() const EIGEN_NOEXCEPT
Definition: Solve.h:73
EIGEN_NOEXCEPT
#define EIGEN_NOEXCEPT
Definition: Macros.h:1418
Eigen::internal::evaluator< Solve< Decomposition, RhsType > >::SolveType
Solve< Decomposition, RhsType > SolveType
Definition: Solve.h:117
internal
Definition: BandTriangularSolver.h:13
Eigen::MatrixBase
Base class for all dense matrices, vectors, and expressions.
Definition: MatrixBase.h:48
Eigen::internal::Assignment< DstXprType, Solve< CwiseUnaryOp< internal::scalar_conjugate_op< typename DecType::Scalar >, const Transpose< const DecType > >, RhsType >, internal::assign_op< Scalar, Scalar >, Dense2Dense >::run
static void run(DstXprType &dst, const SrcXprType &src, const internal::assign_op< Scalar, Scalar > &)
Definition: Solve.h:173
Eigen::internal::evaluator< Solve< Decomposition, RhsType > >::PlainObject
SolveType::PlainObject PlainObject
Definition: Solve.h:118
Eigen::Solve::PlainObject
internal::traits< Solve >::PlainObject PlainObject
Definition: Solve.h:65
cols
int cols
Definition: Tutorial_commainit_02.cpp:1
Eigen::EvalBeforeNestingBit
const unsigned int EvalBeforeNestingBit
Definition: Constants.h:70
i
int i
Definition: BiCGSTAB_step_by_step.cpp:9
Eigen::internal::scalar_conjugate_op
Definition: UnaryFunctors.h:109
Eigen::internal::solve_traits< Decomposition, RhsType, Dense >::PlainObject
make_proper_matrix_type< typename RhsType::Scalar, Decomposition::ColsAtCompileTime, RhsType::ColsAtCompileTime, RhsType::PlainObject::Options, Decomposition::MaxColsAtCompileTime, RhsType::MaxColsAtCompileTime >::type PlainObject
Definition: Solve.h:42
Scalar
SCALAR Scalar
Definition: bench_gemm.cpp:46
Eigen::Index
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:74
Eigen::Dense
Definition: Constants.h:507


gtsam
Author(s):
autogenerated on Fri Nov 1 2024 03:35:32