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

IntelPython / dpctl / 16460688165

23 Jul 2025 03:19AM UTC coverage: 85.936% (+0.05%) from 85.882%
16460688165

Pull #2098

github

web-flow
Merge 1fc9a2587 into aa05645a6
Pull Request #2098: Implement `tensor.isin`

3251 of 3906 branches covered (83.23%)

Branch coverage included in aggregate %.

116 of 120 new or added lines in 7 files covered. (96.67%)

3 existing lines in 3 files now uncovered.

12300 of 14190 relevant lines covered (86.68%)

5902.08 hits per line

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

95.95
/dpctl/tensor/_scalar_utils.py
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
import numbers
1✔
18

19
import numpy as np
1✔
20

21
import dpctl.memory as dpm
1✔
22
import dpctl.tensor as dpt
1✔
23
from dpctl.tensor._usmarray import _is_object_with_buffer_protocol as _is_buffer
1✔
24

25
from ._type_utils import (
1✔
26
    WeakBooleanType,
27
    WeakComplexType,
28
    WeakFloatingType,
29
    WeakIntegralType,
30
    _to_device_supported_dtype,
31
)
32

33

34
def _get_queue_usm_type(o):
1✔
35
    """Return SYCL device where object `o` allocated memory, or None."""
36
    if isinstance(o, dpt.usm_ndarray):
1✔
37
        return o.sycl_queue, o.usm_type
1✔
38
    elif hasattr(o, "__sycl_usm_array_interface__"):
1✔
39
        try:
1✔
40
            m = dpm.as_usm_memory(o)
1✔
41
            return m.sycl_queue, m.get_usm_type()
1✔
42
        except Exception:
1✔
43
            return None, None
1✔
44
    return None, None
1✔
45

46

47
def _get_dtype(o, dev):
1✔
48
    if isinstance(o, dpt.usm_ndarray):
1✔
49
        return o.dtype
1✔
50
    if hasattr(o, "__sycl_usm_array_interface__"):
1✔
51
        return dpt.asarray(o).dtype
1✔
52
    if _is_buffer(o):
1✔
53
        host_dt = np.array(o).dtype
1✔
54
        dev_dt = _to_device_supported_dtype(host_dt, dev)
1✔
55
        return dev_dt
1✔
56
    if hasattr(o, "dtype"):
1!
NEW
57
        dev_dt = _to_device_supported_dtype(o.dtype, dev)
×
NEW
58
        return dev_dt
×
59
    if isinstance(o, bool):
1✔
60
        return WeakBooleanType(o)
1✔
61
    if isinstance(o, int):
1✔
62
        return WeakIntegralType(o)
1✔
63
    if isinstance(o, float):
1✔
64
        return WeakFloatingType(o)
1✔
65
    if isinstance(o, complex):
1✔
66
        return WeakComplexType(o)
1✔
67
    return np.object_
1✔
68

69

70
def _validate_dtype(dt) -> bool:
1✔
71
    return isinstance(
1✔
72
        dt,
73
        (WeakBooleanType, WeakIntegralType, WeakFloatingType, WeakComplexType),
74
    ) or (
75
        isinstance(dt, dpt.dtype)
76
        and dt
77
        in [
78
            dpt.bool,
79
            dpt.int8,
80
            dpt.uint8,
81
            dpt.int16,
82
            dpt.uint16,
83
            dpt.int32,
84
            dpt.uint32,
85
            dpt.int64,
86
            dpt.uint64,
87
            dpt.float16,
88
            dpt.float32,
89
            dpt.float64,
90
            dpt.complex64,
91
            dpt.complex128,
92
        ]
93
    )
94

95

96
def _get_shape(o):
1✔
97
    if isinstance(o, dpt.usm_ndarray):
1✔
98
        return o.shape
1✔
99
    if _is_buffer(o):
1✔
100
        return memoryview(o).shape
1✔
101
    if isinstance(o, numbers.Number):
1✔
102
        return tuple()
1✔
103
    return getattr(o, "shape", tuple())
1✔
104

105

106
__all__ = [
1✔
107
    "_get_dtype",
108
    "_get_queue_usm_type",
109
    "_get_shape",
110
    "_validate_dtype",
111
]
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