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

Grab-bag of minor Python fixes #6725

Merged
merged 1 commit into from
Apr 21, 2022
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
20 changes: 10 additions & 10 deletions python_bindings/src/PyConciseCasts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,34 +6,34 @@ namespace PythonBindings {
void define_concise_casts(py::module &m) {
// explicit cast should be tried before
// the pybind11::implicitly_convertible<T, Expr> conversion
m.def("f64", [](double v) {
m.def("f64", [](double v) -> Expr {
return Expr(v);
});
m.def("f32", [](float v) {
m.def("f32", [](float v) -> Expr {
return Expr(v);
});
m.def("i64", [](int64_t v) {
m.def("i64", [](int64_t v) -> Expr {
return Expr(v);
});
m.def("i32", [](int32_t v) {
m.def("i32", [](int32_t v) -> Expr {
return Expr(v);
});
m.def("i16", [](int16_t v) {
m.def("i16", [](int16_t v) -> Expr {
return Expr(v);
});
m.def("i8", [](int8_t v) {
m.def("i8", [](int8_t v) -> Expr {
return Expr(v);
});
m.def("u64", [](uint64_t v) {
m.def("u64", [](uint64_t v) -> Expr {
return Expr(v);
});
m.def("u32", [](uint32_t v) {
m.def("u32", [](uint32_t v) -> Expr {
return Expr(v);
});
m.def("u16", [](uint16_t v) {
m.def("u16", [](uint16_t v) -> Expr {
return Expr(v);
});
m.def("u8", [](uint8_t v) {
m.def("u8", [](uint8_t v) -> Expr {
return Expr(v);
});
// pybind11::implicitly_convertible<T, Expr> conversions
Expand Down
1 change: 1 addition & 0 deletions python_bindings/src/PyExpr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ void define_expr(py::module &m) {
.def("__nonzero__", to_bool)

.def("type", &Expr::type)
.def("defined", &Expr::defined)
.def("__repr__", [](const Expr &e) -> std::string {
std::ostringstream o;
o << "<halide.Expr of type " << halide_type_to_string(e.type()) << ": " << e << ">";
Expand Down
2 changes: 1 addition & 1 deletion python_bindings/src/PyImageParam.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ void define_image_param(py::module &m) {
auto image_param_class =
py::class_<ImageParam>(m, "ImageParam", output_image_param_class)
.def(py::init<>())
.def(py::init<Type, int>())
.def(py::init<Type, int>(), py::arg("type"), py::arg("dimensions"))
.def(py::init<Type, int, std::string>(), py::arg("type"), py::arg("dimensions"), py::arg("name"))
.def("set", &ImageParam::set)
.def("get", &ImageParam::get)
Expand Down
4 changes: 3 additions & 1 deletion python_bindings/src/PyLoopLevel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ void define_loop_level(py::module &m) {
.def_static("root", &LoopLevel::root)
.def("__repr__", [](const LoopLevel &b) -> std::string {
std::ostringstream o;
o << "<halide.LoopLevel " << (b.defined() ? b.to_string() : "UNDEF") << ">";
// b.to_string() fails for locked LoopLevels. Just output something generic.
// o << "<halide.LoopLevel " << (b.defined() ? b.to_string() : "UNDEF") << ">";
o << "<halide.LoopLevel>";
return o.str();
});
}
Expand Down
10 changes: 10 additions & 0 deletions python_bindings/stub/PyStubImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,16 @@ py::object generate_impl(const GeneratorFactory &factory, const GeneratorContext
} else {
if (py::isinstance<LoopLevel>(value)) {
generator_params[name] = value.cast<LoopLevel>();
} else if (py::isinstance<py::list>(value)) {
// Convert [hl.UInt(8), hl.Int(16)] -> uint8,int16
std::string v;
for (auto t : value) {
if (!v.empty()) {
v += ",";
}
v += py::str(t).cast<std::string>();
}
generator_params[name] = v;
} else {
generator_params[name] = py::str(value).cast<std::string>();
}
Expand Down