-
-
Notifications
You must be signed in to change notification settings - Fork 46.9k
Reduce the complexity of linear_algebra/src/polynom_for_points.py #7948
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
Reduce the complexity of linear_algebra/src/polynom_for_points.py #7948
Conversation
7e67a43
to
38ac4c0
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Co-authored-by: Christian Clauss <[email protected]>
Co-authored-by: Christian Clauss <[email protected]>
062682a
to
0117eb1
Compare
…c/polynom_for_points.py
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome work! Other pull requests that further reduce our max-complexity
would be warmly received.
Unsubscribe
…Sent from my iPhone
On Nov 2, 2022, at 2:25 PM, Christian Clauss ***@***.***> wrote:
@cclauss requested changes on this pull request.
Nice! https://www.scivision.dev/python-f-string-speed
In linear_algebra/src/polynom_for_points.py:
>
- if len(coordinates) == 1 and coordinates[0][0] == 0:
- check = 2
- solved = "x=0"
- except Exception:
- check = 3
+ set_x = {x for x, _ in coordinates}
+ if len(set_x) == 1:
+ return "x=" + str(coordinates[0][0])
Shorter, faster, and easier to read.
⬇️ Suggested change
- return "x=" + str(coordinates[0][0])
+ return f"x={coordinates[0][0]}"
In linear_algebra/src/polynom_for_points.py:
>
- return solved
+ while count < x:
+ remove_e: list[str] = solution[count].split("E")
+ if len(remove_e) > 1:
+ solution[count] = remove_e[0] + "*10^" + remove_e[1]
+ solved += "x^" + str(x - (count + 1)) + "*" + str(solution[count])
⬇️ Suggested change
- solved += "x^" + str(x - (count + 1)) + "*" + str(solution[count])
+ solved += f"x^{x - (count + 1)}*{solution[count]}"
In linear_algebra/src/polynom_for_points.py:
>
- return solved
+ while count < x:
+ remove_e: list[str] = solution[count].split("E")
+ if len(remove_e) > 1:
+ solution[count] = remove_e[0] + "*10^" + remove_e[1]
⬇️ Suggested change
- solution[count] = remove_e[0] + "*10^" + remove_e[1]
+ solution[count] = f"{remove_e[0]}*10^{remove_e[1]}"
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.
|
@will472 Please click the |
Describe your change:
Reduce the complexity of linear_algebra/src/polynom_for_points.py from 23 to 17
Fixes: #7942
Checklist:
Fixes: #{$ISSUE_NO}
.