(
self,
args: List[Union[Tuple[int], Any]],
mx_fn: Callable[..., mx.array],
np_fn: Callable[..., np.array],
atol=1e-2,
rtol=1e-2,
dtype=mx.float32,
**kwargs,
)
| 77 | |
| 78 | # Note if a tuple is passed into args, it will be considered a shape request and convert to a mx.random.normal with the shape matching the tuple |
| 79 | def assertCmpNumpy( |
| 80 | self, |
| 81 | args: List[Union[Tuple[int], Any]], |
| 82 | mx_fn: Callable[..., mx.array], |
| 83 | np_fn: Callable[..., np.array], |
| 84 | atol=1e-2, |
| 85 | rtol=1e-2, |
| 86 | dtype=mx.float32, |
| 87 | **kwargs, |
| 88 | ): |
| 89 | assert dtype != mx.bfloat16, "numpy does not support bfloat16" |
| 90 | args = [ |
| 91 | mx.random.normal(s, dtype=dtype) if isinstance(s, Tuple) else s |
| 92 | for s in args |
| 93 | ] |
| 94 | mx_res = mx_fn(*args, **kwargs) |
| 95 | np_res = np_fn( |
| 96 | *[np.array(a) if isinstance(a, mx.array) else a for a in args], **kwargs |
| 97 | ) |
| 98 | return self.assertEqualArray(mx_res, mx.array(np_res), atol=atol, rtol=rtol) |
| 99 | |
| 100 | def assertEqualArray( |
| 101 | self, |
no test coverage detected