Skip to content

Conversation

jishnub
Copy link
Member

@jishnub jishnub commented Apr 1, 2024

With this, we may convert a structured matrix to Matrix even if its eltype doesn't support zero(T), as long as we may index into the matrix and the elements have zero defined for themselves. This makes the following work:

julia> D = Diagonal(fill(Diagonal([1,3]), 2))
2×2 Diagonal{Diagonal{Int64, Vector{Int64}}, Vector{Diagonal{Int64, Vector{Int64}}}}:
 [1 0; 0 3]           
            [1 0; 0 3]

julia> Matrix{eltype(D)}(D)
2×2 Matrix{Diagonal{Int64, Vector{Int64}}}:
 [1 0; 0 3]  [0 0; 0 0]
 [0 0; 0 0]  [1 0; 0 3]

We also may materialize partly initialized matrices:

julia> D = Diagonal(Vector{BigInt}(undef, 2))
2×2 Diagonal{BigInt, Vector{BigInt}}:
 #undef    ⋅
        #undef

julia> Matrix{eltype(D)}(D)
2×2 Matrix{BigInt}:
 #undef    0
   0     #undef

The performance seems identical for numeric matrices.

@jishnub jishnub added linear algebra Linear algebra arrays [a, r, r, a, y, s] labels Apr 1, 2024
@jishnub jishnub changed the title Use copyto! in converting StructuredMatrix to Matrix Use copyto! in converting Diagonal/Bidiagonal/Tridiagonal to Matrix Apr 1, 2024
@jishnub jishnub merged commit 19919b7 into master Apr 4, 2024
@jishnub jishnub deleted the jishnub/structuredtomatrixcopyto branch April 4, 2024 02:56
KristofferC pushed a commit that referenced this pull request May 9, 2024
KristofferC pushed a commit that referenced this pull request May 13, 2024
@jishnub jishnub restored the jishnub/structuredtomatrixcopyto branch May 14, 2024 04:38
@jishnub jishnub deleted the jishnub/structuredtomatrixcopyto branch May 14, 2024 05:10
lazarusA pushed a commit to lazarusA/julia that referenced this pull request Jul 12, 2024
lazarusA pushed a commit to lazarusA/julia that referenced this pull request Jul 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

arrays [a, r, r, a, y, s] linear algebra Linear algebra

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants