Skip to content
This repository was archived by the owner on Nov 17, 2023. It is now read-only.

Commit 5f29819

Browse files
committed
Change signature for np.full
1 parent e539aa2 commit 5f29819

File tree

3 files changed

+67
-3
lines changed

3 files changed

+67
-3
lines changed

python/mxnet/ndarray/numpy/_op.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ def ones(shape, dtype=_np.float32, order='C', ctx=None):
9999

100100

101101
@set_module('mxnet.ndarray.numpy')
102-
def full(shape, fill_value, dtype=None, ctx=None, out=None):
102+
def full(shape, fill_value, dtype=None, order='C', ctx=None, out=None): # pylint: disable=too-many-arguments
103103
"""
104104
Return a new array of given shape and type, filled with `fill_value`.
105105
Parameters
@@ -111,6 +111,9 @@ def full(shape, fill_value, dtype=None, ctx=None, out=None):
111111
dtype : data-type, optional
112112
The desired data-type for the array. The default, `None`, means
113113
`np.array(fill_value).dtype`.
114+
order : {'C'}, optional
115+
Whether to store multidimensional data in C- or Fortran-contiguous
116+
(row- or column-wise) order in memory. Currently only supports C order.
114117
ctx: to specify the device, e.g. the i-th GPU.
115118
out : ndarray or None, optional
116119
A location into which the result is stored.
@@ -142,6 +145,8 @@ def full(shape, fill_value, dtype=None, ctx=None, out=None):
142145
array([[2, 2],
143146
[2, 2]], dtype=int32)
144147
"""
148+
if order != 'C':
149+
raise NotImplementedError
145150
if ctx is None:
146151
ctx = current_context()
147152
dtype = _np.float32 if dtype is None else dtype

python/mxnet/numpy/multiarray.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1674,7 +1674,7 @@ def ones(shape, dtype=_np.float32, order='C', ctx=None):
16741674

16751675

16761676
@set_module('mxnet.numpy')
1677-
def full(shape, fill_value, dtype=None, ctx=None, out=None):
1677+
def full(shape, fill_value, dtype=None, order='C', ctx=None, out=None): # pylint: disable=too-many-arguments
16781678
"""
16791679
Return a new array of given shape and type, filled with `fill_value`.
16801680
@@ -1687,6 +1687,9 @@ def full(shape, fill_value, dtype=None, ctx=None, out=None):
16871687
dtype : data-type, optional
16881688
The desired data-type for the array. The default, `None`, means
16891689
`np.array(fill_value).dtype`.
1690+
order : {'C'}, optional
1691+
Whether to store multidimensional data in C- or Fortran-contiguous
1692+
(row- or column-wise) order in memory. Currently only supports C order.
16901693
ctx: to specify the device, e.g. the i-th GPU.
16911694
out : ndarray or None, optional
16921695
A location into which the result is stored.
@@ -1723,7 +1726,8 @@ def full(shape, fill_value, dtype=None, ctx=None, out=None):
17231726
array([[2, 2],
17241727
[2, 2]], dtype=int32)
17251728
"""
1726-
return _mx_nd_np.full(shape, fill_value, ctx=ctx, dtype=dtype, out=out)
1729+
return _mx_nd_np.full(shape, fill_value, order=order, ctx=ctx, dtype=dtype, out=out)
1730+
17271731

17281732
@set_module('mxnet.numpy')
17291733
def add(x1, x2, out=None):

python/mxnet/symbol/numpy/_symbol.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -927,6 +927,61 @@ def ones(shape, dtype=_np.float32, order='C', ctx=None):
927927
return _npi.ones(shape=shape, ctx=ctx, dtype=dtype)
928928

929929

930+
@set_module('mxnet.symbol.numpy')
931+
def full(shape, fill_value, dtype=None, order='C', ctx=None, out=None): # pylint: disable=too-many-arguments
932+
"""
933+
Return a new array of given shape and type, filled with `fill_value`.
934+
Parameters
935+
----------
936+
shape : int or sequence of ints
937+
Shape of the new array, e.g., ``(2, 3)`` or ``2``.
938+
fill_value : scalar
939+
Fill value.
940+
dtype : data-type, optional
941+
The desired data-type for the array. The default, `None`, means
942+
`np.array(fill_value).dtype`.
943+
order : {'C'}, optional
944+
Whether to store multidimensional data in C- or Fortran-contiguous
945+
(row- or column-wise) order in memory. Currently only supports C order.
946+
ctx: to specify the device, e.g. the i-th GPU.
947+
out : ndarray or None, optional
948+
A location into which the result is stored.
949+
If provided, it must have the same shape and dtype as input ndarray.
950+
If not provided or `None`, a freshly-allocated array is returned.
951+
Returns
952+
-------
953+
out : ndarray
954+
Array of `fill_value` with the given shape, dtype, and order.
955+
Notes
956+
-----
957+
This function differs from the original `numpy.full
958+
https://docs.scipy.org/doc/numpy/reference/generated/numpy.full.html`_ in
959+
the following way(s):
960+
- Have an additional `ctx` argument to specify the device
961+
- Have an additional `out` argument
962+
- Currently does not support `order` selection
963+
See Also
964+
--------
965+
empty : Return a new uninitialized array.
966+
ones : Return a new array setting values to one.
967+
zeros : Return a new array setting values to zero.
968+
Examples
969+
--------
970+
>>> np.full((2, 2), 10)
971+
array([[10., 10.],
972+
[10., 10.]])
973+
>>> np.full((2, 2), 2, dtype=np.int32, ctx=mx.cpu(0))
974+
array([[2, 2],
975+
[2, 2]], dtype=int32)
976+
"""
977+
if order != 'C':
978+
raise NotImplementedError
979+
if ctx is None:
980+
ctx = current_context()
981+
dtype = _np.float32 if dtype is None else dtype
982+
return _npi.full(shape=shape, value=fill_value, ctx=ctx, dtype=dtype, out=out)
983+
984+
930985
#pylint: disable= too-many-arguments, no-member, protected-access
931986
def _ufunc_helper(lhs, rhs, fn_array, fn_scalar, lfn_scalar, rfn_scalar=None, out=None):
932987
""" Helper function for element-wise operation.

0 commit comments

Comments
 (0)