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

Added cbrt() and exp2() functions in Math module #1594

Merged
merged 5 commits into from
Mar 22, 2023

Conversation

harshsingh-24
Copy link
Contributor

Math Module enhancement:

  • Added cbrt() or cube root function associated with Math module of LPython and it's associated integration tests
  • Added exp2() or exponential of 2 function associated with Math module of LPython and it's associated integration tests

@harshsingh-24
Copy link
Contributor Author

harshsingh-24 commented Mar 20, 2023

Can @Thirumalai-Shaktivel @Smit-create @certik check that why these integration tests are failing?

The following tests FAILED:
	 79 - test_math (Failed)
	114 - test_math_02 (Failed)

Expected Reason (according to me):

In CMakeLists.txt file these integration_tests are being executed on cpython-

RUN(NAME test_math           LABELS cpython llvm)
RUN(NAME test_math_02        LABELS cpython llvm)

I think, CPython does not support these functions?

@certik
Copy link
Contributor

certik commented Mar 20, 2023

The error is:

  File "/home/runner/work/lpython/lpython/integration_tests/test_math_02.py", line 1, in <module>
    from math import (sin, cos, tan, pi, sqrt, log, log10, log2, erf, erfc, gamma,
ImportError: cannot import name 'cbrt' from 'math' (/usr/share/miniconda/envs/test/lib/python3.10/lib-dynload/math.cpython-310-x86_64-linux-gnu.so)

So I assume CPython 3.10 does not implement cbrt?

If so, we need some way to only run these tests with CPython 3.11.

@harshsingh-24
Copy link
Contributor Author

harshsingh-24 commented Mar 20, 2023

The error is:

  File "/home/runner/work/lpython/lpython/integration_tests/test_math_02.py", line 1, in <module>
    from math import (sin, cos, tan, pi, sqrt, log, log10, log2, erf, erfc, gamma,
ImportError: cannot import name 'cbrt' from 'math' (/usr/share/miniconda/envs/test/lib/python3.10/lib-dynload/math.cpython-310-x86_64-linux-gnu.so)

So I assume CPython 3.10 does not implement cbrt?

If so, we need some way to only run these tests with CPython 3.11.

Yes. It was implemented in Python 3.11. So, how can we support tests with CPython 3.11? I am not sure whether CPython 3.11 supports it or not.

@certik
Copy link
Contributor

certik commented Mar 20, 2023

Well, we might need to add this as an option in cmake to only run this in Python 3.11. For now, you can create a dedicated tests for this, and do not register them with cpython, only llvm. That way it works with LPython, but we skip testing it with CPython. We test it manually with CPython 3.11.

@harshsingh-24
Copy link
Contributor Author

harshsingh-24 commented Mar 20, 2023

Well, we might need to add this as an option in cmake to only run this in Python 3.11. For now, you can create a dedicated tests for this, and do not register them with cpython, only llvm. That way it works with LPython, but we skip testing it with CPython. We test it manually with CPython 3.11.

Well, we might need to add this as an option in cmake to only run this in Python 3.11. For now, you can create a dedicated tests for this, and do not register them with cpython, only llvm. That way it works with LPython, but we skip testing it with CPython. We test it manually with CPython 3.11.

Well, we might need to add this as an option in cmake to only run this in Python 3.11. For now, you can create a dedicated tests for this, and do not register them with cpython, only llvm. That way it works with LPython, but we skip testing it with CPython. We test it manually with CPython 3.11.

@certik As I was discussing with @Thirumalai-Shaktivel and what you suggested earlier, I implemented a new backend that support Python 3.11 and updated the settings of those integration tests with Python 3.11. New Backend name is cpython_3_11. Can you please review that ? @Smit-create

@Smit-create
Copy link
Collaborator

Yeah, I'll need to update some tester files and CI to test this which I'll do after merging this PR. This looks good to me. I'll fix the tests once this is merged. Thanks @harshsingh-24

@@ -330,7 +352,7 @@ RUN(NAME test_builtin_round LABELS cpython llvm c)
RUN(NAME test_builtin_divmod LABELS cpython llvm c)
RUN(NAME test_builtin_sum LABELS cpython llvm c)
RUN(NAME test_math1 LABELS cpython llvm c)
RUN(NAME test_math_02 LABELS cpython llvm)
RUN(NAME test_math_02 LABELS cpython_3_11 llvm)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will disable this for current Python, which I would not do.

Split just the functionality that needs Python 3_11 and perhaps put into one file.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, @harshsingh-24 create a separate file and add the cbrt and exp2 tests there and enable cpython_3_11 for it. Leave cpython for the rest of the tests.

Copy link
Collaborator

@Thirumalai-Shaktivel Thirumalai-Shaktivel Mar 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We will not add this new option cpython_3_11 for now, see: #1594 (comment)

@Thirumalai-Shaktivel
Copy link
Collaborator

Thirumalai-Shaktivel commented Mar 21, 2023

There is something that worries me, can we have two versions of python in the conda environment?

@Thirumalai-Shaktivel
Copy link
Collaborator

Thirumalai-Shaktivel commented Mar 21, 2023

I see, we cannot have it: https://stackoverflow.com/a/67595797/15913193

#1594 (comment)
Well, we might need to add this as an option in cmake to only run this in Python 3.11. For now, you can create a dedicated tests for this, and do not register them with cpython, only llvm. That way it works with LPython, but we skip testing it with CPython. We test it manually with CPython 3.11.

@harshsingh-24 do one thing, we will split the cbrt and exp2 tests into a separate file and test only the LLVM. Maybe add a TODO to test with CPython

@harshsingh-24
Copy link
Contributor Author

I have done all the changes as asked @certik @Thirumalai-Shaktivel. Can you please review it?

Copy link
Collaborator

@Smit-create Smit-create left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, will need to squash and merge.

@harshsingh-24
Copy link
Contributor Author

I will do a git squash.

@Smit-create
Copy link
Collaborator

I will do a git squash.

No worries, we can do that while merging.

Copy link
Collaborator

@Thirumalai-Shaktivel Thirumalai-Shaktivel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM as well! Thank you

Copy link
Collaborator

@czgdp1807 czgdp1807 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other than my comment rest looks okay.

integration_tests/CMakeLists.txt Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants