Added checks that tolerance value is between 0 and 1 (#2884)

This commit is contained in:
rlbarker 2024-02-26 22:15:50 +00:00 committed by GitHub
parent e8f68a0159
commit b3a2456f2b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 9 additions and 0 deletions

View file

@ -280,6 +280,9 @@ class Discrete(Univariate):
Discrete distribution with low-importance points removed
"""
cv.check_less_than("tolerance", tolerance, 1.0, equality=True)
cv.check_greater_than("tolerance", tolerance, 0.0, equality=True)
# Determine (reversed) sorted order of probabilities
intensity = self.p * self.x
index_sort = np.argsort(intensity)[::-1]

View file

@ -89,6 +89,12 @@ def test_clip_discrete():
d_same = d.clip(1e-6, inplace=True)
assert d_same is d
with pytest.raises(ValueError):
d.clip(-1.)
with pytest.raises(ValueError):
d.clip(5)
def test_uniform():
a, b = 10.0, 20.0