@@ -1623,6 +1623,29 @@ def test_compile_abs_unsigned(self):
16231623 x = mx .array ([1 , 2 , 3 ], dtype )
16241624 self .assertTrue (mx .array_equal (mx .compile (fun )(x ), fun (x )))
16251625
1626+ def test_compile_different_log_bases (self ):
1627+ # The logs are intermediates, since outputs are not simplified.
1628+ def entropies (p ):
1629+ nats = - mx .sum (p * mx .log (p ))
1630+ bits = - mx .sum (p * mx .log2 (p ))
1631+ return mx .stack ([nats , bits ])
1632+
1633+ p = np .array ([0.1 , 0.2 , 0.3 , 0.4 ], dtype = np .float32 )
1634+ expected = np .array (
1635+ [- (p * np .log (p )).sum (), - (p * np .log2 (p )).sum ()], dtype = np .float32
1636+ )
1637+ out = mx .compile (entropies )(mx .array (p ))
1638+ self .assertTrue (np .allclose (out , expected , atol = 1e-5 ))
1639+
1640+ def test_compile_equal_nan (self ):
1641+ def fun (x ):
1642+ return mx .stack (
1643+ [mx .array_equal (x , x ), mx .array_equal (x , x , equal_nan = True )]
1644+ )
1645+
1646+ x = mx .array ([1.0 , float ("nan" ), 3.0 ])
1647+ self .assertTrue (mx .array_equal (mx .compile (fun )(x ), mx .array ([False , True ])))
1648+
16261649
16271650if __name__ == "__main__" :
16281651 mlx_tests .MLXTestRunner ()
0 commit comments