mirror of
https://github.com/ml-explore/mlx.git
synced 2025-09-04 15:04:40 +08:00
Compile float64 functions on CPU (#2311)
This commit is contained in:
@@ -205,6 +205,8 @@ nb::object to_scalar(mx::array& a) {
|
||||
return nb::cast(static_cast<float>(a.item<mx::bfloat16_t>()));
|
||||
case mx::complex64:
|
||||
return nb::cast(a.item<std::complex<float>>());
|
||||
case mx::float64:
|
||||
return nb::cast(a.item<double>());
|
||||
default:
|
||||
throw nb::type_error("type cannot be converted to Python scalar.");
|
||||
}
|
||||
|
@@ -2,6 +2,7 @@
|
||||
|
||||
import gc
|
||||
import io
|
||||
import math
|
||||
import unittest
|
||||
from functools import partial
|
||||
|
||||
@@ -979,6 +980,17 @@ class TestCompile(mlx_tests.MLXTestCase):
|
||||
|
||||
self.assertEqual(mem_pre, mem_post)
|
||||
|
||||
def test_double_constant(self):
|
||||
with mx.stream(mx.cpu):
|
||||
x = mx.array(1.0, dtype=mx.float64)
|
||||
|
||||
def fun(x):
|
||||
return (x + math.pi) * 2.0
|
||||
|
||||
y = fun(x).item()
|
||||
y_compiled = mx.compile(fun)(x).item()
|
||||
self.assertEqual(y, y_compiled)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
mlx_tests.MLXTestRunner()
|
||||
|
Reference in New Issue
Block a user