Skip to content

Commit

Permalink
allow int shape in parameter (apache#11104)
Browse files Browse the repository at this point in the history
  • Loading branch information
szha authored and piiswrong committed Jun 4, 2018
1 parent b93f90f commit 21997a2
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 3 additions & 1 deletion python/mxnet/gluon/parameter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/python/unittest/test_gluon.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,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))
Expand Down

0 comments on commit 21997a2

Please sign in to comment.