Skip to content

Commit

Permalink
Fix return type for inv(StridedMatrix)
Browse files Browse the repository at this point in the history
  • Loading branch information
andreasnoack committed Jun 11, 2014
1 parent 4173ab1 commit ce6dbb1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
15 changes: 11 additions & 4 deletions base/linalg/dense.jl
Original file line number Diff line number Diff line change
Expand Up @@ -322,10 +322,17 @@ det(x::Number) = x

logdet(A::Matrix) = logdet(lufact(A))

function inv(A::Matrix)
if istriu(A) return inv(Triangular(A, :U, false)) end
if istril(A) return inv(Triangular(A, :L, false)) end
return inv(lufact(A))
function inv{S}(A::StridedMatrix{S})
T = typeof(one(S)/one(S))
Ac = convert(AbstractMatrix{T}, A)
if istriu(Ac)
Ai = inv(Triangular(A, :U, false))
elseif istril(Ac)
Ai = inv(Triangular(A, :L, false))
else
Ai = inv(lufact(Ac))
end
return convert(typeof(Ac), Ai)
end

function factorize{T}(A::Matrix{T})
Expand Down
5 changes: 3 additions & 2 deletions base/linalg/triangular.jl
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ function convert{T,TA,S,UpLo,IsUnit}(::Type{AbstractMatrix{T}}, A::Triangular{TA
M = convert(AbstractMatrix{T}, A.data)
Triangular{T,typeof(M),UpLo,IsUnit}(M)
end
function convert{T,S,UpLo,IsUnit}(::Type{Matrix}, A::Triangular{T,S,UpLo,IsUnit})
B = Array(T, size(A, 1), size(A, 1))
function convert{Tret,T,S,UpLo,IsUnit}(::Type{Matrix{Tret}}, A::Triangular{T,S,UpLo,IsUnit})
B = Array(Tret, size(A, 1), size(A, 1))
copy!(B, A.data)
(UpLo == :L ? tril! : triu!)(B)
if IsUnit
Expand All @@ -104,6 +104,7 @@ function convert{T,S,UpLo,IsUnit}(::Type{Matrix}, A::Triangular{T,S,UpLo,IsUnit}
end
B
end
convert{T,S,UpLo,IsUnit}(::Type{Matrix}, A::Triangular{T,S,UpLo,IsUnit}) = convert(Matrix{T}, A)

function full!{T,S,UpLo,IsUnit}(A::Triangular{T,S,UpLo,IsUnit})
B = A.data
Expand Down

0 comments on commit ce6dbb1

Please sign in to comment.