[Mlir-commits] [mlir] [mlir][python] value casting (PR #69644)
Maksim Levental
llvmlistbot at llvm.org
Tue Oct 31 16:36:08 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);
----------------
makslevental wrote:
Added comment
https://github.com/llvm/llvm-project/pull/69644
More information about the Mlir-commits
mailing list