Add DenseBase::conjugateIf<bool>()

Submitted by Gael Guennebaud @ggael

Assigned to Nobody

Link to original bugzilla bug (#1658)

Description

Adding a conditional conjugateIf<bool>() method would allow to simplify the implementation of some of our solver code. For instance, in PartialPivLU, we have code like:

if (Conjugate) {
dst = m_lu.template triangularView<Upper>().adjoint().solve(rhs);
m_lu.template triangularView<UnitLower>().adjoint().solveInPlace(dst);
} else {
dst = m_lu.template triangularView<Upper>().transpose().solve(rhs);
m_lu.template triangularView<UnitLower>().transpose().solveInPlace(dst);
}

that could be factorized as:

dst = m_lu.template triangularView<Upper>().transpose()
.template conjugateIf<Conjugate>().solve(rhs);
m_lu.template triangularView<UnitLower>().transpose()
.template conjugateIf<Conjugate>().solveInPlace(dst);

More complicated exemples include FullPivLU::_solve_impl_transposed, and some code in PR567: PR-567

We could keep it internal:

dst = internal::conj_if<bool>(m_lu.template triangularView<Upper>().transpose()).solve(rhs);

but (1) it's less readable than as a free function, and (2) if it's good for us, it's probably good for our users too.

Edited Dec 05, 2019 by Eigen Bugzilla
Assignee Loading
Time tracking Loading