MCPcopy Create free account
hub / github.com/ml-explore/mlx / assertCmpNumpy

Method assertCmpNumpy

python/tests/mlx_tests.py:79–98  ·  view source on GitHub ↗
(
        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,
    )

Source from the content-addressed store, hash-verified

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,

Callers 10

test_triMethod · 0.80
test_trilMethod · 0.80
test_triuMethod · 0.80
test_whereMethod · 0.80
test_eyeMethod · 0.80
test_repeatMethod · 0.80
test_tensordotMethod · 0.80
test_innerMethod · 0.80
test_outerMethod · 0.80
test_tileMethod · 0.80

Calls 2

assertEqualArrayMethod · 0.95
arrayMethod · 0.60

Tested by

no test coverage detected