10 #ifndef EIGEN_SOLVETRIANGULAR_H
11 #define EIGEN_SOLVETRIANGULAR_H
21 template<
typename LhsScalar,
typename RhsScalar,
typename Index,
int S
ide,
int Mode,
bool Conjugate,
int StorageOrder>
22 struct triangular_solve_vector;
24 template <
typename Scalar,
typename Index,
int S
ide,
int Mode,
bool Conjugate,
int TriStorageOrder,
int OtherStorageOrder,
int OtherInnerStr
ide>
25 struct triangular_solve_matrix;
28 template<
typename Lhs,
typename Rhs,
int S
ide>
33 RhsIsVectorAtCompileTime = (Side==
OnTheLeft ? Rhs::ColsAtCompileTime : Rhs::RowsAtCompileTime)==1
37 Unrolling = (RhsIsVectorAtCompileTime && Rhs::SizeAtCompileTime !=
Dynamic && Rhs::SizeAtCompileTime <= 8)
39 RhsVectors = RhsIsVectorAtCompileTime ? 1 :
Dynamic
43 template<
typename Lhs,
typename Rhs,
46 int Unrolling = trsolve_traits<Lhs,Rhs,Side>::Unrolling,
47 int RhsVectors = trsolve_traits<Lhs,Rhs,Side>::RhsVectors
49 struct triangular_solver_selector;
51 template<
typename Lhs,
typename Rhs,
int S
ide,
int Mode>
52 struct triangular_solver_selector<Lhs,Rhs,Side,Mode,
NoUnrolling,1>
54 typedef typename Lhs::Scalar LhsScalar;
55 typedef typename Rhs::Scalar RhsScalar;
56 typedef blas_traits<Lhs> LhsProductTraits;
57 typedef typename LhsProductTraits::ExtractType ActualLhsType;
58 typedef Map<Matrix<RhsScalar,Dynamic,1>,
Aligned> MappedRhs;
61 ActualLhsType actualLhs = LhsProductTraits::extract(lhs);
65 bool useRhsDirectly = Rhs::InnerStrideAtCompileTime==1 || rhs.innerStride()==1;
68 (useRhsDirectly ? rhs.data() : 0));
71 MappedRhs(actualRhs,rhs.size()) = rhs;
73 triangular_solve_vector<LhsScalar, RhsScalar,
Index, Side, Mode, LhsProductTraits::NeedToConjugate,
75 ::run(actualLhs.cols(), actualLhs.data(), actualLhs.outerStride(), actualRhs);
78 rhs = MappedRhs(actualRhs, rhs.size());
83 template<
typename Lhs,
typename Rhs,
int S
ide,
int Mode>
86 typedef typename Rhs::Scalar Scalar;
87 typedef blas_traits<Lhs> LhsProductTraits;
88 typedef typename LhsProductTraits::DirectLinearAccessType ActualLhsType;
92 add_const_on_value_type_t<ActualLhsType> actualLhs = LhsProductTraits::extract(lhs);
98 Rhs::MaxRowsAtCompileTime, Rhs::MaxColsAtCompileTime, Lhs::MaxRowsAtCompileTime,4> BlockingType;
100 BlockingType blocking(rhs.rows(), rhs.cols(),
size, 1,
false);
104 ::run(
size, othersize, &actualLhs.coeffRef(0,0), actualLhs.outerStride(), &rhs.coeffRef(0,0), rhs.innerStride(), rhs.outerStride(), blocking);
112 template<
typename Lhs,
typename Rhs,
int Mode,
int LoopIndex,
int Size,
113 bool Stop = LoopIndex==Size>
114 struct triangular_solver_unroller;
116 template<
typename Lhs,
typename Rhs,
int Mode,
int LoopIndex,
int Size>
117 struct triangular_solver_unroller<Lhs,Rhs,Mode,LoopIndex,Size,false> {
120 DiagIndex = IsLower ? LoopIndex : Size - LoopIndex - 1,
121 StartIndex = IsLower ? 0 : DiagIndex+1
126 rhs.coeffRef(DiagIndex) -= lhs.row(DiagIndex).template segment<LoopIndex>(StartIndex).transpose()
127 .cwiseProduct(rhs.template segment<LoopIndex>(StartIndex)).sum();
130 rhs.coeffRef(DiagIndex) /= lhs.coeff(DiagIndex,DiagIndex);
132 triangular_solver_unroller<Lhs,Rhs,Mode,LoopIndex+1,Size>::run(lhs,rhs);
136 template<
typename Lhs,
typename Rhs,
int Mode,
int LoopIndex,
int Size>
137 struct triangular_solver_unroller<Lhs,Rhs,Mode,LoopIndex,Size,true> {
141 template<
typename Lhs,
typename Rhs,
int Mode>
144 { triangular_solver_unroller<Lhs,Rhs,Mode,0,Rhs::SizeAtCompileTime>::run(lhs,rhs); }
147 template<
typename Lhs,
typename Rhs,
int Mode>
151 Transpose<const Lhs> trLhs(lhs);
152 Transpose<Rhs> trRhs(rhs);
154 triangular_solver_unroller<Transpose<const Lhs>,Transpose<Rhs>,
156 0,Rhs::SizeAtCompileTime>::run(trLhs,trRhs);
166 #ifndef EIGEN_PARSED_BY_DOXYGEN
167 template<
typename MatrixType,
unsigned int Mode>
168 template<
int S
ide,
typename OtherDerived>
169 EIGEN_DEVICE_FUNC void TriangularViewImpl<MatrixType,Mode,Dense>::solveInPlace(
const MatrixBase<OtherDerived>& _other)
const
171 OtherDerived& other = _other.const_cast_derived();
175 if (derived().
cols() == 0)
178 enum { copy = (internal::traits<OtherDerived>::Flags &
RowMajorBit) && OtherDerived::IsVectorAtCompileTime && OtherDerived::SizeAtCompileTime!=1};
179 typedef std::conditional_t<copy,
180 typename internal::plain_matrix_type_column_major<OtherDerived>::type, OtherDerived&> OtherCopy;
181 OtherCopy otherCopy(other);
183 internal::triangular_solver_selector<MatrixType, std::remove_reference_t<OtherCopy>,
184 Side, Mode>::run(derived().nestedExpression(), otherCopy);
190 template<
typename Derived,
unsigned int Mode>
191 template<
int S
ide,
typename Other>
192 const internal::triangular_solve_retval<Side,TriangularView<Derived,Mode>,Other>
193 TriangularViewImpl<Derived,Mode,Dense>::solve(
const MatrixBase<Other>& other)
const
195 return internal::triangular_solve_retval<Side,TriangularViewType,Other>(derived(), other.derived());
202 template<
int S
ide,
typename TriangularType,
typename Rhs>
203 struct traits<triangular_solve_retval<Side, TriangularType, Rhs> >
205 typedef typename internal::plain_matrix_type_column_major<Rhs>::type ReturnType;
208 template<
int S
ide,
typename TriangularType,
typename Rhs>
struct triangular_solve_retval
209 :
public ReturnByValue<triangular_solve_retval<Side, TriangularType, Rhs> >
211 typedef remove_all_t<typename Rhs::Nested> RhsNestedCleaned;
212 typedef ReturnByValue<triangular_solve_retval>
Base;
214 triangular_solve_retval(
const TriangularType&
tri,
const Rhs& rhs)
215 : m_triangularMatrix(
tri), m_rhs(rhs)
221 template<
typename Dest>
inline void evalTo(Dest& dst)
const
225 m_triangularMatrix.template solveInPlace<Side>(dst);
229 const TriangularType& m_triangularMatrix;
230 typename Rhs::Nested m_rhs;
#define EIGEN_DEVICE_FUNC
#define ei_declare_aligned_stack_constructed_variable(TYPE, NAME, SIZE, BUFFER)
Tridiagonalization< MatrixXf > tri
internal::dense_xpr_base< ReturnByValue >::type Base
void evalTo(Dest &dst) const
const unsigned int RowMajorBit
bool is_same_dense(const T1 &mat1, const T2 &mat2, std::enable_if_t< possibly_same_dense< T1, T2 >::value > *=0)
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.