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
DOC: Clarify argument documentation for solve
#14402
Conversation
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 a helpful first PR. I agree that this is an improvement.
What exactly was the styling error on the transposed
keyword?
Commit messages are good. After e.g. "DOC
" and "STY
", I've been told to add the subpackage (DOC: linalg:
..., STY: linalg:
), but not many people seem to do that consistently.
The messages could be a little more specific - after looking at the PR, I can't tell what the styling issue was for the transposed
keyword, and the second commit adds default values for parameters of solve
. (But they are already better than most.)
Also, take a look at what the numpydoc style guide has to say about default values of parameters. What you have is fine, but instead of:
transposed : bool, optional
...
Default is False.
you are also allowed to write:
transposed : bool, default: False
Up to you. Just wanted you to know that it was an option.
scipy/linalg/basic.py
Outdated
@@ -41,8 +41,8 @@ def solve(a, b, sym_pos=False, lower=False, overwrite_a=False, | |||
overwrite_b=False, debug=None, check_finite=True, assume_a='gen', | |||
transposed=False): | |||
""" | |||
Solves the linear equation set ``a * x = b`` for the unknown ``x`` | |||
for square ``a`` matrix. | |||
Solves the linear equation set ``ax = b`` for the unknown ``x`` for |
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.
Solves the linear equation set ``ax = b`` for the unknown ``x`` for | |
Solves the linear equation set ``a@x = b`` for the unknown ``x`` for |
I agree that *
was not the right operator, but if this is going to be written as code (between double backticks), consider using the closest operator. I understand that this isn't perfect (we're not using =
as an assignment operator here) but it's closer.
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.
How about changing it to single backticks and write a x = b
or ax = b
(as in numpy.linalg.solve)?
Personally, I'd prefer to use a more mathematical syntax in the documentation over Python syntax.
But I'm also fine with a @ x = b
, if this is preferred way of expressing mathematical equations in the scipy docs.
scipy/linalg/basic.py
Outdated
If True, the calulation is based only on the data in the lower triangle of | ||
matrix `a` instead of data in the upper triangle. |
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.
If True, the calulation is based only on the data in the lower triangle of | |
matrix `a` instead of data in the upper triangle. | |
If True, the calculation uses only the data in the lower triangle of | |
matrix `a`; entries above the diagonal are ignored. |
scipy/linalg/basic.py
Outdated
for complex matrices (only for True). | ||
Default is ``'gen'``. | ||
transposed : bool, optional | ||
If True, calculate ``a^T x = b``. |
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.
Consider:
If True, calculate ``a^T x = b``. | |
If True, solve ``a.T @ x = b``. |
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.
I would leave something in there about raising an error for complex matrices when it's True.
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 something I'm planning to solve with the new version of solve. Then it would be possible to do it with reals and doubles hopefully with a better API.
scipy/linalg/basic.py
Outdated
If True, the calulation is based only on the data in the lower triangle of | ||
matrix `a` instead of data in the upper triangle. | ||
Ignored if ``assume_a == 'gen'``. | ||
Default is False. |
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 is implicit, but consider writing out what this means: the calculation uses only data in the upper triangle; entries below the diagonal are ignored.
scipy/linalg/basic.py
Outdated
lower : bool, optional | ||
If True, only the data contained in the lower triangle of `a`. Default | ||
is to use upper triangle. (ignored for ``'gen'``) | ||
If True, the calulation is based only on the data in the lower triangle of |
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.
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.
True, I didn't see that. I'll fix it
The whole |
@Kaniee would you like to finish this up? If you need help resolving merge conflicts, please let me know. Update: I went ahead and merged main. |
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.
I think this is an improvement. It makes the defaults more obvious, corrects some backticks, and clarifies the description of lower
.
@j-bowhay looks like you came by here. What do you think?
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.
@mdhaber two minor comments from me, neither are blocking.
Whether to check that the input matrices contain only finite numbers. | ||
Disabling may give a performance gain, but may result in problems | ||
(crashes, non-termination) if the inputs do contain infinities or NaNs. | ||
assume_a : str, optional | ||
assume_a : str, {'gen', 'sym', 'her', 'pos'} |
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.
assume_a : str, {'gen', 'sym', 'her', 'pos'} | |
assume_a : str, {'gen', 'sym', 'her', 'pos'}, default: 'gen' |
Given all the other arguments state the default it would be nice to do the same here for consistency
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.
From the style guide
When a parameter can only assume one of a fixed set of values, those values can be listed in braces, with the default appearing first.
The example does not also call out the default explicitly, so this follows the example.
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.
Thanks didn't realise this was the case; you learn something new everyday!
[skip ci] Co-authored-by: Jake Bowhay <60778417+j-bowhay@users.noreply.github.com>
Thanks @j-bowhay. Comments addressed. @Kaniee I'll go ahead and merge this, but if you'd like to propose that equations look more like math than code throughout linalg, I think that sounds helpful. Here I suggested maintaining the existing style (but clarifying) because that was recommended to me a long time ago in the context of |
DOC: linalg.solve: clarify documentation Co-authored-by: Matt Haberland <mhaberla@calpoly.edu> Co-authored-by: Jake Bowhay <60778417+j-bowhay@users.noreply.github.com>
What does this implement/fix?
There was a minor styling error for the transpose keyword.
While fixing this, I took the opportunity to make the documentation on the other keywords a bit clearer and added some lines to document the default values.
Additional information
Since this is my first PR to scipy I highly appreciate your feedback on the Docstring/Commit-Messages/PR/...