|
48 | 48 | __all__ = ["hamming", "hanning"] |
49 | 49 |
|
50 | 50 |
|
| 51 | +def _call_window_kernel( |
| 52 | + M, _window_kernel, device=None, usm_type=None, sycl_queue=None |
| 53 | +): |
| 54 | + |
| 55 | + try: |
| 56 | + M = int(M) |
| 57 | + except Exception as e: |
| 58 | + raise TypeError("M must be an integer") from e |
| 59 | + |
| 60 | + cfd_kwarg = { |
| 61 | + "device": device, |
| 62 | + "usm_type": usm_type, |
| 63 | + "sycl_queue": sycl_queue, |
| 64 | + } |
| 65 | + |
| 66 | + if M < 1: |
| 67 | + return dpnp.empty(0, **cfd_kwarg) |
| 68 | + if M == 1: |
| 69 | + return dpnp.ones(1, **cfd_kwarg) |
| 70 | + |
| 71 | + result = dpnp.empty(M, **cfd_kwarg) |
| 72 | + exec_q = result.sycl_queue |
| 73 | + _manager = dpu.SequentialOrderManager[exec_q] |
| 74 | + |
| 75 | + ht_ev, win_ev = _window_kernel( |
| 76 | + exec_q, dpnp.get_usm_ndarray(result), depends=_manager.submitted_events |
| 77 | + ) |
| 78 | + |
| 79 | + _manager.add_event_pair(ht_ev, win_ev) |
| 80 | + |
| 81 | + return result |
| 82 | + |
| 83 | + |
51 | 84 | def hamming(M, device=None, usm_type=None, sycl_queue=None): |
52 | 85 | r""" |
53 | 86 | Return the Hamming window. |
@@ -127,34 +160,10 @@ def hamming(M, device=None, usm_type=None, sycl_queue=None): |
127 | 160 |
|
128 | 161 | """ |
129 | 162 |
|
130 | | - try: |
131 | | - M = int(M) |
132 | | - except Exception as e: |
133 | | - raise TypeError("M must be an integer") from e |
134 | | - |
135 | | - cfd_kwarg = { |
136 | | - "device": device, |
137 | | - "usm_type": usm_type, |
138 | | - "sycl_queue": sycl_queue, |
139 | | - } |
140 | | - |
141 | | - if M < 1: |
142 | | - return dpnp.empty(0, **cfd_kwarg) |
143 | | - if M == 1: |
144 | | - return dpnp.ones(1, **cfd_kwarg) |
145 | | - |
146 | | - result = dpnp.empty(M, **cfd_kwarg) |
147 | | - exec_q = result.sycl_queue |
148 | | - _manager = dpu.SequentialOrderManager[exec_q] |
149 | | - |
150 | | - ht_ev, win_ev = wi._hamming( |
151 | | - exec_q, dpnp.get_usm_ndarray(result), depends=_manager.submitted_events |
| 163 | + return _call_window_kernel( |
| 164 | + M, wi._hamming, device=device, usm_type=usm_type, sycl_queue=sycl_queue |
152 | 165 | ) |
153 | 166 |
|
154 | | - _manager.add_event_pair(ht_ev, win_ev) |
155 | | - |
156 | | - return result |
157 | | - |
158 | 167 |
|
159 | 168 | def hanning(M, device=None, usm_type=None, sycl_queue=None): |
160 | 169 | r""" |
@@ -235,30 +244,6 @@ def hanning(M, device=None, usm_type=None, sycl_queue=None): |
235 | 244 |
|
236 | 245 | """ |
237 | 246 |
|
238 | | - try: |
239 | | - M = int(M) |
240 | | - except Exception as e: |
241 | | - raise TypeError("M must be an integer") from e |
242 | | - |
243 | | - cfd_kwarg = { |
244 | | - "device": device, |
245 | | - "usm_type": usm_type, |
246 | | - "sycl_queue": sycl_queue, |
247 | | - } |
248 | | - |
249 | | - if M < 1: |
250 | | - return dpnp.empty(0, **cfd_kwarg) |
251 | | - if M == 1: |
252 | | - return dpnp.ones(1, **cfd_kwarg) |
253 | | - |
254 | | - result = dpnp.empty(int(M), **cfd_kwarg) |
255 | | - exec_q = result.sycl_queue |
256 | | - _manager = dpu.SequentialOrderManager[exec_q] |
257 | | - |
258 | | - ht_ev, win_ev = wi._hanning( |
259 | | - exec_q, dpnp.get_usm_ndarray(result), depends=_manager.submitted_events |
| 247 | + return _call_window_kernel( |
| 248 | + M, wi._hanning, device=device, usm_type=usm_type, sycl_queue=sycl_queue |
260 | 249 | ) |
261 | | - |
262 | | - _manager.add_event_pair(ht_ev, win_ev) |
263 | | - |
264 | | - return result |
0 commit comments