-
-
Notifications
You must be signed in to change notification settings - Fork 5.1k
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
ENH: in scipy.sparse.linalg.norm implement spectral norm #8472
Conversation
Some comments here:
|
Ok, thanks for comment! I fixed this things. |
Ok, without csc_matrix and info about float in matrix - svds raise error
With this it works correctly. |
@c-f-h everything is ok now? |
I think that it can be merge? |
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.
I'm certainly not an expert on this, but added a suggestion re: the duplicated code.
from scipy.sparse.linalg import svds | ||
x = csc_matrix(x, dtype=float) | ||
u, s, vt = svds(x, k=1) | ||
return s[0] |
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.
The spectral norm algorithm is duplicated here, right? It might be more suitable to define a function and call it for the conditions where a spectral norm is to be used, as the duplication of code could be a maintenance burden.
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.
The 'spec'
alias should be removed.
====== ============================ | ||
None Frobenius norm | ||
'fro' Frobenius norm | ||
'spec' Spectral norm |
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 add the 'spec'
alias, the ord=2
is sufficient.
from scipy.sparse.linalg import svds | ||
x = csc_matrix(x, dtype=float) | ||
u, s, vt = svds(x, k=1) | ||
return s[0] |
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.
The 'spec'
alias should be removed.
if ord in (2, 'spec'): | ||
# spectral norm | ||
from scipy.sparse import csc_matrix | ||
from scipy.sparse.linalg import svds |
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.
The imports should be on top of the file.
# spectral norm | ||
from scipy.sparse import csc_matrix | ||
from scipy.sparse.linalg import svds | ||
x = csc_matrix(x, dtype=float) |
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.
The conversion to csc_matrix
shouldn't be necessary.
Moreover, one also has to be able to compute norms of complex matrices.
ENH: in scipy.sparse.linalg.norm implement spectral norm
Reference to: #7268