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
[Demo PR] Apply black formatting to sympy/solvers #22434
Conversation
As recommended for existing projects, string normalization is switched off: https://black.readthedocs.io/en/stable/the_black_code_style/current_style.html#strings Other config options, such as line width, are explained here: https://black.readthedocs.io/en/stable/usage_and_configuration/the_basics.html#configuration-format A config for isort was added in to ensure that isort is applied in agreement with black once/if isort is applied
Pre-commit allows for incremental changes and pins the version of the tool that is applied. Install as folllows: python3 -m pip install pre-commit pre-commit install
See #17287 (comment) Applied formatting as follows: # python3 -m pip install black==21.10b0 black sympy/solvers
See #17287 (comment) Applied formatting as follows: # python3 -m pip install black==21.10b0 black sympy/solvers
✅ Hi, I am the SymPy bot (v162). I'm here to help you write a release notes entry. Please read the guide on how to write release notes.
Click here to see the pull request description that was parsed.
|
🟠Hi, I am the SymPy bot (v162). I've noticed that some of your commits add or delete files. Since this is sometimes done unintentionally, I wanted to alert you about it. This is an experimental feature of SymPy Bot. If you have any feedback on it, please comment at sympy/sympy-bot#75. The following commits add new files: If these files were added/deleted on purpose, you can ignore this message. |
Ahh missed this, see also #22432 |
assert diop_solve(0 * x - y - 5) == (-5,) | ||
assert diop_solve(3 * y + 2 * x - 5) == (3 * t_0 - 5, -2 * t_0 + 5) | ||
assert diop_solve(2 * x - 3 * y - 5) == (3 * t_0 - 5, 2 * t_0 - 5) | ||
assert diop_solve(-2 * x - 3 * y - 5) == (3 * t_0 + 5, -2 * t_0 - 5) | ||
assert diop_solve(7 * x + 5 * y) == (5 * t_0, -7 * t_0) | ||
assert diop_solve(2 * x + 4 * y) == (2 * t_0, -t_0) | ||
assert diop_solve(4 * x + 6 * y - 4) == (3 * t_0 - 2, -2 * t_0 + 2) | ||
assert diop_solve(4 * x + 6 * y - 3) == (None, None) | ||
assert diop_solve(0 * x + 3 * y - 4 * z + 5) == (4 * t_0 + 5, 3 * t_0 + 5) | ||
assert diop_solve(4 * x + 3 * y - 4 * z + 5) == ( | ||
t_0, | ||
8 * t_0 + 4 * t_1 + 5, | ||
7 * t_0 + 3 * t_1 + 5, | ||
) | ||
assert diop_solve(4 * x + 3 * y - 4 * z + 5, None) == (0, 5, 5) | ||
assert diop_solve(4 * x + 2 * y + 8 * z - 5) == (None, None, None) | ||
assert diop_solve(5 * x + 7 * y - 2 * z - 6) == ( | ||
t_0, | ||
-3 * t_0 + 2 * t_1 + 6, | ||
-8 * t_0 + 7 * t_1 + 18, | ||
) | ||
assert diop_solve(3 * x - 6 * y + 12 * z - 9) == (2 * t_0 + 3, t_0 + 2 * t_1, t_1) | ||
assert diop_solve(6 * w + 9 * x + 20 * y - z) == ( | ||
t_0, | ||
t_1, | ||
t_1 + t_2, | ||
6 * t_0 + 29 * t_1 + 20 * t_2, | ||
) |
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.
@oscarbenjamin this is probably what you meant in #17287 (comment). See also #17287 (comment)
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.
Is it possible to configure black so that it does not force spaces around all operators?
Not being able to visually distinguish operator precedence is not good. If this is forced by black then that's a deal-breaker as far as I'm concerned.
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.
It seems not:
https://black.readthedocs.io/en/stable/the_black_code_style/current_style.html
Black is intentionally hardly configurable. (I personally prefer that, but can see that is problematic for math-oriented code.) A possible way out is to put fmt:on/off
around the code block.
Yapf is more configurable and seems to be able to handle this operator style:
https://github.com/google/yapf#knobs
Afaik yapfs is less popular, but was mentioned in the original issue #17287 (comment)
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.
Then I don't think we can use black. I commented here: psf/black#538 (comment)
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.
A post-process that closes up space on desired operators wouldn't be too hard, would it?
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.
Then I don't think we can use black. I commented here: psf/black#538 (comment)
Thanks for investigating this and reporting it upstream!
A post-process that closes up space on desired operators wouldn't be too hard, would it?
I wouldn't go for a post-process. The motivation to use black is to have standardised formatting, so if there is some post-formatting, you remove the reason of using black.
def test_transformation_to_normal(): | ||
assert is_normal_transformation_ok(x**2 + 3*y**2 + z**2 - 13*x*y - 16*y*z + 12*x*z) | ||
assert is_normal_transformation_ok(x**2 + 3*y**2 - 100*z**2) | ||
assert is_normal_transformation_ok(x**2 + 23*y*z) | ||
assert is_normal_transformation_ok(3*y**2 - 100*z**2 - 12*x*y) | ||
assert is_normal_transformation_ok(x**2 + 23*x*y - 34*y*z + 12*x*z) | ||
assert is_normal_transformation_ok(z**2 + 34*x*y - 23*y*z + x*z) | ||
assert is_normal_transformation_ok(x**2 + y**2 + z**2 - x*y - y*z - x*z) | ||
assert is_normal_transformation_ok(x**2 + 2*y*z + 3*z**2) | ||
assert is_normal_transformation_ok(x*y + 2*x*z + 3*y*z) | ||
assert is_normal_transformation_ok(2*x*z + 3*y*z) | ||
assert is_normal_transformation_ok( | ||
x ** 2 + 3 * y ** 2 + z ** 2 - 13 * x * y - 16 * y * z + 12 * x * z | ||
) | ||
assert is_normal_transformation_ok(x ** 2 + 3 * y ** 2 - 100 * z ** 2) | ||
assert is_normal_transformation_ok(x ** 2 + 23 * y * z) | ||
assert is_normal_transformation_ok(3 * y ** 2 - 100 * z ** 2 - 12 * x * y) | ||
assert is_normal_transformation_ok(x ** 2 + 23 * x * y - 34 * y * z + 12 * x * z) | ||
assert is_normal_transformation_ok(z ** 2 + 34 * x * y - 23 * y * z + x * z) | ||
assert is_normal_transformation_ok(x ** 2 + y ** 2 + z ** 2 - x * y - y * z - x * z) | ||
assert is_normal_transformation_ok(x ** 2 + 2 * y * z + 3 * z ** 2) | ||
assert is_normal_transformation_ok(x * y + 2 * x * z + 3 * y * z) | ||
assert is_normal_transformation_ok(2 * x * z + 3 * y * z) |
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.
This is horrible
Benchmark results from GitHub Actions Lower numbers are good, higher numbers are bad. A ratio less than 1 Significantly changed benchmark results (PR vs master) Significantly changed benchmark results (master vs previous release) before after ratio
[907895ac] [3a49fc4d]
- 4.97±0.03s 310±4ms 0.06 polygon.PolygonArbitraryPoint.time_bench01
Full benchmark results can be found as artifacts in GitHub Actions |
I wonder why this PR didn't raise an error like the other one did in #22432. Maybe you used a more recent version of black. My imports didn't move the
Your version kept 2 |
Probably because we formatted different modules? There are also some lint ignores that need to be moved to the right place. |
So I start to think black is indeed not a viable option for sympy, given the spacing around arithmetic operators. As an alternative, yapf with some additional configuration for those operators is illustrated in #22437. |
This PR serves as a demo and test only and is not to be merged. See #17287 (comment).
Formatting was applied over a few different commits, so changes can best be discussed through its commit history.
Release Notes
NO ENTRY