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

Commit

Permalink
make default dtype is float32
Browse files Browse the repository at this point in the history
  • Loading branch information
gyshi committed Sep 14, 2019
1 parent bea9be8 commit c9af675
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 143 deletions.
62 changes: 18 additions & 44 deletions python/mxnet/ndarray/numpy/_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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).
Expand Down Expand Up @@ -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:
Expand All @@ -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.
Expand All @@ -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).
Expand Down Expand Up @@ -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:
Expand All @@ -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
Expand All @@ -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).
Expand All @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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)
68 changes: 15 additions & 53 deletions python/mxnet/numpy/multiarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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).
Expand Down Expand Up @@ -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:
Expand All @@ -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.
Expand All @@ -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).
Expand Down Expand Up @@ -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:
Expand All @@ -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
Expand All @@ -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).
Expand All @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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)
Loading

0 comments on commit c9af675

Please sign in to comment.