Implement all NumPy intrinsics via ASR
With high performance implementation both at compile time and at runtime.
I was trying to breakdown this project and would appreciate if someone can guide me in the right direction.
I see some functions like empty(), zeroes() are supported. I also saw issues through the numpy label to implement numpy.clip() and numpy.size().
Is this project about implementing various routines found at https://numpy.org/doc/stable/reference/routines.html . If yes, we can discuss about which Array creation/manipulation routines we want to prioritize. Also some popular NumPy mathematical modules or decorators for array operations (like @vectorize) can be added.
Is this project about implementing various routines found at https://numpy.org/doc/stable/reference/routines.html
Yes.
We can prioritize those that we already support in ASR.
We can prioritize those that we already support in ASR.
I would like to have some clarity on this.
Following the numpy label I come across the 2 files supporting numpy functions.
-
https://github.com/lcompilers/lpython/blob/main/src/runtime/lpython_intrinsic_numpy.py - Containing all mathematical and trigonometric routines (all of them follow the intrinsic architecture in
src/libasr/pass/intrinsic_function_registry.h). -
https://github.com/lcompilers/lpython/blob/main/src/lpython/semantics/python_ast_to_asr.cpp - Containing
numpyarray creation routines likeempty(),size()etc. (not ported to the intrinsic function files yet).
Which functions are to be focussed upon and implemented via ASR?
@rebcabin I observed a lot of your work in the issue tracker uses Numpy. Would be great if you chime in here and mention any numpy intrinsics you would like to be implemented. Thanks !
I would like to summarize the target of the project for my own understanding, kindly guide me if I am deviating from the goal here.
Let's say we want to use a trigo functions from numpy like sin(x). For a snippet like -
from numpy import array, empty, float64,
def f(xi32: f64[:]) -> f64:
xi32[0] = 0.1
xi32[1] = 0.2
xi32[2] = 0.3
print(sin(xi32))
def d():
ai32: f64[3] = empty(3, dtype=float64)
f(ai32)
d()
Right now, this is handled here and due to the@vectorizedecorator we are able to handle array inputs.
https://github.com/lcompilers/lpython/blob/60981579d24e655399f1045263941100584b003a/src/runtime/lpython_intrinsic_numpy.py#L9-L12
So we already are able to generate the ASR, from lpython_instrinsic_numpy.py file but we want this to be handled by the instantiate_Sin/ create_Sin functions from intrinsic_function_registry.h.
This should be updated to instead create the Sin intrinsic as IntrinsicElementalFunction in ASR, and it should be done in https://github.com/lcompilers/lpython/blob/main/src/lpython/semantics/python_ast_to_asr.cpp.