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

IntelPython / dpctl / 15026962728

14 May 2025 05:16PM UTC coverage: 85.626% (-0.7%) from 86.372%
15026962728

push

github

web-flow
Merge pull request #2080 from david-cortes-intel/conda_details

DOC: Clarify details about conda installs

2959 of 3720 branches covered (79.54%)

Branch coverage included in aggregate %.

12178 of 13958 relevant lines covered (87.25%)

6965.51 hits per line

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

88.79
/dpctl/tensor/_testing.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 numpy as np
1✔
18

19
import dpctl.tensor as dpt
1✔
20
import dpctl.utils as du
1✔
21

22
from ._manipulation_functions import _broadcast_shape_impl
1✔
23
from ._type_utils import _to_device_supported_dtype
1✔
24

25

26
def _allclose_complex_fp(z1, z2, atol, rtol, equal_nan):
1✔
27
    z1r = dpt.real(z1)
1✔
28
    z1i = dpt.imag(z1)
1✔
29
    z2r = dpt.real(z2)
1✔
30
    z2i = dpt.imag(z2)
1✔
31
    if equal_nan:
1✔
32
        check1 = dpt.all(dpt.isnan(z1r) == dpt.isnan(z2r)) and dpt.all(
1✔
33
            dpt.isnan(z1i) == dpt.isnan(z2i)
34
        )
35
    else:
36
        check1 = (
1✔
37
            dpt.logical_not(dpt.any(dpt.isnan(z1r)))
38
            and dpt.logical_not(dpt.any(dpt.isnan(z1i)))
39
        ) and (
40
            dpt.logical_not(dpt.any(dpt.isnan(z2r)))
41
            and dpt.logical_not(dpt.any(dpt.isnan(z2i)))
42
        )
43
    if not check1:
1✔
44
        return check1
1✔
45
    mr = dpt.isinf(z1r)
1✔
46
    mi = dpt.isinf(z1i)
1✔
47
    check2 = dpt.all(mr == dpt.isinf(z2r)) and dpt.all(mi == dpt.isinf(z2i))
1✔
48
    if not check2:
1✔
49
        return check2
1✔
50
    check3 = dpt.all(z1r[mr] == z2r[mr]) and dpt.all(z1i[mi] == z2i[mi])
1✔
51
    if not check3:
1✔
52
        return check3
1✔
53
    mr = dpt.isfinite(z1r)
1✔
54
    mi = dpt.isfinite(z1i)
1✔
55
    mv1 = z1r[mr]
1✔
56
    mv2 = z2r[mr]
1✔
57
    check4 = dpt.all(
1✔
58
        dpt.abs(mv1 - mv2)
59
        < dpt.maximum(atol, rtol * dpt.maximum(dpt.abs(mv1), dpt.abs(mv2)))
60
    )
61
    if not check4:
×
62
        return check4
×
63
    mv1 = z1i[mi]
×
64
    mv2 = z2i[mi]
×
65
    check5 = dpt.all(
×
66
        dpt.abs(mv1 - mv2)
67
        <= dpt.maximum(atol, rtol * dpt.maximum(dpt.abs(mv1), dpt.abs(mv2)))
68
    )
69
    return check5
×
70

71

72
def _allclose_real_fp(r1, r2, atol, rtol, equal_nan):
1✔
73
    if equal_nan:
1✔
74
        check1 = dpt.all(dpt.isnan(r1) == dpt.isnan(r2))
1✔
75
    else:
76
        check1 = dpt.logical_not(dpt.any(dpt.isnan(r1))) and dpt.logical_not(
1✔
77
            dpt.any(dpt.isnan(r2))
78
        )
79
    if not check1:
1✔
80
        return check1
1✔
81
    mr = dpt.isinf(r1)
1✔
82
    check2 = dpt.all(mr == dpt.isinf(r2))
1✔
83
    if not check2:
1✔
84
        return check2
1✔
85
    check3 = dpt.all(r1[mr] == r2[mr])
1✔
86
    if not check3:
1✔
87
        return check3
1✔
88
    m = dpt.isfinite(r1)
1✔
89
    mv1 = r1[m]
1✔
90
    mv2 = r2[m]
1✔
91
    check4 = dpt.all(
1✔
92
        dpt.abs(mv1 - mv2)
93
        <= dpt.maximum(atol, rtol * dpt.maximum(dpt.abs(mv1), dpt.abs(mv2)))
94
    )
95
    return check4
×
96

97

98
def _allclose_others(r1, r2):
1✔
99
    return dpt.all(r1 == r2)
1✔
100

101

102
def allclose(a1, a2, atol=1e-8, rtol=1e-5, equal_nan=False):
1✔
103
    """allclose(a1, a2, atol=1e-8, rtol=1e-5, equal_nan=False)
104

105
    Returns True if two arrays are element-wise equal within tolerances.
106

107
    The testing is based on the following elementwise comparison:
108

109
           abs(a - b) <= max(atol, rtol * max(abs(a), abs(b)))
110
    """
111
    if not isinstance(a1, dpt.usm_ndarray):
1✔
112
        raise TypeError(
1✔
113
            f"Expected dpctl.tensor.usm_ndarray type, got {type(a1)}."
114
        )
115
    if not isinstance(a2, dpt.usm_ndarray):
1✔
116
        raise TypeError(
1✔
117
            f"Expected dpctl.tensor.usm_ndarray type, got {type(a2)}."
118
        )
119
    atol = float(atol)
1✔
120
    rtol = float(rtol)
1✔
121
    if atol < 0.0 or rtol < 0.0:
1!
122
        raise ValueError(
×
123
            "Absolute and relative tolerances must be non-negative"
124
        )
125
    equal_nan = bool(equal_nan)
1✔
126
    exec_q = du.get_execution_queue(tuple(a.sycl_queue for a in (a1, a2)))
1✔
127
    if exec_q is None:
1!
128
        raise du.ExecutionPlacementError(
×
129
            "Execution placement can not be unambiguously inferred "
130
            "from input arguments."
131
        )
132
    res_sh = _broadcast_shape_impl([a1.shape, a2.shape])
1✔
133
    b1 = a1
1✔
134
    b2 = a2
1✔
135
    if b1.dtype == b2.dtype:
1✔
136
        res_dt = b1.dtype
1✔
137
    else:
138
        res_dt = np.promote_types(b1.dtype, b2.dtype)
1✔
139
        res_dt = _to_device_supported_dtype(res_dt, exec_q.sycl_device)
1✔
140
        b1 = dpt.astype(b1, res_dt)
1✔
141
        b2 = dpt.astype(b2, res_dt)
1✔
142

143
    b1 = dpt.broadcast_to(b1, res_sh)
1✔
144
    b2 = dpt.broadcast_to(b2, res_sh)
1✔
145

146
    k = b1.dtype.kind
1✔
147
    if k == "c":
1✔
148
        return _allclose_complex_fp(b1, b2, atol, rtol, equal_nan)
1✔
149
    elif k == "f":
1✔
150
        return _allclose_real_fp(b1, b2, atol, rtol, equal_nan)
1✔
151
    else:
152
        return _allclose_others(b1, b2)
1✔
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

© 2026 Coveralls, Inc