diff --git a/src/Combinatorics/Matroids/matroids.jl b/src/Combinatorics/Matroids/matroids.jl index 5fc0f2cbf7a9..8be56c69b268 100644 --- a/src/Combinatorics/Matroids/matroids.jl +++ b/src/Combinatorics/Matroids/matroids.jl @@ -864,4 +864,9 @@ julia> automorphism_group(M) Group([ (3,4), (1,2), (2,3) ]) ``` """ -automorphism_group(m::Matroid) = automorphism_group(IncidenceMatrix(bases(m));action=:on_cols) +function automorphism_group(m::Matroid) + @req length(m) > 0 "The matroid should not be empty." + I = rank(m) < 1 ? IncidenceMatrix(bases(dual_matroid(m))) : IncidenceMatrix(bases(m)) + resize!(I, nrows(I), length(m)) + return automorphism_group(I; action=:on_cols) +end diff --git a/test/Combinatorics/Matroids/Matroids.jl b/test/Combinatorics/Matroids/Matroids.jl index 242f911da2c8..b53d571425c9 100644 --- a/test/Combinatorics/Matroids/Matroids.jl +++ b/test/Combinatorics/Matroids/Matroids.jl @@ -343,5 +343,8 @@ @testset "matroid automorphism" begin M = uniform_matroid(3, 5) @test order(automorphism_group(M)) == 120 + @test automorphism_group(uniform_matroid(0, 2)) == symmetric_group(2) + U = matroid_from_bases([[1,2],[2,3],[1,3]],5) + @test automorphism_group(U) == automorphism_group(dual_matroid(U)) end end