From 8c9415c79aab1f24e630b5be5690de80b5b6e6fc Mon Sep 17 00:00:00 2001 From: Jason Ansel Date: Sat, 1 Jun 2024 17:20:42 -0700 Subject: [PATCH] Python binding support for int64 literals This makes >32bit python integers get mapped to `hl.i64` implicitly. Fixes #8224 --- python_bindings/src/halide/halide_/PyExpr.cpp | 2 ++ python_bindings/test/correctness/basics.py | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/python_bindings/src/halide/halide_/PyExpr.cpp b/python_bindings/src/halide/halide_/PyExpr.cpp index 880d8ee7ac7d..1403e2db9a72 100644 --- a/python_bindings/src/halide/halide_/PyExpr.cpp +++ b/python_bindings/src/halide/halide_/PyExpr.cpp @@ -29,6 +29,7 @@ void define_expr(py::module &m) { // PyBind11 searches in declared order, // int should be tried before float conversion .def(py::init()) + .def(py::init()) // Python float is implemented by double // But Halide prohibits implicitly construct by double. .def(py::init([](double v) { @@ -65,6 +66,7 @@ void define_expr(py::module &m) { // int should be tried before float conversion py::implicitly_convertible(); py::implicitly_convertible(); + py::implicitly_convertible(); py::implicitly_convertible(); py::implicitly_convertible(); diff --git a/python_bindings/test/correctness/basics.py b/python_bindings/test/correctness/basics.py index 814fe70a30a1..204966418e41 100644 --- a/python_bindings/test/correctness/basics.py +++ b/python_bindings/test/correctness/basics.py @@ -445,6 +445,11 @@ def test_requirements(): assert False, "Did not see expected exception!" +def test_implicit_convert_int64(): + assert (hl.i32(0) + 0x7fffffff).type() == hl.Int(32) + assert (hl.i32(0) + (0x7fffffff+1)).type() == hl.Int(64) + + if __name__ == "__main__": test_compiletime_error() test_runtime_error() @@ -463,3 +468,4 @@ def test_requirements(): test_scalar_funcs() test_bool_conversion() test_requirements() + test_implicit_convert_int64()