Skip to content
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

Add a fully typed Diagonal constructor from AbstractMatrixes #52487

Merged
merged 6 commits into from
Dec 27, 2023

Conversation

jishnub
Copy link
Contributor

@jishnub jishnub commented Dec 11, 2023

The following works after this PR:

julia> oftype(Diagonal(Float32[1,2]), [1 0; 0 2])
2×2 Diagonal{Float32, Vector{Float32}}:
 1.0    
     2.0

This changes the behavior of the constructor to copy the diagonal, so now

julia> D = Diagonal([1,2]);

julia> typeof(D)(D).diag === D.diag
false

whereas this used to be true previously. This probably doesn't matter much, as in most non-trivial cases it'd be copied anyway, and this conversion is unusual in the trivial case.

@jishnub jishnub added the linear algebra Linear algebra label Dec 11, 2023
@jishnub jishnub force-pushed the jishnub/convertdiagonal branch from 2af7c62 to a272307 Compare December 13, 2023 06:26
@jishnub jishnub requested a review from dkarrasch December 18, 2023 12:44
@jishnub
Copy link
Contributor Author

jishnub commented Dec 18, 2023

The test failure appears to be unrelated

@jishnub
Copy link
Contributor Author

jishnub commented Dec 22, 2023

Good to go?

Copy link
Member

@dkarrasch dkarrasch left a comment

Choose a reason for hiding this comment

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

One last comment, otherwise let's go.

stdlib/LinearAlgebra/src/diagonal.jl Outdated Show resolved Hide resolved
Co-authored-by: Daniel Karrasch <[email protected]>
@jishnub jishnub merged commit 66e9410 into master Dec 27, 2023
5 of 7 checks passed
@jishnub jishnub deleted the jishnub/convertdiagonal branch December 27, 2023 06:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
linear algebra Linear algebra
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants