This is an automated email from the ASF dual-hosted git repository. cjolivier01 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 5518986 Explicitly convert float value (#8758) 5518986 is described below commit 55189860dbeb9486f745403760e10619f40de488 Author: reminisce <wujun....@gmail.com> AuthorDate: Wed Nov 22 08:25:55 2017 -0800 Explicitly convert float value (#8758) * Explicitly convert float value * Add unit test function --- python/mxnet/ndarray/ndarray.py | 2 +- tests/python/unittest/test_ndarray.py | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/python/mxnet/ndarray/ndarray.py b/python/mxnet/ndarray/ndarray.py index 91d0e03..a45a6a8 100644 --- a/python/mxnet/ndarray/ndarray.py +++ b/python/mxnet/ndarray/ndarray.py @@ -691,7 +691,7 @@ fixed-size items. value.copyto(self) elif isinstance(value, numeric_types): _internal._full(shape=shape, ctx=self.context, - dtype=self.dtype, value=value, out=self) + dtype=self.dtype, value=float(value), out=self) elif isinstance(value, (np.ndarray, np.generic)): if isinstance(value, np.generic) or value.shape != shape: value = np.broadcast_to(value, shape) diff --git a/tests/python/unittest/test_ndarray.py b/tests/python/unittest/test_ndarray.py index 8e1f68f..5512b07 100644 --- a/tests/python/unittest/test_ndarray.py +++ b/tests/python/unittest/test_ndarray.py @@ -926,6 +926,16 @@ def test_ndarray_indexing(): test_getitem_autograd(np_array, index[0]) +def test_assign_float_value_to_ndarray(): + """Test case from https://github.com/apache/incubator-mxnet/issues/8668""" + a = np.array([47.844944], dtype=np.float32) + b = mx.nd.zeros(1, dtype=np.float32) + b[0] = a + assert same(a, b.asnumpy()) + b[0] = a[0] + assert same(a, b.asnumpy()) + + if __name__ == '__main__': import nose nose.runmodule() -- To stop receiving notification emails like this one, please contact ['"comm...@mxnet.apache.org" <comm...@mxnet.apache.org>'].