You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mxnet.apache.org by zh...@apache.org on 2017/12/14 21:01:02 UTC

[incubator-mxnet] branch v1.0.0 updated: Fix __repr__ for gluon.Parameter (#8956)

This is an automated email from the ASF dual-hosted git repository.

zhasheng pushed a commit to branch v1.0.0
in repository https://gitbox.apache.org/repos/asf/incubator-mxnet.git


The following commit(s) were added to refs/heads/v1.0.0 by this push:
     new e337286  Fix __repr__ for gluon.Parameter (#8956)
e337286 is described below

commit e3372869fcbecedebb894cb8ad86dadca2c1eac0
Author: Julian Salazar <ju...@slzr.me>
AuthorDate: Fri Dec 8 16:36:16 2017 -0800

    Fix __repr__ for gluon.Parameter (#8956)
    
    * Fix __repr__ for gluon.parameter
    
    * Add to contributors (PRs #8565, #8956, etc.)
    
    * Add unit test for gluon.Parameter string
---
 CONTRIBUTORS.md                     |  5 +++++
 python/mxnet/gluon/parameter.py     |  2 +-
 tests/python/unittest/test_gluon.py | 17 +++++++++++++++++
 3 files changed, 23 insertions(+), 1 deletion(-)

diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md
index 64cd29d..bd69dc6 100644
--- a/CONTRIBUTORS.md
+++ b/CONTRIBUTORS.md
@@ -149,3 +149,8 @@ List of Contributors
 * [Jean Kossaifi](https://github.com/JeanKossaifi/)
 * [Kenta Kubo](https://github.com/kkk669/)
 * [Manu Seth](https://github.com/mseth10/)
+* [Calum Leslie](https://github.com/calumleslie)
+* [Andre Tamm](https://github.com/andretamm)
+* [Marco de Abreu](https://github.com/marcoabreu)
+ - Marco is the creator of the current MXNet CI.
+* [Julian Salazar](https://github.com/JulianSlzr)
diff --git a/python/mxnet/gluon/parameter.py b/python/mxnet/gluon/parameter.py
index 537d636..fa38285 100644
--- a/python/mxnet/gluon/parameter.py
+++ b/python/mxnet/gluon/parameter.py
@@ -117,7 +117,7 @@ class Parameter(object):
 
     def __repr__(self):
         s = 'Parameter {name} (shape={shape}, dtype={dtype})'
-        return s.format(**self.__dict__)
+        return s.format(name=self.name, shape=self.shape, dtype=self.dtype)
 
     @property
     def grad_req(self):
diff --git a/tests/python/unittest/test_gluon.py b/tests/python/unittest/test_gluon.py
index df9f78e..2e5c522 100644
--- a/tests/python/unittest/test_gluon.py
+++ b/tests/python/unittest/test_gluon.py
@@ -69,6 +69,23 @@ def test_parameter_sharing():
     net3.load_params('net1.params', mx.cpu())
 
 
+def test_parameter_str():
+    class Net(gluon.Block):
+        def __init__(self, **kwargs):
+            super(Net, self).__init__(**kwargs)
+            with self.name_scope():
+                self.dense0 = nn.Dense(10, in_units=5, use_bias=False)
+
+    net = Net(prefix='net1_')
+    lines = str(net.collect_params()).splitlines()
+
+    assert lines[0] == 'net1_ ('
+    assert 'net1_dense0_weight' in lines[1]
+    assert '(10, 5)' in lines[1]
+    assert 'numpy.float32' in lines[1]
+    assert lines[2] == ')'
+
+
 def test_basic():
     model = nn.Sequential()
     model.add(nn.Dense(128, activation='tanh', in_units=10, flatten=False))

-- 
To stop receiving notification emails like this one, please contact
['"commits@mxnet.apache.org" <co...@mxnet.apache.org>'].