-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Implement missing cmath
functions
#3039
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
Comments
Hey i am very new but i would love to contribute could you tell me which files do i have to edit ? |
Hey @CTZxVULKAN the module is located at After making your changes don't forget to test things out by running the Python tests with Leave a comment on what you'll try and work on, though, so others can know. |
nvm this is too complex for me rn. |
You could drop me a message on gitter and I'll walk through most of it with you if you want. Everything is complex until you start doing mistakes with it and learning from them. |
Hi I would like to pick up acos and acosh,
On going through x.acos(), the implementation is:
Could you please guide me more, on what specifically needs to be implemented and where? This should give me a good heads up and help me get acquainted with the codebase. |
Hm, you're currently looking at the implementation of
|
Hello there, I would like to work on sqrt, sin and cos. I have worked with C,Python and JS but have no experience using rust tbh tho. |
Sure, go for it. If you get stuck at any point you can always drop by on gitter. |
@DimitrisJim |
@DimitrisJim Hey I implemented sin and cos, |
Just make sure you've updated your fork of Rustpython (to include the changes you made in the previous PR) and then base the new branch off that. I don't see anything about sending a file (maybe the talk was about the test file being edited, which I'll guide you through once you've opened the PR). |
@DimitrisJim I updated my fork and created a pull request, Thankyou for being so patient and helpful! |
I have no idea about sending file. it doesn't sound like something PR-related stuff. fetch & rebase comment is this one: #3047 (comment) |
The good news is that we can rely on methods from the |
I think some (like |
Hello, I would like to work on tan and tanh :) |
go for it @tony-jinwoo-ahn |
@DimitrisJim I'd like to work on |
@emhagman great, work on them! |
Hey I would also love to contribute, what should work on? |
|
I would like to start working on |
If it is ok, I can try to contribute |
@egemengol sure, go for it. @Rishit-Khandelwal you can pick up |
I actually just finished both and was going to submit the PR if that's okay |
that's fine, I'll try and find another issue for Melih then. |
Okay thanks 👍🏼 |
sure @DimitrisJim I would like that 👍 |
There is a problem for When I take the let c = Complex64::new(0.2, 0.0);
let sin = c.asin();
let cos = c.acos();
println!("sin {:?} cos {:?}", sin.im, cos.im); // sin -0.0, cos -0.0 Just like we expect. However, when we calculate the When I use CPython cmath, imaginary part is 0. When I use RustPython cmath with I wonder if this is related to floating point arithmetic errors? Does anyone have an idea on how to handle this? |
99% a rounding error that propagates. Don't worry too much about it, there's other edge cases we currently do not handle in a correct way yet. Add a |
Whatever it is, it's pretty weird since using the log forms for calculating it (as def ln(c):
r, th = cmath.polar(c)
return complex(math.log(r), th)
def asin(c):
one, i = complex(1), complex(0, 1)
return -i * ln(cmath.sqrt(one - c*c) + i*c) Both CPython and RustPython return: |
@egemengol @Rishit-Khandelwal there's an unfortunate conflict between your PRs (#3198 and #3200). Since we can't push both one is going to have to be closed. I'll be able to find another good issue for the other person to contribute to make up for it. As it stands, @Rishit-Khandelwal has the fact that they requested to contribute first which we should respect (though I do believe @egemengol has touched a bit more on some edgecases!). Sorry for this but it happens when a big issue like this might be opened. |
Ah, I missed #3198, my bad :) Although I think communicating a bit more would prevent this duplication of work, no worries. Thanks @DimitrisJim for sincere consideration. I'm definitely willing to contribute more, see you guys in different threads :) |
Yup, I agree there. I'll try and find a new issue for you though. If you have any particular interests, of course, you can grep for |
@egemengol see if #3217 might interest you. |
Thank you all! |
Uh oh!
There was an error while loading. Please reload this page.
The following functions are currently missing:
acos
acosh
asin
asinh
atan
atanh
cos
cosh
exp
log
log10
sin
sinh
sqrt
tan
tanh
Inspiration for how their implementation might look can be found in
Modules/cmathmodule.c
(andModules/clinic/cmathmodule.c.h
for argument parsing) of the CPython codebase.Lib/src/stdlib/math.rs
equivalent functions should also be roughly similar.Note to contributors: due to the way tests are organized, you'll need to add your function to the list of tested functions in the
test_functions
class attribute ofCMathTests
(on line 58 inLib/tests/test_cmath.py
). I.e, if you want to addlog
, add italphabetically at the list used in the comprehension:
If anyone wants to pick a function or two up, leave a comment naming the functions so other people can see who's working on what. Hopefully that will minimize conflicts.
The text was updated successfully, but these errors were encountered: