lpython icon indicating copy to clipboard operation
lpython copied to clipboard

Implement all NumPy intrinsics via ASR

Open certik opened this issue 1 year ago • 6 comments

With high performance implementation both at compile time and at runtime.

certik avatar Jan 31 '24 18:01 certik

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.

faze-geek avatar Feb 04 '24 10:02 faze-geek

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.

certik avatar Feb 05 '24 05:02 certik

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.

  1. 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).

  2. https://github.com/lcompilers/lpython/blob/main/src/lpython/semantics/python_ast_to_asr.cpp - Containing numpy array creation routines like empty(), size() etc. (not ported to the intrinsic function files yet).

Which functions are to be focussed upon and implemented via ASR?

faze-geek avatar Feb 11 '24 10:02 faze-geek

@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 !

faze-geek avatar Feb 12 '24 08:02 faze-geek

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.

faze-geek avatar Feb 16 '24 14:02 faze-geek

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.

certik avatar Feb 16 '24 19:02 certik