From 80375370dab732613480a74b00f619690a1cbe0f Mon Sep 17 00:00:00 2001 From: Florian Pfaff <6773539+FlorianPfaff@users.noreply.github.com> Date: Tue, 14 Jul 2026 13:00:21 +0200 Subject: [PATCH 1/2] Handle matrix sequence conversion runtime errors --- src/pyrecest/smoothers/abstract_smoother.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pyrecest/smoothers/abstract_smoother.py b/src/pyrecest/smoothers/abstract_smoother.py index 6c9f1e9e9..1af479d23 100644 --- a/src/pyrecest/smoothers/abstract_smoother.py +++ b/src/pyrecest/smoothers/abstract_smoother.py @@ -58,7 +58,7 @@ def _normalize_matrix_sequence( # pylint: disable=too-many-return-statements,to try: values_arr = asarray(values) - except (TypeError, ValueError): + except (TypeError, ValueError, RuntimeError): values_arr = None if values_arr is not None: if ndim(values_arr) == 0: From 32f6be31450601f04a34d282e3d6bb63f21358d6 Mon Sep 17 00:00:00 2001 From: Florian Pfaff <6773539+FlorianPfaff@users.noreply.github.com> Date: Tue, 14 Jul 2026 13:00:31 +0200 Subject: [PATCH 2/2] Add matrix sequence runtime fallback regression --- ..._smoother_matrix_sequence_runtime_error.py | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 tests/smoothers/test_abstract_smoother_matrix_sequence_runtime_error.py diff --git a/tests/smoothers/test_abstract_smoother_matrix_sequence_runtime_error.py b/tests/smoothers/test_abstract_smoother_matrix_sequence_runtime_error.py new file mode 100644 index 000000000..c38b3f8c4 --- /dev/null +++ b/tests/smoothers/test_abstract_smoother_matrix_sequence_runtime_error.py @@ -0,0 +1,30 @@ +import numpy as np + +import pyrecest.smoothers.abstract_smoother as abstract_smoother_module +from pyrecest.smoothers.abstract_smoother import AbstractSmoother + + +def test_matrix_sequence_falls_back_after_backend_runtime_error(monkeypatch): + matrices = [np.eye(2), 2.0 * np.eye(2)] + backend_asarray = abstract_smoother_module.asarray + + def asarray_with_outer_conversion_failure(value): + if value is matrices: + raise RuntimeError("backend cannot stack the matrix sequence") + return backend_asarray(value) + + monkeypatch.setattr( + abstract_smoother_module, + "asarray", + asarray_with_outer_conversion_failure, + ) + + normalized = AbstractSmoother._normalize_matrix_sequence( + matrices, + length=2, + name="transition_matrices", + matrix_dim=2, + ) + + np.testing.assert_allclose(normalized[0], matrices[0]) + np.testing.assert_allclose(normalized[1], matrices[1])