File indexing completed on 2025-12-16 10:28:51
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #ifndef EIGEN_SOLVEWITHGUESS_H
0011 #define EIGEN_SOLVEWITHGUESS_H
0012
0013 namespace RivetEigen {
0014
0015 template<typename Decomposition, typename RhsType, typename GuessType> class SolveWithGuess;
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029 namespace internal {
0030
0031
0032 template<typename Decomposition, typename RhsType, typename GuessType>
0033 struct traits<SolveWithGuess<Decomposition, RhsType, GuessType> >
0034 : traits<Solve<Decomposition,RhsType> >
0035 {};
0036
0037 }
0038
0039
0040 template<typename Decomposition, typename RhsType, typename GuessType>
0041 class SolveWithGuess : public internal::generic_xpr_base<SolveWithGuess<Decomposition,RhsType,GuessType>, MatrixXpr, typename internal::traits<RhsType>::StorageKind>::type
0042 {
0043 public:
0044 typedef typename internal::traits<SolveWithGuess>::Scalar Scalar;
0045 typedef typename internal::traits<SolveWithGuess>::PlainObject PlainObject;
0046 typedef typename internal::generic_xpr_base<SolveWithGuess<Decomposition,RhsType,GuessType>, MatrixXpr, typename internal::traits<RhsType>::StorageKind>::type Base;
0047 typedef typename internal::ref_selector<SolveWithGuess>::type Nested;
0048
0049 SolveWithGuess(const Decomposition &dec, const RhsType &rhs, const GuessType &guess)
0050 : m_dec(dec), m_rhs(rhs), m_guess(guess)
0051 {}
0052
0053 EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
0054 Index rows() const EIGEN_NOEXCEPT { return m_dec.cols(); }
0055 EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
0056 Index cols() const EIGEN_NOEXCEPT { return m_rhs.cols(); }
0057
0058 EIGEN_DEVICE_FUNC const Decomposition& dec() const { return m_dec; }
0059 EIGEN_DEVICE_FUNC const RhsType& rhs() const { return m_rhs; }
0060 EIGEN_DEVICE_FUNC const GuessType& guess() const { return m_guess; }
0061
0062 protected:
0063 const Decomposition &m_dec;
0064 const RhsType &m_rhs;
0065 const GuessType &m_guess;
0066
0067 private:
0068 Scalar coeff(Index row, Index col) const;
0069 Scalar coeff(Index i) const;
0070 };
0071
0072 namespace internal {
0073
0074
0075 template<typename Decomposition, typename RhsType, typename GuessType>
0076 struct evaluator<SolveWithGuess<Decomposition,RhsType, GuessType> >
0077 : public evaluator<typename SolveWithGuess<Decomposition,RhsType,GuessType>::PlainObject>
0078 {
0079 typedef SolveWithGuess<Decomposition,RhsType,GuessType> SolveType;
0080 typedef typename SolveType::PlainObject PlainObject;
0081 typedef evaluator<PlainObject> Base;
0082
0083 evaluator(const SolveType& solve)
0084 : m_result(solve.rows(), solve.cols())
0085 {
0086 ::new (static_cast<Base*>(this)) Base(m_result);
0087 m_result = solve.guess();
0088 solve.dec()._solve_with_guess_impl(solve.rhs(), m_result);
0089 }
0090
0091 protected:
0092 PlainObject m_result;
0093 };
0094
0095
0096
0097 template<typename DstXprType, typename DecType, typename RhsType, typename GuessType, typename Scalar>
0098 struct Assignment<DstXprType, SolveWithGuess<DecType,RhsType,GuessType>, internal::assign_op<Scalar,Scalar>, Dense2Dense>
0099 {
0100 typedef SolveWithGuess<DecType,RhsType,GuessType> SrcXprType;
0101 static void run(DstXprType &dst, const SrcXprType &src, const internal::assign_op<Scalar,Scalar> &)
0102 {
0103 Index dstRows = src.rows();
0104 Index dstCols = src.cols();
0105 if((dst.rows()!=dstRows) || (dst.cols()!=dstCols))
0106 dst.resize(dstRows, dstCols);
0107
0108 dst = src.guess();
0109 src.dec()._solve_with_guess_impl(src.rhs(), dst);
0110 }
0111 };
0112
0113 }
0114
0115 }
0116
0117 #endif