-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Define copy!, setindex!, and arithmetic for Symmetric and Hermitian #19228
Changes from 1 commit
374cc7b
91d28bd
3009d49
de7d086
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -250,3 +250,28 @@ let a = randn(2,2) | |
cc = copy(c) | ||
@test conj!(c) == conj(Array(c)) | ||
end | ||
|
||
# 19225 | ||
let X = sparse([1 -1; -1 1]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think these should to into the sparse tests for modularity. However, you might want to test the functionality with dense arrays as well. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I removed the |
||
for T in (Symmetric, Hermitian) | ||
Y = T(copy(X)) | ||
_Y = similar(Y) | ||
copy!(_Y, Y) | ||
@test _Y == Y | ||
|
||
W = T(copy(X), :L) | ||
copy!(W, Y) | ||
@test W.data == Y.data | ||
@test W.uplo != Y.uplo | ||
|
||
W[1,1] = 4 | ||
@test W == T(sparse([4 -1; -1 1])) | ||
|
||
@test Y + I == T(sparse([2 -1; -1 2])) | ||
@test Y - I == T(sparse([0 -1; -1 0])) | ||
@test Y + 1 == T(sparse([2 0; 0 2])) | ||
end | ||
|
||
@test_throws ArgumentError Hermitian(X) + 2im*I | ||
@test_throws ArgumentError Hermitian(X) - 2im*I | ||
end |
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 don't think this is right. It should only be allowed to modify the diagonal. Modifying off-diagonals will effectively change two values at a time so I think it should be an error.
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.
That makes sense. Then I'm back to defining specific methods for things, since only being able to set the diagonal doesn't allow more general operations, but maybe that's fine.