ENH: testing: Add check_device parameter#835
Conversation
Signed-off-by: Pradyot Ranjan <99216956+pradyotRanjan@users.noreply.github.com>
Signed-off-by: Pradyot Ranjan <99216956+pradyotRanjan@users.noreply.github.com>
| a = xp.asarray([0, 3, 6, 10], device=device) | ||
| b = xp.asarray([1, 2, 3, 10], device=device) | ||
| expected = xp.asarray([True, False, True, False]) | ||
| expected = xp.asarray([True, False, True, False], device=device) |
There was a problem hiding this comment.
Need to specify device here; otherwise, it fails in the assert_equal statement below with:
Actual: array_api_strict.Device('device1')
Desired: array_api_strict.Device('CPU_DEVICE')
The reason is that res.device is set by the pytest fixture (as device1) and expected.device is set by array_api_strict default unless specified.
| res = isclose(a, b) | ||
| assert get_device(res) == device | ||
| assert_equal(res, xp.asarray([False, False, False, False, True])) | ||
| assert_equal(res, xp.asarray([False, False, False, False, True], device=device)) |
There was a problem hiding this comment.
Same reason as above.
|
CC @j-bowhay |
j-bowhay
left a comment
There was a problem hiding this comment.
It would be nice to have some tests :)
Signed-off-by: Pradyot Ranjan <99216956+pradyotRanjan@users.noreply.github.com>
|
Some irrelevant device checks have been removed as assert functions check for the device by default now. I've also added checks for non-default device. |
| def test_device(self, xp: ModuleType, device: Device): | ||
| x = xp.asarray([1, 2, 3, 4], device=device) | ||
| y = apply_where(x % 2 == 0, x, self.f1, self.f2) | ||
| assert get_device(y) == device | ||
| y = apply_where(x % 2 == 0, x, self.f1, fill_value=0) | ||
| assert get_device(y) == device | ||
| y = apply_where(x % 2 == 0, x, self.f1, fill_value=x) | ||
| assert get_device(y) == device |
There was a problem hiding this comment.
hmm, I'm not convinced that these tests are redundant yet. The device picture gives us a non-default device where possible:
array-api-extra/tests/conftest.py
Lines 222 to 237 in 064cbf7
IIUC dropping the tests removes that testing coverage of non-default devices. I don't think we should do that until we have an improved solution.
Towards: #833