Skip to content

ENH: Add a hermitian argument to pinv and svd, matching matrix_rank #12693

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 2 commits into from
Jan 13, 2019

Conversation

eric-wieser
Copy link
Member

@eric-wieser eric-wieser commented Jan 8, 2019

Related to gh-9436 (pinging @perimosocordiae)

An alternative to #12665 with a lower maintenance burden (cc @jordan-melendez), although admittedly with some small sign-juggling overhead.

Runs in 60% of the time of the non-hermitian version for a mid-size test:

In [1]: a = np.random.random((300, 300))

In [2]: a = a.T @ a

In [3]: %timeit np.linalg.svd(a)
287 ms ± 21.4 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)

In [4]: %timeit np.linalg.svd(a, hermitian=1)
168 ms ± 12 ms per loop (mean ± std. dev. of 7 runs, 10 loops each)
``

u = u[..., ::-1]
# singular values are unsigned, move the sign into v
vt = transpose(u * sign(s)[..., None, :]).conjugate()
s = abs(s)
Copy link
Member Author

Choose a reason for hiding this comment

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

When called through pinv, these lines are a waste of time because the terms get multiplied anyway. I suspect that's not worth optimizing though.

@perimosocordiae
Copy link
Contributor

Looks reasonable to me.

@mattip mattip merged commit 1176ae8 into numpy:master Jan 13, 2019
@mattip
Copy link
Member

mattip commented Jan 13, 2019

Thanks Eric

@charris
Copy link
Member

charris commented Jan 13, 2019

The United States and Great Britain are two countries separated by a common language.

G.B. Shaw

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.

4 participants