Skip to content

Commit

Permalink
Merge pull request #1970 from IntelPython/improve-coverage-stats
Browse files Browse the repository at this point in the history
Improve coverage stats
  • Loading branch information
oleksandr-pavlyk authored Jan 17, 2025
2 parents a7e85a2 + b51a19f commit 653f579
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 32 deletions.
2 changes: 1 addition & 1 deletion dpctl/_init_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
and os.path.isfile(os.path.join(sys.exec_prefix, "pyvenv.cfg"))
)

if is_venv_win32:
if is_venv_win32: # pragma: no cover
# For virtual environments on Windows, add folder
# with DPC++ libraries to the DLL search path gh-1745
dll_dir = os.path.join(sys.exec_prefix, "Library", "bin")
Expand Down
4 changes: 2 additions & 2 deletions dpctl/tensor/_numpy_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@

_npver = np.lib.NumpyVersion(np.__version__)

if _npver < "1.25.0":
if _npver < "1.25.0": # pragma: no cover
from numpy import AxisError
else:
from numpy.exceptions import AxisError

if _npver >= "2.0.0":
from numpy._core.numeric import normalize_axis_index, normalize_axis_tuple
else:
else: # pragma: no cover
from numpy.core.numeric import normalize_axis_index, normalize_axis_tuple


Expand Down
52 changes: 25 additions & 27 deletions dpctl/tensor/_types.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,25 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import numpy as np


# these typenum values are aligned to values in NumPy
cdef int UAR_BOOL = 0
cdef int UAR_BYTE = 1
cdef int UAR_UBYTE = 2
cdef int UAR_SHORT = 3
cdef int UAR_USHORT = 4
cdef int UAR_INT = 5
cdef int UAR_UINT = 6
cdef int UAR_LONG = 7
cdef int UAR_ULONG = 8
cdef int UAR_LONGLONG = 9
cdef int UAR_ULONGLONG = 10
cdef int UAR_FLOAT = 11
cdef int UAR_DOUBLE = 12
cdef int UAR_CFLOAT = 14
cdef int UAR_CDOUBLE = 15
cdef int UAR_TYPE_SENTINEL = 17
cdef int UAR_HALF = 23
cdef:
int UAR_BOOL = 0 # pragma: no cover
int UAR_BYTE = 1 # pragma: no cover
int UAR_UBYTE = 2 # pragma: no cover
int UAR_SHORT = 3 # pragma: no cover
int UAR_USHORT = 4 # pragma: no cover
int UAR_INT = 5 # pragma: no cover
int UAR_UINT = 6 # pragma: no cover
int UAR_LONG = 7 # pragma: no cover
int UAR_ULONG = 8 # pragma: no cover
int UAR_LONGLONG = 9 # pragma: no cover
int UAR_ULONGLONG = 10 # pragma: no cover
int UAR_FLOAT = 11 # pragma: no cover
int UAR_DOUBLE = 12 # pragma: no cover
int UAR_CFLOAT = 14 # pragma: no cover
int UAR_CDOUBLE = 15 # pragma: no cover
int UAR_TYPE_SENTINEL = 17 # pragma: no cover
int UAR_HALF = 23 # pragma: no cover

cdef int type_bytesize(int typenum):
"""
Expand Down Expand Up @@ -74,7 +72,7 @@ cdef int type_bytesize(int typenum):
sizeof(float complex),
sizeof(double complex), -1]

if typenum < 0:
if typenum < 0: # pragma: no cover
return -1
if typenum > 16:
if typenum == 23:
Expand All @@ -92,12 +90,12 @@ cdef str _make_typestr(int typenum):
"|i", "|u", "|i", "|u", "|i", "|u",
"|f", "|f", "", "|c", "|c", ""]

if (typenum < 0):
if (typenum < 0): # pragma: no cover
return ""
if (typenum > 16):
if (typenum == 23):
return "|f2"
return ""
return "" # pragma: no cover

return type_to_str[typenum] + str(type_bytesize(typenum))

Expand Down Expand Up @@ -126,10 +124,10 @@ cdef int descr_to_typenum(object dtype):
if (not isinstance(obj, list) or len(obj) != 1):
return -1 # token for ValueError
obj = obj[0]
if (not isinstance(obj, tuple) or len(obj) != 2 or obj[0]):
if (not isinstance(obj, tuple) or len(obj) != 2 or obj[0]): # pragma: no cover
return -1
obj = obj[1]
if not isinstance(obj, str):
if not isinstance(obj, str): # pragma: no cover
return -1
return typenum_from_format(obj)

Expand All @@ -146,9 +144,9 @@ cdef int dtype_to_typenum(dtype):
dt = np.dtype(dtype)
except TypeError:
return -3
except Exception:
except Exception: # pragma: no cover
return -1
if hasattr(dt, 'descr'):
return descr_to_typenum(dt)
else:
else: # pragma: no cover
return -3 # token for TypeError
6 changes: 6 additions & 0 deletions dpctl/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,12 @@ def test_intel_device_info():
assert test, err_msg


def test_intel_device_info_validation():
invalid_device = dict()
with pytest.raises(TypeError):
dpctl.utils.intel_device_info(invalid_device)


def test_order_manager():
try:
q = dpctl.SyclQueue()
Expand Down
4 changes: 2 additions & 2 deletions dpctl/utils/_intel_device_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,11 @@ def intel_device_info(dev, /):
if not isinstance(dev, SyclDevice):
raise TypeError(f"Expected dpctl.SyclDevice, got {type(dev)}")
dev_id = intel_device_info_device_id(dev)
if dev_id:
if dev_id: # pragma: no cover
res = {
"device_id": dev_id,
}
if dev.has_aspect_gpu:
if dev.has_aspect_gpu: # pragma: no cover
eu_count = intel_device_info_gpu_eu_count(dev)
if eu_count:
res["gpu_eu_count"] = eu_count
Expand Down

0 comments on commit 653f579

Please sign in to comment.