[Mlir-commits] [mlir] [mlir][python] value casting (PR #69644)

Oleksandr Alex Zinenko llvmlistbot at llvm.org
Tue Oct 31 02:48:51 PDT 2023


================
@@ -88,6 +88,20 @@ void PyGlobals::registerTypeCaster(MlirTypeID mlirTypeID,
   }
 }
 
+void PyGlobals::registerValueCaster(MlirTypeID mlirTypeID,
+                                    pybind11::function valueCaster,
+                                    bool replace) {
+  pybind11::object &found = valueCasterMap[mlirTypeID];
+  if (found && !found.is_none() && !replace)
+    throw std::runtime_error("Value caster is already registered: " +
+                             py::repr(found).cast<std::string>());
+  found = std::move(valueCaster);
+  const auto foundIt = valueCasterMapCache.find(mlirTypeID);
----------------
ftynse wrote:

Nit: if we ask for a non-const iterator here, it should be possible to reuse it below for assignment. Is there a reason not to?

https://github.com/llvm/llvm-project/pull/69644


More information about the Mlir-commits mailing list