Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python binding support for int64 literals #8254

Merged
merged 1 commit into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions python_bindings/src/halide/halide_/PyExpr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int>())
.def(py::init<int64_t>())
// Python float is implemented by double
// But Halide prohibits implicitly construct by double.
.def(py::init([](double v) {
Expand Down Expand Up @@ -65,6 +66,7 @@ void define_expr(py::module &m) {
// int should be tried before float conversion
py::implicitly_convertible<bool, Expr>();
py::implicitly_convertible<int, Expr>();
py::implicitly_convertible<int64_t, Expr>();
py::implicitly_convertible<float, Expr>();
py::implicitly_convertible<double, Expr>();

Expand Down
6 changes: 6 additions & 0 deletions python_bindings/test/correctness/basics.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -463,3 +468,4 @@ def test_requirements():
test_scalar_funcs()
test_bool_conversion()
test_requirements()
test_implicit_convert_int64()
Loading