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

DOC: Clarify argument documentation for solve #14402

Merged
merged 5 commits into from Oct 7, 2022
Merged

Conversation

Kaniee
Copy link
Contributor

@Kaniee Kaniee commented Jul 13, 2021

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/...

Copy link
Contributor

@mdhaber mdhaber left a 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.

@@ -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
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
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.

Copy link
Contributor Author

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.

Comment on lines 77 to 78
If True, the calulation is based only on the data in the lower triangle of
matrix `a` instead of data in the upper triangle.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
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.

for complex matrices (only for True).
Default is ``'gen'``.
transposed : bool, optional
If True, calculate ``a^T x = b``.
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider:

Suggested change
If True, calculate ``a^T x = b``.
If True, solve ``a.T @ x = b``.

Copy link
Contributor

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.

Copy link
Member

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.

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.
Copy link
Contributor

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.

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
Copy link
Contributor

@mdhaber mdhaber Jul 15, 2021

Choose a reason for hiding this comment

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

This line is a few characters too long; it's causing the failure in "scipy.scipy (Main Lint)"
image
The other failures seem to be in master right now.

Copy link
Contributor Author

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

@ilayn
Copy link
Member

ilayn commented Jul 15, 2021

The whole transposed keyword, obviously in hindsight, was a mistake. We should have thought it a bit better. Other than that this looks good to me.

@rgommers rgommers added Documentation Issues related to the SciPy documentation. Also check https://github.com/scipy/scipy.org scipy.linalg labels Jul 20, 2021
@mdhaber
Copy link
Contributor

mdhaber commented Sep 28, 2022

@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.

@j-bowhay j-bowhay added the needs-work Items that are pending response from the author label Oct 3, 2022
scipy/linalg/_basic.py Outdated Show resolved Hide resolved
scipy/linalg/_basic.py Outdated Show resolved Hide resolved
Copy link
Contributor

@mdhaber mdhaber left a 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?

Copy link
Member

@j-bowhay j-bowhay left a 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.

scipy/linalg/_basic.py Outdated Show resolved Hide resolved
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'}
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
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

Copy link
Contributor

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.

Copy link
Member

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>
@mdhaber
Copy link
Contributor

mdhaber commented Oct 7, 2022

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 optimize.linprog IIRC, but it is somewhat inconsistent throughout linalg. There is one example of an italicized equation like you suggest, and there is this one that is teletype, and the rest are in plain text! Picking a standard (other than plain text) would be preferable, I think!

@mdhaber mdhaber merged commit acac275 into scipy:main Oct 7, 2022
ev-br pushed a commit to ev-br/scipy that referenced this pull request Oct 14, 2022
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>
@mdhaber mdhaber added this to the 1.10.0 milestone Nov 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Documentation Issues related to the SciPy documentation. Also check https://github.com/scipy/scipy.org needs-work Items that are pending response from the author scipy.linalg
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants