|
6 | 6 | import itertools |
7 | 7 | import math |
8 | 8 | import os |
9 | | -from functools import wraps |
10 | 9 |
|
11 | 10 | import numpy |
12 | 11 | import scipy |
@@ -244,52 +243,6 @@ def _union1d(a, b, xp): |
244 | 243 | return xp.unique_values(xp.concat([xp.unique_values(a), xp.unique_values(b)])) |
245 | 244 |
|
246 | 245 |
|
247 | | -def isdtype(dtype, kind, *, xp): |
248 | | - """Returns a boolean indicating whether a provided dtype is of type "kind". |
249 | | -
|
250 | | - Included in the v2022.12 of the Array API spec. |
251 | | - https://data-apis.org/array-api/latest/API_specification/generated/array_api.isdtype.html |
252 | | - """ |
253 | | - if isinstance(kind, tuple): |
254 | | - return any(_isdtype_single(dtype, k, xp=xp) for k in kind) |
255 | | - else: |
256 | | - return _isdtype_single(dtype, kind, xp=xp) |
257 | | - |
258 | | - |
259 | | -def _isdtype_single(dtype, kind, *, xp): |
260 | | - if isinstance(kind, str): |
261 | | - if kind == "bool": |
262 | | - return dtype == xp.bool |
263 | | - elif kind == "signed integer": |
264 | | - return dtype in {xp.int8, xp.int16, xp.int32, xp.int64} |
265 | | - elif kind == "unsigned integer": |
266 | | - return dtype in {xp.uint8, xp.uint16, xp.uint32, xp.uint64} |
267 | | - elif kind == "integral": |
268 | | - return any( |
269 | | - _isdtype_single(dtype, k, xp=xp) |
270 | | - for k in ("signed integer", "unsigned integer") |
271 | | - ) |
272 | | - elif kind == "real floating": |
273 | | - return dtype in supported_float_dtypes(xp) |
274 | | - elif kind == "complex floating": |
275 | | - # Some name spaces might not have support for complex dtypes. |
276 | | - complex_dtypes = set() |
277 | | - if hasattr(xp, "complex64"): |
278 | | - complex_dtypes.add(xp.complex64) |
279 | | - if hasattr(xp, "complex128"): |
280 | | - complex_dtypes.add(xp.complex128) |
281 | | - return dtype in complex_dtypes |
282 | | - elif kind == "numeric": |
283 | | - return any( |
284 | | - _isdtype_single(dtype, k, xp=xp) |
285 | | - for k in ("integral", "real floating", "complex floating") |
286 | | - ) |
287 | | - else: |
288 | | - raise ValueError(f"Unrecognized data type kind: {kind!r}") |
289 | | - else: |
290 | | - return dtype == kind |
291 | | - |
292 | | - |
293 | 246 | def supported_float_dtypes(xp, device=None): |
294 | 247 | """Supported floating point types for the namespace. |
295 | 248 |
|
@@ -342,20 +295,6 @@ def ensure_common_namespace_device(reference, *arrays): |
342 | 295 | return arrays |
343 | 296 |
|
344 | 297 |
|
345 | | -def _check_device_cpu(device): |
346 | | - if device not in {"cpu", None}: |
347 | | - raise ValueError(f"Unsupported device for NumPy: {device!r}") |
348 | | - |
349 | | - |
350 | | -def _accept_device_cpu(func): |
351 | | - @wraps(func) |
352 | | - def wrapped_func(*args, **kwargs): |
353 | | - _check_device_cpu(kwargs.pop("device", None)) |
354 | | - return func(*args, **kwargs) |
355 | | - |
356 | | - return wrapped_func |
357 | | - |
358 | | - |
359 | 298 | def _remove_non_arrays(*arrays, remove_none=True, remove_types=(str,)): |
360 | 299 | """Filter arrays to exclude None and/or specific types. |
361 | 300 |
|
|
0 commit comments