changes added to other methods
@@ -2,17 +2,12 @@ import numpy
import cupy
from cupy import core
-from cupy.creation import basic
-from cupy.creation import from_data
-from cupy.creation import ranges
-from cupy.math import trigonometric
-
_blackman_kernel = core.ElementwiseKernel(
"float32 alpha",
- "float64 arr",
+ "float64 out",
"""
- arr = 0.42 - (0.5 * cos(i * alpha)) + (0.08 * cos(2 * alpha * i));
+ out = 0.42 - (0.5 * cos(i * alpha)) + (0.08 * cos(2 * alpha * i));
""")
@@ -45,6 +40,14 @@ def blackman(M):
return _blackman_kernel(alpha, out)
+_hamming_kernel = core.ElementwiseKernel(
+ "float32 alpha",
+ "float64 out",
+ """
+ out = 0.54 - 0.46 * cos(i * alpha);
+ """)
+
+
def hamming(M):
"""Returns the Hamming window.
@@ -64,12 +67,21 @@ def hamming(M):
.. seealso:: :func:`numpy.hamming`
"""
- if M < 1:
- return from_data.array([])
if M == 1:
- return basic.ones(1, float)
- n = ranges.arange(0, M)
- return 0.54 - 0.46 * trigonometric.cos(2.0 * numpy.pi * n / (M - 1))
+ return cupy.array([1.])
+ if M <= 0:
+ return cupy.array([])
+ alpha = (numpy.pi * 2)/(M - 1)
+ out = cupy.empty(M, dtype=cupy.float64)
+ return _hamming_kernel(alpha, out)
+
+
+_hanning_kernel = core.ElementwiseKernel(
+ "float32 alpha",
+ "float64 out",
+ """
+ out = 0.5 - 0.5 * cos(i * alpha);
+ """)
def hanning(M):
@@ -91,12 +103,13 @@ def hanning(M):
.. seealso:: :func:`numpy.hanning`
"""
- if M < 1:
- return from_data.array([])
if M == 1:
- return basic.ones(1, float)
- n = ranges.arange(0, M)
- return 0.5 - 0.5 * trigonometric.cos(2.0 * numpy.pi * n / (M - 1))
+ return cupy.array([1.])
+ if M <= 0:
+ return cupy.array([])
+ alpha = (numpy.pi * 2)/(M - 1)
+ out = cupy.empty(M, dtype=cupy.float64)
+ return _hanning_kernel(alpha, out)
_kaiser_kernel = core.ElementwiseKernel(
