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

get rid of one sage_eval in complex numbers #38391

Merged
merged 7 commits into from
Aug 3, 2024

Conversation

fchapoton
Copy link
Contributor

this is parsing in a simple way the string input for complex number constructor, avoiding usage of sage_eval there

📝 Checklist

  • The title is concise and informative.
  • The description explains in detail what this PR is about.
  • I have linked a relevant issue or discussion.
  • I have created tests covering the changes.
  • I have updated the documentation and checked the documentation preview.

Copy link

github-actions bot commented Jul 19, 2024

Documentation preview for this PR (built with commit 191dd38; changes) is ready! 🎉
This preview will update shortly after each push to this PR.

@fchapoton fchapoton changed the title get rid of one sage_eval get rid of one sage_eval in complex numbers Jul 20, 2024
@user202729
Copy link
Contributor

user202729 commented Jul 20, 2024

Depends on how much external code uses the string constructor of ℂ, this may break badly.

Here are some examples

sage: CC("e")
2.71828182845905
sage: CC("e**j")
0.540302305868140 + 0.841470984807897*I
sage: CC("3+I")
3.00000000000000 + 1.00000000000000*I
sage: CC("I**2")
-1.00000000000000
sage: CC("12 34")
1234.00000000000

Also, is it faster than sage_eval (or just do a eval?)

@fchapoton
Copy link
Contributor Author

This parser is not supposed to perform computations ; it should only accept inputs that are already just one complex number in full explicit form.

@fchapoton
Copy link
Contributor Author

after

sage: %timeit CC('13.67788e26+1.20958686e-14*I')
2.83 µs ± 7.93 ns per loop (mean ± std. dev. of 7 runs, 100,000 loops each)

versus before

sage: %timeit CC('13.67788e26+1.20958686e-14*I')
27.3 µs ± 151 ns per loop (mean ± std. dev. of 7 runs, 10,000 loops each)

Copy link
Member

@mkoeppe mkoeppe left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks for working on this!

vbraun pushed a commit to vbraun/sage that referenced this pull request Jul 25, 2024
    
this is parsing in a simple way the string input for complex number
constructor, avoiding usage of `sage_eval` there


### 📝 Checklist

- [x] The title is concise and informative.
- [x] The description explains in detail what this PR is about.
- [ ] I have linked a relevant issue or discussion.
- [x] I have created tests covering the changes.
- [ ] I have updated the documentation and checked the documentation
preview.
    
URL: sagemath#38391
Reported by: Frédéric Chapoton
Reviewer(s): Matthias Köppe
vbraun pushed a commit to vbraun/sage that referenced this pull request Jul 31, 2024
    
this is parsing in a simple way the string input for complex number
constructor, avoiding usage of `sage_eval` there


### 📝 Checklist

- [x] The title is concise and informative.
- [x] The description explains in detail what this PR is about.
- [ ] I have linked a relevant issue or discussion.
- [x] I have created tests covering the changes.
- [ ] I have updated the documentation and checked the documentation
preview.
    
URL: sagemath#38391
Reported by: Frédéric Chapoton
Reviewer(s): Matthias Köppe
vbraun pushed a commit to vbraun/sage that referenced this pull request Aug 2, 2024
    
this is parsing in a simple way the string input for complex number
constructor, avoiding usage of `sage_eval` there


### 📝 Checklist

- [x] The title is concise and informative.
- [x] The description explains in detail what this PR is about.
- [ ] I have linked a relevant issue or discussion.
- [x] I have created tests covering the changes.
- [ ] I have updated the documentation and checked the documentation
preview.
    
URL: sagemath#38391
Reported by: Frédéric Chapoton
Reviewer(s): Matthias Köppe
@vbraun vbraun merged commit f8ac0af into sagemath:develop Aug 3, 2024
22 checks passed
@mkoeppe mkoeppe added this to the sage-10.5 milestone Aug 3, 2024
@fchapoton fchapoton deleted the no_sage_eval_cplx branch August 4, 2024 06:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants