8000 ENH: Allow use of svd on empty arrays by eric-wieser · Pull Request #11424 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

ENH: Allow use of svd on empty arrays #11424

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

Merged
merged 1 commit into from
Jun 27, 2018
Merged

Conversation

eric-wieser
Copy link
Member
@eric-wieser eric-wieser commented Jun 26, 2018

part of #8654

Revived from over a year ago

cc @convexset

Copy link
Contributor
@mhvk mhvk left a comment

Choose a reason for hiding this comment

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

Looks good to me

Copy link
Member
@seberg seberg left a comment

Choose a reason for hiding this comment

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

The changes are probably good, I guess there are practically tests run now when deleting those lines, but... IIRC the svd should probably have a specific form at least when full_matrices is set to True, and I doubt that this is already being tested?

@@ -2771,6 +2770,15 @@ static NPY_INLINE void
if ('N' == params.JOBZ) {
delinearize_@REALTYPE@_matrix(args[1], params.S, &s_out);
} else {
if ('A' == params.JOBZ && min_m_n == 0) {
/* Lapack has betrayed us and left these uninitialized,
Copy link
Member

Choose a reason for hiding this comment

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

NIT: comment should start on the next line.

@seberg
Copy link
Member
seberg commented Jun 27, 2018

Heh, that was quicker then possible ;), LGTM with the new test now.

@seberg
Copy link
Member
seberg commented Jun 27, 2018

Hmm, actually, I am not 100% sure right now if this goes into Lapack, I am a bit worried that things might not work for annoying lapack implementations. And the thing is on a quick look over I am not sure it does not sometimes go into lapack.

@eric-wieser are you pretty sure it is either not going in or lapack standard should error out cleanly?

@eric-wieser
Copy link
Member Author

full_matrices is true by default. I've added a test for the identity matrix though, which was otherwise not tested for

@eric-wieser
Copy link
Member Author

This does go into lapack, but it passes parameters that conform. Typically our mistakes in this area have been setting LDA = M rather than LDA = max(M, 1), but svd already does this correctly.

I'd probably say put it in - there's no way for lapack to produce an invalid result here, since in the 0-size case all of the outputs are overwritten after the call anyway. If it returns an error code, then we can handle that if/when we get a report of it. And if it clobbers arbitrary memory... Then I think the authors of the lapack implementation need strong words.

@seberg
Copy link
Member
seberg commented Jun 27, 2018

OK, if you are certain enough that this is safe. I don't really know these lapack details well, vaguely remember that max(M, 1) thing. It also seems a bit like we are already doing this without complains in other functions, so seems fine.

@seberg
Copy link
Member
seberg commented Jun 27, 2018

OK, tests succeed, so will put this in. Thanks Eric!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
0