Skip to content

fix: define zero-column rank detection contract#578

Merged
igerber merged 1 commit into
igerber:mainfrom
shawcharles:fix/linalg-zero-column-rank-contract
Jul 2, 2026
Merged

fix: define zero-column rank detection contract#578
igerber merged 1 commit into
igerber:mainfrom
shawcharles:fix/linalg-zero-column-rank-contract

Conversation

@shawcharles

Copy link
Copy Markdown
Contributor

Closes #577.

Summary

This PR defines _detect_rank_deficiency() behaviour for design matrices with zero columns.

Previously, _detect_rank_deficiency(np.empty((n, 0))) reached pivoted QR, received an empty QR diagonal, and raised an IndexError when indexing r_diag[0].

The new behaviour treats an (n, 0) design as rank 0, with no dropped columns and an empty pivot array. That gives the helper an explicit empty-design contract without changing rank-deficiency handling for any matrix with columns.

Changes

  • Add an early return for k == 0 in _detect_rank_deficiency().
  • Add a direct regression test for the zero-column contract.
  • Keep existing rank-zero non-empty-column behaviour unchanged.

Validation

  • PYTHONPATH=. DIFF_DIFF_BACKEND=python pytest tests/test_linalg.py::TestNumericalStability::test_rank_detection_zero_column_matrix_returns_empty_contract -q
  • PYTHONPATH=. DIFF_DIFF_BACKEND=python pytest tests/test_linalg.py::TestNumericalStability -q
  • PYTHONPATH=. DIFF_DIFF_BACKEND=python pytest tests/test_linalg.py -q
  • PYTHONPATH=. DIFF_DIFF_BACKEND=python .venv-py39/bin/python -m pytest tests/test_linalg.py::TestNumericalStability::test_rank_detection_zero_column_matrix_returns_empty_contract -q
  • git diff --check

Security / privacy

Confirmed: no secrets or PII in this PR.

@shawcharles shawcharles marked this pull request as ready for review June 29, 2026 21:57
@shawcharles shawcharles force-pushed the fix/linalg-zero-column-rank-contract branch from 1e5c429 to 86129d4 Compare June 29, 2026 21:57
@shawcharles

Copy link
Copy Markdown
Contributor Author

Ready for review from my side.

I rebased the branch onto current upstream/main and reran the focused checks:

  • PYTHONPATH=. DIFF_DIFF_BACKEND=python pytest tests/test_linalg.py::TestNumericalStability::test_rank_detection_zero_column_matrix_returns_empty_contract -q
  • PYTHONPATH=. DIFF_DIFF_BACKEND=python pytest tests/test_linalg.py -q
  • PYTHONPATH=. DIFF_DIFF_BACKEND=python .venv-py39/bin/python -m pytest tests/test_linalg.py::TestNumericalStability::test_rank_detection_zero_column_matrix_returns_empty_contract -q
  • python -m ruff check diff_diff/linalg.py
  • git diff --check upstream/main...HEAD

Scope note: this only defines the helper contract for an (n, 0) design matrix. It is not intended to change any estimator or statistical-method behaviour.

The current CI Gate failure is only the repository label gate:

The ready-for-ci label is required to run CI tests.

I do not have permission to apply that label, so this is ready whenever you want to label it.

@igerber igerber added the ready-for-ci Triggers CI test workflows label Jul 2, 2026
@igerber igerber self-requested a review July 2, 2026 11:35

@igerber igerber left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good self-contained solve for this issue

@igerber igerber merged commit 7a7debf into igerber:main Jul 2, 2026
30 of 31 checks passed
@igerber igerber mentioned this pull request Jul 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-for-ci Triggers CI test workflows

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Define rank-deficiency behaviour for zero-column designs

2 participants