From 9706546a14e3b05f00f2caff407f33abe9228339 Mon Sep 17 00:00:00 2001 From: Rasmus Munk Larsen <4643818-rmlarsen1@users.noreply.gitlab.com> Date: Fri, 27 Mar 2026 20:49:43 -0700 Subject: [PATCH] Add Householder blocked-right regression test libeigen/eigen!2348 Co-authored-by: Rasmus Munk Larsen --- test/householder.cpp | 48 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/test/householder.cpp b/test/householder.cpp index 0107759a0..f884a7837 100644 --- a/test/householder.cpp +++ b/test/householder.cpp @@ -213,6 +213,51 @@ void householder_update(const MatrixType& m) { } } +template +void householder_blocked_right_regression() { + typedef Matrix MatrixX; + typedef Matrix VectorX; + typedef HouseholderSequence LeftSequence; + typedef HouseholderSequence RightSequence; + + const Index rows = 256; + const Index cols = 128; + const Index shift = 17; + + // Force the blocked path added for right-side Householder application. + VERIFY(cols >= 48 && rows - shift >= 4 * 48); + + MatrixX input = MatrixX::Random(rows, cols); + MatrixX qr_input = input.block(shift, 0, rows - shift, cols); + HouseholderQR qr(qr_input); + + MatrixX packed = input; + packed.block(shift, 0, rows - shift, cols) = qr.matrixQR(); + VectorX hcoeffs = qr.hCoeffs().conjugate(); + + LeftSequence hseq(packed, hcoeffs); + hseq.setLength(hcoeffs.size()).setShift(shift); + MatrixX dense_left = MatrixX(hseq); + + MatrixX packed_transposed = packed.transpose(); + RightSequence rhseq(packed_transposed, hcoeffs); + rhseq.setLength(hcoeffs.size()).setShift(shift); + MatrixX dense_right = MatrixX(rhseq); + + MatrixX left_rhs = MatrixX::Random(rows, rows + 9); + MatrixX right_lhs = MatrixX::Random(rows + 7, rows); + + VERIFY_IS_APPROX(hseq * left_rhs, dense_left * left_rhs); + VERIFY_IS_APPROX(hseq.adjoint() * left_rhs, dense_left.adjoint() * left_rhs); + VERIFY_IS_APPROX(right_lhs * hseq, right_lhs * dense_left); + VERIFY_IS_APPROX(right_lhs * hseq.adjoint(), right_lhs * dense_left.adjoint()); + + VERIFY_IS_APPROX(rhseq * left_rhs, dense_right * left_rhs); + VERIFY_IS_APPROX(rhseq.adjoint() * left_rhs, dense_right.adjoint() * left_rhs); + VERIFY_IS_APPROX(right_lhs * rhseq, right_lhs * dense_right); + VERIFY_IS_APPROX(right_lhs * rhseq.adjoint(), right_lhs * dense_right.adjoint()); +} + EIGEN_DECLARE_TEST(householder) { for (int i = 0; i < g_repeat; i++) { CALL_SUBTEST_1(householder(Matrix())); @@ -232,4 +277,7 @@ EIGEN_DECLARE_TEST(householder) { CALL_SUBTEST_9(householder_update( MatrixXcf(internal::random(1, EIGEN_TEST_MAX_SIZE), internal::random(1, EIGEN_TEST_MAX_SIZE)))); } + + CALL_SUBTEST_10(householder_blocked_right_regression()); + CALL_SUBTEST_11(householder_blocked_right_regression>()); }