-
Notifications
You must be signed in to change notification settings - Fork 52
Add specification for computing the pseudo-inverse (linalg: pinv) #118
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
Conversation
I'd say no. We should avoid variable number of returns as much as possible. Returning a tuple doesn't help at all; changing the tuple length would still be a serious backwards compat break. I'll comment on gh-95, after looking at some of these PRs that's worth reconsidering. |
The default value here is given as
|
Re: |
Re: namedtuple. Another alternative is to simply return a dictionary. |
Renamed |
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.
Just a quick comment 🙂
Renamed |
btw CuPy will support batched |
2f8f5e4
to
0607525
Compare
Thanks, @leofang, for the review! This is ready for merge... |
This PR
Notes
Following Torch, MXNet, TF, NumPy, and JAX, this proposal allows for providing a stack of square matrices. CuPy does not currently support providing stacks.
Dask does not provide an API for computing the pseudo-inverse.
TF supports a
validate_args
argument for embedding additional validations within its computational graph.NumPy, MXNet, and Torch (latest
master
) supporting providing ahermitian
keyword argument to indicate that more efficient computation methods be used. This PR omits this keyword, as more of an implementation detail, than a generalizable API.NumPy, MXNet, CuPy, and Torch set the default
rcond
value to1e-15
, while JAX and TF compute a default value based on the machine epsilon associated with the input array data type and the number of rows/cols. This PR follows JAX and TF in computing the default value (as1e-15
does not make sense for non-float64
input, such asfloat32
orbfloat16
) and requiring thatrcond
be a broadcast compatible array (or afloat
).This proposal renames the
rcond
keyword argument tortol
in order to unify keyword arguments forpinv
,lstsq
, andmatrix_rank
which all support specifying relative tolerances. The default value is also the same across these APIs.Question: should this return a namedtuple to allow for a variable number of returns (see API for variable number of returns in linalg #95)? SciPy, e.g., does support returning multiple values (the matrix
B
along with the effectiverank
of the result). In theory, other info could be returned, such as error info, but not clear whether this is enough of a forward-looking concern.