|
45 | 45 | import dpnp |
46 | 46 | import dpnp.backend.extensions.window._window_impl as wi |
47 | 47 |
|
48 | | -__all__ = ["blackman", "hamming", "hanning"] |
| 48 | +__all__ = ["bartlett", "blackman", "hamming", "hanning"] |
49 | 49 |
|
50 | 50 |
|
51 | 51 | def _call_window_kernel( |
@@ -174,6 +174,99 @@ def blackman(M, device=None, usm_type=None, sycl_queue=None): |
174 | 174 | ) |
175 | 175 |
|
176 | 176 |
|
| 177 | +def bartlett(M, device=None, usm_type=None, sycl_queue=None): |
| 178 | + r""" |
| 179 | + Return the Bartlett window. |
| 180 | +
|
| 181 | + The Bartlett window is very similar to a triangular window, except that the |
| 182 | + end points are at zero. It is often used in signal processing for tapering |
| 183 | + a signal, without generating too much ripple in the frequency domain. |
| 184 | +
|
| 185 | + For full documentation refer to :obj:`numpy.bartlett`. |
| 186 | +
|
| 187 | + Parameters |
| 188 | + ---------- |
| 189 | + M : int |
| 190 | + Number of points in the output window. If zero or less, an empty array |
| 191 | + is returned. |
| 192 | + device : {None, string, SyclDevice, SyclQueue, Device}, optional |
| 193 | + An array API concept of device where the output array is created. |
| 194 | + `device` can be ``None``, a oneAPI filter selector string, an instance |
| 195 | + of :class:`dpctl.SyclDevice` corresponding to a non-partitioned SYCL |
| 196 | + device, an instance of :class:`dpctl.SyclQueue`, or a |
| 197 | + :class:`dpctl.tensor.Device` object returned by |
| 198 | + :attr:`dpnp.ndarray.device`. |
| 199 | +
|
| 200 | + Default: ``None``. |
| 201 | + usm_type : {None, "device", "shared", "host"}, optional |
| 202 | + The type of SYCL USM allocation for the output array. |
| 203 | +
|
| 204 | + Default: ``None``. |
| 205 | + sycl_queue : {None, SyclQueue}, optional |
| 206 | + A SYCL queue to use for output array allocation and copying. The |
| 207 | + `sycl_queue` can be passed as ``None`` (the default), which means |
| 208 | + to get the SYCL queue from `device` keyword if present or to use |
| 209 | + a default queue. |
| 210 | +
|
| 211 | + Default: ``None``. |
| 212 | +
|
| 213 | + Returns |
| 214 | + ------- |
| 215 | + out : dpnp.ndarray of shape (M,) |
| 216 | + The triangular window, with the maximum value normalized to one |
| 217 | + (the value one appears only if the number of samples is odd), with the |
| 218 | + first and last samples equal to zero. |
| 219 | +
|
| 220 | + See Also |
| 221 | + -------- |
| 222 | + :obj:`dpnp.blackman` : Return the Blackman window. |
| 223 | + :obj:`dpnp.hamming` : Return the Hamming window. |
| 224 | + :obj:`dpnp.hanning` : Return the Hanning window. |
| 225 | + :obj:`dpnp.kaiser` : Return the Kaiser window. |
| 226 | +
|
| 227 | + Notes |
| 228 | + ----- |
| 229 | + The Bartlett window is defined as |
| 230 | +
|
| 231 | + .. math:: w(n) = \frac{2}{M-1} \left(\frac{M-1}{2} - |
| 232 | + \left|n - \frac{M-1}{2}\right|\right) |
| 233 | +
|
| 234 | + Examples |
| 235 | + -------- |
| 236 | + >>> import dpnp as np |
| 237 | + >>> np.bartlett(12) |
| 238 | + array([0. , 0.18181818, 0.36363636, 0.54545455, 0.72727273, |
| 239 | + 0.90909091, 0.90909091, 0.72727273, 0.54545455, 0.36363636, |
| 240 | + 0.18181818, 0. ]) |
| 241 | +
|
| 242 | + Creating the output array on a different device or with a |
| 243 | + specified usm_type: |
| 244 | +
|
| 245 | + >>> x = np.bartlett(4) # default case |
| 246 | + >>> x, x.device, x.usm_type |
| 247 | + (array([0. , 0.66666667, 0.66666667, 0. ]), |
| 248 | + Device(level_zero:gpu:0), |
| 249 | + 'device') |
| 250 | +
|
| 251 | + >>> y = np.bartlett(4, device="cpu") |
| 252 | + >>> y, y.device, y.usm_type |
| 253 | + (array([0. , 0.66666667, 0.66666667, 0. ]), |
| 254 | + Device(opencl:cpu:0), |
| 255 | + 'device') |
| 256 | +
|
| 257 | + >>> z = np.bartlett(4, usm_type="host") |
| 258 | + >>> z, z.device, z.usm_type |
| 259 | + (array([0. , 0.66666667, 0.66666667, 0. ]), |
| 260 | + Device(level_zero:gpu:0), |
| 261 | + 'host') |
| 262 | +
|
| 263 | + """ |
| 264 | + |
| 265 | + return _call_window_kernel( |
| 266 | + M, wi._bartlett, device=device, usm_type=usm_type, sycl_queue=sycl_queue |
| 267 | + ) |
| 268 | + |
| 269 | + |
177 | 270 | def hamming(M, device=None, usm_type=None, sycl_queue=None): |
178 | 271 | r""" |
179 | 272 | Return the Hamming window. |
|
0 commit comments