Skip to content

__rmul__ did not act as expected #214

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
songjhaha opened this issue Aug 29, 2022 · 1 comment
Closed

__rmul__ did not act as expected #214

songjhaha opened this issue Aug 29, 2022 · 1 comment

Comments

@songjhaha
Copy link

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

@cjdoris
Copy link
Collaborator

cjdoris commented Sep 3, 2022

Thanks - all the reversed operands were not actually reversing their operands! This is fixed on the main branch now.

@cjdoris cjdoris closed this as completed Sep 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants