From 87f5a2b23a9d2d02b8b810de329b8b9d71e866b9 Mon Sep 17 00:00:00 2001 From: Anirudh Subramanian Date: Tue, 25 Jul 2017 22:45:58 +0000 Subject: [PATCH 1/4] Modify and Add documentation for mx.nd.zeros --- python/mxnet/ndarray/ndarray_utils.py | 28 ++++++++++++++++++++++++++ python/mxnet/ndarray/sparse_ndarray.py | 6 +++--- 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/python/mxnet/ndarray/ndarray_utils.py b/python/mxnet/ndarray/ndarray_utils.py index 2516372d1b55..c74249f776ac 100644 --- a/python/mxnet/ndarray/ndarray_utils.py +++ b/python/mxnet/ndarray/ndarray_utils.py @@ -8,6 +8,34 @@ def zeros(shape, ctx=None, dtype=None, stype=None, aux_types=None, **kwargs): + """Return a new array of given shape and type, filled with zeros. + + Parameters + ---------- + shape : int or tuple of int + The shape of the empty array + stype: string + The storage type of the empty array, such as 'row_sparse', 'csr', etc + ctx : Context, optional + An optional device context (default is the current default context) + dtype : str or numpy.dtype, optional + An optional value type (default is `float32`) + aux_types: list of numpy.dtype, optional + An optional type for the aux data for SparseNDArray (default values depends + on the storage type) + + Returns + ------- + SparseNDArray + A created array + Examples + -------- + >>> mx.nd.zeros((1,2), mx.gpu(0), stype='csr') + + >>> mx.nd.zeros((1,2), mx.gpu(0), 'float16', stype='row_sparse').asnumpy() + array([[ 0., 0.]], dtype=float16) + """ + if stype is None: return _zeros_ndarray(shape, ctx, dtype, **kwargs) else: diff --git a/python/mxnet/ndarray/sparse_ndarray.py b/python/mxnet/ndarray/sparse_ndarray.py index bd98e58e9547..4ac285d4f0df 100644 --- a/python/mxnet/ndarray/sparse_ndarray.py +++ b/python/mxnet/ndarray/sparse_ndarray.py @@ -613,9 +613,9 @@ def _zeros_sparse_ndarray(stype, shape, ctx=None, dtype=None, aux_types=None, ** A created array Examples -------- - >>> mx.nd.zeros('csr', (1,2), mx.gpu(0)) - - >>> mx.nd.zeros('row_sparse', (1,2), mx.gpu(0), 'float16').asnumpy() + >>> mx.nd.zeros((1,2), mx.cpu(), stype='csr') + + >>> mx.nd.zeros((1,2), mx.cpu(), 'float16', stype='row_sparse').asnumpy() array([[ 0., 0.]], dtype=float16) """ if stype == 'default': From c9f694a4f77315be8d2ad66df9ac0a37387441b5 Mon Sep 17 00:00:00 2001 From: Anirudh Subramanian Date: Tue, 25 Jul 2017 22:53:27 +0000 Subject: [PATCH 2/4] Change context to cpu --- python/mxnet/ndarray/ndarray_utils.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/python/mxnet/ndarray/ndarray_utils.py b/python/mxnet/ndarray/ndarray_utils.py index c74249f776ac..c5b0cdc2f3ab 100644 --- a/python/mxnet/ndarray/ndarray_utils.py +++ b/python/mxnet/ndarray/ndarray_utils.py @@ -30,9 +30,9 @@ def zeros(shape, ctx=None, dtype=None, stype=None, aux_types=None, **kwargs): A created array Examples -------- - >>> mx.nd.zeros((1,2), mx.gpu(0), stype='csr') + >>> mx.nd.zeros((1,2), mx.cpu(), stype='csr') - >>> mx.nd.zeros((1,2), mx.gpu(0), 'float16', stype='row_sparse').asnumpy() + >>> mx.nd.zeros((1,2), mx.cpu(), 'float16', stype='row_sparse').asnumpy() array([[ 0., 0.]], dtype=float16) """ From 94ce5f0b83b5ab4c61f98b218424edc32c377f33 Mon Sep 17 00:00:00 2001 From: Anirudh Subramanian Date: Tue, 25 Jul 2017 23:55:32 +0000 Subject: [PATCH 3/4] Change stype to optional --- python/mxnet/ndarray/ndarray_utils.py | 2 +- python/mxnet/ndarray/sparse_ndarray.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/python/mxnet/ndarray/ndarray_utils.py b/python/mxnet/ndarray/ndarray_utils.py index c5b0cdc2f3ab..96002d29b1d7 100644 --- a/python/mxnet/ndarray/ndarray_utils.py +++ b/python/mxnet/ndarray/ndarray_utils.py @@ -14,7 +14,7 @@ def zeros(shape, ctx=None, dtype=None, stype=None, aux_types=None, **kwargs): ---------- shape : int or tuple of int The shape of the empty array - stype: string + stype: string, optional The storage type of the empty array, such as 'row_sparse', 'csr', etc ctx : Context, optional An optional device context (default is the current default context) diff --git a/python/mxnet/ndarray/sparse_ndarray.py b/python/mxnet/ndarray/sparse_ndarray.py index 4ac285d4f0df..2ea4fca8f449 100644 --- a/python/mxnet/ndarray/sparse_ndarray.py +++ b/python/mxnet/ndarray/sparse_ndarray.py @@ -597,7 +597,7 @@ def _zeros_sparse_ndarray(stype, shape, ctx=None, dtype=None, aux_types=None, ** ---------- shape : int or tuple of int The shape of the empty array - stype: string + stype: string, optional The storage type of the empty array, such as 'row_sparse', 'csr', etc ctx : Context, optional An optional device context (default is the current default context) From 9247acb5bcf54791114fa2911e7c47ed4377cad9 Mon Sep 17 00:00:00 2001 From: Anirudh Subramanian Date: Wed, 26 Jul 2017 15:39:36 +0000 Subject: [PATCH 4/4] Change ordering and remove optional for _zeros_sparse_ndarray --- python/mxnet/ndarray/ndarray_utils.py | 4 ++-- python/mxnet/ndarray/sparse_ndarray.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/python/mxnet/ndarray/ndarray_utils.py b/python/mxnet/ndarray/ndarray_utils.py index 96002d29b1d7..7531464cdf20 100644 --- a/python/mxnet/ndarray/ndarray_utils.py +++ b/python/mxnet/ndarray/ndarray_utils.py @@ -14,12 +14,12 @@ def zeros(shape, ctx=None, dtype=None, stype=None, aux_types=None, **kwargs): ---------- shape : int or tuple of int The shape of the empty array - stype: string, optional - The storage type of the empty array, such as 'row_sparse', 'csr', etc ctx : Context, optional An optional device context (default is the current default context) dtype : str or numpy.dtype, optional An optional value type (default is `float32`) + stype: string, optional + The storage type of the empty array, such as 'row_sparse', 'csr', etc aux_types: list of numpy.dtype, optional An optional type for the aux data for SparseNDArray (default values depends on the storage type) diff --git a/python/mxnet/ndarray/sparse_ndarray.py b/python/mxnet/ndarray/sparse_ndarray.py index 2ea4fca8f449..6aad396bf08e 100644 --- a/python/mxnet/ndarray/sparse_ndarray.py +++ b/python/mxnet/ndarray/sparse_ndarray.py @@ -595,10 +595,10 @@ def _zeros_sparse_ndarray(stype, shape, ctx=None, dtype=None, aux_types=None, ** Parameters ---------- + stype: string + The storage type of the empty array, such as 'row_sparse', 'csr', etc shape : int or tuple of int The shape of the empty array - stype: string, optional - The storage type of the empty array, such as 'row_sparse', 'csr', etc ctx : Context, optional An optional device context (default is the current default context) dtype : str or numpy.dtype, optional