Skip to content

Commit 5a86c42

Browse files
committed
fix inferrence issues due to using @invoke for lu keyword arguments
1 parent 33b641d commit 5a86c42

File tree

2 files changed

+19
-25
lines changed

2 files changed

+19
-25
lines changed

src/lu.jl

+12-19
Original file line numberDiff line numberDiff line change
@@ -30,28 +30,21 @@ function Base.show(io::IO, mime::MIME{Symbol("text/plain")}, F::LU)
3030
end
3131

3232
# LU decomposition
33-
function lu(A::StaticMatrix, pivot::Union{Val{false},Val{true}}=Val(true); check = true)
34-
L, U, p = _lu(A, pivot, check)
35-
LU(L, U, p)
36-
end
37-
38-
# For the square version, return explicit lower and upper triangular matrices.
39-
# We would do this for the rectangular case too, but Base doesn't support that.
40-
function lu(A::StaticMatrix{N,N}, pivot::Union{Val{false},Val{true}}=Val(true);
41-
check = true) where {N}
42-
L, U, p = _lu(A, pivot, check)
43-
LU(LowerTriangular(L), UpperTriangular(U), p)
44-
end
33+
for pv in (:true, :false)
34+
# ... define each `pivot::Val{true/false}` method individually to avoid ambiguties
35+
@eval function lu(A::StaticMatrix, pivot::Val{$pv}; check = true)
36+
L, U, p = _lu(A, pivot, check)
37+
LU(L, U, p)
38+
end
4539

46-
@static if VERSION >= v"1.7-DEV"
47-
# disambiguation
48-
for p in (:true, :false)
49-
@eval function lu(A::StaticMatrix{N,N}, pivot::Val{$p}; check = true) where {N}
50-
Base.@invoke lu(A::StaticMatrix{N,N} where N,
51-
pivot::Union{Val{false},Val{true}}; check)
52-
end
40+
# For the square version, return explicit lower and upper triangular matrices.
41+
# We would do this for the rectangular case too, but Base doesn't support that.
42+
@eval function lu(A::StaticMatrix{N,N}, pivot::Val{$pv}; check = true) where {N}
43+
L, U, p = _lu(A, pivot, check)
44+
LU(LowerTriangular(L), UpperTriangular(U), p)
5345
end
5446
end
47+
lu(A::StaticMatrix; check = true) = lu(A, Val(true); check=check)
5548

5649
# location of the first zero on the diagonal, 0 when not found
5750
function _first_zero_on_diagonal(A::StaticMatrix{M,N,T}) where {M,N,T}

test/lu.jl

+7-6
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,11 @@ end
6868

6969
@testset "LU method ambiguity" begin
7070
# Issue #920; just test that methods do not throw an ambiguity error when called
71-
A = @SMatrix [1.0 2.0; 3.0 4.0]
72-
@test isa(lu(A), StaticArrays.LU)
73-
@test isa(lu(A, Val(true)), StaticArrays.LU)
74-
@test isa(lu(A, Val(false)), StaticArrays.LU)
75-
@test isa(lu(A; check=false), StaticArrays.LU)
76-
@test isa(lu(A; check=true), StaticArrays.LU)
71+
for A in ((@SMatrix [1.0 2.0; 3.0 4.0]), (@SMatrix [1.0 2.0 3.0; 4.0 5.0 6.0]))
72+
@test isa(lu(A), StaticArrays.LU)
73+
@test isa(lu(A, Val(true)), StaticArrays.LU)
74+
@test isa(lu(A, Val(false)), StaticArrays.LU)
75+
@test isa(lu(A; check=false), StaticArrays.LU)
76+
@test isa(lu(A; check=true), StaticArrays.LU)
77+
end
7778
end

0 commit comments

Comments
 (0)