|
45 | 45 | import dpnp |
46 | 46 | import dpnp.backend.extensions.window._window_impl as wi |
47 | 47 |
|
48 | | -__all__ = ["hamming", "hanning"] |
| 48 | +__all__ = ["blackman", "hamming", "hanning"] |
49 | 49 |
|
50 | 50 |
|
51 | 51 | def _call_window_kernel( |
@@ -81,6 +81,99 @@ def _call_window_kernel( |
81 | 81 | return result |
82 | 82 |
|
83 | 83 |
|
| 84 | +def blackman(M, device=None, usm_type=None, sycl_queue=None): |
| 85 | + r""" |
| 86 | + Return the Blackman window. |
| 87 | +
|
| 88 | + The Blackman window is a taper formed by using the first three terms of a |
| 89 | + summation of cosines. It was designed to have close to the minimal leakage |
| 90 | + possible. It is close to optimal, only slightly worse than a Kaiser window. |
| 91 | +
|
| 92 | + For full documentation refer to :obj:`numpy.blackman`. |
| 93 | +
|
| 94 | + Parameters |
| 95 | + ---------- |
| 96 | + M : int |
| 97 | + Number of points in the output window. If zero or less, an empty array |
| 98 | + is returned. |
| 99 | + device : {None, string, SyclDevice, SyclQueue, Device}, optional |
| 100 | + An array API concept of device where the output array is created. |
| 101 | + `device` can be ``None``, a oneAPI filter selector string, an instance |
| 102 | + of :class:`dpctl.SyclDevice` corresponding to a non-partitioned SYCL |
| 103 | + device, an instance of :class:`dpctl.SyclQueue`, or a |
| 104 | + :class:`dpctl.tensor.Device` object returned by |
| 105 | + :attr:`dpnp.ndarray.device`. |
| 106 | +
|
| 107 | + Default: ``None``. |
| 108 | + usm_type : {None, "device", "shared", "host"}, optional |
| 109 | + The type of SYCL USM allocation for the output array. |
| 110 | +
|
| 111 | + Default: ``None``. |
| 112 | + sycl_queue : {None, SyclQueue}, optional |
| 113 | + A SYCL queue to use for output array allocation and copying. The |
| 114 | + `sycl_queue` can be passed as ``None`` (the default), which means |
| 115 | + to get the SYCL queue from `device` keyword if present or to use |
| 116 | + a default queue. |
| 117 | +
|
| 118 | + Default: ``None``. |
| 119 | +
|
| 120 | + Returns |
| 121 | + ------- |
| 122 | + out : dpnp.ndarray of shape (M,) |
| 123 | + The window, with the maximum value normalized to one (the value one |
| 124 | + appears only if the number of samples is odd). |
| 125 | +
|
| 126 | + See Also |
| 127 | + -------- |
| 128 | + :obj:`dpnp.bartlett` : Return the Bartlett window. |
| 129 | + :obj:`dpnp.hamming` : Return the Hamming window. |
| 130 | + :obj:`dpnp.hanning` : Return the Hanning window. |
| 131 | + :obj:`dpnp.kaiser` : Return the Kaiser window. |
| 132 | +
|
| 133 | + Notes |
| 134 | + ----- |
| 135 | + The Blackman window is defined as |
| 136 | +
|
| 137 | + .. math:: w(n) = 0.42 - 0.5\cos\left(\frac{2\pi{n}}{M-1}\right) |
| 138 | + + 0.08\cos\left(\frac{4\pi{n}}{M-1}\right) |
| 139 | + \qquad 0 \leq n \leq M-1 |
| 140 | +
|
| 141 | + Examples |
| 142 | + -------- |
| 143 | + >>> import dpnp as np |
| 144 | + >>> np.blackman(12) |
| 145 | + array([-1.38777878e-17, 3.26064346e-02, 1.59903635e-01, 4.14397981e-01, |
| 146 | + 7.36045180e-01, 9.67046769e-01, 9.67046769e-01, 7.36045180e-01, |
| 147 | + 4.14397981e-01, 1.59903635e-01, 3.26064346e-02, -1.38777878e-17]) |
| 148 | +
|
| 149 | + Creating the output array on a different device or with a |
| 150 | + specified usm_type: |
| 151 | +
|
| 152 | + >>> x = np.blackman(3) # default case |
| 153 | + >>> x, x.device, x.usm_type |
| 154 | + (array([-1.38777878e-17, 1.00000000e+00, -1.38777878e-17]), |
| 155 | + Device(level_zero:gpu:0), |
| 156 | + 'device') |
| 157 | +
|
| 158 | + >>> y = np.blackman(3, device="cpu") |
| 159 | + >>> y, y.device, y.usm_type |
| 160 | + (array([-1.38777878e-17, 1.00000000e+00, -1.38777878e-17]), |
| 161 | + Device(opencl:cpu:0), |
| 162 | + 'device') |
| 163 | +
|
| 164 | + >>> z = np.blackman(3, usm_type="host") |
| 165 | + >>> z, z.device, z.usm_type |
| 166 | + (array([-1.38777878e-17, 1.00000000e+00, -1.38777878e-17]), |
| 167 | + Device(level_zero:gpu:0), |
| 168 | + 'host') |
| 169 | +
|
| 170 | + """ |
| 171 | + |
| 172 | + return _call_window_kernel( |
| 173 | + M, wi._blackman, device=device, usm_type=usm_type, sycl_queue=sycl_queue |
| 174 | + ) |
| 175 | + |
| 176 | + |
84 | 177 | def hamming(M, device=None, usm_type=None, sycl_queue=None): |
85 | 178 | r""" |
86 | 179 | Return the Hamming window. |
|
0 commit comments