Skip to content
Closed
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
4 changes: 1 addition & 3 deletions src/pyrecest/_backend/pytorch/random.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,9 +267,7 @@ def _validate_randint_array_dtype_bounds(low, high, dtype):
# representable by the output dtype, as in randint(255, 256, dtype=uint8).
# For int64, input tensors cannot represent max + 1, so every accepted high
# value is already within the valid endpoint range.
if dtype != _torch.int64 and bool(
_torch.any(high_int64 > dtype_info.max + 1)
):
if dtype != _torch.int64 and bool(_torch.any(high_int64 > dtype_info.max + 1)):
raise ValueError(f"high is out of bounds for {dtype_name}")


Expand Down
2 changes: 1 addition & 1 deletion src/pyrecest/models/linear_gaussian.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

from numbers import Complex, Integral, Real

from pyrecest.backend import all as backend_all
from pyrecest.backend import (
all as backend_all,
asarray,
)
from pyrecest.backend import copy as backend_copy
Expand Down
5 changes: 1 addition & 4 deletions tests/backend/test_pytorch_randint_dtype_bounds.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import numpy as np
import pytest


torch = pytest.importorskip("torch")

from pyrecest._backend.pytorch import random # noqa: E402
Expand All @@ -16,9 +15,7 @@
([0], [129], np.int8, "high is out of bounds for int8"),
],
)
def test_array_randint_rejects_bounds_outside_output_dtype(
low, high, dtype, message
):
def test_array_randint_rejects_bounds_outside_output_dtype(low, high, dtype, message):
with pytest.raises(ValueError, match=message):
random.randint(low, high, dtype=dtype)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import numpy as np
import pytest

from pyrecest.backend import array, diag
from pyrecest.distributions import EllipsoidalBallUniformDistribution

Expand Down
8 changes: 6 additions & 2 deletions tests/filters/test_relaxed_s3f_process_noise_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ def test_rejects_nonsymmetric_process_noise_without_mutating_state(self):

self.assertTrue(
bool(
(filter_.filter_state.linear_distributions[0].C == covariance_before).all()
(
filter_.filter_state.linear_distributions[0].C == covariance_before
).all()
)
)

Expand All @@ -45,7 +47,9 @@ def test_rejects_indefinite_process_noise_without_mutating_state(self):

self.assertTrue(
bool(
(filter_.filter_state.linear_distributions[0].C == covariance_before).all()
(
filter_.filter_state.linear_distributions[0].C == covariance_before
).all()
)
)

Expand Down
24 changes: 6 additions & 18 deletions tests/models/test_linear_gaussian_finite_inputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,19 @@ def test_models_reject_nonfinite_system_and_measurement_matrices(self):
for value in (np.nan, np.inf, -np.inf):
with self.subTest(model="transition", value=value):
with self.assertRaisesRegex(ValueError, "matrix.*finite"):
LinearGaussianTransitionModel(
array([[value]]), array([[1.0]])
)
LinearGaussianTransitionModel(array([[value]]), array([[1.0]]))
with self.subTest(model="measurement", value=value):
with self.assertRaisesRegex(ValueError, "matrix.*finite"):
LinearGaussianMeasurementModel(
array([[value]]), array([[1.0]])
)
LinearGaussianMeasurementModel(array([[value]]), array([[1.0]]))

def test_models_reject_nonfinite_noise_covariances(self):
for value in (np.nan, np.inf, -np.inf):
with self.subTest(model="transition", value=value):
with self.assertRaisesRegex(ValueError, "noise_cov.*finite"):
LinearGaussianTransitionModel(
array([[1.0]]), array([[value]])
)
LinearGaussianTransitionModel(array([[1.0]]), array([[value]]))
with self.subTest(model="measurement", value=value):
with self.assertRaisesRegex(ValueError, "noise_cov.*finite"):
LinearGaussianMeasurementModel(
array([[1.0]]), array([[value]])
)
LinearGaussianMeasurementModel(array([[1.0]]), array([[value]]))

def test_transition_model_rejects_nonfinite_offset(self):
for value in (np.nan, np.inf, -np.inf):
Expand All @@ -55,12 +47,8 @@ def test_identity_models_reject_nonfinite_scalar_noise(self):
IdentityGaussianMeasurementModel(1, value)

def test_prediction_rejects_nonfinite_state_inputs(self):
transition = LinearGaussianTransitionModel(
array([[1.0]]), array([[1.0]])
)
measurement = LinearGaussianMeasurementModel(
array([[1.0]]), array([[1.0]])
)
transition = LinearGaussianTransitionModel(array([[1.0]]), array([[1.0]]))
measurement = LinearGaussianMeasurementModel(array([[1.0]]), array([[1.0]]))

for value in (np.nan, np.inf, -np.inf):
with self.subTest(method="transition mean", value=value):
Expand Down
6 changes: 3 additions & 3 deletions tests/test_deprecation_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ def test_deprecated_decorator_supports_partial_callables():
def add(left, right):
return left + right

legacy_add_one = deprecated(
since="2.3.0", remove_in="3.0.0", replacement="add"
)(functools.partial(add, 1))
legacy_add_one = deprecated(since="2.3.0", remove_in="3.0.0", replacement="add")(
functools.partial(add, 1)
)

with warnings.catch_warnings(record=True) as caught:
warnings.simplefilter("always")
Expand Down
1 change: 0 additions & 1 deletion tests/test_evidence_terminal_posterior_validation.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import pytest

from pyrecest.evidence import EvidenceComputationMode


Expand Down
1 change: 0 additions & 1 deletion tests/test_gaussian_sampler_zero_samples.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import numpy as np

from pyrecest.sampling.euclidean_sampler import GaussianSampler


Expand Down