Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

Commit

Permalink
Fix scipy dependency in probability module (#18689)
Browse files Browse the repository at this point in the history
* Fix scipy dependency in probability module

* Fix copy-paste error

* dtype='float32' for digamma and gammaln
  • Loading branch information
leezu authored Jul 11, 2020
1 parent a9b16f7 commit 19e373d
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions python/mxnet/gluon/probability/distributions/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@
from functools import update_wrapper
from numbers import Number
import numpy as onp
import scipy.special as sc
try:
import scipy.special as sc
except ImportError:
sc = None
from .... import symbol as sym
from .... import ndarray as nd

Expand All @@ -48,7 +51,10 @@ def compute(value):
"""Return digamma(value)
"""
if isinstance(value, Number):
return sc.digamma(value, dtype='float32')
if sc is not None:
return sc.digamma(value, dtype='float32')
else:
raise ValueError('Numbers are not supported as input if scipy is not installed')
return F.npx.digamma(value)
return compute

Expand All @@ -60,7 +66,10 @@ def compute(value):
"""Return log(gamma(value))
"""
if isinstance(value, Number):
return sc.gammaln(value, dtype='float32')
if sc is not None:
return sc.gammaln(value, dtype='float32')
else:
raise ValueError('Numbers are not supported as input if scipy is not installed')
return F.npx.gammaln(value)
return compute

Expand All @@ -70,7 +79,10 @@ def erf(F):
"""
def compute(value):
if isinstance(value, Number):
return sc.erf(value)
if sc is not None:
return sc.erf(value)
else:
raise ValueError('Numbers are not supported as input if scipy is not installed')
return F.npx.erf(value)
return compute

Expand All @@ -80,7 +92,10 @@ def erfinv(F):
"""
def compute(value):
if isinstance(value, Number):
return sc.erfinv(value)
if sc is not None:
return sc.erfinv(value)
else:
raise ValueError('Numbers are not supported as input if scipy is not installed')
return F.npx.erfinv(value)
return compute

Expand Down

0 comments on commit 19e373d

Please sign in to comment.