-
-
Notifications
You must be signed in to change notification settings - Fork 649
Euclidean norm crashfix sparse matrices #40493
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
Euclidean norm crashfix sparse matrices #40493
Conversation
src/sage/matrix/matrix2.pyx
Outdated
A = self.dense_matrix().change_ring(CDF) | ||
else: | ||
A = self.change_ring(CDF) | ||
|
||
A = A.conjugate().transpose() * A |
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.
while we're at it, maybe you can change this to .conjugate_transpose()
.
src/sage/matrix/matrix2.pyx
Outdated
if self.is_sparse(): | ||
A = self.dense_matrix().change_ring(CDF) | ||
else: | ||
A = self.change_ring(CDF) |
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.
overcomplicated, you could call .dense_matrix()
unconditionally.
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.
True, the cost is null if the matrix is already dense.
actually there's #39831 that adds Either way, at least for sparse matrix over CDF, I think it's cleaner to implement although even with that, it may still be better for performance to call |
I see your point. I am unfamiliar with SVD and just wanted to patch the crash. |
Fixes #40492.
The call to
.norm()
ornorm()
with default parameter (p = 2
for euclidean norm) crashes for sparse matrices.I go around it by checking if the matrix is sparse and if so, copy it into a dense matrix internally to compute the norm. This must be done since the euclidean norm uses the
.SVD()
method which is not exposed for sparse matrices.📝 Checklist
⌛ Dependencies