This is an automated email from the ASF dual-hosted git repository.
xidulu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-mxnet.git
The following commit(s) were added to refs/heads/master by this push:
new c292813 [BUGFIX] Fixed problem with Distribution repr due to
cached_property (#19721)
c292813 is described below
commit c29281302f387ad703af549b1da6555d71341c8a
Author: Gerges Dib <[email protected]>
AuthorDate: Fri Jan 1 07:20:28 2021 -0800
[BUGFIX] Fixed problem with Distribution repr due to cached_property
(#19721)
* Fixed problem with Distribution repr due to cached_property
* added comment about change made in Distribution __repr__
Co-authored-by: George Dib <[email protected]>
---
.../gluon/probability/distributions/distribution.py | 18 +++++++++++++-----
1 file changed, 13 insertions(+), 5 deletions(-)
diff --git a/python/mxnet/gluon/probability/distributions/distribution.py
b/python/mxnet/gluon/probability/distributions/distribution.py
index 3600248..736f3dc 100644
--- a/python/mxnet/gluon/probability/distributions/distribution.py
+++ b/python/mxnet/gluon/probability/distributions/distribution.py
@@ -179,12 +179,20 @@ class Distribution(object):
mode = self.F
args_string = ''
if 'symbol' not in mode.__name__:
- for k, _ in self.arg_constraints.items():
- v = self.__dict__[k]
- if isinstance(v, Number):
- shape_v = ()
+ for k in self.arg_constraints:
+ try:
+ v = self.__dict__[k]
+ except KeyError:
+ # TODO: Some of the keys in `arg_constraints` are
cached_properties, which
+ # are set as instance property only after they are called
(hence won't
+ # be in self.__dict__). In case they have not been called
yet, we set shape
+ # to `None` - as a quick fix, since it is not known.
+ shape_v = None
else:
- shape_v = v.shape
+ if isinstance(v, Number):
+ shape_v = ()
+ else:
+ shape_v = v.shape
args_string += '{}: size {}'.format(k, shape_v) + ', '
args_string += ', '.join(['F: {}'.format(mode.__name__),
'event_dim: {}'.format(self.event_dim)])