Skip to content

Commit

Permalink
Add convert(Matrix{T},Bidigonal{S}) method. Fixes #12729.
Browse files Browse the repository at this point in the history
  • Loading branch information
andreasnoack committed Aug 21, 2015
1 parent 1f8d44e commit da7cc55
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
15 changes: 14 additions & 1 deletion base/linalg/bidiag.jl
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,20 @@ end

#Converting from Bidiagonal to dense Matrix
full{T}(M::Bidiagonal{T}) = convert(Matrix{T}, M)
convert{T}(::Type{Matrix{T}}, A::Bidiagonal{T})=diagm(A.dv) + diagm(A.ev, A.isupper?1:-1)
function convert{T}(::Type{Matrix{T}}, A::Bidiagonal)
n = size(A, 1)
B = zeros(T, n, n)
for i = 1:n - 1
B[i,i] = A.dv[i]
if A.isupper
B[i, i + 1] = A.ev[i]
else
B[i + 1, i] = A.ev[i]
end
end
B[n,n] = A.dv[n]
return B
end
convert{T}(::Type{Matrix}, A::Bidiagonal{T}) = convert(Matrix{T}, A)
promote_rule{T,S}(::Type{Matrix{T}}, ::Type{Bidiagonal{S}})=Matrix{promote_type(T,S)}

Expand Down
3 changes: 3 additions & 0 deletions test/linalg/bidiag.jl
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,9 @@ for relty in (Float32, Float64, BigFloat), elty in (relty, Complex{relty})
debug && println("Inverse")
@test_approx_eq inv(T)*Tfull eye(elty,n)
end

@test Matrix{Complex{Float64}}(BD) == BD

end

# Issue 10742 and similar
Expand Down

0 comments on commit da7cc55

Please sign in to comment.