Skip to content
Open
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
8 changes: 5 additions & 3 deletions src/pyrecest/_backend/numpy/linalg.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,19 @@
expm,
)

from .._shared_numpy.linalg import fractional_matrix_power as _fractional_matrix_power
from .._shared_numpy.linalg import (
fractional_matrix_power as _fractional_matrix_power,
is_single_matrix_pd,
logm as _logm,
)
from .._shared_numpy.linalg import logm as _logm
from .._shared_numpy.linalg import (
polar,
qr,
quadratic_assignment,
solve,
solve_sylvester,
sqrtm as _sqrtm,
)
from .._shared_numpy.linalg import sqrtm as _sqrtm


def _empty_zero_by_zero_matrix_result(value):
Expand Down
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
1 change: 0 additions & 1 deletion src/pyrecest/distributions/abstract_custom_distribution.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

from .abstract_distribution_type import AbstractDistributionType


_INVALID_INTEGRAL_TYPES = (
bool,
np.bool_,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@
from pyrecest.distributions.nonperiodic.custom_linear_distribution import (
CustomLinearDistribution,
)
from pyrecest.distributions.nonperiodic.gaussian_distribution import GaussianDistribution
from pyrecest.distributions.nonperiodic.gaussian_distribution import (
GaussianDistribution,
)
from pyrecest.distributions.nonperiodic.linear_mixture import LinearMixture


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@

from .abstract_hyperspherical_distribution import AbstractHypersphericalDistribution


_INVALID_REAL_SCALAR_TYPES = (
bool,
np.bool_,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
from .abstract_hyperspherical_distribution import AbstractHypersphericalDistribution
from .bingham_distribution import BinghamDistribution


_INVALID_REAL_SCALAR_TYPES = (
bool,
np.bool_,
Expand Down
7 changes: 3 additions & 4 deletions src/pyrecest/evaluation/check_and_fix_config.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from numbers import Integral, Real

import numpy as np

from pyrecest.distributions import AbstractManifoldSpecificDistribution


Expand All @@ -12,9 +11,9 @@ def _is_integer_count(value):


def _validate_probability(value, name):
if isinstance(value, (bool, np.bool_, np.datetime64, np.timedelta64)) or not isinstance(
value, Real
):
if isinstance(
value, (bool, np.bool_, np.datetime64, np.timedelta64)
) or not isinstance(value, Real):
raise TypeError(f"{name} must be a real scalar")
value = float(value)
if not np.isfinite(value) or not 0.0 <= value <= 1.0:
Expand Down
4 changes: 1 addition & 3 deletions src/pyrecest/evaluation/get_distance_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,7 @@ def distance_function(xest, xtrue):
return distance_function


def _target_matrix_candidates(
value, name: str
) -> list[tuple[numpy.ndarray, int]]:
def _target_matrix_candidates(value, name: str) -> list[tuple[numpy.ndarray, int]]:
value = _as_real_numeric_array(value, name)
if value.ndim not in (1, 2):
raise ValueError(f"{name} must be a one- or two-dimensional target set")
Expand Down
1 change: 0 additions & 1 deletion src/pyrecest/filters/global_nearest_neighbor.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

from .abstract_nearest_neighbor_tracker import AbstractNearestNeighborTracker


_INVALID_PAIRWISE_COST_SCALAR_TYPES = (
type(None),
bool,
Expand Down
4 changes: 1 addition & 3 deletions src/pyrecest/filters/mode_rbpf_manifold_ukf_tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -876,9 +876,7 @@ def _normalize_probs(probs):
)
total = float(np.sum(probs))
if total <= 0.0:
raise ValueError(
"initial_mode_probs must have positive total probability"
)
raise ValueError("initial_mode_probs must have positive total probability")
return probs / total

@staticmethod
Expand Down
5 changes: 2 additions & 3 deletions src/pyrecest/filters/sequence_association.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,9 +360,8 @@ def _validate_integer(value: object, name: str) -> int:
raise ValueError(message) from exc
if value_array.ndim != 0 or value_array.dtype == np.bool_:
raise ValueError(message)
if (
value_array.dtype.kind in {"S", "U", "c"}
or _is_temporal_scalar_array(value_array)
if value_array.dtype.kind in {"S", "U", "c"} or _is_temporal_scalar_array(
value_array
):
raise ValueError(message)

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
4 changes: 1 addition & 3 deletions src/pyrecest/smoothers/abstract_smoother.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,7 @@ def _normalize_vector_sequence( # pylint: disable=too-many-return-statements
expected_shape = (vector_dim,)
shape_error = f"{name} must contain vectors with shape {expected_shape}."

if isinstance(values, (list, tuple)) and any(
value is None for value in values
):
if isinstance(values, (list, tuple)) and any(value is None for value in values):
values_arr = None
else:
try:
Expand Down
1 change: 0 additions & 1 deletion src/pyrecest/utils/_point_set_registration_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
from scipy.optimize import linear_sum_assignment
from scipy.spatial.distance import cdist


_INVALID_REAL_SCALAR_TYPES = (
type(None),
bool,
Expand Down
6 changes: 1 addition & 5 deletions src/pyrecest/utils/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -579,11 +579,7 @@ def _as_covariance_stack(

def _as_positive_int(value: Any, name: str) -> int:
array = np.asarray(value)
if (
array.ndim != 0
or array.dtype == np.bool_
or array.dtype.kind in {"M", "m"}
):
if array.ndim != 0 or array.dtype == np.bool_ or array.dtype.kind in {"M", "m"}:
raise ValueError(f"{name} must be a positive integer")
scalar = array.item()
if isinstance(scalar, (int, np.integer)) and not isinstance(scalar, bool):
Expand Down
6 changes: 4 additions & 2 deletions src/pyrecest/utils/point_set_registration.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,10 @@ def _validate_positive_integer(value, name: str, *, minimum: int = 1) -> int:
except TypeError:
pass

if isinstance(value, np.ndarray) and value.shape == () and isinstance(
value.item(), temporal_types
if (
isinstance(value, np.ndarray)
and value.shape == ()
and isinstance(value.item(), temporal_types)
):
raise ValueError(error_message)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import pytest
from pyrecest._backend.numpy import linalg


_MATRIX = np.diag([4.0, 9.0])


Expand All @@ -16,9 +15,7 @@
np.timedelta64(2, "ns"),
np.datetime64("1970-01-01T00:00:00.000000002"),
np.array(np.timedelta64(2, "ns"), dtype=object),
np.array(
np.datetime64("1970-01-01T00:00:00.000000002"), dtype=object
),
np.array(np.datetime64("1970-01-01T00:00:00.000000002"), dtype=object),
"0.5",
0.5 + 0.0j,
],
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.numpy import linalg


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,7 +1,6 @@
import numpy as np
import pytest


torch = pytest.importorskip("torch")
from pyrecest._backend.pytorch import random # noqa: E402

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import unittest

import numpy as np

from pyrecest.distributions.abstract_mixture import _validate_mixture_weight_values


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from fractions import Fraction

import numpy as np

from pyrecest.distributions.hypersphere_subset.complex_angular_central_gaussian_distribution import (
_validate_positive_sample_count,
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import numpy as np
import pytest

import pyrecest.backend
import pytest
from pyrecest.backend import array, complex128
from pyrecest.distributions import ComplexWatsonDistribution


pytestmark = pytest.mark.skipif(
pyrecest.backend.__backend_name__ == "jax",
reason="Complex Watson sampling is not supported on the JAX backend",
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
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import unittest

import numpy as np

from pyrecest.backend import array
from pyrecest.distributions import GaussianDistribution

Expand Down
8 changes: 2 additions & 6 deletions tests/distributions/test_gaussian_mixture_complex_mean.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,8 @@

class GaussianMixtureComplexMeanTest(unittest.TestCase):
def test_set_mean_rejects_complex_target_without_mutating_components(self):
component_1 = GaussianDistribution(
array([0.0, 1.0]), diag(array([1.0, 2.0]))
)
component_2 = GaussianDistribution(
array([2.0, 3.0]), diag(array([3.0, 4.0]))
)
component_1 = GaussianDistribution(array([0.0, 1.0]), diag(array([1.0, 2.0])))
component_2 = GaussianDistribution(array([2.0, 3.0]), diag(array([3.0, 4.0])))
mixture = GaussianMixture([component_1, component_2], array([0.25, 0.75]))
original_means = [to_numpy(dist.mu).copy() for dist in mixture.dists]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from math import pi

import numpy as np

from pyrecest.backend import __backend_name__ as backend_name
from pyrecest.backend import array
from pyrecest.distributions.cart_prod.hypercylindrical_state_space_subdivision_distribution import (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ def test_rejects_mixed_boolean_evaluation_points(self):

def test_numeric_python_sequences_remain_valid(self):
npt.assert_allclose(as_shift_vector([0.0, 1.0], 2), [0.0, 1.0])
npt.assert_allclose(
as_hypertoroidal_points([[0.0, 1.0]], 2), [[0.0, 1.0]]
)
npt.assert_allclose(as_hypertoroidal_points([[0.0, 1.0]], 2), [[0.0, 1.0]])


if __name__ == "__main__":
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import numpy as np
import numpy.testing as npt
import pytest

from pyrecest import backend
from pyrecest.distributions import AbstractHypertoroidalDistribution

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
from pyrecest.distributions.nonperiodic.linear_box_particle_distribution import (
LinearBoxParticleDistribution,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import numpy as np
import numpy.testing as npt

from pyrecest.backend import array
from pyrecest.distributions.cart_prod.partially_wrapped_normal_distribution import (
PartiallyWrappedNormalDistribution,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import numpy as np
import pytest

from pyrecest.distributions.circle.piecewise_constant_distribution import (
PiecewiseConstantDistribution,
)
Expand Down
9 changes: 6 additions & 3 deletions tests/distributions/test_se2_dirac_temporal_particle_count.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import numpy as np
import pytest

from pyrecest.distributions import SE2DiracDistribution
from pyrecest.distributions.cart_prod.abstract_hypercylindrical_distribution import (
AbstractHypercylindricalDistribution,
Expand All @@ -18,10 +17,14 @@ def sample(self, n):
raise AssertionError("invalid temporal counts must not reach sampling")

def marginalize_linear(self):
raise AssertionError("marginalization must not be evaluated for count validation")
raise AssertionError(
"marginalization must not be evaluated for count validation"
)

def marginalize_periodic(self):
raise AssertionError("marginalization must not be evaluated for count validation")
raise AssertionError(
"marginalization must not be evaluated for count validation"
)


@pytest.mark.parametrize(
Expand Down
1 change: 0 additions & 1 deletion tests/distributions/test_so3_conversion_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
SO3TangentGaussianDistribution,
)


_TEMPORAL_VALUES = (
np.timedelta64(3, "ns"),
np.timedelta64(3, "us"),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import numpy as np
import pytest

from pyrecest.distributions import VonMisesDistribution


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

from pyrecest.distributions import WrappedNormalDistribution


Expand Down
Loading