Skip to content

Commit

Permalink
fix inferrence issues due to using @invoke for lu keyword arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
thchr committed Jul 2, 2021
1 parent 33b641d commit 5a86c42
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 25 deletions.
31 changes: 12 additions & 19 deletions src/lu.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,28 +30,21 @@ function Base.show(io::IO, mime::MIME{Symbol("text/plain")}, F::LU)
end

# LU decomposition
function lu(A::StaticMatrix, pivot::Union{Val{false},Val{true}}=Val(true); check = true)
L, U, p = _lu(A, pivot, check)
LU(L, U, p)
end

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

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

# location of the first zero on the diagonal, 0 when not found
function _first_zero_on_diagonal(A::StaticMatrix{M,N,T}) where {M,N,T}
Expand Down
13 changes: 7 additions & 6 deletions test/lu.jl
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,11 @@ end

@testset "LU method ambiguity" begin
# Issue #920; just test that methods do not throw an ambiguity error when called
A = @SMatrix [1.0 2.0; 3.0 4.0]
@test isa(lu(A), StaticArrays.LU)
@test isa(lu(A, Val(true)), StaticArrays.LU)
@test isa(lu(A, Val(false)), StaticArrays.LU)
@test isa(lu(A; check=false), StaticArrays.LU)
@test isa(lu(A; check=true), StaticArrays.LU)
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]))
@test isa(lu(A), StaticArrays.LU)
@test isa(lu(A, Val(true)), StaticArrays.LU)
@test isa(lu(A, Val(false)), StaticArrays.LU)
@test isa(lu(A; check=false), StaticArrays.LU)
@test isa(lu(A; check=true), StaticArrays.LU)
end
end

0 comments on commit 5a86c42

Please sign in to comment.