From c9af675648457c330c8add9fe1e9994ffa5fb729 Mon Sep 17 00:00:00 2001 From: sguangyo <1360024032@qq.com> Date: Sat, 14 Sep 2019 17:38:09 +0800 Subject: [PATCH] make default dtype is float32 --- python/mxnet/ndarray/numpy/_op.py | 62 ++++++++----------------- python/mxnet/numpy/multiarray.py | 68 ++++++---------------------- python/mxnet/symbol/numpy/_symbol.py | 63 ++++++++------------------ src/operator/numpy/np_window_op.h | 2 +- 4 files changed, 52 insertions(+), 143 deletions(-) diff --git a/python/mxnet/ndarray/numpy/_op.py b/python/mxnet/ndarray/numpy/_op.py index e9ca85986924..f25ab6943dc7 100644 --- a/python/mxnet/ndarray/numpy/_op.py +++ b/python/mxnet/ndarray/numpy/_op.py @@ -2148,7 +2148,7 @@ def argmax(a, axis=None, out=None): @set_module('mxnet.ndarray.numpy') -def hanning(M, dtype=_np.float64, ctx=None): +def hanning(M, dtype=None, ctx=None): r"""Return the Hanning window. The Hanning window is a taper formed by using a weighted cosine. @@ -2159,7 +2159,7 @@ def hanning(M, dtype=_np.float64, ctx=None): Number of points in the output window. If zero or less, an empty array is returned. dtype : str or numpy.dtype, optional - An optional value type. Default is `numpy.float64`. Note that you need + An optional value type. Default is `float32`. Note that you need select numpy.float32 or float64 in this operator. ctx : Context, optional An optional device context (default is the current default context). @@ -2206,9 +2206,9 @@ def hanning(M, dtype=_np.float64, ctx=None): Examples -------- >>> np.hanning(12) - array([0.00000000e+00, 7.93732437e-02, 2.92292528e-01, 5.71157416e-01, - 8.27430424e-01, 9.79746513e-01, 9.79746489e-01, 8.27430268e-01, - 5.71157270e-01, 2.92292448e-01, 7.93731320e-02, 1.06192832e-13], dtype=float64) + array([0. , 0.07937324, 0.29229254, 0.5711574 , 0.8274304 , + 0.9797465 , 0.97974646, 0.82743025, 0.5711573 , 0.29229245, + 0.07937312, 0. ]) Plot the window and its frequency response: @@ -2225,14 +2225,14 @@ def hanning(M, dtype=_np.float64, ctx=None): >>> plt.show() """ if dtype is None: - dtype = _np.float64 + dtype = _np.float32 if ctx is None: ctx = current_context() return _npi.hanning(M, dtype=dtype, ctx=ctx) @set_module('mxnet.ndarray.numpy') -def hamming(M, dtype=_np.float64, ctx=None): +def hamming(M, dtype=None, ctx=None): r"""Return the hamming window. The hamming window is a taper formed by using a weighted cosine. @@ -2243,7 +2243,7 @@ def hamming(M, dtype=_np.float64, ctx=None): Number of points in the output window. If zero or less, an empty array is returned. dtype : str or numpy.dtype, optional - An optional value type. Default is `numpy.float64`. Note that you need + An optional value type. Default is `float32`. Note that you need select numpy.float32 or float64 in this operator. ctx : Context, optional An optional device context (default is the current default context). @@ -2288,9 +2288,9 @@ def hamming(M, dtype=_np.float64, ctx=None): Examples -------- >>> np.hamming(12) - array([0.08 , 0.15302338, 0.34890913, 0.60546482, 0.84123599, - 0.98136679, 0.98136677, 0.84123585, 0.60546469, 0.34890905, - 0.15302328, 0.08 ], dtype=float64) + array([0.08000001, 0.15302339, 0.34890914, 0.6054648 , 0.841236 , + 0.9813669 , 0.9813668 , 0.8412359 , 0.6054647 , 0.34890908, + 0.15302327, 0.08000001]) Plot the window and its frequency response: @@ -2307,14 +2307,14 @@ def hamming(M, dtype=_np.float64, ctx=None): >>> plt.show() """ if dtype is None: - dtype = _np.float64 + dtype = _np.float32 if ctx is None: ctx = current_context() return _npi.hamming(M, dtype=dtype, ctx=ctx) @set_module('mxnet.ndarray.numpy') -def blackman(M, dtype=_np.float64, ctx=None): +def blackman(M, dtype=None, ctx=None): r"""Return the Blackman window. The Blackman window is a taper formed by using the first three @@ -2328,7 +2328,7 @@ def blackman(M, dtype=_np.float64, ctx=None): Number of points in the output window. If zero or less, an empty array is returned. dtype : str or numpy.dtype, optional - An optional value type. Default is `numpy.float64`. Note that you need + An optional value type. Default is `float32`. Note that you need select numpy.float32 or float64 in this operator. ctx : Context, optional An optional device context (default is the current default context). @@ -2339,32 +2339,6 @@ def blackman(M, dtype=_np.float64, ctx=None): The window, with the maximum value normalized to one (the value one appears only if the number of samples is odd). - See Also - -------- - bartlett, hamming, hanning, kaiser - - Notes - ----- - The Blackman window is defined as - - .. math:: w(n) = 0.42 - 0.5 \cos(2\pi n/{M-1}) + 0.08 \cos(4\pi n/{M-1}) - - Most references to the Blackman window come from the signal processing - literature, where it is used as one of many windowing functions for - smoothing values. It is also known as an apodization (which means - "removing the foot", i.e. smoothing discontinuities at the beginning - and end of the sampled signal) or tapering function. It is known as a - "near optimal" tapering function, almost as good (by some measures) - as the kaiser window. - - References - ---------- - Blackman, R.B. and Tukey, J.W., (1958) The measurement of power spectra, - Dover Publications, New York. - - Oppenheim, A.V., and R.W. Schafer. Discrete-Time Signal Processing. - Upper Saddle River, NJ: Prentice-Hall, 1999, pp. 468-471. - See Also -------- hamming, hanning @@ -2394,9 +2368,9 @@ def blackman(M, dtype=_np.float64, ctx=None): Examples -------- >>> np.blackman(12) - array([-1.38777878e-17, 3.26064393e-02, 1.59903660e-01, 4.14397978e-01, - 7.36045260e-01, 9.67046812e-01, 9.67046772e-01, 7.36045039e-01, - 4.14397819e-01, 1.59903601e-01, 3.26063877e-02, 3.82194276e-14], dtype=float64) + array([-1.4901161e-08, 3.2606423e-02, 1.5990365e-01, 4.1439798e-01, + 7.3604530e-01, 9.6704686e-01, 9.6704674e-01, 7.3604506e-01, + 4.1439781e-01, 1.5990359e-01, 3.2606363e-02, -1.4901161e-08]) Plot the window and its frequency response: @@ -2413,7 +2387,7 @@ def blackman(M, dtype=_np.float64, ctx=None): >>> plt.show() """ if dtype is None: - dtype = _np.float64 + dtype = _np.float32 if ctx is None: ctx = current_context() return _npi.blackman(M, dtype=dtype, ctx=ctx) diff --git a/python/mxnet/numpy/multiarray.py b/python/mxnet/numpy/multiarray.py index 47bd1b89aa76..56282fc6e697 100644 --- a/python/mxnet/numpy/multiarray.py +++ b/python/mxnet/numpy/multiarray.py @@ -3592,7 +3592,7 @@ def argmax(a, axis=None, out=None): @set_module('mxnet.numpy') -def hanning(M, dtype=_np.float64, ctx=None): +def hanning(M, dtype=None, ctx=None): r"""Return the Hanning window. The Hanning window is a taper formed by using a weighted cosine. @@ -3603,7 +3603,7 @@ def hanning(M, dtype=_np.float64, ctx=None): Number of points in the output window. If zero or less, an empty array is returned. dtype : str or numpy.dtype, optional - An optional value type. Default is `numpy.float64`. Note that you need + An optional value type. Default is `float32`. Note that you need select numpy.float32 or float64 in this operator. ctx : Context, optional An optional device context (default is the current default context). @@ -3650,9 +3650,9 @@ def hanning(M, dtype=_np.float64, ctx=None): Examples -------- >>> np.hanning(12) - array([0.00000000e+00, 7.93732437e-02, 2.92292528e-01, 5.71157416e-01, - 8.27430424e-01, 9.79746513e-01, 9.79746489e-01, 8.27430268e-01, - 5.71157270e-01, 2.92292448e-01, 7.93731320e-02, 1.06192832e-13], dtype=float64) + array([0. , 0.07937324, 0.29229254, 0.5711574 , 0.8274304 , + 0.9797465 , 0.97974646, 0.82743025, 0.5711573 , 0.29229245, + 0.07937312, 0. ]) Plot the window and its frequency response: @@ -3668,15 +3668,11 @@ def hanning(M, dtype=_np.float64, ctx=None): Text(0.5, 0, 'Sample') >>> plt.show() """ - if dtype is None: - dtype = _np.float64 - if ctx is None: - ctx = current_context() return _mx_nd_np.hanning(M, dtype=dtype, ctx=ctx) @set_module('mxnet.numpy') -def hamming(M, dtype=_np.float64, ctx=None): +def hamming(M, dtype=None, ctx=None): r"""Return the hamming window. The hamming window is a taper formed by using a weighted cosine. @@ -3687,7 +3683,7 @@ def hamming(M, dtype=_np.float64, ctx=None): Number of points in the output window. If zero or less, an empty array is returned. dtype : str or numpy.dtype, optional - An optional value type. Default is `numpy.float64`. Note that you need + An optional value type. Default is `float32`. Note that you need select numpy.float32 or float64 in this operator. ctx : Context, optional An optional device context (default is the current default context). @@ -3732,9 +3728,9 @@ def hamming(M, dtype=_np.float64, ctx=None): Examples -------- >>> np.hamming(12) - array([0.08 , 0.15302338, 0.34890913, 0.60546482, 0.84123599, - 0.98136679, 0.98136677, 0.84123585, 0.60546469, 0.34890905, - 0.15302328, 0.08 ], dtype=float64) + array([0.08000001, 0.15302339, 0.34890914, 0.6054648 , 0.841236 , + 0.9813669 , 0.9813668 , 0.8412359 , 0.6054647 , 0.34890908, + 0.15302327, 0.08000001]) Plot the window and its frequency response: @@ -3750,15 +3746,11 @@ def hamming(M, dtype=_np.float64, ctx=None): Text(0.5, 0, 'Sample') >>> plt.show() """ - if dtype is None: - dtype = _np.float64 - if ctx is None: - ctx = current_context() return _mx_nd_np.hamming(M, dtype=dtype, ctx=ctx) @set_module('mxnet.numpy') -def blackman(M, dtype=_np.float64, ctx=None): +def blackman(M, dtype=None, ctx=None): r"""Return the Blackman window. The Blackman window is a taper formed by using the first three @@ -3772,7 +3764,7 @@ def blackman(M, dtype=_np.float64, ctx=None): Number of points in the output window. If zero or less, an empty array is returned. dtype : str or numpy.dtype, optional - An optional value type. Default is `numpy.float64`. Note that you need + An optional value type. Default is `float32`. Note that you need select numpy.float32 or float64 in this operator. ctx : Context, optional An optional device context (default is the current default context). @@ -3783,32 +3775,6 @@ def blackman(M, dtype=_np.float64, ctx=None): The window, with the maximum value normalized to one (the value one appears only if the number of samples is odd). - See Also - -------- - bartlett, hamming, hanning, kaiser - - Notes - ----- - The Blackman window is defined as - - .. math:: w(n) = 0.42 - 0.5 \cos(2\pi n/{M-1}) + 0.08 \cos(4\pi n/{M-1}) - - Most references to the Blackman window come from the signal processing - literature, where it is used as one of many windowing functions for - smoothing values. It is also known as an apodization (which means - "removing the foot", i.e. smoothing discontinuities at the beginning - and end of the sampled signal) or tapering function. It is known as a - "near optimal" tapering function, almost as good (by some measures) - as the kaiser window. - - References - ---------- - Blackman, R.B. and Tukey, J.W., (1958) The measurement of power spectra, - Dover Publications, New York. - - Oppenheim, A.V., and R.W. Schafer. Discrete-Time Signal Processing. - Upper Saddle River, NJ: Prentice-Hall, 1999, pp. 468-471. - See Also -------- hamming, hanning @@ -3838,9 +3804,9 @@ def blackman(M, dtype=_np.float64, ctx=None): Examples -------- >>> np.blackman(12) - array([-1.38777878e-17, 3.26064393e-02, 1.59903660e-01, 4.14397978e-01, - 7.36045260e-01, 9.67046812e-01, 9.67046772e-01, 7.36045039e-01, - 4.14397819e-01, 1.59903601e-01, 3.26063877e-02, 3.82194276e-14], dtype=float64) + array([-1.4901161e-08, 3.2606423e-02, 1.5990365e-01, 4.1439798e-01, + 7.3604530e-01, 9.6704686e-01, 9.6704674e-01, 7.3604506e-01, + 4.1439781e-01, 1.5990359e-01, 3.2606363e-02, -1.4901161e-08]) Plot the window and its frequency response: @@ -3856,8 +3822,4 @@ def blackman(M, dtype=_np.float64, ctx=None): Text(0.5, 0, 'Sample') >>> plt.show() """ - if dtype is None: - dtype = _np.float64 - if ctx is None: - ctx = current_context() return _mx_nd_np.blackman(M, dtype=dtype, ctx=ctx) diff --git a/python/mxnet/symbol/numpy/_symbol.py b/python/mxnet/symbol/numpy/_symbol.py index 3adabdbd8fe5..93c69315a317 100644 --- a/python/mxnet/symbol/numpy/_symbol.py +++ b/python/mxnet/symbol/numpy/_symbol.py @@ -2509,7 +2509,7 @@ def argmax(a, axis=None, out=None): @set_module('mxnet.symbol.numpy') -def hanning(M, dtype=_np.float64, ctx=None): +def hanning(M, dtype=None, ctx=None): r"""Return the Hanning window. The Hanning window is a taper formed by using a weighted cosine. @@ -2520,7 +2520,7 @@ def hanning(M, dtype=_np.float64, ctx=None): Number of points in the output window. If zero or less, an empty array is returned. dtype : str or numpy.dtype, optional - An optional value type. Default is `numpy.float64`. Note that you need + An optional value type. Default is `float32`. Note that you need select numpy.float32 or float64 in this operator. ctx : Context, optional An optional device context (default is the current default context). @@ -2567,9 +2567,9 @@ def hanning(M, dtype=_np.float64, ctx=None): Examples -------- >>> np.hanning(12) - array([0.00000000e+00, 7.93732437e-02, 2.92292528e-01, 5.71157416e-01, - 8.27430424e-01, 9.79746513e-01, 9.79746489e-01, 8.27430268e-01, - 5.71157270e-01, 2.92292448e-01, 7.93731320e-02, 1.06192832e-13], dtype=float64) + array([0. , 0.07937324, 0.29229254, 0.5711574 , 0.8274304 , + 0.9797465 , 0.97974646, 0.82743025, 0.5711573 , 0.29229245, + 0.07937312, 0. ]) Plot the window and its frequency response: @@ -2586,17 +2586,16 @@ def hanning(M, dtype=_np.float64, ctx=None): >>> plt.show() """ if dtype is None: - dtype = _np.float64 + dtype = _np.float32 if ctx is None: ctx = current_context() return _npi.hanning(M, dtype=dtype, ctx=ctx) @set_module('mxnet.symbol.numpy') -def hamming(M, dtype=_np.float64, ctx=None): +def hamming(M, dtype=None, ctx=None): r"""Return the hamming window. - The hamming window is a taper formed by using a weighted cosine. Parameters @@ -2605,7 +2604,7 @@ def hamming(M, dtype=_np.float64, ctx=None): Number of points in the output window. If zero or less, an empty array is returned. dtype : str or numpy.dtype, optional - An optional value type. Default is `numpy.float64`. Note that you need + An optional value type. Default is `float32`. Note that you need select numpy.float32 or float64 in this operator. ctx : Context, optional An optional device context (default is the current default context). @@ -2650,9 +2649,9 @@ def hamming(M, dtype=_np.float64, ctx=None): Examples -------- >>> np.hamming(12) - array([0.08 , 0.15302338, 0.34890913, 0.60546482, 0.84123599, - 0.98136679, 0.98136677, 0.84123585, 0.60546469, 0.34890905, - 0.15302328, 0.08 ], dtype=float64) + array([0.08000001, 0.15302339, 0.34890914, 0.6054648 , 0.841236 , + 0.9813669 , 0.9813668 , 0.8412359 , 0.6054647 , 0.34890908, + 0.15302327, 0.08000001]) Plot the window and its frequency response: @@ -2669,14 +2668,14 @@ def hamming(M, dtype=_np.float64, ctx=None): >>> plt.show() """ if dtype is None: - dtype = _np.float64 + dtype = _np.float32 if ctx is None: ctx = current_context() return _npi.hamming(M, dtype=dtype, ctx=ctx) @set_module('mxnet.symbol.numpy') -def blackman(M, dtype=_np.float64, ctx=None): +def blackman(M, dtype=None, ctx=None): r"""Return the Blackman window. The Blackman window is a taper formed by using the first three @@ -2690,7 +2689,7 @@ def blackman(M, dtype=_np.float64, ctx=None): Number of points in the output window. If zero or less, an empty array is returned. dtype : str or numpy.dtype, optional - An optional value type. Default is `numpy.float64`. Note that you need + An optional value type. Default is `float32`. Note that you need select numpy.float32 or float64 in this operator. ctx : Context, optional An optional device context (default is the current default context). @@ -2727,38 +2726,12 @@ def blackman(M, dtype=_np.float64, ctx=None): Oppenheim, A.V., and R.W. Schafer. Discrete-Time Signal Processing. Upper Saddle River, NJ: Prentice-Hall, 1999, pp. 468-471. - See Also - -------- - hamming, hanning - - Notes - ----- - The Blackman window is defined as - - .. math:: w(n) = 0.42 - 0.5 \cos(2\pi n/{M-1}) + 0.08 \cos(4\pi n/{M-1}) - - Most references to the Blackman window come from the signal processing - literature, where it is used as one of many windowing functions for - smoothing values. It is also known as an apodization (which means - "removing the foot", i.e. smoothing discontinuities at the beginning - and end of the sampled signal) or tapering function. It is known as a - "near optimal" tapering function, almost as good (by some measures) - as the kaiser window. - - References - ---------- - Blackman, R.B. and Tukey, J.W., (1958) The measurement of power spectra, - Dover Publications, New York. - - Oppenheim, A.V., and R.W. Schafer. Discrete-Time Signal Processing. - Upper Saddle River, NJ: Prentice-Hall, 1999, pp. 468-471. - Examples -------- >>> np.blackman(12) - array([-1.38777878e-17, 3.26064393e-02, 1.59903660e-01, 4.14397978e-01, - 7.36045260e-01, 9.67046812e-01, 9.67046772e-01, 7.36045039e-01, - 4.14397819e-01, 1.59903601e-01, 3.26063877e-02, 3.82194276e-14], dtype=float64) + array([-1.4901161e-08, 3.2606423e-02, 1.5990365e-01, 4.1439798e-01, + 7.3604530e-01, 9.6704686e-01, 9.6704674e-01, 7.3604506e-01, + 4.1439781e-01, 1.5990359e-01, 3.2606363e-02, -1.4901161e-08]) Plot the window and its frequency response: @@ -2775,7 +2748,7 @@ def blackman(M, dtype=_np.float64, ctx=None): >>> plt.show() """ if dtype is None: - dtype = _np.float64 + dtype = _np.float32 if ctx is None: ctx = current_context() return _npi.blackman(M, dtype=dtype, ctx=ctx) diff --git a/src/operator/numpy/np_window_op.h b/src/operator/numpy/np_window_op.h index 63c14546ec74..7501c7643b8e 100644 --- a/src/operator/numpy/np_window_op.h +++ b/src/operator/numpy/np_window_op.h @@ -54,7 +54,7 @@ struct NumpyWindowsParam : public dmlc::Parameter { .describe("Context of output, in format [cpu|gpu|cpu_pinned](n)." "Only used for imperative calls."); DMLC_DECLARE_FIELD(dtype) - .set_default(mshadow::kFloat64) + .set_default(mshadow::kFloat32) MXNET_ADD_ALL_TYPES .describe("Data-type of the returned array."); }