Closed
Description
Here is a small demo to reproduce the problem:
using PythonCall
struct MyArray
x::Array
end
function Base.:*(a::MyArray, b::AbstractArray)
println("calling *(MyArray, AbstractArray)")
return a.x * b
end
function Base.:*(a::AbstractArray, b::MyArray)
println("calling *(AbstractArray, MyArray)")
return a * b.x
end
a = [1 2; 3 4]
b = MyArray([4 3; 2 1])
a * b
# [8 5; 20 13]
pya = pyjlraw(a) # try not to use pya.__mul__()
pyb = pyconvert(Py, b)
# it's calling pyb.__rmul__(pya)
pya * pyb
# calling *(MyArray, AbstractArray)
# Python ArrayValue: <jl [13 20; 5 8]>
looks like pyb.__rmul__(pya)
is calling *(MyArray, AbstractArray)
, so gets wrong result
Metadata
Metadata
Assignees
Labels
No labels