You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mxnet.apache.org by GitBox <gi...@apache.org> on 2018/06/04 17:43:45 UTC
[GitHub] piiswrong closed pull request #11104: allow int shape in parameter
piiswrong closed pull request #11104: allow int shape in parameter
URL: https://github.com/apache/incubator-mxnet/pull/11104
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
diff --git a/python/mxnet/gluon/parameter.py b/python/mxnet/gluon/parameter.py
index 3265fef2b6c..c0d89fbd4cc 100644
--- a/python/mxnet/gluon/parameter.py
+++ b/python/mxnet/gluon/parameter.py
@@ -68,7 +68,7 @@ class Parameter(object):
iteration when using this option.
- 'null' means gradient is not requested for this parameter. gradient arrays
will not be allocated.
- shape : tuple of int, default None
+ shape : int or tuple of int, default None
Shape of this parameter. By default shape is not specified. Parameter with
unknown shape can be used for :py:class:`Symbol` API, but ``init`` will throw an error
when using :py:class:`NDArray` API.
@@ -112,6 +112,8 @@ def __init__(self, name, grad_req='write', shape=None, dtype=mx_real_t,
self._differentiable = differentiable
self._allow_deferred_init = allow_deferred_init
self._grad_req = None
+ if isinstance(shape, int):
+ shape = (shape,)
self._shape = shape
self.name = name
self.dtype = dtype
diff --git a/tests/python/unittest/test_gluon.py b/tests/python/unittest/test_gluon.py
index 2384812ef64..14619a5793a 100644
--- a/tests/python/unittest/test_gluon.py
+++ b/tests/python/unittest/test_gluon.py
@@ -349,7 +349,7 @@ def test_sparse_symbol_block():
def test_sparse_hybrid_block():
params = gluon.ParameterDict('net_')
params.get('weight', shape=(5,5), stype='row_sparse', dtype='float32')
- params.get('bias', shape=(5,), dtype='float32')
+ params.get('bias', shape=(5), dtype='float32')
net = gluon.nn.Dense(5, params=params)
net.initialize()
x = mx.nd.ones((2,5))
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services