int() and float() for mx.array (#1360)

This commit is contained in:
Alex Barron
2024-08-25 20:41:44 -07:00
committed by GitHub
parent 8081df79be
commit d1183821a7
3 changed files with 21 additions and 0 deletions

View File

@@ -160,6 +160,10 @@ nb::ndarray<> mlx_to_dlpack(const array& a) {
}
nb::object to_scalar(array& a) {
if (a.size() != 1) {
throw std::invalid_argument(
"[convert] Only length-1 arrays can be converted to Python scalars.");
}
{
nb::gil_scoped_release nogil;
a.eval();