You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mxnet.apache.org by cj...@apache.org on 2017/11/22 17:18:46 UTC

[incubator-mxnet] branch v1.0.0 updated: Explicitly convert float value (#8758)

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

cjolivier01 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 b63bec6  Explicitly convert float value (#8758)
b63bec6 is described below

commit b63bec687099cdb09dde8b521b9d0eb930cbc8db
Author: reminisce <wu...@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
['"commits@mxnet.apache.org" <co...@mxnet.apache.org>'].