(
self,
mx_res: mx.array,
expected: mx.array,
atol=1e-2,
rtol=1e-2,
)
| 98 | return self.assertEqualArray(mx_res, mx.array(np_res), atol=atol, rtol=rtol) |
| 99 | |
| 100 | def assertEqualArray( |
| 101 | self, |
| 102 | mx_res: mx.array, |
| 103 | expected: mx.array, |
| 104 | atol=1e-2, |
| 105 | rtol=1e-2, |
| 106 | ): |
| 107 | self.assertEqual( |
| 108 | tuple(mx_res.shape), |
| 109 | tuple(expected.shape), |
| 110 | msg=f"shape mismatch expected={expected.shape} got={mx_res.shape}", |
| 111 | ) |
| 112 | self.assertEqual( |
| 113 | mx_res.dtype, |
| 114 | expected.dtype, |
| 115 | msg=f"dtype mismatch expected={expected.dtype} got={mx_res.dtype}", |
| 116 | ) |
| 117 | if not isinstance(mx_res, mx.array) and not isinstance(expected, mx.array): |
| 118 | np.testing.assert_allclose(mx_res, expected, rtol=rtol, atol=atol) |
| 119 | return |
| 120 | elif not isinstance(mx_res, mx.array): |
| 121 | mx_res = mx.array(mx_res) |
| 122 | elif not isinstance(expected, mx.array): |
| 123 | expected = mx.array(expected) |
| 124 | self.assertTrue(mx.allclose(mx_res, expected, rtol=rtol, atol=atol)) |
no test coverage detected