Skip to content

Implementing hyperbolic trigonometric, exponential and rounding functions in NumPy #959

Closed
@czgdp1807

Description

@czgdp1807

Below I have provided some links to get started and then explained what you both are supposed to do,

Links to get started

  1. https://github.com/lcompilers/lpython/blob/main/src/runtime/lpython_intrinsic_numpy.py - Contains definitions of sin, cos, tan, log, log2, log10, sqrt for f32 and f64 types. Some points to be noted - i) @vectorize decorator automatically vectorizes the function. Now by "vectorizes the function" I mean even if the functions are defined for single number input and single number outputs, you can call them upon are array inputs as well.
  2. https://github.com/lcompilers/lpython/blob/main/integration_tests/elemental_01.py, https://github.com/lcompilers/lpython/blob/main/integration_tests/elemental_04.py - These are the test files for NumPy functions. You can see how sin, cos, log are called with array inputs even though they were defined for single input and single output. @vectorize does the job for you. You can also notice how the functions are tested. You can make the tests as natural/complicated as you want to. For example for testing sin, cos simultaneously, you can just verify sin(array)**2 + cos(array)**2 == 1. Similarly for trigonometric function, you can take a few trigonometric identities and try verifying them in the tests (with 1d, 2d, 5d, 6d, etc arrays as inputs). In fact you can also try finding the derivative of functions using arrays. For example for a function f, you can do (f(array + harray) - f(array))/harray and match with the formula you know for derivative of f you know. Bottomline is you can use your creativity to the full extent to write interesting test cases. In case you get errors don't work around the test case, instead let me know and I will fix the error for you.

Overall this task is easy-medium. Easy because extending src/runtime/lpython_intrinsic_numpy.py is fairly easy (just follow the already existing pattern) and medium because writing test cases requires some creativity and effort.

What you have to do?

If you complete the above tasks then please let me know. Feel free to reach out if you have any questions. :-)

Metadata

Metadata

Assignees

No one assigned

    Labels

    numpyBugs and feature requests regarding NumPy support

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions