Skip to content

cbrt and exp2 functions implemented #564

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

Closed
wants to merge 7 commits into from

Conversation

Madhav2310
Copy link
Contributor

No description provided.

@certik
Copy link
Contributor

certik commented Jun 9, 2022

@Madhav2310 you should try to setup LPython locally and simply test this locally before pushing. You can then iterate very quickly, instead of waiting for the CI to finish.


pi: f64 = 3.141592653589793238462643383279502884197
e: f64 = 2.718281828459045235360287471352662497757
tau: f64 = 6.283185307179586
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we need this level of precision for testing? I think 4-5 decimal places is fine.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ultimately these constants should be imported from the builtin math module.

"""
Returns cube root of a number x
"""
return x**(1/3)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do these expressions actually work with Lpython?

Copy link
Collaborator

Choose a reason for hiding this comment

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

yeah, they should.

@Madhav2310
Copy link
Contributor Author

@Smit-create Could you please see why it is failing to import the functions in the test files?

@namannimmo10
Copy link
Collaborator

@Smit-create Could you please see why it is failing to import the functions in the test files?

@Madhav2310 -- you should merge this with the latest main.

@Madhav2310
Copy link
Contributor Author

@Smit-create Could you please see why it is failing to import the functions in the test files?

@Madhav2310 -- you should merge this with the latest main.

@namannimmo10 My local repository is up to date, could you elaborate on what to do exactly?

Comment on lines +7 to +9
pi: f64 = 3.141592653589793238462643383279502884197
e: f64 = 2.718281828459045235360287471352662497757
tau: f64 = 6.283185307179586
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you please try removing these global variables and try running tests with local variables?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure I'll do that

@Smit-create
Copy link
Collaborator

Are these functions actually available in CPython's math? If not then it will definitely raise an error.

@Smit-create
Copy link
Collaborator

I don't see these functions here: https://docs.python.org/3/library/math.html

@Madhav2310
Copy link
Contributor Author

I don't see these functions here: https://docs.python.org/3/library/math.html

Right, I just saw it. It is very weird, they have tests for these functions, but not the functions themselves https://github.com/python/cpython/blob/2d787971c65b005d0cce219399b9a8e2b70d4ef4/Lib/test/test_math.py

@namannimmo10
Copy link
Collaborator

Assuming that you've added remote origin as github.com/Madhav2310/lpython.git and upstream as github.com/lcompilers/lpython.git, this is what you can do:

$ git checkout main
$ git pull upstream main
$ git checkout madhav
$ git rebase main

Now, if you run the integration tests, they'll pass.

@Smit-create
Copy link
Collaborator

Now, if you run the integration tests, they'll pass.

Well, that won't pass for sure.

>>> from math import exp2
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: cannot import name 'exp2' from 'math' (/Users/thebigbool/opt/anaconda3/envs/lp/lib/python3.10/lib-dynload/math.cpython-310-darwin.so)

@Smit-create
Copy link
Collaborator

It is very weird, they have tests for these functions

See the test carefully, they have tested for TypeError.

def testCbrt(self):
        self.assertRaises(TypeError, math.cbrt)

@namannimmo10
Copy link
Collaborator

Now, if you run the integration tests, they'll pass.

Well, that won't pass for sure.

>>> from math import exp2
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: cannot import name 'exp2' from 'math' (/Users/thebigbool/opt/anaconda3/envs/lp/lib/python3.10/lib-dynload/math.cpython-310-darwin.so)

My bad. Yes, they won't pass because of this.

@Madhav2310
Copy link
Contributor Author

It is very weird, they have tests for these functions

See the test carefully, they have tested for TypeError.

def testCbrt(self):
        self.assertRaises(TypeError, math.cbrt)

I see, thank you! I'll take care of it in the future

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.

5 participants