|
| 1 | +import dpctl |
| 2 | +import dpctl.tensor as dpt |
| 3 | +import numpy |
| 4 | +import pytest |
| 5 | + |
| 6 | +import dpnp |
| 7 | + |
| 8 | + |
| 9 | +class TestIsSupportedArrayOrScalar: |
| 10 | + @pytest.mark.parametrize( |
| 11 | + "array", |
| 12 | + [ |
| 13 | + dpnp.array([1, 2, 3]), |
| 14 | + dpnp.array(1), |
| 15 | + dpt.asarray([1, 2, 3]), |
| 16 | + ], |
| 17 | + ) |
| 18 | + def test_valid_arrays(self, array): |
| 19 | + assert dpnp.is_supported_array_or_scalar(array) is True |
| 20 | + |
| 21 | + @pytest.mark.parametrize( |
| 22 | + "value", |
| 23 | + [ |
| 24 | + 42, |
| 25 | + True, |
| 26 | + "1", |
| 27 | + ], |
| 28 | + ) |
| 29 | + def test_valid_scalars(self, value): |
| 30 | + assert dpnp.is_supported_array_or_scalar(value) is True |
| 31 | + |
| 32 | + @pytest.mark.parametrize( |
| 33 | + "array", |
| 34 | + [ |
| 35 | + [1, 2, 3], |
| 36 | + (1, 2, 3), |
| 37 | + None, |
| 38 | + numpy.array([1, 2, 3]), |
| 39 | + ], |
| 40 | + ) |
| 41 | + def test_invalid_arrays(self, array): |
| 42 | + assert not dpnp.is_supported_array_or_scalar(array) is True |
| 43 | + |
| 44 | + |
| 45 | +class TestSynchronizeArrayData: |
| 46 | + @pytest.mark.parametrize( |
| 47 | + "array", |
| 48 | + [ |
| 49 | + dpnp.array([1, 2, 3]), |
| 50 | + dpt.asarray([1, 2, 3]), |
| 51 | + ], |
| 52 | + ) |
| 53 | + def test_synchronize_array_data(self, array): |
| 54 | + a_copy = dpnp.copy(array, sycl_queue=array.sycl_queue) |
| 55 | + try: |
| 56 | + dpnp.synchronize_array_data(a_copy) |
| 57 | + except Exception as e: |
| 58 | + pytest.fail(f"synchronize_array_data failed: {e}") |
| 59 | + |
| 60 | + @pytest.mark.parametrize( |
| 61 | + "input", |
| 62 | + [ |
| 63 | + [1, 2, 3], |
| 64 | + numpy.array([1, 2, 3]), |
| 65 | + ], |
| 66 | + ) |
| 67 | + def test_unsupported_type(self, input): |
| 68 | + with pytest.raises(TypeError): |
| 69 | + dpnp.synchronize_array_data(input) |
0 commit comments