• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

IntelPython / dpctl / 17226425457

26 Aug 2025 02:46AM UTC coverage: 85.902% (+0.005%) from 85.897%
17226425457

Pull #2139

github

web-flow
Merge f9fb7f5c1 into b4e0dca88
Pull Request #2139: Bump github/codeql-action from 3.29.10 to 3.29.11

3230 of 3880 branches covered (83.25%)

Branch coverage included in aggregate %.

12241 of 14130 relevant lines covered (86.63%)

5856.16 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

86.27
/dpctl/tensor/_types.pxi
1
#                       Data Parallel Control (dpctl)
2
#
3
#  Copyright 2020-2025 Intel Corporation
4
#
5
#  Licensed under the Apache License, Version 2.0 (the "License");
6
#  you may not use this file except in compliance with the License.
7
#  You may obtain a copy of the License at
8
#
9
#     http://www.apache.org/licenses/LICENSE-2.0
10
#
11
#  Unless required by applicable law or agreed to in writing, software
12
#  distributed under the License is distributed on an "AS IS" BASIS,
13
#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
#  See the License for the specific language governing permissions and
15
#  limitations under the License.
16

17
# these typenum values are aligned to values in NumPy
18
cdef:
19
    int UAR_BOOL = 0  # pragma: no cover
20
    int UAR_BYTE = 1  # pragma: no cover
21
    int UAR_UBYTE = 2  # pragma: no cover
22
    int UAR_SHORT = 3  # pragma: no cover
23
    int UAR_USHORT = 4  # pragma: no cover
24
    int UAR_INT = 5  # pragma: no cover
25
    int UAR_UINT = 6  # pragma: no cover
26
    int UAR_LONG = 7  # pragma: no cover
27
    int UAR_ULONG = 8  # pragma: no cover
28
    int UAR_LONGLONG = 9  # pragma: no cover
29
    int UAR_ULONGLONG = 10  # pragma: no cover
30
    int UAR_FLOAT = 11  # pragma: no cover
31
    int UAR_DOUBLE = 12  # pragma: no cover
32
    int UAR_CFLOAT = 14  # pragma: no cover
33
    int UAR_CDOUBLE = 15  # pragma: no cover
34
    int UAR_TYPE_SENTINEL = 17  # pragma: no cover
35
    int UAR_HALF = 23  # pragma: no cover
36

37
cdef int type_bytesize(int typenum):
×
38
    """
39
    NPY_BOOL=0         : 1
40
    NPY_BYTE=1         : 1
41
    NPY_UBYTE=2        : 1
42
    NPY_SHORT=3        : 2
43
    NPY_USHORT=4       : 2
44
    NPY_INT=5          : sizeof(int)
45
    NPY_UINT=6         : sizeof(unsigned int)
46
    NPY_LONG=7         : sizeof(long)
47
    NPY_ULONG=8        : sizeof(unsigned long)
48
    NPY_LONGLONG=9     : 8
49
    NPY_ULONGLONG=10   : 8
50
    NPY_FLOAT=11       : 4
51
    NPY_DOUBLE=12      : 8
52
    NPY_LONGDOUBLE=13  : N/A
53
    NPY_CFLOAT=14      : 8
54
    NPY_CDOUBLE=15     : 16
55
    NPY_CLONGDOUBLE=16 : N/A
56
    NPY_HALF=23        : 2
57
    """
58
    cdef int *type_to_bytesize = [
1✔
59
        1,
60
        sizeof(char),
61
        sizeof(unsigned char),
62
        sizeof(short),
63
        sizeof(unsigned short),
64
        sizeof(int),
65
        sizeof(unsigned int),
66
        sizeof(long),
67
        sizeof(unsigned long),
68
        sizeof(long long),
69
        sizeof(unsigned long long),
70
        sizeof(float),
71
        sizeof(double), -1,
72
        sizeof(float complex),
73
        sizeof(double complex), -1]
74

75
    if typenum < 0:  # pragma: no cover
76
        return -1
1✔
77
    if typenum > 16:
1✔
78
        if typenum == 23:
1✔
79
            return 2
1✔
80
        return -1
1✔
81

82
    return type_to_bytesize[typenum]
1✔
83

84

85
cdef str _make_typestr(int typenum):
×
86
    """
87
    Make typestring from type number
88
    """
89
    cdef type_to_str = ["|b", "|i", "|u", "|i", "|u",
1✔
90
                        "|i", "|u", "|i", "|u", "|i", "|u",
91
                        "|f", "|f", "", "|c", "|c", ""]
92

93
    if (typenum < 0):  # pragma: no cover
94
        return ""
×
95
    if (typenum > 16):
1✔
96
        if (typenum == 23):
1✔
97
            return "|f2"
1✔
98
        return ""  # pragma: no cover
99

100
    return type_to_str[typenum] + str(type_bytesize(typenum))
1✔
101

102

103
cdef int typenum_from_format(str s):
1✔
104
    """
105
    Internal utility to convert string describing type format
106

107
    Format is [<|=>][biufc]#
108
    Shortcuts for formats are i, u, d, D
109
    """
110
    if not s:
1✔
111
        return -1
1✔
112
    try:
1✔
113
        dt = np.dtype(s)
1✔
114
    except Exception:
1✔
115
        return -1
1✔
116
    if (dt.byteorder == ">"):
1✔
117
        return -2
1✔
118
    return dt.num
1✔
119

120

121
cdef int descr_to_typenum(object dtype):
1✔
122
    """
123
    Returns typenum for argumentd dtype that has attribute descr,
124
    assumed numpy.dtype
125
    """
126
    obj = getattr(dtype, "descr")
1✔
127
    if (not isinstance(obj, list) or len(obj) != 1):
1✔
128
        return -1    # token for ValueError
1✔
129
    obj = obj[0]
1✔
130
    if (
1✔
131
        not isinstance(obj, tuple) or len(obj) != 2 or obj[0]
1✔
132
    ):  # pragma: no cover
133
        return -1
×
134
    obj = obj[1]
1✔
135
    if not isinstance(obj, str):  # pragma: no cover
136
        return -1
×
137
    return typenum_from_format(obj)
1✔
138

139

140
cdef int dtype_to_typenum(dtype):
1✔
141
    if isinstance(dtype, str):
1✔
142
        return typenum_from_format(dtype)
1✔
143
    elif isinstance(dtype, bytes):
1✔
144
        return typenum_from_format(dtype.decode("UTF-8"))
1✔
145
    elif hasattr(dtype, "descr"):
1✔
146
        return descr_to_typenum(dtype)
1✔
147
    else:
148
        try:
1✔
149
            dt = np.dtype(dtype)
1✔
150
        except TypeError:
1✔
151
            return -3
1✔
152
        except Exception:  # pragma: no cover
153
            return -1
×
154
        if hasattr(dt, "descr"):
1✔
155
            return descr_to_typenum(dt)
1✔
156
        else:  # pragma: no cover
157
            return -3  # token for TypeError
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc