From 995d34760e976076e33ffadf05528c84988e656e Mon Sep 17 00:00:00 2001 From: JiangZhaoh Date: Tue, 25 Feb 2020 08:14:48 +0000 Subject: [PATCH] modify docs --- python/mxnet/ndarray/numpy/_op.py | 71 ++++++++++++------- python/mxnet/ndarray/numpy/random.py | 20 ++++-- python/mxnet/numpy/multiarray.py | 56 ++++++++++----- python/mxnet/numpy/random.py | 10 +-- python/mxnet/symbol/numpy/_symbol.py | 52 +++++++++----- python/mxnet/symbol/numpy/random.py | 20 ++++-- python/mxnet/util.py | 40 ++++++----- .../main/scala/org/apache/mxnet/LibInfo.scala | 2 - .../scala/org/apache/mxnet/NumpyScope.scala | 12 ---- .../native/org_apache_mxnet_native_c_api.cc | 16 ----- .../native/org_apache_mxnet_native_c_api.h | 16 ----- src/operator/numpy/np_true_divide-inl.h | 4 +- 12 files changed, 181 insertions(+), 138 deletions(-) diff --git a/python/mxnet/ndarray/numpy/_op.py b/python/mxnet/ndarray/numpy/_op.py index 36216801e408..c6c513553825 100644 --- a/python/mxnet/ndarray/numpy/_op.py +++ b/python/mxnet/ndarray/numpy/_op.py @@ -94,7 +94,9 @@ def zeros(shape, dtype=float, order='C', ctx=None): # pylint: disable=redefined shape : int or tuple of int The shape of the empty array. dtype : str or numpy.dtype, optional - An optional value type (default is `float32` or 'float64', which depends on your current default dtype). + An optional value type. + - When npx.is_np_default_dtype() returns Flase, default dtype is float32; + - When npx.is_np_default_dtype() returns True, default dtype is float64. Note that this behavior is different from NumPy's `zeros` function where `float64` is the default value, here we can set 'float32' or 'float64' as your default dtype, because `float32` is considered as the default data type in deep learning. @@ -129,7 +131,9 @@ def ones(shape, dtype=None, order='C', ctx=None): # pylint: disable=redefined-o shape : int or tuple of int The shape of the empty array. dtype : str or numpy.dtype, optional - An optional value type. Default is depend on your current default dtype. + An optional value type. + - When npx.is_np_default_dtype() returns Flase, default dtype is float32; + - When npx.is_np_default_dtype() returns True, default dtype is float64. Note that this behavior is different from NumPy's `ones` function where `float64` is the default value. order : {'C'}, optional, default: 'C' @@ -315,6 +319,8 @@ def full(shape, fill_value, dtype=None, order='C', ctx=None, out=None): # pylin dtype : data-type, optional The desired data-type for the array. The default, `None`, means `np.array(fill_value).dtype`. + - When npx.is_np_default_dtype() returns Flase, default dtype is float32; + - When npx.is_np_default_dtype() returns True, default dtype is float64. order : {'C'}, optional Whether to store multidimensional data in C- or Fortran-contiguous (row- or column-wise) order in memory. Currently only supports C order. @@ -524,8 +530,9 @@ def arange(start, stop=None, step=1, dtype=None, ctx=None): step size is 1. If `step` is specified as a position argument, `start` must also be given. dtype : dtype - The type of the output array. The default is `float32` or 'float64', - which depends on your current default dtype. + The type of the output array. + - When npx.is_np_default_dtype() returns Flase, default dtype is float32; + - When npx.is_np_default_dtype() returns True, default dtype is float64. Returns ------- @@ -565,7 +572,8 @@ def identity(n, dtype=None, ctx=None): Number of rows (and columns) in `n` x `n` output. dtype : data-type, optional Data-type of the output. - Default dtype is 'float32' or 'float64', which depends on your current default dtype. + - When npx.is_np_default_dtype() returns Flase, default dtype is float32; + - When npx.is_np_default_dtype() returns True, default dtype is float64. ctx : Context, optional An optional device context (default is the current default context). @@ -1077,8 +1085,9 @@ def divide(x1, x2, out=None, **kwargs): according to the following rules: * If both inputs are of floating number types, the output is the more precise type. * If only one of the inputs is floating number type, the result is that type. - * If both inputs are of integer types (including boolean), the output is of float32 or - float64 type, which depends on your current default dtype. + * If both inputs are of integer types (including boolean), the output is of default dtype. + - When npx.is_np_default_dtype() returns Flase, default dtype is float32; + - When npx.is_np_default_dtype() returns True, default dtype is float64. """ return _ufunc_helper(x1, x2, _npi.true_divide, _np.divide, _npi.true_divide_scalar, _npi.rtrue_divide_scalar, out) @@ -1116,8 +1125,9 @@ def true_divide(x1, x2, out=None): according to the following rules: * If both inputs are of floating number types, the output is the more precise type. * If only one of the inputs is floating number type, the result is that type. - * If both inputs are of integer types (including boolean), the output is of float32 or - float64 type, which depends on your current default dtype. + * If both inputs are of integer types (including boolean), the output is of default dtype. + - When npx.is_np_default_dtype() returns Flase, default dtype is float32; + - When npx.is_np_default_dtype() returns True, default dtype is float64. """ return _ufunc_helper(x1, x2, _npi.true_divide, _np.divide, _npi.true_divide_scalar, _npi.rtrue_divide_scalar, out) @@ -1621,6 +1631,8 @@ def eye(N, M=None, k=0, dtype=float, **kwargs): and a negative value to a lower diagonal. dtype : data-type, optional Data-type of the returned array. + - When npx.is_np_default_dtype() returns Flase, default dtype is float32; + - When npx.is_np_default_dtype() returns True, default dtype is float64. Returns ------- @@ -4505,8 +4517,9 @@ def average(a, axis=None, weights=None, returned=False, out=None): Return the average along the specified axis. When returned is True, return a tuple with the average as the first element and the sum of the weights as the second element. sum_of_weights is of the same type as retval. - If a is integral, the result dtype will be float32 or float64, which depends on your current - default dtype, otherwise it will be the same as dtype of a. + If a is integral, the result dtype will be current default dtype, otherwise it will be the same + as dtype of a. (i.e. When npx.is_np_default_dtype() returns Flase, default dtype is float32; When + npx.is_np_default_dtype() returns True, default dtype is float64.) Raises -------- @@ -4529,7 +4542,9 @@ def average(a, axis=None, weights=None, returned=False, out=None): - Does not guarantee the same behavior with numpy when given float16 dtype and overflow happens - Does not support complex dtype - The dtypes of a and weights must be the same - - Integral a results in float32 or float64 returned dtype, which depends on your current default dtype + - Integral a results in default dtype. + i.e. When npx.is_np_default_dtype() returns Flase, default dtype is float32; + When npx.is_np_default_dtype() returns True, default dtype is float64. Examples -------- @@ -4573,8 +4588,9 @@ def mean(a, axis=None, dtype=None, out=None, keepdims=False): # pylint: disable instead of a single axis or all the axes as before. dtype : data-type, optional Type to use in computing the mean. - For integer inputs, the default is float32 or float64, which depends on your current default dtype ; - for floating point inputs, it is the same as the input dtype. + For integer inputs, the default is your current default dtype (i.e. When npx.is_np_default_dtype() returns + Flase, default dtype is float32; When npx.is_np_default_dtype() returns True, default dtype is float64.); + For floating point inputs, it is the same as the input dtype. out : ndarray, optional Alternate output array in which to place the result. The default is None; if provided, it must have the same shape and type as the expected output @@ -4596,7 +4612,9 @@ def mean(a, axis=None, dtype=None, out=None, keepdims=False): # pylint: disable `_ in the following way(s): - only ndarray is accepted as valid input, python iterables or scalar is not supported - - default data type for integer input is float32 or float64, which depends on your current default dtype + - default data type for integer input is float32 or float64, which depends on your current default dtype. + When npx.is_np_default_dtype() returns Flase, default dtype is float32; + When npx.is_np_default_dtype() returns True, default dtype is float64. Examples -------- >>> a = np.array([[1, 2], [3, 4]]) @@ -4700,9 +4718,11 @@ def var(a, axis=None, dtype=None, out=None, ddof=0, keepdims=False): # pylint: If this is a tuple of ints, a variance is performed over multiple axes, instead of a single axis or all the axes as before. dtype : data-type, optional - Type to use in computing the variance. For arrays of integer type - the default is `float32` or 'float64', which depends on your current - default dtype; for arrays of float types it is the same as the array type. + Type to use in computing the variance. + For arrays of integer type the default is `float32` or 'float64', + When npx.is_np_default_dtype() returns Flase, default dtype is float32, + When npx.is_np_default_dtype() returns True, default dtype is float64; + For arrays of float types it is the same as the array type. out : ndarray, optional Alternate output array in which to place the result. It must have the same shape as the expected output, but the type is cast if @@ -4763,7 +4783,7 @@ def indices(dimensions, dtype=None, ctx=None): dimensions : sequence of ints The shape of the grid. dtype : data-type, optional - The desired data-type for the array. Default is `int32`. + The desired data-type for the array. Default is `int64`. ctx : device context, optional Device context on which the memory is allocated. Default is `mxnet.context.current_context()`. @@ -4793,10 +4813,10 @@ def indices(dimensions, dtype=None, ctx=None): (2, 2, 3) >>> grid[0] # row indices array([[0, 0, 0], - [1, 1, 1]], dtype=int32) + [1, 1, 1]], dtype=int64) >>> grid[1] # column indices array([[0, 0, 0], - [1, 1, 1]], dtype=int32) + [1, 1, 1]], dtype=int64) The indices can be used as an index into an array. @@ -5018,7 +5038,8 @@ def hanning(M, ctx=None): out : ndarray, shape(M,) The window, with the maximum value normalized to one (the value one appears only if `M` is odd). - Default is 'float32' or 'float64', which depends on your current default dtype. + When npx.is_np_default_dtype() returns Flase, default dtype is float32; + When npx.is_np_default_dtype() returns True, default dtype is float64. Note that you need select numpy.float32 or float64 in this operator. See Also @@ -5099,7 +5120,8 @@ def hamming(M, ctx=None): out : ndarray, shape(M,) The window, with the maximum value normalized to one (the value one appears only if `M` is odd). - Default is 'float32' or 'float64', which depends on your current default dtype. + When npx.is_np_default_dtype() returns Flase, default dtype is float32; + When npx.is_np_default_dtype() returns True, default dtype is float64. Note that you need select numpy.float32 or float64 in this operator. See Also @@ -5181,7 +5203,8 @@ def blackman(M, ctx=None): out : ndarray The window, with the maximum value normalized to one (the value one appears only if the number of samples is odd). - Default is 'float32' or 'float64', which depends on your current default dtype. + When npx.is_np_default_dtype() returns Flase, default dtype is float32; + When npx.is_np_default_dtype() returns True, default dtype is float64. Note that you need select numpy.float32 or float64 in this operator. See Also diff --git a/python/mxnet/ndarray/numpy/random.py b/python/mxnet/ndarray/numpy/random.py index af887081764d..2cdfe8d822bd 100644 --- a/python/mxnet/ndarray/numpy/random.py +++ b/python/mxnet/ndarray/numpy/random.py @@ -111,7 +111,9 @@ def uniform(low=0.0, high=1.0, size=None, dtype=None, ctx=None, out=None): a scalar tensor containing a single value is returned if ``low`` and ``high`` are both scalars. dtype : {'float16', 'float32', 'float64'}, optional - Data type of output samples. Default is 'float32' + Data type of output samples. + When npx.is_np_default_dtype() returns Flase, default dtype is float32; + When npx.is_np_default_dtype() returns True, default dtype is float64. ctx : Context, optional Device context of output. Default is current context. out : ``ndarray``, optional @@ -160,7 +162,9 @@ def normal(loc=0.0, scale=1.0, size=None, dtype=None, ctx=None, out=None): samples are drawn. If size is `None` (default), a scalar tensor containing a single value is returned if loc and scale are both scalars. dtype : {'float16', 'float32', 'float64'}, optional - Data type of output samples. Default is 'float32' + Data type of output samples. + When npx.is_np_default_dtype() returns Flase, default dtype is float32; + When npx.is_np_default_dtype() returns True, default dtype is float64. ctx : Context, optional Device context of output. Default is current context. out : ``ndarray``, optional @@ -768,7 +772,9 @@ def gamma(shape, scale=1.0, size=None, dtype=None, ctx=None, out=None): a single value is returned if ``shape`` and ``scale`` are both scalars. Otherwise, ``np.broadcast(shape, scale).size`` samples are drawn. dtype : {'float16', 'float32', 'float64'}, optional - Data type of output samples. Default is 'float32'. + Data type of output samples. + When npx.is_np_default_dtype() returns Flase, default dtype is float32; + When npx.is_np_default_dtype() returns True, default dtype is float64. ctx : Context, optional Device context of output. Default is current context. @@ -834,7 +840,9 @@ def beta(a, b, size=None, dtype=None, ctx=None): a single value is returned if ``a`` and ``b`` are both scalars. Otherwise, ``np.broadcast(a, b).size`` samples are drawn. dtype : {'float16', 'float32', 'float64'}, optional - Data type of output samples. Default is 'float32'. + Data type of output samples. + When npx.is_np_default_dtype() returns Flase, default dtype is float32; + When npx.is_np_default_dtype() returns True, default dtype is float64. ctx : Context, optional Device context of output. Default is current context. @@ -881,7 +889,9 @@ def chisquare(df, size=None, dtype=None, ctx=None): a single value is returned if ``df`` is a scalar. Otherwise, ``np.array(df).size`` samples are drawn. dtype : {'float16', 'float32', 'float64'}, optional - Data type of output samples. Default is 'float32'. + Data type of output samples. + When npx.is_np_default_dtype() returns Flase, default dtype is float32; + When npx.is_np_default_dtype() returns True, default dtype is float64. Dtype 'float32' or 'float64' is strongly recommended, since lower precision might lead to out of range issue. ctx : Context, optional diff --git a/python/mxnet/numpy/multiarray.py b/python/mxnet/numpy/multiarray.py index b779a1171c9f..325089155e29 100644 --- a/python/mxnet/numpy/multiarray.py +++ b/python/mxnet/numpy/multiarray.py @@ -2196,6 +2196,8 @@ def empty(shape, dtype=float, order='C', ctx=None): # pylint: disable=redefined Note that this behavior is different from NumPy's `empty` function where `float64` is the default value, here you can set your default dtype as 'float32' or 'float64' because `float32` is considered as the default data type in deep learning. + When npx.is_np_default_dtype() returns Flase, default dtype is float32; + When npx.is_np_default_dtype() returns True, default dtype is float64. order : {'C'}, optional, default: 'C' How to store multi-dimensional data in memory, currently only row-major (C-style) is supported. @@ -2241,7 +2243,9 @@ def array(object, dtype=None, ctx=None): An array, any object exposing the array interface, an object whose __array__ method returns an array, or any (nested) sequence. dtype : data-type, optional - The desired data-type for the array. Default is depends on your current default dtype. + The desired data-type for the array. + When npx.is_np_default_dtype() returns Flase, default dtype is float32; + When npx.is_np_default_dtype() returns True, default dtype is float64. ctx : device context, optional Device context on which the memory is allocated. Default is `mxnet.context.current_context()`. @@ -2334,7 +2338,9 @@ def zeros(shape, dtype=float, order='C', ctx=None): # pylint: disable=redefined shape : int or tuple of int The shape of the empty array. dtype : str or numpy.dtype, optional - An optional value type (default is `float32` or 'float64', which depends on your current default dtype). + An optional value type, + When npx.is_np_default_dtype() returns Flase, default dtype is float32, + When npx.is_np_default_dtype() returns True, default dtype is float64. Note that this behavior is different from NumPy's `zeros` function where `float64` is the default value, here we can set 'float32' or 'float64' as your default dtype, because `float32` is considered as the default data type in deep learning. @@ -2376,6 +2382,8 @@ def ones(shape, dtype=None, order='C', ctx=None): # pylint: disable=redefined-o The shape of the empty array. dtype : str or numpy.dtype, optional An optional value type. Default is depend on your current default dtype. + When npx.is_np_default_dtype() returns Flase, default dtype is float32; + When npx.is_np_default_dtype() returns True, default dtype is float64. Note that this behavior is different from NumPy's `ones` function where `float64` is the default value. order : {'C'}, optional, default: 'C' @@ -2570,7 +2578,8 @@ def identity(n, dtype=None, ctx=None): Number of rows (and columns) in `n` x `n` output. dtype : data-type, optional Data-type of the output. - Default dtype is 'float32' or 'float64', which depends on your current default dtype. + When npx.is_np_default_dtype() returns Flase, default dtype is float32; + When npx.is_np_default_dtype() returns True, default dtype is float64. ctx : Context, optional An optional device context (default is the current default context). @@ -2942,6 +2951,8 @@ def divide(x1, x2, out=None, **kwargs): * If only one of the inputs is floating number type, the result is that type. * If both inputs are of integer types (including boolean), the output is of float32 or float64 type, which depends on your current default dtype. + When npx.is_np_default_dtype() returns Flase, default dtype is float32; + When npx.is_np_default_dtype() returns True, default dtype is float64. Examples -------- @@ -2985,6 +2996,8 @@ def true_divide(x1, x2, out=None): * If only one of the inputs is floating number type, the result is that type. * If both inputs are of integer types (including boolean), the output is of float32 or float64 type, which depends on your current default dtype. + When npx.is_np_default_dtype() returns Flase, default dtype is float32; + When npx.is_np_default_dtype() returns True, default dtype is float64. Examples -------- @@ -4992,6 +5005,8 @@ def eye(N, M=None, k=0, dtype=float, **kwargs): and a negative value to a lower diagonal. dtype : data-type, optional Data-type of the returned array. + When npx.is_np_default_dtype() returns Flase, default dtype is float32; + When npx.is_np_default_dtype() returns True, default dtype is float64. Returns ------- @@ -6326,8 +6341,10 @@ def average(a, axis=None, weights=None, returned=False, out=None): Return the average along the specified axis. When returned is True, return a tuple with the average as the first element and the sum of the weights as the second element. sum_of_weights is of the same type as retval. - If a is integral, the result dtype will be float32 or float64, which depends on your current - default dtype, otherwise it will be the same as dtype of a. + If a is integral, the result dtype will be current default dtype, + When npx.is_np_default_dtype() returns Flase, default dtype is float32, + When npx.is_np_default_dtype() returns True, default dtype is float64; + otherwise it will be the same as dtype of a. Raises -------- @@ -6391,8 +6408,10 @@ def mean(a, axis=None, dtype=None, out=None, keepdims=False): # pylint: disable instead of a single axis or all the axes as before. dtype : data-type, optional Type to use in computing the mean. - For integer inputs, the default is float32 or float64, which depends on your current default dtype ; - for floating point inputs, it is the same as the input dtype. + For integer inputs, the default is of your current default dtype, + When npx.is_np_default_dtype() returns Flase, default dtype is float32, + When npx.is_np_default_dtype() returns True, default dtype is float64; + For floating point inputs, it is the same as the input dtype. out : ndarray, optional Alternate output array in which to place the result. The default is None; if provided, it must have the same shape and type as the expected output. @@ -6571,9 +6590,11 @@ def var(a, axis=None, dtype=None, out=None, ddof=0, keepdims=False): # pylint: If this is a tuple of ints, a variance is performed over multiple axes, instead of a single axis or all the axes as before. dtype : data-type, optional - Type to use in computing the variance. For arrays of integer type - the default is `float32` or 'float64', which depends on your current - default dtype; for arrays of float types it is the same as the array type. + Type to use in computing the variance. + For arrays of integer type, the default is of your current default dtype, + When npx.is_np_default_dtype() returns Flase, default dtype is float32, + When npx.is_np_default_dtype() returns True, default dtype is float64. + For arrays of float types it is the same as the array type. out : ndarray, optional Alternate output array in which to place the result. It must have the same shape as the expected output, but the type is cast if @@ -6634,7 +6655,7 @@ def indices(dimensions, dtype=None, ctx=None): dimensions : sequence of ints The shape of the grid. dtype : data-type, optional - The desired data-type for the array. Default is `int32`. + The desired data-type for the array. Default is `int64`. ctx : device context, optional Device context on which the memory is allocated. Default is `mxnet.context.current_context()`. @@ -6664,10 +6685,10 @@ def indices(dimensions, dtype=None, ctx=None): (2, 2, 3) >>> grid[0] # row indices array([[0, 0, 0], - [1, 1, 1]], dtype=int32) + [1, 1, 1]], dtype=int64) >>> grid[1] # column indices array([[0, 0, 0], - [1, 1, 1]], dtype=int32) + [1, 1, 1]], dtype=int64) The indices can be used as an index into an array. @@ -6869,7 +6890,8 @@ def hanning(M, ctx=None): out : ndarray, shape(M,) The window, with the maximum value normalized to one (the value one appears only if `M` is odd). - Default is 'float32' or 'float64', which depends on your current default dtype. + When npx.is_np_default_dtype() returns Flase, default dtype is float32; + When npx.is_np_default_dtype() returns True, default dtype is float64. Note that you need select numpy.float32 or float64 in this operator. See Also @@ -6948,7 +6970,8 @@ def hamming(M, ctx=None): out : ndarray, shape(M,) The window, with the maximum value normalized to one (the value one appears only if `M` is odd). - Default is 'float32' or 'float64', which depends on your current default dtype. + When npx.is_np_default_dtype() returns Flase, default dtype is float32; + When npx.is_np_default_dtype() returns True, default dtype is float64. Note that you need select numpy.float32 or float64 in this operator. See Also @@ -7028,7 +7051,8 @@ def blackman(M, ctx=None): out : ndarray The window, with the maximum value normalized to one (the value one appears only if the number of samples is odd). - Default is 'float32' or 'float64', which depends on your current default dtype. + When npx.is_np_default_dtype() returns Flase, default dtype is float32; + When npx.is_np_default_dtype() returns True, default dtype is float64. Note that you need select numpy.float32 or float64 in this operator. See Also diff --git a/python/mxnet/numpy/random.py b/python/mxnet/numpy/random.py index 23fe4422bd8f..30db52bc496f 100644 --- a/python/mxnet/numpy/random.py +++ b/python/mxnet/numpy/random.py @@ -101,8 +101,9 @@ def uniform(low=0.0, high=1.0, size=None, dtype=None, ctx=None, out=None): ``low`` and ``high`` are both scalars. Otherwise, ``np.broadcast(low, high).size`` samples are drawn. dtype : {'float16', 'float32', 'float64'}, optional - Data type of output samples. Default is 'float32' or 'float64', which - denends on your current default dtype. + Data type of output samples. + When npx.is_np_default_dtype() returns Flase, default dtype is float32; + When npx.is_np_default_dtype() returns True, default dtype is float64. ctx : Context, optional Device context of output. Default is current context. @@ -154,8 +155,9 @@ def normal(loc=0.0, scale=1.0, size=None, dtype=None, ctx=None, out=None): a single value is returned if loc and scale are both scalars. Otherwise, ``np.broadcast(low, high).size`` samples are drawn. dtype : {'float16', 'float32', 'float64'}, optional - Data type of output samples. Default is 'float32' or 'float64', which depends - on your current default dtype. + Data type of output samples. + When npx.is_np_default_dtype() returns Flase, default dtype is float32; + When npx.is_np_default_dtype() returns True, default dtype is float64. ctx : Context, optional Device context of output, default is current context. out : ``ndarray``, optional diff --git a/python/mxnet/symbol/numpy/_symbol.py b/python/mxnet/symbol/numpy/_symbol.py index 9a05d136d2a6..82308882c1d3 100644 --- a/python/mxnet/symbol/numpy/_symbol.py +++ b/python/mxnet/symbol/numpy/_symbol.py @@ -1020,7 +1020,9 @@ def zeros(shape, dtype=float, order='C', ctx=None): shape : int or tuple of int The shape of the empty array. dtype : str or numpy.dtype, optional - An optional value type (default is `float32` or 'float64', which depends on your current default dtype). + An optional value type . + When npx.is_np_default_dtype() returns Flase, default dtype is float32; + When npx.is_np_default_dtype() returns True, default dtype is float64. Note that this behavior is different from NumPy's `zeros` function where `float64` is the default value, here we can set 'float32' or 'float64' as your default dtype, because `float32` is considered as the default data type in deep learning. @@ -1055,7 +1057,9 @@ def ones(shape, dtype=None, order='C', ctx=None): shape : int or tuple of int The shape of the empty array. dtype : str or numpy.dtype, optional - An optional value type. Default is depend on your current default dtype. + An optional value type. + When npx.is_np_default_dtype() returns Flase, default dtype is float32; + When npx.is_np_default_dtype() returns True, default dtype is float64. Note that this behavior is different from NumPy's `ones` function where `float64` is the default value. order : {'C'}, optional, default: 'C' @@ -1209,6 +1213,8 @@ def full(shape, fill_value, dtype=None, order='C', ctx=None, out=None): # pylin fill_value : scalar or _Symbol Fill value. dtype : data-type, optional + When npx.is_np_default_dtype() returns Flase, default dtype is float32; + When npx.is_np_default_dtype() returns True, default dtype is float64. The desired data-type for the array. The default, `None`, means `np.array(fill_value).dtype`. order : {'C'}, optional @@ -1401,7 +1407,8 @@ def identity(n, dtype=None, ctx=None): Number of rows (and columns) in `n` x `n` output. dtype : data-type, optional Data-type of the output. - Default dtype is 'float32' or 'float64', which depends on your current default dtype. + When npx.is_np_default_dtype() returns Flase, default dtype is float32; + When npx.is_np_default_dtype() returns True, default dtype is float64. ctx : Context, optional An optional device context (default is the current default context). @@ -1865,6 +1872,8 @@ def eye(N, M=None, k=0, dtype=float, **kwargs): and a negative value to a lower diagonal. dtype : data-type, optional Data-type of the returned array. + When npx.is_np_default_dtype() returns Flase, default dtype is float32; + When npx.is_np_default_dtype() returns True, default dtype is float64. Returns ------- @@ -3419,8 +3428,9 @@ def arange(start, stop=None, step=1, dtype=None, ctx=None): step size is 1. If `step` is specified as a position argument, `start` must also be given. dtype : dtype - The type of the output array. The default is `float32` or 'float64', - which depends on your current default dtype. + The type of the output array. + When npx.is_np_default_dtype() returns Flase, default dtype is float32; + When npx.is_np_default_dtype() returns True, default dtype is float64. Returns ------- @@ -4247,8 +4257,10 @@ def average(a, axis=None, weights=None, returned=False, out=None): Return the average along the specified axis. When returned is True, return a tuple with the average as the first element and the sum of the weights as the second element. sum_of_weights is of the same type as retval. - If a is integral, the result dtype will be float32 or float64, which depends on your current - default dtype, otherwise it will be the same as dtype of a. + If a is integral, the result dtype will beyour current default dtype, + When npx.is_np_default_dtype() returns Flase, default dtype is float32, + When npx.is_np_default_dtype() returns True, default dtype is float64; + otherwise it will be the same as dtype of a. Raises -------- @@ -4318,7 +4330,8 @@ def mean(a, axis=None, dtype=None, out=None, keepdims=False): # pylint: disable instead of a single axis or all the axes as before. dtype : data-type, optional Type to use in computing the mean. - For integer inputs, the default is float32 or float64, which depends on your current default dtype ; + For integer inputs, When npx.is_np_default_dtype() returns Flase, default dtype is float32, + When npx.is_np_default_dtype() returns True, default dtype is float64; for floating point inputs, it is the same as the input dtype. out : _Symbol, optional Dummy parameter to keep the consistency with the ndarray counterpart. @@ -4430,9 +4443,11 @@ def var(a, axis=None, dtype=None, out=None, ddof=0, keepdims=False): # pylint: If this is a tuple of ints, computation is performed over multiple axes, instead of a single axis or all the axes as before. dtype : data-type, optional - Type to use in computing the variance. For arrays of integer type - the default is `float32` or 'float64', which depends on your current - default dtype; for arrays of float types it is the same as the array type. + Type to use in computing the variance. + For arrays of integer type, + When npx.is_np_default_dtype() returns Flase, default dtype is float32, + When npx.is_np_default_dtype() returns True, default dtype is float64; + For arrays of float types it is the same as the array type. out : _Symbol, optional Dummy parameter to keep the consistency with the ndarray counterpart. keepdims : bool, optional @@ -4475,7 +4490,7 @@ def indices(dimensions, dtype=None, ctx=None): dimensions : sequence of ints The shape of the grid. dtype : data-type, optional - The desired data-type for the array. Default is `int32`. + The desired data-type for the array. Default is `int64`. ctx : device context, optional Device context on which the memory is allocated. Default is `mxnet.context.current_context()`. @@ -4505,10 +4520,10 @@ def indices(dimensions, dtype=None, ctx=None): (2, 2, 3) >>> grid[0] # row indices array([[0, 0, 0], - [1, 1, 1]], dtype=int32) + [1, 1, 1]], dtype=int64) >>> grid[1] # column indices array([[0, 0, 0], - [1, 1, 1]], dtype=int32) + [1, 1, 1]], dtype=int64) The indices can be used as an index into an array. @@ -4693,7 +4708,8 @@ def hanning(M, ctx=None): out : _Symbol, shape(M,) The window, with the maximum value normalized to one (the value one appears only if `M` is odd). - Default is 'float32' or 'float64', which depends on your current default dtype. + When npx.is_np_default_dtype() returns Flase, default dtype is float32; + When npx.is_np_default_dtype() returns True, default dtype is float64. Note that you need select numpy.float32 or float64 in this operator. See Also @@ -4774,7 +4790,8 @@ def hamming(M, ctx=None): out : _Symbol, shape(M,) The window, with the maximum value normalized to one (the value one appears only if `M` is odd). - Default is 'float32' or 'float64', which depends on your current default dtype. + When npx.is_np_default_dtype() returns Flase, default dtype is float32; + When npx.is_np_default_dtype() returns True, default dtype is float64. Note that you need select numpy.float32 or float64 in this operator. See Also @@ -4856,7 +4873,8 @@ def blackman(M, ctx=None): out : _Symbol The window, with the maximum value normalized to one (the value one appears only if the number of samples is odd). - Default is 'float32' or 'float64', which depends on your current default dtype. + When npx.is_np_default_dtype() returns Flase, default dtype is float32; + When npx.is_np_default_dtype() returns True, default dtype is float64. Note that you need select numpy.float32 or float64 in this operator. See Also diff --git a/python/mxnet/symbol/numpy/random.py b/python/mxnet/symbol/numpy/random.py index 46562bea7ca1..8d334e2c3635 100644 --- a/python/mxnet/symbol/numpy/random.py +++ b/python/mxnet/symbol/numpy/random.py @@ -139,7 +139,9 @@ def uniform(low=0.0, high=1.0, size=None, dtype=None, ctx=None, out=None): a scalar tensor containing a single value is returned if ``low`` and ``high`` are both scalars. dtype : {'float16', 'float32', 'float64'}, optional - Data type of output samples. Default is 'float32' + Data type of output samples. + When npx.is_np_default_dtype() returns Flase, default dtype is float32; + When npx.is_np_default_dtype() returns True, default dtype is float64. ctx : Context, optional Device context of output. Default is current context. @@ -188,7 +190,9 @@ def normal(loc=0.0, scale=1.0, size=None, dtype=None, ctx=None, out=None): samples are drawn. If size is `None` (default), a scalar tensor containing a single value is returned if loc and scale are both scalars. dtype : {'float16', 'float32', 'float64'}, optional - Data type of output samples. Default is 'float32'. + Data type of output samples. + When npx.is_np_default_dtype() returns Flase, default dtype is float32; + When npx.is_np_default_dtype() returns True, default dtype is float64. ctx : Context, optional Device context of output. Default is current context. @@ -434,7 +438,9 @@ def gamma(shape, scale=1.0, size=None, dtype=None, ctx=None, out=None): a single value is returned if ``shape`` and ``scale`` are both scalars. Otherwise, ``np.broadcast(shape, scale).size`` samples are drawn. dtype : {'float16', 'float32', 'float64'}, optional - Data type of output samples. Default is 'float32'. + Data type of output samples. + When npx.is_np_default_dtype() returns Flase, default dtype is float32; + When npx.is_np_default_dtype() returns True, default dtype is float64. ctx : Context, optional Device context of output. Default is current context. @@ -536,7 +542,9 @@ def beta(a, b, size=None, dtype=None, ctx=None): a single value is returned if ``a`` and ``b`` are both scalars. Otherwise, ``np.broadcast(a, b).size`` samples are drawn. dtype : {'float16', 'float32', 'float64'}, optional - Data type of output samples. Default is 'float32'. + Data type of output samples. + When npx.is_np_default_dtype() returns Flase, default dtype is float32; + When npx.is_np_default_dtype() returns True, default dtype is float64. Dtype 'float32' or 'float64' is strongly recommended, since lower precision might lead to out of range issue. ctx : Context, optional @@ -585,7 +593,9 @@ def chisquare(df, size=None, dtype=None, ctx=None): a single value is returned if ``df`` is a scalar. Otherwise, ``np.array(df).size`` samples are drawn. dtype : {'float16', 'float32', 'float64'}, optional - Data type of output samples. Default is 'float32'. + Data type of output samples. + When npx.is_np_default_dtype() returns Flase, default dtype is float32; + When npx.is_np_default_dtype() returns True, default dtype is float64. ctx : Context, optional Device context of output. Default is current context. diff --git a/python/mxnet/util.py b/python/mxnet/util.py index 874e225641d0..2a416cd01d1e 100644 --- a/python/mxnet/util.py +++ b/python/mxnet/util.py @@ -674,7 +674,7 @@ def _set_np_array(active): return cur_state -def set_np(shape=True, array=True): +def set_np(shape=True, array=True, dtype=True): """Setting NumPy shape and array semantics at the same time. It is required to keep NumPy shape semantics active while activating NumPy array semantics. Deactivating NumPy shape semantics while NumPy array semantics is still active is not allowed. @@ -692,7 +692,10 @@ def set_np(shape=True, array=True): When this flag is set to `True`, it enables Gluon code flow to use or generate `mxnet.numpy.ndarray`s instead of `mxnet.ndarray.NDArray`. For example, a `Block` would create parameters of type `mxnet.numpy.ndarray`. - + dtype : bool + A boolean value indicating whether the NumPy-dtype semantics should be turned on or off. + When this flag is set to `True`, default dtype is float64. + When this flag is set to `False`, default dtype is float32. Examples -------- >>> import mxnet as mx @@ -733,6 +736,8 @@ def set_np(shape=True, array=True): array(1.) >>> np.ones(shape=(2, 0, 3)) array([], shape=(2, 0, 3)) + >>> np.ones(shape=()).dtype + dtype('float64') When the `array` flag is `True`, Gluon layers would create parameters and outputs of type `mx.np.ndarray`. @@ -751,11 +756,12 @@ def set_np(shape=True, array=True): raise ValueError('NumPy Shape semantics is required in using NumPy array semantics.') _set_np_array(array) set_np_shape(shape) + set_np_default_dtype(dtype) def reset_np(): - """Deactivate NumPy shape and array semantics at the same time.""" - set_np(shape=False, array=False) + """Deactivate NumPy shape and array and deafult dtype semantics at the same time.""" + set_np(shape=False, array=False, dtype=False) _CUDA_SUCCESS = 0 @@ -849,8 +855,7 @@ def __exit__(self, ptype, value, trace): def np_default_dtype(active=True): """Returns an activated/deactivated NumPy-default_dtype scope to be used in 'with' statement - and captures code that needs the NumPy default dtype semantics, i.e. default dtype is float64 - or int64. + and captures code that needs the NumPy default dtype semantics. i.e. default dtype is float64. Please note that this is designed as an infrastructure for the incoming MXNet-NumPy operators. Legacy operators registered in the modules @@ -870,27 +875,22 @@ def np_default_dtype(active=True): Example:: with mx.np_default_Dtype(active=True): - # Default Dtype is 'float64' (or 'int64'), consistent with offical NumPy behavior. + # Default Dtype is 'float64', consistent with offical NumPy behavior. arr = mx.nd.array([1, 2, 3]) assert arr.dtype == float64 - grid = mx.nd.indices((2, 3)) - assert grid.dtype == int64 - with mx.np_default_dtype(active=False): - # Default Dtype is 'float32' (or 'int32') in the legacy default dtype definition. + # Default Dtype is 'float32' in the legacy default dtype definition. arr = mx.nd.array([1, 2, 3]) assert arr.dtype == float32 - grid = mx.nd.indices((2, 3)) - assert grid.dtype == int32 """ return _NumpyDefaultDtypeScope(active) def use_np_default_dtype(func): """A decorator wrapping a function or class with activated NumPy-default_dtype semantics. When `func` is a function, this ensures that the execution of the function is scoped with NumPy - default dtype semantics, with the support for 64 bit data storage, i.e. 'float64' and ''int64. + default dtype semantics, with the support for float64 as default dtype. When`func` is a class, it ensures that all the methods, static functions, and properties of the class are executed with the NumPy-default_dtype semantics. @@ -961,7 +961,7 @@ def _with_np_default_dtype(*args, **kwargs): def is_np_default_dtype(): """Checks whether the NumPy default dtype semantics is currently turned on. - In NumPy default dtype semantics, i.e. default dtype is float64 or int64. + In NumPy default dtype semantics, default dtype is float64. Please note that this is designed as an infrastructure for the incoming MXNet-NumPy operators. Legacy operators registered in the modules @@ -975,10 +975,11 @@ def is_np_default_dtype(): Example ------- >>> import mxnet as mx - >>> prev_state = mx.set_np_default_dtype(True) + >>> from mxnet import npx + >>> prev_state = npx.set_np_default_dtype(True) >>> print(prev_state) False - >>> print(mx.is_np_default_dtype()) + >>> print(npx.is_np_default_dtype()) True """ curr = ctypes.c_bool() @@ -1008,10 +1009,11 @@ def set_np_default_dtype(is_np_default_dtype=True): # pylint: disable=redefined Example ------- >>> import mxnet as mx - >>> prev_state = mx.set_np_default_dtype(True) + >>> from mxnet import npx + >>> prev_state = npx.set_np_default_dtype(True) >>> print(prev_state) False - >>> print(mx.is_np_shape()) + >>> print(npx.is_np_default_dtype()) True """ global _set_np_default_dtype_logged diff --git a/scala-package/core/src/main/scala/org/apache/mxnet/LibInfo.scala b/scala-package/core/src/main/scala/org/apache/mxnet/LibInfo.scala index 95cefe8cb341..0ee6476be365 100644 --- a/scala-package/core/src/main/scala/org/apache/mxnet/LibInfo.scala +++ b/scala-package/core/src/main/scala/org/apache/mxnet/LibInfo.scala @@ -375,6 +375,4 @@ private[mxnet] class LibInfo { // Numpy @native def mxIsNumpyShape(compatible: RefInt): Int @native def mxSetIsNumpyShape(isNpComp: Int, prev: RefInt): Int - @native def mxIsNumpyDefaultDtype(compatible: RefInt): Int - @native def mxSetIsDefaultDtype(isNpComp: Int, prev: RefInt): Int } diff --git a/scala-package/core/src/main/scala/org/apache/mxnet/NumpyScope.scala b/scala-package/core/src/main/scala/org/apache/mxnet/NumpyScope.scala index f15762ad4f1a..b63095a10cc1 100644 --- a/scala-package/core/src/main/scala/org/apache/mxnet/NumpyScope.scala +++ b/scala-package/core/src/main/scala/org/apache/mxnet/NumpyScope.scala @@ -37,18 +37,6 @@ object NumpyScope { if (curr.value != 0) true else false } - def setNumpyDefaultDtype(isNpComp: Boolean): Boolean = { - val prev = new RefInt() - checkCall(_LIB.mxSetIsNumpyDefaultDtype(if (isNpComp) 1 else 0, prev)) - if (prev.value != 0) true else false - } - - def isNumpyDefaultDtype: Boolean = { - val curr = new RefInt - checkCall(_LIB.mxIsNumpyDefaultDtype(curr)) - if (curr.value != 0) true else false - } - def enableNumpyShape: NumpyScope = { new NumpyScope(true) } diff --git a/scala-package/native/src/main/native/org_apache_mxnet_native_c_api.cc b/scala-package/native/src/main/native/org_apache_mxnet_native_c_api.cc index 06ca01f19d47..26eea3dd062b 100644 --- a/scala-package/native/src/main/native/org_apache_mxnet_native_c_api.cc +++ b/scala-package/native/src/main/native/org_apache_mxnet_native_c_api.cc @@ -2790,19 +2790,3 @@ JNIEXPORT jint JNICALL Java_org_apache_mxnet_LibInfo_mxSetIsNumpyShape SetIntField(env, prevRef, prev); return ret; } - -JNIEXPORT jint JNICALL Java_org_apache_mxnet_LibInfo_mxIsNumpyDefaultDtype - (JNIEnv *env, jobject obj, jobject compatibleRef) { - int DefaultDtype; - int ret = MXIsNumpyDefaultDtype(&DefaultDtype); - SetIntField(env, compatibleRef, DefaultDtype); - return ret; -} - -JNIEXPORT jint JNICALL Java_org_apache_mxnet_LibInfo_mxSetIsNumpyDefaultDtype - (JNIEnv *env, jobject obj, jint DefDtype, jobject prevRef) { - int prev; - int ret = MXSetIsNumpyDefaultDtype(DefDtype, &prev); - SetIntField(env, prevRef, prev); - return ret; -} diff --git a/scala-package/native/src/main/native/org_apache_mxnet_native_c_api.h b/scala-package/native/src/main/native/org_apache_mxnet_native_c_api.h index 154d1043e293..c8ee0ce8d22b 100644 --- a/scala-package/native/src/main/native/org_apache_mxnet_native_c_api.h +++ b/scala-package/native/src/main/native/org_apache_mxnet_native_c_api.h @@ -927,22 +927,6 @@ JNIEXPORT jint JNICALL Java_org_apache_mxnet_LibInfo_mxIsNumpyShape JNIEXPORT jint JNICALL Java_org_apache_mxnet_LibInfo_mxSetIsNumpyShape (JNIEnv *, jobject, jint, jobject); -/* - * Class: org_apache_mxnet_LibInfo - * Method: mxIsNumpyDefaultDtype - * Signature: (Lorg/apache/mxnet/Base/RefInt;)I - */ -JNIEXPORT jint JNICALL Java_org_apache_mxnet_LibInfo_mxIsNumpyDefaultDtype - (JNIEnv *, jobject, jobject); - -/* - * Class: org_apache_mxnet_LibInfo - * Method: mxSetIsNumpyDefaultDtype - * Signature: (ILorg/apache/mxnet/Base/RefInt;)I - */ -JNIEXPORT jint JNICALL Java_org_apache_mxnet_LibInfo_mxSetIsNumpyDefaultDtype - (JNIEnv *, jobject, jint, jobject); - #ifdef __cplusplus } #endif diff --git a/src/operator/numpy/np_true_divide-inl.h b/src/operator/numpy/np_true_divide-inl.h index ff9861f17d20..319660066aae 100644 --- a/src/operator/numpy/np_true_divide-inl.h +++ b/src/operator/numpy/np_true_divide-inl.h @@ -106,7 +106,7 @@ void TrueDivideElemwiseCompute(const nnvm::NodeAttrs &attrs, }); } else { // If both are the same integers, output is float32 or float64 - CHECK_EQ(out.type_flag_, mxnet::common::GetDefaultDtype()) + CHECK_EQ(out.type_flag_, mxnet::common::GetDefaultDtype()) << "true_divide only supports float32 and float64" " output when input's dtype is " << type_string(lhs.type_flag_); @@ -290,7 +290,7 @@ void TrueDivideBroadcastCompute(const nnvm::NodeAttrs& attrs, lhs.dptr(), rhs.dptr(), out.dptr()); }); } else { - CHECK_EQ(out.type_flag_, GetDefaultDtype()) + CHECK_EQ(out.type_flag_, mxnet::common::GetDefaultDtype()) << "true_divide only supports float32 and float64 output when input's dtype is " << type_string(lhs.type_flag_); MXNET_INT_TYPE_SWITCH(lhs.type_flag_, DType, {