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

Commit

Permalink
Fix HybridLambda repr (#8565)
Browse files Browse the repository at this point in the history
* fix HybridLambda repr

* ensure function name printed by HybridBlock repr when string
  • Loading branch information
JulianSlzr authored and szha committed Nov 15, 2017
1 parent 710bf4e commit 25ef9bb
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions python/mxnet/gluon/nn/basic_layers.py
Original file line number Diff line number Diff line change
Expand Up @@ -490,8 +490,8 @@ class Lambda(Block):
Output:
- ** *outputs **: one or more output data. Their shapes depend on the function.
"""
def __init__(self, function):
super(Lambda, self).__init__()
def __init__(self, function, prefix=None):
super(Lambda, self).__init__(prefix=prefix)
if isinstance(function, str):
assert hasattr(nd, function), \
"Function name %s is not found in ndarray." % function
Expand Down Expand Up @@ -534,14 +534,17 @@ class HybridLambda(HybridBlock):
Output:
- ** *outputs **: one or more output data. Their shapes depend on the function.
"""
def __init__(self, function):
super(HybridLambda, self).__init__()
def __init__(self, function, prefix=None):
super(HybridLambda, self).__init__(prefix=prefix)
if isinstance(function, str):
assert hasattr(nd, function) and hasattr(sym, function), \
"Function name %s is not found in symbol/ndarray." % function
self._func = lambda F, *args: getattr(F, function)(*args)
func_dict = {sym: getattr(sym, function), nd: getattr(nd, function)}
self._func = lambda F, *args: func_dict[F](*args)
self._func_name = function
elif callable(function):
self._func = function
self._func_name = function.__name__
else:
raise ValueError(
"Unrecognized function in lambda: {} of type {}"
Expand All @@ -552,4 +555,4 @@ def hybrid_forward(self, F, x, *args):

def __repr__(self):
return '{name}({function})'.format(name=self.__class__.__name__,
function=self._func_impl.__name__)
function=self._func_name)

0 comments on commit 25ef9bb

Please sign in to comment.