Skip to content
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

Allow arithmetic of jlwrap in Python #676

Closed
marius311 opened this issue Apr 8, 2019 · 1 comment
Closed

Allow arithmetic of jlwrap in Python #676

marius311 opened this issue Apr 8, 2019 · 1 comment

Comments

@marius311
Copy link
Contributor

If you're in PyJulia and grabbed some Julia object which has custom +/-/*/etc.. defined, it'd be nice if you can do that directly in Python. E.g.

In [1]: %load_ext julia.magic 
Initializing Julia interpreter. This may take some time...

In [2]: %julia using LinearAlgebra 

In [3]: x = %julia I 

In [4]: 2*x 
   ...:                                                                                                                             
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-4-cac53a56d728> in <module>
----> 1 2*x

TypeError: unsupported operand type(s) for *: 'int' and 'PyCall.jlwrap'

where that error is the current behavior but it would be nice if it instead returned:

<PyCall.jlwrap UniformScaling{Int64}
2*I>

I think I can probably implement this if you think you'd accept this functionality.

From a quick glance it looks like the way to proceed is to give the jlwrap object __add__, __mul__, etc... via some mechanism or another somewhere near https://github.com/JuliaPy/PyCall.jl/blob/master/src/pytype.jl#L379, either by adding to that if-clause, or something else. Am I on the right track?

@tkf
Copy link
Member

tkf commented Apr 8, 2019

If you want to try this right now, you can use one of my prior attempts:

I think the direction of PyBase.jl is the way to go. That is to say, implement it as a Julia package; or rather, the current plan is to put it in PyCall (yay!): #617. It's in the PyCall 2.0 roadmap #629 so I think we will eventually have this out-of-the-box. If you want to make it happen sooner, see my comment here: #617 (comment)

Let me close this and let's continue the discussion in #617

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