Skip to content

Commit

Permalink
Added checks that tolerance value is between 0 and 1 (#2884)
Browse files Browse the repository at this point in the history
  • Loading branch information
rlbarker committed Feb 26, 2024
1 parent e8f68a0 commit b3a2456
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
3 changes: 3 additions & 0 deletions openmc/stats/univariate.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,9 @@ def clip(self, tolerance: float = 1e-6, inplace: bool = False) -> Discrete:
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]
Expand Down
6 changes: 6 additions & 0 deletions tests/unit_tests/test_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b3a2456

Please sign in to comment.