How to store PythonObject in DynamicVector?

I'm trying the following:
let module = Python.import_module("my_module")
let dv = DynamicVector[PythonObject]()
let result = my_module.my_func()
dv.push_back(result)
let module = Python.import_module("my_module")
let dv = DynamicVector[PythonObject]()
let result = my_module.my_func()
dv.push_back(result)
And getting:
cannot bind generic !mlirtype to memory-only type 'PythonObject'
cannot bind generic !mlirtype to memory-only type 'PythonObject'
I tried different combinations, but as long the type is non-imperative type, this won't work. What is a workaround for this?
5 Replies
ModularBot
ModularBot•15mo ago
Congrats @Mahmoud Abduljawad, you just advanced to level 2!
Dimitar Yosifov
Dimitar Yosifov•15mo ago
"let" defines a variable that's immutable. "let dv = DynamicVectorPythonObject" Have you tried using "var"?
Mahmoud Abduljawad
Mahmoud AbduljawadOP•15mo ago
Yes. The problem isn't whether dv is immutable or not, it is that PythonObject is not "passable".
Dimitar Yosifov
Dimitar Yosifov•15mo ago
This is as far as I got 🙂
let obj = test_mod.return_int()
var dv = DynamicVector[Pointer[PythonObject]]()
dv.push_back(obj.py_object)
let obj = test_mod.return_int()
var dv = DynamicVector[Pointer[PythonObject]]()
dv.push_back(obj.py_object)
error: invalid call to 'push_back': method argument #0 cannot be converted from 'PyObjectPtr' to 'Pointer[PythonObject]
error: invalid call to 'push_back': method argument #0 cannot be converted from 'PyObjectPtr' to 'Pointer[PythonObject]
No idea where to get PyObjectPtr so it can be specified in DynamicVector parameter. Not sure if it even makes sense. Compiler errors are confusing in different scenarios. There's a lot of undocumented stuff.
Mahmoud Abduljawad
Mahmoud AbduljawadOP•15mo ago
This looks like a progress :mojo: I knew the answer would be in using pointers but didn't know how to put in code.
Want results from more Discord servers?
Add your server