Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/pyrecest/smoothers/abstract_smoother.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
@@ -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])
Loading