Closed
Description
Minimum example (using ipython3
).
I have a list of tuples Tuple{Int,Int,Float64}
, and I can copy the values from the julia array to a np.array
of the same type on the python side, but I can't perform this copy of elements on the Julia side, because setindex!
is not defined.
Would it be possible to support any isbits
type?
In [6]: from juliacall import Main as jl
In [7]: jl.seval("""
...: function copy_value(python_list, julia_list)
...: python_list[1] = julia_list[1]
...: end
...: """)
Out[7]: copy_value (generic function with 1 method)
In [8]: import numpy as np
In [9]: python_list = np.array([(0,0.0)], dtype='i,f')
In [10]: julia_list = jl.seval("[(0,0.0)]")
In [11]: python_list[0] = julia_list[0] # works!
In [12]: jl.copy_value(python_list, julia_list)
---------------------------------------------------------------------------
JuliaError Traceback (most recent call last)
<ipython-input-12-e89b29633981> in <module>
----> 1 jl.copy_value(python_list, julia_list)
~/.local/lib/python3.10/site-packages/juliacall/__init__.py in __call__(self, *args, **kwargs)
199 return ValueBase.__dir__(self) + self._jl_callmethod($(pyjl_methodnum(pyjlany_dir)))
200 def __call__(self, *args, **kwargs):
--> 201 return self._jl_callmethod($(pyjl_methodnum(pyjlany_call)), args, kwargs)
202 def __len__(self):
203 return self._jl_callmethod($(pyjl_methodnum(pyjlany_op(length))))
JuliaError: MethodError: no method matching setindex!(::PythonCall.PyIterable{PythonCall.Py}, ::Tuple{Int64, Float64}, ::Int64)
Stacktrace:
[1] copy_value(python_list::PythonCall.PyIterable{PythonCall.Py}, julia_list::Vector{Tuple{Int64, Float64}})
@ Main ./none:3
[2] pyjlany_call(self::typeof(copy_value), args_::PythonCall.Py, kwargs_::PythonCall.Py)
@ PythonCall ~/.julia/packages/PythonCall/2Y5CR/src/jlwrap/any.jl:31
[3] _pyjl_callmethod(f::Any, self_::Ptr{PythonCall.C.PyObject}, args_::Ptr{PythonCall.C.PyObject}, nargs::Int64)
@ PythonCall ~/.julia/packages/PythonCall/2Y5CR/src/jlwrap/base.jl:69
[4] _pyjl_callmethod(o::Ptr{PythonCall.C.PyObject}, args::Ptr{PythonCall.C.PyObject})
@ PythonCall.C ~/.julia/packages/PythonCall/2Y5CR/src/cpython/jlwrap.jl:47
Metadata
Metadata
Assignees
Labels
No labels