Skip to content

Commit 2b924e4

Browse files
committed
type stability of left division
1 parent 52c41f7 commit 2b924e4

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

src/generic.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1224,6 +1224,7 @@ true
12241224
function (\)(A::AbstractMatrix, B::AbstractVecOrMat)
12251225
require_one_based_indexing(A, B)
12261226
m, n = size(A)
1227+
T = promote_op(\, eltype(A), eltype(B))
12271228
if m == n
12281229
if istril(A)
12291230
if istriu(A)
@@ -1235,9 +1236,9 @@ function (\)(A::AbstractMatrix, B::AbstractVecOrMat)
12351236
if istriu(A)
12361237
return UpperTriangular(A) \ B
12371238
end
1238-
return lu(A) \ B
1239+
return _lu(_lucopy(A, T)) \ B
12391240
end
1240-
return qr(A, ColumnNorm()) \ B
1241+
return _qr(copy_similar(A, _qreltype(T)), ColumnNorm()) \ B
12411242
end
12421243

12431244
(\)(a::AbstractVector, b::AbstractArray) = pinv(a) * b

test/generic.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -954,4 +954,14 @@ end
954954
@test Int[] Int[]
955955
end
956956

957+
@testset "issue 930" begin
958+
A = rand(Int, 2, 2)
959+
B = rand(Int, 2, 3)
960+
for M (A, B), T (Float32, BigFloat)
961+
v = randn(T, 2)
962+
x = @inferred M \ v
963+
@test eltype(x) <: T
964+
end
965+
end
966+
957967
end # module TestGeneric

0 commit comments

Comments
 (0)