Skip to content

Commit

Permalink
Cleaned up _ppf_single after reviewer comment.
Browse files Browse the repository at this point in the history
  • Loading branch information
pvanmulbregt authored and gwgundersen committed Jul 18, 2020
1 parent 0e6a03f commit 80edda0
Showing 1 changed file with 9 additions and 15 deletions.
24 changes: 9 additions & 15 deletions scipy/stats/_distn_infrastructure.py
Original file line number Diff line number Diff line change
Expand Up @@ -1655,26 +1655,20 @@ def _ppf_to_solve(self, x, q, *args):
return self.cdf(*(x, )+args)-q

def _ppf_single(self, q, *args):
left = right = None
_a, _b = self._get_support(*args)
if _a > -np.inf:
left = _a

factor = 10.
if not left: # i.e. self.a = -inf
left = -1.*factor
left, right = self._get_support(*args)

if np.isinf(left):
left = min(-factor, right)
while self._ppf_to_solve(left, q, *args) > 0.:
right = left
left *= factor
left, right = left * factor, left
# left is now such that cdf(left) < q
# if right has changed, then cdf(rught) >= q

if _b < np.inf:
right = _b
else:
right = factor
if np.isinf(right):
right = max(factor, left)
while self._ppf_to_solve(right, q, *args) < 0.:
left = right
right *= factor
left, right = right, right * factor
# right is now such that cdf(right) > q

return optimize.brentq(self._ppf_to_solve,
Expand Down

0 comments on commit 80edda0

Please sign in to comment.