|
40 | 40 | ) |
41 | 41 | class TestDot(unittest.TestCase): |
42 | 42 |
|
| 43 | + # Avoid overflow |
| 44 | + skip_dtypes = { |
| 45 | + (numpy.int8, numpy.int8), |
| 46 | + (numpy.int8, numpy.uint8), |
| 47 | + (numpy.uint8, numpy.uint8), |
| 48 | + } |
| 49 | + |
43 | 50 | @testing.for_all_dtypes_combination(["dtype_a", "dtype_b"]) |
44 | 51 | @testing.numpy_cupy_allclose(type_check=has_support_aspect64()) |
45 | 52 | def test_dot(self, xp, dtype_a, dtype_b): |
| 53 | + if (dtype_a, dtype_b) in self.skip_dtypes or ( |
| 54 | + dtype_b, |
| 55 | + dtype_a, |
| 56 | + ) in self.skip_dtypes: |
| 57 | + pytest.skip("avoid overflow") |
46 | 58 | shape_a, shape_b = self.shape |
47 | 59 | if self.trans_a: |
48 | 60 | a = testing.shaped_arange(shape_a[::-1], xp, dtype_a).T |
@@ -241,13 +253,17 @@ def test_dot_vec3(self, xp, dtype): |
241 | 253 | @testing.for_all_dtypes() |
242 | 254 | @testing.numpy_cupy_allclose() |
243 | 255 | def test_transposed_dot(self, xp, dtype): |
| 256 | + if dtype in [numpy.int8, numpy.uint8]: |
| 257 | + pytest.skip("avoid overflow") |
244 | 258 | a = testing.shaped_arange((2, 3, 4), xp, dtype).transpose(1, 0, 2) |
245 | 259 | b = testing.shaped_arange((2, 3, 4), xp, dtype).transpose(0, 2, 1) |
246 | 260 | return xp.dot(a, b) |
247 | 261 |
|
248 | 262 | @testing.for_all_dtypes() |
249 | 263 | @testing.numpy_cupy_allclose() |
250 | 264 | def test_transposed_dot_with_out(self, xp, dtype): |
| 265 | + if dtype in [numpy.int8, numpy.uint8]: |
| 266 | + pytest.skip("avoid overflow") |
251 | 267 | a = testing.shaped_arange((2, 3, 4), xp, dtype).transpose(1, 0, 2) |
252 | 268 | b = testing.shaped_arange((4, 2, 3), xp, dtype).transpose(2, 0, 1) |
253 | 269 | c = xp.ndarray((3, 2, 3, 2), dtype=dtype) |
@@ -323,13 +339,17 @@ def test_reversed_inner(self, xp, dtype): |
323 | 339 | @testing.for_all_dtypes() |
324 | 340 | @testing.numpy_cupy_allclose() |
325 | 341 | def test_multidim_inner(self, xp, dtype): |
| 342 | + if dtype in [numpy.int8, numpy.uint8]: |
| 343 | + pytest.skip("avoid overflow") |
326 | 344 | a = testing.shaped_arange((2, 3, 4), xp, dtype) |
327 | 345 | b = testing.shaped_arange((3, 2, 4), xp, dtype) |
328 | 346 | return xp.inner(a, b) |
329 | 347 |
|
330 | 348 | @testing.for_all_dtypes() |
331 | 349 | @testing.numpy_cupy_allclose() |
332 | 350 | def test_transposed_higher_order_inner(self, xp, dtype): |
| 351 | + if dtype in [numpy.int8, numpy.uint8]: |
| 352 | + pytest.skip("avoid overflow") |
333 | 353 | a = testing.shaped_arange((2, 4, 3), xp, dtype).transpose(2, 0, 1) |
334 | 354 | b = testing.shaped_arange((4, 2, 3), xp, dtype).transpose(1, 2, 0) |
335 | 355 | return xp.inner(a, b) |
@@ -358,13 +378,17 @@ def test_multidim_outer(self, xp, dtype): |
358 | 378 | @testing.for_all_dtypes() |
359 | 379 | @testing.numpy_cupy_allclose() |
360 | 380 | def test_tensordot(self, xp, dtype): |
| 381 | + if dtype in [numpy.int8, numpy.uint8]: |
| 382 | + pytest.skip("avoid overflow") |
361 | 383 | a = testing.shaped_arange((2, 3, 4), xp, dtype) |
362 | 384 | b = testing.shaped_arange((3, 4, 5), xp, dtype) |
363 | 385 | return xp.tensordot(a, b) |
364 | 386 |
|
365 | 387 | @testing.for_all_dtypes() |
366 | 388 | @testing.numpy_cupy_allclose() |
367 | 389 | def test_transposed_tensordot(self, xp, dtype): |
| 390 | + if dtype in [numpy.int8, numpy.uint8]: |
| 391 | + pytest.skip("avoid overflow") |
368 | 392 | a = testing.shaped_arange((2, 3, 4), xp, dtype).transpose(1, 0, 2) |
369 | 393 | b = testing.shaped_arange((4, 3, 2), xp, dtype).transpose(2, 0, 1) |
370 | 394 | return xp.tensordot(a, b) |
@@ -519,12 +543,16 @@ def test_matrix_power_1(self, xp, dtype): |
519 | 543 | @testing.for_all_dtypes() |
520 | 544 | @testing.numpy_cupy_allclose() |
521 | 545 | def test_matrix_power_2(self, xp, dtype): |
| 546 | + if dtype in [numpy.int8, numpy.uint8]: |
| 547 | + pytest.skip("avoid overflow") |
522 | 548 | a = testing.shaped_arange((3, 3), xp, dtype) |
523 | 549 | return xp.linalg.matrix_power(a, 2) |
524 | 550 |
|
525 | 551 | @testing.for_all_dtypes() |
526 | 552 | @testing.numpy_cupy_allclose() |
527 | 553 | def test_matrix_power_3(self, xp, dtype): |
| 554 | + if dtype in [numpy.int8, numpy.uint8]: |
| 555 | + pytest.skip("avoid overflow") |
528 | 556 | a = testing.shaped_arange((3, 3), xp, dtype) |
529 | 557 | return xp.linalg.matrix_power(a, 3) |
530 | 558 |
|
|
0 commit comments