Skip to content

Commit

Permalink
use and improve densifiers
Browse files Browse the repository at this point in the history
  • Loading branch information
dkarrasch committed Mar 15, 2022
1 parent 8702ee7 commit 55a7e6b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
12 changes: 10 additions & 2 deletions stdlib/LinearAlgebra/src/diagonal.jl
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,16 @@ Diagonal{T}(D::Diagonal{T}) where {T} = D
Diagonal{T}(D::Diagonal) where {T} = Diagonal{T}(D.diag)

AbstractMatrix{T}(D::Diagonal) where {T} = Diagonal{T}(D)
Matrix(D::Diagonal) = diagm(0 => D.diag)
Array(D::Diagonal) = Matrix(D)
Matrix(D::Diagonal{T}) where {T} = Matrix{T}(D)
Array(D::Diagonal{T}) where {T} = Matrix{T}(D)
function Matrix{T}(D::Diagonal) where {T}
n = size(D, 1)
B = zeros(T, n, n)
for i in 1:n
B[i,i] = D.diag[i]
end
return B
end

"""
Diagonal{T}(undef, n)
Expand Down
4 changes: 2 additions & 2 deletions stdlib/LinearAlgebra/src/special.jl
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ function _qlmul(Q::AbstractQ, B)
end
function _qlmul(adjQ::Adjoint{<:Any,<:AbstractQ}, B)
TQB = promote_type(eltype(adjQ), eltype(B))
lmul!(adjoint(convert(AbstractMatrix{TQB}, parent(adjQ))), copy_similar(B, TQB))
lmul!(adjoint(convert(AbstractMatrix{TQB}, parent(adjQ))), Matrix{TQB}(B))
end

*(Q::AbstractQ, B::AbstractTriangular) = _qlmul(Q, B)
Expand All @@ -325,7 +325,7 @@ rmul!(A::AbstractTriangular, Q::Adjoint{<:Any,<:AbstractQ}) = rmul!(full!(A), Q)

function _qrmul(A, Q::AbstractQ)
TAQ = promote_type(eltype(A), eltype(Q))
return rmul!(copy_similar(A, TAQ), convert(AbstractMatrix{TAQ}, Q))
return rmul!(Matrix{TAQ}(A), convert(AbstractMatrix{TAQ}, Q))
end
function _qrmul(A, adjQ::Adjoint{<:Any,<:AbstractQ})
Q = adjQ.parent
Expand Down
7 changes: 3 additions & 4 deletions stdlib/LinearAlgebra/src/tridiag.jl
Original file line number Diff line number Diff line change
Expand Up @@ -571,15 +571,14 @@ function size(M::Tridiagonal, d::Integer)
end
end

function Matrix{T}(M::Tridiagonal{T}) where T
function Matrix{T}(M::Tridiagonal) where {T}
A = zeros(T, size(M))
for i = 1:length(M.d)
for i in 1:length(M.d)-1
A[i,i] = M.d[i]
end
for i = 1:length(M.d)-1
A[i+1,i] = M.dl[i]
A[i,i+1] = M.du[i]
end
A[n,n] = M.d[n]
A
end
Matrix(M::Tridiagonal{T}) where {T} = Matrix{T}(M)
Expand Down

0 comments on commit 55a7e6b

Please sign in to comment.