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
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
from functools import partial
from operator import index as operator_index

from pyrecest.backend import all as backend_all
from pyrecest.backend import any as backend_any
from pyrecest.backend import asarray, concatenate, ndim, stack, sum
from pyrecest.backend import asarray, concatenate, isfinite, ndim, stack, sum
from pyrecest.distributions import (
AbstractHypercylindricalDistribution,
AbstractHyperhemisphericalDistribution,
Expand Down Expand Up @@ -92,6 +93,8 @@ def __init__(
self.window_weights = asarray(window_weights).reshape(-1)
if self.window_weights.shape[0] != self.window_size:
raise ValueError("window_weights must have length window_size.")
if not bool(backend_all(isfinite(self.window_weights))):
raise ValueError("window_weights must be finite.")
if backend_any(self.window_weights < 0):
raise ValueError("window_weights must be non-negative.")
if sum(self.window_weights) <= 0:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import unittest

import numpy as np
from pyrecest.backend import array
from pyrecest.smoothers import SlidingWindowManifoldMeanSmoother


class SlidingWindowManifoldMeanSmootherNonfiniteWeightsTest(unittest.TestCase):
def test_rejects_nonfinite_window_weights(self):
invalid_weight_vectors = (
array([1.0, np.nan, 1.0]),
array([1.0, np.inf, 1.0]),
array([1.0, -np.inf, 1.0]),
)

for window_weights in invalid_weight_vectors:
with self.subTest(window_weights=window_weights):
with self.assertRaisesRegex(ValueError, "finite"):
SlidingWindowManifoldMeanSmoother(
window_size=3,
window_weights=window_weights,
)


if __name__ == "__main__":
unittest.main()
Loading