From ce6dbb177971c22044992e539ae821d13af732d2 Mon Sep 17 00:00:00 2001 From: Andreas Noack Jensen Date: Wed, 11 Jun 2014 15:42:30 +0200 Subject: [PATCH] Fix return type for inv(StridedMatrix) --- base/linalg/dense.jl | 15 +++++++++++---- base/linalg/triangular.jl | 5 +++-- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/base/linalg/dense.jl b/base/linalg/dense.jl index e783d85d8da12..37e0634114e05 100644 --- a/base/linalg/dense.jl +++ b/base/linalg/dense.jl @@ -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}) diff --git a/base/linalg/triangular.jl b/base/linalg/triangular.jl index e9e791a0e1452..01a82f8c3e225 100644 --- a/base/linalg/triangular.jl +++ b/base/linalg/triangular.jl @@ -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 @@ -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