Skip to content
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
1 change: 1 addition & 0 deletions mlir/include/mlir/Bindings/Python/Nanobind.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include <nanobind/stl/string_view.h>
#include <nanobind/stl/tuple.h>
#include <nanobind/stl/vector.h>
#include <nanobind/typing.h>
#if defined(__clang__) || defined(__GNUC__)
#pragma GCC diagnostic pop
#endif
Expand Down
14 changes: 14 additions & 0 deletions mlir/lib/Bindings/Python/MainModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ using namespace mlir::python;

NB_MODULE(_mlir, m) {
m.doc() = "MLIR Python Native Extension";
m.attr("T") = nb::type_var("T");
m.attr("U") = nb::type_var("U");

nb::class_<PyGlobals>(m, "_Globals")
.def_prop_rw("dialect_search_modules",
Expand Down Expand Up @@ -102,6 +104,10 @@ NB_MODULE(_mlir, m) {
return opClass;
});
},
// clang-format off
nb::sig("def register_operation(dialect_class: type, *, replace: bool = False) "
"-> typing.Callable[[type[T]], type[T]]"),
// clang-format on
"dialect_class"_a, nb::kw_only(), "replace"_a = false,
"Produce a class decorator for registering an Operation class as part of "
"a dialect");
Expand All @@ -114,6 +120,10 @@ NB_MODULE(_mlir, m) {
return typeCaster;
});
},
// clang-format off
nb::sig("def register_type_caster(typeid: _mlir.ir.TypeID, *, replace: bool = False) "
"-> typing.Callable[[typing.Callable[[T], U]], typing.Callable[[T], U]]"),
// clang-format on
"typeid"_a, nb::kw_only(), "replace"_a = false,
"Register a type caster for casting MLIR types to custom user types.");
m.def(
Expand All @@ -126,6 +136,10 @@ NB_MODULE(_mlir, m) {
return valueCaster;
});
},
// clang-format off
nb::sig("def register_value_caster(typeid: _mlir.ir.TypeID, *, replace: bool = False) "
"-> typing.Callable[[typing.Callable[[T], U]], typing.Callable[[T], U]]"),
// clang-format on
"typeid"_a, nb::kw_only(), "replace"_a = false,
"Register a value caster for casting MLIR values to custom user values.");

Expand Down
Loading