diff --git a/src/bidiag.jl b/src/bidiag.jl index 2ccf6cf5..9bfd5332 100644 --- a/src/bidiag.jl +++ b/src/bidiag.jl @@ -189,10 +189,20 @@ end #Converting from Bidiagonal to dense Matrix function Matrix{T}(A::Bidiagonal) where T B = Matrix{T}(undef, size(A)) + iszero(size(B,1)) && return B if haszero(T) # optimized path for types with zero(T) defined size(B,1) > 1 && fill!(B, zero(T)) - copyto!(diagview(B), A.dv) - copyto!(diagview(B, _offdiagind(A.uplo)), A.ev) + isupper = A.uplo == 'U' + if isupper + B[1,1] = A.dv[1] + end + for col in axes(A.ev,1) + B[col+!isupper, col+isupper] = A.ev[col] + B[col+isupper, col+isupper] = A.dv[col+isupper] + end + if !isupper + B[end,end] = A.dv[end] + end else copyto!(B, A) end diff --git a/src/tridiag.jl b/src/tridiag.jl index 226b9417..4fcbfe9a 100644 --- a/src/tridiag.jl +++ b/src/tridiag.jl @@ -635,11 +635,15 @@ axes(M::Tridiagonal) = (ax = axes(M.d,1); (ax, ax)) function Matrix{T}(M::Tridiagonal) where {T} A = Matrix{T}(undef, size(M)) + iszero(size(A,1)) && return A if haszero(T) # optimized path for types with zero(T) defined size(A,1) > 2 && fill!(A, zero(T)) - copyto!(diagview(A), M.d) - copyto!(diagview(A,1), M.du) - copyto!(diagview(A,-1), M.dl) + for i in axes(M.dl,1) + A[i,i] = M.d[i] + A[i+1,i] = M.dl[i] + A[i,i+1] = M.du[i] + end + A[end,end] = M.d[end] else copyto!(A, M) end