Create a copy while evaluating eigvals(::Diagonal)#45048
Merged
dkarrasch merged 2 commits intoJuliaLang:masterfrom May 2, 2022
Merged
Create a copy while evaluating eigvals(::Diagonal)#45048dkarrasch merged 2 commits intoJuliaLang:masterfrom
dkarrasch merged 2 commits intoJuliaLang:masterfrom
Conversation
Currently, `eigvals(D::Diagonal{<:Number})` returns `D.diag`, which means that subsequent changes to `D` will change previously computed eigenvalues.
```
julia> D = Diagonal([1,2,3])
3×3 Diagonal{Int64, Vector{Int64}}:
1 ⋅ ⋅
⋅ 2 ⋅
⋅ ⋅ 3
julia> λ = eigvals(D)
3-element Vector{Int64}:
1
2
3
julia> D[3,3] = 4
4
julia> λ
3-element Vector{Int64}:
1
2
4
```
Creating a copy should fix this
Member
Author
|
@dkarrasch would like your view on this |
Member
|
Yes, this is the right way to do it. This should be backported to all versions >= v1.6. This aliasing issue was also found in #43856, but the "fix" (in the context of |
KristofferC
pushed a commit
that referenced
this pull request
May 16, 2022
(cherry picked from commit b9d8280)
45 tasks
KristofferC
pushed a commit
that referenced
this pull request
May 16, 2022
(cherry picked from commit b9d8280)
67 tasks
KristofferC
pushed a commit
that referenced
this pull request
Dec 21, 2022
(cherry picked from commit b9d8280)
staticfloat
pushed a commit
that referenced
this pull request
Dec 23, 2022
(cherry picked from commit b9d8280)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Currently,
eigvals(D::Diagonal{<:Number})returnsD.diag, which means that subsequent changes toDwill change previously computed eigenvalues.Creating a copy should fix this.