From c06103369841b0feb23bb2c85865784aa083521e Mon Sep 17 00:00:00 2001 From: Florian Pfaff <6773539+FlorianPfaff@users.noreply.github.com> Date: Wed, 5 Aug 2026 11:34:12 +0800 Subject: [PATCH 1/4] Add one-shot ellipse symmetrization patch workflow --- ...agent-stabilize-ellipse-symmetrization.yml | 103 ++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100644 .github/workflows/agent-stabilize-ellipse-symmetrization.yml diff --git a/.github/workflows/agent-stabilize-ellipse-symmetrization.yml b/.github/workflows/agent-stabilize-ellipse-symmetrization.yml new file mode 100644 index 0000000000..8318554aa3 --- /dev/null +++ b/.github/workflows/agent-stabilize-ellipse-symmetrization.yml @@ -0,0 +1,103 @@ +name: One-shot ellipse symmetrization patch + +on: + push: + branches: + - agent/stabilize-ellipse-symmetrization + +permissions: + contents: write + +jobs: + patch: + if: github.actor != 'github-actions[bot]' + runs-on: ubuntu-latest + steps: + - name: Check out patch branch + uses: actions/checkout@v4 + with: + fetch-depth: 0 + ref: agent/stabilize-ellipse-symmetrization + + - name: Apply fix and regression tests + shell: bash + run: | + python - <<'PY' + from pathlib import Path + + source_path = Path("src/pyrecest/tracking/ellipse_geometry.py") + source = source_path.read_text(encoding="utf-8") + old = " return 0.5 * (matrix + matrix.T)\n" + new = " return 0.5 * matrix + 0.5 * matrix.T\n" + if source.count(old) != 1: + raise SystemExit("expected exactly one ellipse symmetrization expression") + source_path.write_text(source.replace(old, new), encoding="utf-8") + + test_path = Path( + "tests/tracking/test_ellipse_geometry_extreme_symmetrization.py" + ) + test_path.write_text( + '''from __future__ import annotations + +import numpy as np +import numpy.testing as npt +from pyrecest.tracking.ellipse_geometry import ( + project_symmetric_covariance, + symmetrize, +) + + +def test_symmetrize_preserves_extreme_finite_diagonal() -> None: + covariance = np.diag([1.0e308, 2.0e307]) + + with np.errstate(over="raise", invalid="raise"): + symmetric = np.asarray(symmetrize(covariance)) + + assert np.all(np.isfinite(symmetric)) + npt.assert_array_equal(symmetric, covariance) + + +def test_covariance_projection_preserves_extreme_finite_diagonal() -> None: + covariance = np.diag([1.0e308, 2.0e307]) + + with np.errstate(over="raise", invalid="raise"): + projected = np.asarray(project_symmetric_covariance(covariance)) + + assert np.all(np.isfinite(projected)) + npt.assert_array_equal(projected, covariance) +''', + encoding="utf-8", + ) + + Path( + ".github/workflows/agent-stabilize-ellipse-symmetrization.yml" + ).unlink() + PY + + - name: Validate patch sources + shell: bash + run: | + python -m py_compile \ + src/pyrecest/tracking/ellipse_geometry.py \ + tests/tracking/test_ellipse_geometry_extreme_symmetrization.py + python - <<'PY' + import numpy as np + + matrix = np.diag([1.0e308, 2.0e307]) + with np.errstate(over="raise", invalid="raise"): + result = 0.5 * matrix + 0.5 * matrix.T + np.testing.assert_array_equal(result, matrix) + assert np.all(np.isfinite(result)) + PY + + - name: Commit patch + shell: bash + run: | + git config user.name "github-actions[bot]" + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" + git add \ + src/pyrecest/tracking/ellipse_geometry.py \ + tests/tracking/test_ellipse_geometry_extreme_symmetrization.py \ + .github/workflows/agent-stabilize-ellipse-symmetrization.yml + git commit -m "Stabilize ellipse covariance symmetrization" + git push origin HEAD:agent/stabilize-ellipse-symmetrization From cc9e61c7432ff485eadbfc24630383e357a80d5a Mon Sep 17 00:00:00 2001 From: Florian Pfaff <6773539+FlorianPfaff@users.noreply.github.com> Date: Wed, 5 Aug 2026 11:36:21 +0800 Subject: [PATCH 2/4] Stabilize ellipse covariance symmetrization --- src/pyrecest/tracking/ellipse_geometry.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pyrecest/tracking/ellipse_geometry.py b/src/pyrecest/tracking/ellipse_geometry.py index 163e55f633..489ca72306 100644 --- a/src/pyrecest/tracking/ellipse_geometry.py +++ b/src/pyrecest/tracking/ellipse_geometry.py @@ -37,7 +37,7 @@ def symmetrize(matrix): """Return the symmetric part of ``matrix``.""" matrix = asarray(matrix) - return 0.5 * (matrix + matrix.T) + return 0.5 * matrix + 0.5 * matrix.T def project_symmetric_covariance(covariance, minimum_eigenvalue=0.0): From fbfdb07a0a5ed66b5a09b184ec0bb25a6d075fb9 Mon Sep 17 00:00:00 2001 From: Florian Pfaff <6773539+FlorianPfaff@users.noreply.github.com> Date: Wed, 5 Aug 2026 11:36:36 +0800 Subject: [PATCH 3/4] Test extreme finite ellipse covariance symmetrization --- ...ellipse_geometry_extreme_symmetrization.py | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 tests/tracking/test_ellipse_geometry_extreme_symmetrization.py diff --git a/tests/tracking/test_ellipse_geometry_extreme_symmetrization.py b/tests/tracking/test_ellipse_geometry_extreme_symmetrization.py new file mode 100644 index 0000000000..c9210b5291 --- /dev/null +++ b/tests/tracking/test_ellipse_geometry_extreme_symmetrization.py @@ -0,0 +1,28 @@ +from __future__ import annotations + +import numpy as np +import numpy.testing as npt +from pyrecest.tracking.ellipse_geometry import ( + project_symmetric_covariance, + symmetrize, +) + + +def test_symmetrize_preserves_extreme_finite_diagonal() -> None: + covariance = np.diag([1.0e308, 2.0e307]) + + with np.errstate(over="raise", invalid="raise"): + symmetric = np.asarray(symmetrize(covariance)) + + assert np.all(np.isfinite(symmetric)) + npt.assert_array_equal(symmetric, covariance) + + +def test_covariance_projection_preserves_extreme_finite_diagonal() -> None: + covariance = np.diag([1.0e308, 2.0e307]) + + with np.errstate(over="raise", invalid="raise"): + projected = np.asarray(project_symmetric_covariance(covariance)) + + assert np.all(np.isfinite(projected)) + npt.assert_array_equal(projected, covariance) From cb7b549f4f1037ae02a2dd7ec02a0fe2fb5e7e91 Mon Sep 17 00:00:00 2001 From: Florian Pfaff <6773539+FlorianPfaff@users.noreply.github.com> Date: Wed, 5 Aug 2026 11:36:43 +0800 Subject: [PATCH 4/4] Remove one-shot ellipse patch workflow --- ...agent-stabilize-ellipse-symmetrization.yml | 103 ------------------ 1 file changed, 103 deletions(-) delete mode 100644 .github/workflows/agent-stabilize-ellipse-symmetrization.yml diff --git a/.github/workflows/agent-stabilize-ellipse-symmetrization.yml b/.github/workflows/agent-stabilize-ellipse-symmetrization.yml deleted file mode 100644 index 8318554aa3..0000000000 --- a/.github/workflows/agent-stabilize-ellipse-symmetrization.yml +++ /dev/null @@ -1,103 +0,0 @@ -name: One-shot ellipse symmetrization patch - -on: - push: - branches: - - agent/stabilize-ellipse-symmetrization - -permissions: - contents: write - -jobs: - patch: - if: github.actor != 'github-actions[bot]' - runs-on: ubuntu-latest - steps: - - name: Check out patch branch - uses: actions/checkout@v4 - with: - fetch-depth: 0 - ref: agent/stabilize-ellipse-symmetrization - - - name: Apply fix and regression tests - shell: bash - run: | - python - <<'PY' - from pathlib import Path - - source_path = Path("src/pyrecest/tracking/ellipse_geometry.py") - source = source_path.read_text(encoding="utf-8") - old = " return 0.5 * (matrix + matrix.T)\n" - new = " return 0.5 * matrix + 0.5 * matrix.T\n" - if source.count(old) != 1: - raise SystemExit("expected exactly one ellipse symmetrization expression") - source_path.write_text(source.replace(old, new), encoding="utf-8") - - test_path = Path( - "tests/tracking/test_ellipse_geometry_extreme_symmetrization.py" - ) - test_path.write_text( - '''from __future__ import annotations - -import numpy as np -import numpy.testing as npt -from pyrecest.tracking.ellipse_geometry import ( - project_symmetric_covariance, - symmetrize, -) - - -def test_symmetrize_preserves_extreme_finite_diagonal() -> None: - covariance = np.diag([1.0e308, 2.0e307]) - - with np.errstate(over="raise", invalid="raise"): - symmetric = np.asarray(symmetrize(covariance)) - - assert np.all(np.isfinite(symmetric)) - npt.assert_array_equal(symmetric, covariance) - - -def test_covariance_projection_preserves_extreme_finite_diagonal() -> None: - covariance = np.diag([1.0e308, 2.0e307]) - - with np.errstate(over="raise", invalid="raise"): - projected = np.asarray(project_symmetric_covariance(covariance)) - - assert np.all(np.isfinite(projected)) - npt.assert_array_equal(projected, covariance) -''', - encoding="utf-8", - ) - - Path( - ".github/workflows/agent-stabilize-ellipse-symmetrization.yml" - ).unlink() - PY - - - name: Validate patch sources - shell: bash - run: | - python -m py_compile \ - src/pyrecest/tracking/ellipse_geometry.py \ - tests/tracking/test_ellipse_geometry_extreme_symmetrization.py - python - <<'PY' - import numpy as np - - matrix = np.diag([1.0e308, 2.0e307]) - with np.errstate(over="raise", invalid="raise"): - result = 0.5 * matrix + 0.5 * matrix.T - np.testing.assert_array_equal(result, matrix) - assert np.all(np.isfinite(result)) - PY - - - name: Commit patch - shell: bash - run: | - git config user.name "github-actions[bot]" - git config user.email "41898282+github-actions[bot]@users.noreply.github.com" - git add \ - src/pyrecest/tracking/ellipse_geometry.py \ - tests/tracking/test_ellipse_geometry_extreme_symmetrization.py \ - .github/workflows/agent-stabilize-ellipse-symmetrization.yml - git commit -m "Stabilize ellipse covariance symmetrization" - git push origin HEAD:agent/stabilize-ellipse-symmetrization