Repository navigation
ENH: Warn to change lstsq default for rcond #9582
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1810,7 +1810,7 @@ def det(a): | |
|
|
||
| # Linear Least Squares | ||
|
|
||
| def lstsq(a, b, rcond=-1): | ||
| def lstsq(a, b, rcond="warn"): | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This would be better as
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. At least, that's consistent with how I implemented this kind of thing for the axis argument to MaskedArray.argmin
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thought about that at some point, but then decided that the NoValue thingy actually has a very specific purpose for functions dispatching to methods, and "warn" gives a much clearer idea when looking at the signature.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You could argue, NoValue means the same in the sense of "not passed in", but I just don't think we need a singleton like this here when a meaningful string will do. Just my opinion though.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think @eric-wieser has a point. The original motivation for
So the argument here is that if someone passes
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. True, I don't feel much either way. Thought the main point of NoValue was for thing like
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It was invented mostly for "keepdims", so I don't know that we really have a tradition yet. I don't feel strongly either way about using it in this case. I thought "warn" was a bit unusual, but not particularly problematic. I confess to a certain weakness for things that are just a bit different, and this was one of them. |
||
| """ | ||
| Return the least-squares solution to a linear matrix equation. | ||
|
|
||
|
|
@@ -1836,6 +1836,13 @@ def lstsq(a, b, rcond=-1): | |
| as zero if they are smaller than `rcond` times the largest singular | ||
| value of `a`. | ||
|
|
||
| .. versionchanged:: 1.14.0 | ||
| If not set, a FutureWarning is given. The previous default | ||
| of ``-1`` will use the machine precision as `rcond` parameter, | ||
| the new default will use the machine precision times `max(M, N)`. | ||
| To silence the warning and use the new default, use ``rcond=None``, | ||
| to keep using the old behavior, use ``rcond=-1``. | ||
|
|
||
| Returns | ||
| ------- | ||
| x : {(N,), (N, K)} ndarray | ||
|
|
@@ -1909,6 +1916,20 @@ def lstsq(a, b, rcond=-1): | |
| if m != b.shape[0]: | ||
| raise LinAlgError('Incompatible dimensions') | ||
| t, result_t = _commonType(a, b) | ||
| # Determine default rcond value | ||
| if rcond == "warn": | ||
| # 2017-08-19, 1.14.0 | ||
| warnings.warn("`rcond` parameter will change to the default of " | ||
| "machine precision times ``max(M, N)`` where M and N " | ||
| "are the input matrix dimensions.\n" | ||
| "To use the future default and silence this warning " | ||
| "we advise to pass `rcond=None`, to keep using the old, " | ||
| "explicitly pass `rcond=-1`.", | ||
| FutureWarning, stacklevel=2) | ||
| rcond = -1 | ||
| if rcond is None: | ||
| rcond = finfo(t).eps * ldb | ||
|
|
||
| result_real_t = _realType(result_t) | ||
| real_t = _linalgRealType(t) | ||
| bstar = zeros((ldb, n_rhs), t) | ||
|
|
||
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.
Don't need this blank line.
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.
But doesn't hurt, I will edit the notes later in any case.