File indexing completed on 2025-01-18 09:56:18
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #ifndef EIGEN_SOLVE_H
0011 #define EIGEN_SOLVE_H
0012
0013 namespace Eigen {
0014
0015 template<typename Decomposition, typename RhsType, typename StorageKind> class SolveImpl;
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 StorageKind> struct solve_traits;
0033
0034 template<typename Decomposition, typename RhsType>
0035 struct solve_traits<Decomposition,RhsType,Dense>
0036 {
0037 typedef typename make_proper_matrix_type<typename RhsType::Scalar,
0038 Decomposition::ColsAtCompileTime,
0039 RhsType::ColsAtCompileTime,
0040 RhsType::PlainObject::Options,
0041 Decomposition::MaxColsAtCompileTime,
0042 RhsType::MaxColsAtCompileTime>::type PlainObject;
0043 };
0044
0045 template<typename Decomposition, typename RhsType>
0046 struct traits<Solve<Decomposition, RhsType> >
0047 : traits<typename solve_traits<Decomposition,RhsType,typename internal::traits<RhsType>::StorageKind>::PlainObject>
0048 {
0049 typedef typename solve_traits<Decomposition,RhsType,typename internal::traits<RhsType>::StorageKind>::PlainObject PlainObject;
0050 typedef typename promote_index_type<typename Decomposition::StorageIndex, typename RhsType::StorageIndex>::type StorageIndex;
0051 typedef traits<PlainObject> BaseTraits;
0052 enum {
0053 Flags = BaseTraits::Flags & RowMajorBit,
0054 CoeffReadCost = HugeCost
0055 };
0056 };
0057
0058 }
0059
0060
0061 template<typename Decomposition, typename RhsType>
0062 class Solve : public SolveImpl<Decomposition,RhsType,typename internal::traits<RhsType>::StorageKind>
0063 {
0064 public:
0065 typedef typename internal::traits<Solve>::PlainObject PlainObject;
0066 typedef typename internal::traits<Solve>::StorageIndex StorageIndex;
0067
0068 Solve(const Decomposition &dec, const RhsType &rhs)
0069 : m_dec(dec), m_rhs(rhs)
0070 {}
0071
0072 EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR Index rows() const EIGEN_NOEXCEPT { return m_dec.cols(); }
0073 EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR Index cols() const EIGEN_NOEXCEPT { return m_rhs.cols(); }
0074
0075 EIGEN_DEVICE_FUNC const Decomposition& dec() const { return m_dec; }
0076 EIGEN_DEVICE_FUNC const RhsType& rhs() const { return m_rhs; }
0077
0078 protected:
0079 const Decomposition &m_dec;
0080 const RhsType &m_rhs;
0081 };
0082
0083
0084
0085 template<typename Decomposition, typename RhsType>
0086 class SolveImpl<Decomposition,RhsType,Dense>
0087 : public MatrixBase<Solve<Decomposition,RhsType> >
0088 {
0089 typedef Solve<Decomposition,RhsType> Derived;
0090
0091 public:
0092
0093 typedef MatrixBase<Solve<Decomposition,RhsType> > Base;
0094 EIGEN_DENSE_PUBLIC_INTERFACE(Derived)
0095
0096 private:
0097
0098 Scalar coeff(Index row, Index col) const;
0099 Scalar coeff(Index i) const;
0100 };
0101
0102
0103 template<typename Decomposition, typename RhsType, typename StorageKind>
0104 class SolveImpl : public internal::generic_xpr_base<Solve<Decomposition,RhsType>, MatrixXpr, StorageKind>::type
0105 {
0106 public:
0107 typedef typename internal::generic_xpr_base<Solve<Decomposition,RhsType>, MatrixXpr, StorageKind>::type Base;
0108 };
0109
0110 namespace internal {
0111
0112
0113 template<typename Decomposition, typename RhsType>
0114 struct evaluator<Solve<Decomposition,RhsType> >
0115 : public evaluator<typename Solve<Decomposition,RhsType>::PlainObject>
0116 {
0117 typedef Solve<Decomposition,RhsType> SolveType;
0118 typedef typename SolveType::PlainObject PlainObject;
0119 typedef evaluator<PlainObject> Base;
0120
0121 enum { Flags = Base::Flags | EvalBeforeNestingBit };
0122
0123 EIGEN_DEVICE_FUNC explicit evaluator(const SolveType& solve)
0124 : m_result(solve.rows(), solve.cols())
0125 {
0126 ::new (static_cast<Base*>(this)) Base(m_result);
0127 solve.dec()._solve_impl(solve.rhs(), m_result);
0128 }
0129
0130 protected:
0131 PlainObject m_result;
0132 };
0133
0134
0135
0136 template<typename DstXprType, typename DecType, typename RhsType, typename Scalar>
0137 struct Assignment<DstXprType, Solve<DecType,RhsType>, internal::assign_op<Scalar,Scalar>, Dense2Dense>
0138 {
0139 typedef Solve<DecType,RhsType> SrcXprType;
0140 static void run(DstXprType &dst, const SrcXprType &src, const internal::assign_op<Scalar,Scalar> &)
0141 {
0142 Index dstRows = src.rows();
0143 Index dstCols = src.cols();
0144 if((dst.rows()!=dstRows) || (dst.cols()!=dstCols))
0145 dst.resize(dstRows, dstCols);
0146
0147 src.dec()._solve_impl(src.rhs(), dst);
0148 }
0149 };
0150
0151
0152 template<typename DstXprType, typename DecType, typename RhsType, typename Scalar>
0153 struct Assignment<DstXprType, Solve<Transpose<const DecType>,RhsType>, internal::assign_op<Scalar,Scalar>, Dense2Dense>
0154 {
0155 typedef Solve<Transpose<const DecType>,RhsType> SrcXprType;
0156 static void run(DstXprType &dst, const SrcXprType &src, const internal::assign_op<Scalar,Scalar> &)
0157 {
0158 Index dstRows = src.rows();
0159 Index dstCols = src.cols();
0160 if((dst.rows()!=dstRows) || (dst.cols()!=dstCols))
0161 dst.resize(dstRows, dstCols);
0162
0163 src.dec().nestedExpression().template _solve_impl_transposed<false>(src.rhs(), dst);
0164 }
0165 };
0166
0167
0168 template<typename DstXprType, typename DecType, typename RhsType, typename Scalar>
0169 struct Assignment<DstXprType, Solve<CwiseUnaryOp<internal::scalar_conjugate_op<typename DecType::Scalar>, const Transpose<const DecType> >,RhsType>,
0170 internal::assign_op<Scalar,Scalar>, Dense2Dense>
0171 {
0172 typedef Solve<CwiseUnaryOp<internal::scalar_conjugate_op<typename DecType::Scalar>, const Transpose<const DecType> >,RhsType> SrcXprType;
0173 static void run(DstXprType &dst, const SrcXprType &src, const internal::assign_op<Scalar,Scalar> &)
0174 {
0175 Index dstRows = src.rows();
0176 Index dstCols = src.cols();
0177 if((dst.rows()!=dstRows) || (dst.cols()!=dstCols))
0178 dst.resize(dstRows, dstCols);
0179
0180 src.dec().nestedExpression().nestedExpression().template _solve_impl_transposed<true>(src.rhs(), dst);
0181 }
0182 };
0183
0184 }
0185
0186 }
0187
0188 #endif