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
4 changes: 4 additions & 0 deletions test/test_distributions.py
Original file line number Diff line number Diff line change
Expand Up @@ -1126,6 +1126,10 @@ def test_uniform(self):
self.assertEqual(uniform.log_prob(above_high).item(), -float('inf'), allow_inf=True)
self.assertEqual(uniform.log_prob(below_low).item(), -float('inf'), allow_inf=True)

# check cdf computation when value outside range
self.assertEqual(uniform.cdf(below_low).item(), 0)
self.assertEqual(uniform.cdf(above_high).item(), 1)

set_rng_seed(1)
self._gradcheck_log_prob(Uniform, (low, high))
self._gradcheck_log_prob(Uniform, (low, 1.0))
Expand Down
2 changes: 1 addition & 1 deletion torch/distributions/uniform.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def cdf(self, value):
if self._validate_args:
self._validate_sample(value)
result = (value - self.low) / (self.high - self.low)
return result
return result.clamp(min=0, max=1)

def icdf(self, value):
if self._validate_args:
Expand Down