julia
19919b70 - Use `copyto!` in converting `Diagonal`/`Bidiagonal`/`Tridiagonal` to `Matrix` (#53912)

Commit
1 year ago
Use `copyto!` in converting `Diagonal`/`Bidiagonal`/`Tridiagonal` to `Matrix` (#53912) 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 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 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.
Author
Parents
Loading