|
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( |
@@ -81,6 +81,100 @@ def _call_window_kernel( |
81 | 81 | return result |
82 | 82 |
|
83 | 83 |
|
| 84 | +def bartlett(M, device=None, usm_type=None, sycl_queue=None): |
| 85 | + r""" |
| 86 | + Return the Bartlett window. |
| 87 | +
|
| 88 | + The Bartlett window is very similar to a triangular window, except that the |
| 89 | + end points are at zero. It is often used in signal processing for tapering |
| 90 | + a signal, without generating too much ripple in the frequency domain. |
| 91 | +
|
| 92 | + For full documentation refer to :obj:`numpy.bartlett`. |
| 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 triangular window, with the maximum value normalized to one |
| 124 | + (the value one appears only if the number of samples is odd), with the |
| 125 | + first and last samples equal to zero. |
| 126 | +
|
| 127 | + See Also |
| 128 | + -------- |
| 129 | + :obj:`dpnp.blackman` : Return the Blackman window. |
| 130 | + :obj:`dpnp.hamming` : Return the Hamming window. |
| 131 | + :obj:`dpnp.hanning` : Return the Hanning window. |
| 132 | + :obj:`dpnp.kaiser` : Return the Kaiser window. |
| 133 | +
|
| 134 | + Notes |
| 135 | + ----- |
| 136 | + The Bartlett window is defined as |
| 137 | +
|
| 138 | + .. math:: w(n) = \frac{2}{M-1} \left(\frac{M-1}{2} - |
| 139 | + \left|n - \frac{M-1}{2}\right|\right) |
| 140 | + \qquad 0 \leq n \leq M-1 |
| 141 | +
|
| 142 | + Examples |
| 143 | + -------- |
| 144 | + >>> import dpnp as np |
| 145 | + >>> np.bartlett(12) |
| 146 | + array([0. , 0.18181818, 0.36363636, 0.54545455, 0.72727273, |
| 147 | + 0.90909091, 0.90909091, 0.72727273, 0.54545455, 0.36363636, |
| 148 | + 0.18181818, 0. ]) |
| 149 | +
|
| 150 | + Creating the output array on a different device or with a |
| 151 | + specified usm_type: |
| 152 | +
|
| 153 | + >>> x = np.bartlett(4) # default case |
| 154 | + >>> x, x.device, x.usm_type |
| 155 | + (array([0. , 0.66666667, 0.66666667, 0. ]), |
| 156 | + Device(level_zero:gpu:0), |
| 157 | + 'device') |
| 158 | +
|
| 159 | + >>> y = np.bartlett(4, device="cpu") |
| 160 | + >>> y, y.device, y.usm_type |
| 161 | + (array([0. , 0.66666667, 0.66666667, 0. ]), |
| 162 | + Device(opencl:cpu:0), |
| 163 | + 'device') |
| 164 | +
|
| 165 | + >>> z = np.bartlett(4, usm_type="host") |
| 166 | + >>> z, z.device, z.usm_type |
| 167 | + (array([0. , 0.66666667, 0.66666667, 0. ]), |
| 168 | + Device(level_zero:gpu:0), |
| 169 | + 'host') |
| 170 | +
|
| 171 | + """ |
| 172 | + |
| 173 | + return _call_window_kernel( |
| 174 | + M, wi._bartlett, device=device, usm_type=usm_type, sycl_queue=sycl_queue |
| 175 | + ) |
| 176 | + |
| 177 | + |
84 | 178 | def blackman(M, device=None, usm_type=None, sycl_queue=None): |
85 | 179 | r""" |
86 | 180 | Return the Blackman window. |
|
0 commit comments