[Mlir-commits] [mlir] [mlir][python] value casting (PR #69644)
Oleksandr Alex Zinenko
llvmlistbot at llvm.org
Tue Oct 31 02:48:51 PDT 2023
================
@@ -1899,13 +1899,26 @@ bool PyTypeID::operator==(const PyTypeID &other) const {
}
//------------------------------------------------------------------------------
-// PyValue and subclases.
+// PyValue and subclasses.
//------------------------------------------------------------------------------
pybind11::object PyValue::getCapsule() {
return py::reinterpret_steal<py::object>(mlirPythonValueToCapsule(get()));
}
+pybind11::object PyValue::maybeDownCast() {
+ MlirType type = mlirValueGetType(get());
+ MlirTypeID mlirTypeID = mlirTypeGetTypeID(type);
+ assert(!mlirTypeIDIsNull(mlirTypeID) &&
+ "mlirTypeID was expected to be non-null.");
+ std::optional<pybind11::function> valueCaster =
+ PyGlobals::get().lookupValueCaster(mlirTypeID, mlirTypeGetDialect(type));
+ py::object thisObj = py::cast(this, py::return_value_policy::move);
----------------
ftynse wrote:
Nit: I'm often confused by various ownership/return value rules. What does `move` imply here?
https://github.com/llvm/llvm-project/pull/69644
More information about the Mlir-commits
mailing list