Skip to content

Commit

Permalink
[Numpy] Fix apache#19454
Browse files Browse the repository at this point in the history
  • Loading branch information
barry-jin committed Oct 30, 2020
1 parent 0faecf0 commit 012eb95
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions python/mxnet/numpy/fallback.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,16 @@

fallback_mod = sys.modules[__name__]

def get_func(obj, doc):
"""Get new numpy function with object and doc"""
def fn(*args, **kwargs):
return obj(*args, **kwargs)
fn.__doc__ = doc
return fn

for obj_name in fallbacks:
onp_obj = getattr(onp, obj_name)
if callable(onp_obj):
def fn(*args, **kwargs):
return onp_obj(*args, **kwargs)
new_fn_doc = onp_obj.__doc__
if obj_name in {'divmod', 'float_power', 'frexp', 'heaviside', 'modf', 'signbit', 'spacing'}:
# remove reference of kwargs doc and the reference to ufuncs
Expand All @@ -128,8 +133,7 @@ def fn(*args, **kwargs):
# remove unused reference
new_fn_doc = new_fn_doc.replace(
'.. [1] Wikipedia page: https://en.wikipedia.org/wiki/Trapezoidal_rule', '')
fn.__doc__ = new_fn_doc
setattr(fallback_mod, obj_name, fn)
setattr(fallback_mod, obj_name, get_func(onp_obj, new_fn_doc))
else:
setattr(fallback_mod, obj_name, onp_obj)

Expand Down

0 comments on commit 012eb95

Please sign in to comment.