|
14 | 14 | # See the License for the specific language governing permissions and |
15 | 15 | # limitations under the License. |
16 | 16 |
|
17 | | -import ctypes |
18 | | - |
19 | 17 | import numpy as np |
20 | 18 | import pytest |
21 | 19 |
|
22 | | -import dpctl |
23 | 20 | import dpctl.tensor as dpt |
24 | 21 | from dpctl.tensor._type_utils import _can_cast |
25 | 22 | from dpctl.tests.helper import get_queue_or_skip, skip_if_dtype_not_supported |
26 | 23 |
|
27 | | -from .utils import _all_dtypes, _compare_dtypes, _usm_types |
| 24 | +from .utils import _all_dtypes, _compare_dtypes |
28 | 25 |
|
29 | 26 |
|
30 | 27 | @pytest.mark.parametrize("op1_dtype", _all_dtypes[1:]) |
@@ -77,123 +74,6 @@ def test_subtract_bool(): |
77 | 74 | dpt.subtract(ar1, ar2) |
78 | 75 |
|
79 | 76 |
|
80 | | -@pytest.mark.parametrize("op1_usm_type", _usm_types) |
81 | | -@pytest.mark.parametrize("op2_usm_type", _usm_types) |
82 | | -def test_subtract_usm_type_matrix(op1_usm_type, op2_usm_type): |
83 | | - get_queue_or_skip() |
84 | | - |
85 | | - sz = 128 |
86 | | - ar1 = dpt.ones(sz, dtype="i4", usm_type=op1_usm_type) |
87 | | - ar2 = dpt.ones_like(ar1, dtype="i4", usm_type=op2_usm_type) |
88 | | - |
89 | | - r = dpt.subtract(ar1, ar2) |
90 | | - assert isinstance(r, dpt.usm_ndarray) |
91 | | - expected_usm_type = dpctl.utils.get_coerced_usm_type( |
92 | | - (op1_usm_type, op2_usm_type) |
93 | | - ) |
94 | | - assert r.usm_type == expected_usm_type |
95 | | - |
96 | | - |
97 | | -def test_subtract_order(): |
98 | | - get_queue_or_skip() |
99 | | - |
100 | | - test_shape = ( |
101 | | - 20, |
102 | | - 20, |
103 | | - ) |
104 | | - test_shape2 = tuple(2 * dim for dim in test_shape) |
105 | | - n = test_shape[-1] |
106 | | - |
107 | | - for dt1, dt2 in zip(["i4", "i4", "f4"], ["i4", "f4", "i4"]): |
108 | | - ar1 = dpt.ones(test_shape, dtype=dt1, order="C") |
109 | | - ar2 = dpt.ones(test_shape, dtype=dt2, order="C") |
110 | | - r1 = dpt.subtract(ar1, ar2, order="C") |
111 | | - assert r1.flags.c_contiguous |
112 | | - r2 = dpt.subtract(ar1, ar2, order="F") |
113 | | - assert r2.flags.f_contiguous |
114 | | - r3 = dpt.subtract(ar1, ar2, order="A") |
115 | | - assert r3.flags.c_contiguous |
116 | | - r4 = dpt.subtract(ar1, ar2, order="K") |
117 | | - assert r4.flags.c_contiguous |
118 | | - |
119 | | - ar1 = dpt.ones(test_shape, dtype=dt1, order="F") |
120 | | - ar2 = dpt.ones(test_shape, dtype=dt2, order="F") |
121 | | - r1 = dpt.subtract(ar1, ar2, order="C") |
122 | | - assert r1.flags.c_contiguous |
123 | | - r2 = dpt.subtract(ar1, ar2, order="F") |
124 | | - assert r2.flags.f_contiguous |
125 | | - r3 = dpt.subtract(ar1, ar2, order="A") |
126 | | - assert r3.flags.f_contiguous |
127 | | - r4 = dpt.subtract(ar1, ar2, order="K") |
128 | | - assert r4.flags.f_contiguous |
129 | | - |
130 | | - ar1 = dpt.ones(test_shape2, dtype=dt1, order="C")[:20, ::-2] |
131 | | - ar2 = dpt.ones(test_shape2, dtype=dt2, order="C")[:20, ::-2] |
132 | | - r4 = dpt.subtract(ar1, ar2, order="K") |
133 | | - assert r4.strides == (n, -1) |
134 | | - r5 = dpt.subtract(ar1, ar2, order="C") |
135 | | - assert r5.strides == (n, 1) |
136 | | - |
137 | | - ar1 = dpt.ones(test_shape2, dtype=dt1, order="C")[:20, ::-2].mT |
138 | | - ar2 = dpt.ones(test_shape2, dtype=dt2, order="C")[:20, ::-2].mT |
139 | | - r4 = dpt.subtract(ar1, ar2, order="K") |
140 | | - assert r4.strides == (-1, n) |
141 | | - r5 = dpt.subtract(ar1, ar2, order="C") |
142 | | - assert r5.strides == (n, 1) |
143 | | - |
144 | | - |
145 | | -def test_subtract_broadcasting(): |
146 | | - get_queue_or_skip() |
147 | | - |
148 | | - m = dpt.ones((100, 5), dtype="i4") |
149 | | - v = dpt.arange(5, dtype="i4") |
150 | | - |
151 | | - r = dpt.subtract(m, v) |
152 | | - assert ( |
153 | | - dpt.asnumpy(r) == np.arange(1, -4, step=-1, dtype="i4")[np.newaxis, :] |
154 | | - ).all() |
155 | | - |
156 | | - r2 = dpt.subtract(v, m) |
157 | | - assert ( |
158 | | - dpt.asnumpy(r2) == np.arange(-1, 4, dtype="i4")[np.newaxis, :] |
159 | | - ).all() |
160 | | - |
161 | | - |
162 | | -@pytest.mark.parametrize("arr_dt", _all_dtypes[1:]) |
163 | | -def test_subtract_python_scalar(arr_dt): |
164 | | - q = get_queue_or_skip() |
165 | | - skip_if_dtype_not_supported(arr_dt, q) |
166 | | - |
167 | | - X = dpt.zeros((10, 10), dtype=arr_dt, sycl_queue=q) |
168 | | - py_zeros = ( |
169 | | - bool(0), |
170 | | - int(0), |
171 | | - float(0), |
172 | | - complex(0), |
173 | | - np.float32(0), |
174 | | - ctypes.c_int(0), |
175 | | - ) |
176 | | - for sc in py_zeros: |
177 | | - R = dpt.subtract(X, sc) |
178 | | - assert isinstance(R, dpt.usm_ndarray) |
179 | | - R = dpt.subtract(sc, X) |
180 | | - assert isinstance(R, dpt.usm_ndarray) |
181 | | - |
182 | | - |
183 | | -@pytest.mark.parametrize("dtype", _all_dtypes[1:]) |
184 | | -def test_subtract_inplace_python_scalar(dtype): |
185 | | - q = get_queue_or_skip() |
186 | | - skip_if_dtype_not_supported(dtype, q) |
187 | | - X = dpt.zeros((10, 10), dtype=dtype, sycl_queue=q) |
188 | | - dt_kind = X.dtype.kind |
189 | | - if dt_kind in "ui": |
190 | | - X -= int(0) |
191 | | - elif dt_kind == "f": |
192 | | - X -= float(0) |
193 | | - elif dt_kind == "c": |
194 | | - X -= complex(0) |
195 | | - |
196 | | - |
197 | 77 | @pytest.mark.parametrize("op1_dtype", _all_dtypes[1:]) |
198 | 78 | @pytest.mark.parametrize("op2_dtype", _all_dtypes[1:]) |
199 | 79 | def test_subtract_inplace_dtype_matrix(op1_dtype, op2_dtype): |
@@ -221,15 +101,3 @@ def test_subtract_inplace_dtype_matrix(op1_dtype, op2_dtype): |
221 | 101 | else: |
222 | 102 | with pytest.raises(ValueError): |
223 | 103 | ar1 -= ar2 |
224 | | - |
225 | | - |
226 | | -def test_subtract_inplace_broadcasting(): |
227 | | - get_queue_or_skip() |
228 | | - |
229 | | - m = dpt.ones((100, 5), dtype="i4") |
230 | | - v = dpt.arange(5, dtype="i4") |
231 | | - |
232 | | - m -= v |
233 | | - assert ( |
234 | | - dpt.asnumpy(m) == np.arange(1, -4, step=-1, dtype="i4")[np.newaxis, :] |
235 | | - ).all() |
0 commit comments