From 47877115faa3aca47fb638c42c59f10e4bcf15f0 Mon Sep 17 00:00:00 2001 From: Nikita Grigorian Date: Tue, 23 Jan 2024 15:56:17 -0800 Subject: [PATCH 1/3] Moves dpt.isdtype to _type_utils.py --- dpctl/tensor/__init__.py | 3 +-- dpctl/tensor/_data_types.py | 43 ------------------------------------- dpctl/tensor/_type_utils.py | 43 +++++++++++++++++++++++++++++++++++++ 3 files changed, 44 insertions(+), 45 deletions(-) diff --git a/dpctl/tensor/__init__.py b/dpctl/tensor/__init__.py index ef8e604952..77c4e23d8c 100644 --- a/dpctl/tensor/__init__.py +++ b/dpctl/tensor/__init__.py @@ -51,7 +51,6 @@ int16, int32, int64, - isdtype, uint8, uint16, uint32, @@ -188,7 +187,7 @@ ) from ._sorting import argsort, sort from ._testing import allclose -from ._type_utils import can_cast, finfo, iinfo, result_type +from ._type_utils import can_cast, finfo, iinfo, isdtype, result_type __all__ = [ "Device", diff --git a/dpctl/tensor/_data_types.py b/dpctl/tensor/_data_types.py index bee557cf18..78e8714607 100644 --- a/dpctl/tensor/_data_types.py +++ b/dpctl/tensor/_data_types.py @@ -50,48 +50,6 @@ complex128 = dtype("complex128") -def isdtype(dtype_, kind): - """isdtype(dtype, kind) - - Returns a boolean indicating whether a provided `dtype` is - of a specified data type `kind`. - - See [array API](array_api) for more information. - - [array_api]: https://data-apis.org/array-api/latest/ - """ - - if not isinstance(dtype_, dtype): - raise TypeError(f"Expected instance of `dpt.dtype`, got {dtype_}") - - if isinstance(kind, dtype): - return dtype_ == kind - - elif isinstance(kind, str): - if kind == "bool": - return dtype_ == dtype("bool") - elif kind == "signed integer": - return dtype_.kind == "i" - elif kind == "unsigned integer": - return dtype_.kind == "u" - elif kind == "integral": - return dtype_.kind in "iu" - elif kind == "real floating": - return dtype_.kind == "f" - elif kind == "complex floating": - return dtype_.kind == "c" - elif kind == "numeric": - return dtype_.kind in "iufc" - else: - raise ValueError(f"Unrecognized data type kind: {kind}") - - elif isinstance(kind, tuple): - return any(isdtype(dtype_, k) for k in kind) - - else: - raise TypeError(f"Unsupported data type kind: {kind}") - - def _get_dtype(inp_dt, sycl_obj, ref_type=None): """ Type inference utility to construct data type @@ -121,7 +79,6 @@ def _get_dtype(inp_dt, sycl_obj, ref_type=None): __all__ = [ "dtype", "_get_dtype", - "isdtype", "bool", "int8", "uint8", diff --git a/dpctl/tensor/_type_utils.py b/dpctl/tensor/_type_utils.py index 3021db1841..541ff7ff9f 100644 --- a/dpctl/tensor/_type_utils.py +++ b/dpctl/tensor/_type_utils.py @@ -662,6 +662,48 @@ def _supported_dtype(dtypes): return True +def isdtype(dtype, kind): + """isdtype(dtype, kind) + + Returns a boolean indicating whether a provided `dtype` is + of a specified data type `kind`. + + See [array API](array_api) for more information. + + [array_api]: https://data-apis.org/array-api/latest/ + """ + + if not isinstance(dtype, np.dtype): + raise TypeError(f"Expected instance of `dpt.dtype`, got {dtype}") + + if isinstance(kind, dtype): + return dtype == kind + + elif isinstance(kind, str): + if kind == "bool": + return dtype == np.dtype("bool") + elif kind == "signed integer": + return dtype.kind == "i" + elif kind == "unsigned integer": + return dtype.kind == "u" + elif kind == "integral": + return dtype.kind in "iu" + elif kind == "real floating": + return dtype.kind == "f" + elif kind == "complex floating": + return dtype.kind == "c" + elif kind == "numeric": + return dtype.kind in "iufc" + else: + raise ValueError(f"Unrecognized data type kind: {kind}") + + elif isinstance(kind, tuple): + return any(isdtype(dtype, k) for k in kind) + + else: + raise TypeError(f"Unsupported data type kind: {kind}") + + __all__ = [ "_find_buf_dtype", "_find_buf_dtype2", @@ -676,6 +718,7 @@ def _supported_dtype(dtypes): "can_cast", "finfo", "iinfo", + "isdtype", "result_type", "WeakBooleanType", "WeakIntegralType", From ce3147ccfcab4e44b1ab91d6b32baac2f4aade76 Mon Sep 17 00:00:00 2001 From: Nikita Grigorian Date: Tue, 23 Jan 2024 15:57:56 -0800 Subject: [PATCH 2/3] Experiment with disabling deadline for array API conformity workflow --- .github/workflows/conda-package.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/conda-package.yml b/.github/workflows/conda-package.yml index 6d04a43ce6..9219606df9 100644 --- a/.github/workflows/conda-package.yml +++ b/.github/workflows/conda-package.yml @@ -642,7 +642,7 @@ jobs: python -c "import dpctl; dpctl.lsplatform()" export ARRAY_API_TESTS_MODULE=dpctl.tensor cd /home/runner/work/array-api-tests - pytest --json-report --json-report-file=$FILE --skips-file ${GITHUB_WORKSPACE}/.github/workflows/array-api-skips.txt array_api_tests/ || true + pytest --json-report --json-report-file=$FILE --disable-deadline --skips-file ${GITHUB_WORKSPACE}/.github/workflows/array-api-skips.txt array_api_tests/ || true - name: Set Github environment variables shell: bash -l {0} run: | From 7a1bef70e70296c2158cc07756cd5a0df75c57ee Mon Sep 17 00:00:00 2001 From: Nikita Grigorian Date: Tue, 23 Jan 2024 16:39:30 -0800 Subject: [PATCH 3/3] Fixes typo in isdtype --- dpctl/tensor/_type_utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dpctl/tensor/_type_utils.py b/dpctl/tensor/_type_utils.py index 541ff7ff9f..00e47db97a 100644 --- a/dpctl/tensor/_type_utils.py +++ b/dpctl/tensor/_type_utils.py @@ -676,7 +676,7 @@ def isdtype(dtype, kind): if not isinstance(dtype, np.dtype): raise TypeError(f"Expected instance of `dpt.dtype`, got {dtype}") - if isinstance(kind, dtype): + if isinstance(kind, np.dtype): return dtype == kind elif isinstance(kind, str):