Skip to content

Commit

Permalink
use in-place inv, since lufact already made a copy
Browse files Browse the repository at this point in the history
  • Loading branch information
fredrikekre committed Jul 13, 2017
1 parent 8678b5e commit cad74f6
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion base/linalg/dense.jl
Original file line number Diff line number Diff line change
Expand Up @@ -653,7 +653,7 @@ function inv(A::StridedMatrix{T}) where T
Ai = inv(LowerTriangular(AA))
Ai = convert(typeof(parent(Ai)), Ai)
else
Ai = inv(lufact(AA))
Ai = inv!(lufact(AA))
Ai = convert(typeof(parent(Ai)), Ai)
end
return Ai
Expand Down
6 changes: 4 additions & 2 deletions base/linalg/lu.jl
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ convert(::Type{LU{T,S}}, F::LU) where {T,S} = LU{T,S}(convert(S, F.factors), F.i
convert(::Type{Factorization{T}}, F::LU{T}) where {T} = F
convert(::Type{Factorization{T}}, F::LU) where {T} = convert(LU{T}, F)

copy(A::LU{T,S}) where {T,S} = LU{T,S}(copy(A.factors), copy(A.ipiv), A.info)

size(A::LU) = size(A.factors)
size(A::LU,n) = size(A.factors,n)
Expand Down Expand Up @@ -313,8 +314,9 @@ end

inv!(A::LU{<:BlasFloat,<:StridedMatrix}) =
@assertnonsingular LAPACK.getri!(A.factors, A.ipiv) A.info
inv(A::LU{<:BlasFloat,<:StridedMatrix}) =
inv!(LU(copy(A.factors), copy(A.ipiv), copy(A.info)))
inv!(A::LU{T,<:StridedMatrix}) where {T} =
@assertnonsingular A_ldiv_B!(A.factors, copy(A), eye(T, size(A, 1))) A.info
inv(A::LU{<:BlasFloat,<:StridedMatrix}) = inv!(copy(A))

function _cond1Inf(A::LU{<:BlasFloat,<:StridedMatrix}, p::Number, normA::Real)
if p != 1 && p != Inf
Expand Down
1 change: 1 addition & 0 deletions test/linalg/lu.jl
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ debug && println("(Automatic) Square LU decomposition. eltya: $eltya, eltyb: $el
@test l*u a[p,:]
@test (l*u)[invperm(p),:] a
@test a * inv(lua) eye(n)
@test copy(lua) == lua

lstring = sprint(show,l)
ustring = sprint(show,u)
Expand Down

0 comments on commit cad74f6

Please sign in to comment.