Skip to content

Fix dpctl.tensor.isdtype function signature #1501

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/conda-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down
3 changes: 1 addition & 2 deletions dpctl/tensor/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@
int16,
int32,
int64,
isdtype,
uint8,
uint16,
uint32,
Expand Down Expand Up @@ -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",
Expand Down
43 changes: 0 additions & 43 deletions dpctl/tensor/_data_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -121,7 +79,6 @@ def _get_dtype(inp_dt, sycl_obj, ref_type=None):
__all__ = [
"dtype",
"_get_dtype",
"isdtype",
"bool",
"int8",
"uint8",
Expand Down
43 changes: 43 additions & 0 deletions dpctl/tensor/_type_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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, np.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",
Expand All @@ -676,6 +718,7 @@ def _supported_dtype(dtypes):
"can_cast",
"finfo",
"iinfo",
"isdtype",
"result_type",
"WeakBooleanType",
"WeakIntegralType",
Expand Down