Skip to content

Implement all NumPy intrinsics via ASR #2474

Open

Description

@certik

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

Activity

  1. faze-geek commented on Feb 4, 2024

    @faze-geek
    Contributor

    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.

  2. certik commented on Feb 5, 2024

    @certik
    ContributorAuthor

    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.

  3. faze-geek commented on Feb 11, 2024

    @faze-geek
    Contributor

    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?

  4. faze-geek commented on Feb 12, 2024

    @faze-geek
    Contributor

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

  5. faze-geek commented on Feb 16, 2024

    @faze-geek
    Contributor

    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.

    @overload
    @vectorize
    def sin(x: f64) -> f64:
    return _lfortran_dsin(x)

    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.

  6. certik commented on Feb 16, 2024

    @certik
    ContributorAuthor

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions