diff --git a/Eigen/src/Householder/Householder.h b/Eigen/src/Householder/Householder.h index e5d2d4fac..f77e54f15 100644 --- a/Eigen/src/Householder/Householder.h +++ b/Eigen/src/Householder/Householder.h @@ -17,9 +17,17 @@ namespace Eigen { namespace internal { -template +template struct decrement_size { - enum { ret = n == Dynamic ? n : n - 1 }; + static constexpr int ret = N - 1; +}; +template <> +struct decrement_size<0> { + static constexpr int ret = 0; +}; +template <> +struct decrement_size { + static constexpr int ret = Dynamic; }; } // namespace internal @@ -67,9 +75,9 @@ EIGEN_DEVICE_FUNC void MatrixBase::makeHouseholder(EssentialPart& essen using numext::conj; EIGEN_STATIC_ASSERT_VECTOR_ONLY(EssentialPart) - VectorBlock tail(derived(), 1, size() - 1); + const VectorBlock tail(derived(), 1, size() - 1); - RealScalar tailSqNorm = size() == 1 ? RealScalar(0) : tail.squaredNorm(); + RealScalar tailSqNorm = size() == 1 ? RealScalar(0) : tail.unwind().squaredNorm(); Scalar c0 = coeff(0); const RealScalar tol = (std::numeric_limits::min)(); @@ -80,7 +88,7 @@ EIGEN_DEVICE_FUNC void MatrixBase::makeHouseholder(EssentialPart& essen } else { beta = numext::sqrt(numext::abs2(c0) + tailSqNorm); if (numext::real(c0) >= RealScalar(0)) beta = -beta; - essential = tail / (c0 - beta); + essential = tail.unwind() / (c0 - beta); tau = conj((beta - c0) / beta); } } @@ -110,10 +118,10 @@ EIGEN_DEVICE_FUNC void MatrixBase::applyHouseholderOnTheLeft(const Esse Map::type> tmp(workspace, cols()); Block bottom(derived(), 1, 0, rows() - 1, cols()); - tmp.noalias() = essential.adjoint() * bottom; - tmp += this->row(0); - this->row(0) -= tau * tmp; - bottom.noalias() -= tau * essential * tmp; + tmp.noalias() = essential.adjoint() * bottom.unwind(); + tmp = tau * (tmp + this->row(0)); + this->row(0) = this->row(0) - tmp; + bottom.unwind().noalias() -= essential * tmp; } } @@ -142,10 +150,10 @@ EIGEN_DEVICE_FUNC void MatrixBase::applyHouseholderOnTheRight(const Ess Map::type> tmp(workspace, rows()); Block right(derived(), 0, 1, rows(), cols() - 1); - tmp.noalias() = right * essential; - tmp += this->col(0); - this->col(0) -= tau * tmp; - right.noalias() -= tau * tmp * essential.adjoint(); + tmp.noalias() = right.unwind() * essential; + tmp = tau * (tmp + this->col(0)); + this->col(0) = this->col(0) - tmp; + right.unwind().noalias() -= tmp * essential.adjoint(); } }