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

PyJL: Julia without type annotations #536

Open
j-fu opened this issue Jan 27, 2023 · 4 comments
Open

PyJL: Julia without type annotations #536

j-fu opened this issue Jan 27, 2023 · 4 comments
Labels

Comments

@j-fu
Copy link

j-fu commented Jan 27, 2023

Hi, would it be possible to have an option which removes all type annotations for when emitting Julia code ?

@MiguelMarcelino
Copy link
Contributor

Hello!
It would be an interesting feature to add, for sure. Currently, I am a bit delayed in delivering some features I have implemented for Py2Many (you can see my fork here). I am trying to find some time leftover to continue this work, as I believe the community could benefit from this. But I will add this suggestion to the list of things that would be interesting to implement!

@j-fu
Copy link
Author

j-fu commented Jan 28, 2023

Cool! The point here is that this would help to leverage the abilities of Julia concerning generic programming and multiple dispatch.
A function f(x,y)=... can be easily called with e.g. dual numbers, allowing to differentiate through it, while f(x,y)::Float64 would prevent this possibility. Coming from classical C++/typed languages I also had to unlearn the habit to annotate types everywhere just "to be sure"...

@jayvdb
Copy link
Member

jayvdb commented Feb 13, 2023

Just to clarify, if there are explicit type annotations in the Python, should they also be removed from the emitted Julia? My guess is you only want the types inferred by py2many to be removed from the output.

It would be very helpful if you could provide a sample input where not emitting the types allows for "better" Julia output.

Another approach to this may be to allow annotating the input Python with type Any, or a union of allowable types, either explicitly or within py2many, which would tell PyJL that it shouldn't emit a type annotation for a single type.

@j-fu
Copy link
Author

j-fu commented Feb 13, 2023

Thanks for coming back!
I tend to second your clarification, however I am so far not familiar with type annotations in python (switched to Julia before this became a thing...). I guess they are done to help Python to create faster code. If this is true (will try to read up on this), then the situation in Julia is a bit different.

For function calls, basically, Julia autodetects parameter types and emits specialized code without the need of annotation - very much like with a generic C++ header lib. The almost only case where you type-annotate parameters for Julia function is in oder to distinguish different implementations for different types.

For struct entries, the situation is different - here, type annotations are critical for performance.

I will try to come up with a more elaborated example to continue the discussion. May take some time as I am juggling too many balls currently...

@jayvdb jayvdb added the Julia label Jan 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants