Skip to content

Commit

Permalink
fix qr method ambiguities (#931) and lingering lu ambiguities (#920)
Browse files Browse the repository at this point in the history
  • Loading branch information
thchr committed Jul 1, 2021
1 parent 1a06987 commit 33b641d
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/lu.jl
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,11 @@ end

@static if VERSION >= v"1.7-DEV"
# disambiguation
function lu(A::StaticMatrix{N,N}, pivot::Val{true}) where {N}
Base.@invoke lu(A::StaticMatrix{N,N} where N, pivot::Union{Val{false},Val{true}})
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
end
end

Expand Down
9 changes: 9 additions & 0 deletions src/qr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,15 @@ true
end
end

@static if VERSION >= v"1.7-DEV"
# disambiguation
for p in (:true, :false)
@eval function qr(A::StaticMatrix, pivot::Val{$p})
Base.@invoke qr(A::StaticMatrix, pivot::Union{Val{false},Val{true}})
end
end
end

function identity_perm(R::StaticMatrix{N,M,T}) where {N,M,T}
return similar_type(R, Int, Size((M,)))(ntuple(x -> x, Val{M}()))
end
Expand Down
10 changes: 10 additions & 0 deletions test/lu.jl
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,13 @@ end
@test_throws SingularException lu(A)
@test !issuccess(lu(A; check = false))
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)
end
8 changes: 8 additions & 0 deletions test/qr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,11 @@ Random.seed!(42)
test_qr(arr)
end
end

@testset "QR method ambiguity" begin
# Issue #931; just test that methods do not throw an ambiguity error when called
A = @SMatrix [1.0 2.0 3.0; 4.0 5.0 6.0]
@test isa(qr(A), StaticArrays.QR)
@test isa(qr(A, Val(true)), StaticArrays.QR)
@test isa(qr(A, Val(false)), StaticArrays.QR)
end

0 comments on commit 33b641d

Please sign in to comment.