From 709f421e8a39c690434db8a44f10e1b4a55f5bf1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20G=C3=B6ttgens?= Date: Wed, 9 Oct 2024 23:31:09 +0200 Subject: [PATCH] Some MatrixRing fixes (#1852) * Error on MatrixRing of size -1 * Fix characteristic of `matrix_ring(R, 0)` --- src/MatRing.jl | 1 + src/generic/MatRing.jl | 1 + test/generic/MatRing-test.jl | 4 ++++ 3 files changed, 6 insertions(+) diff --git a/src/MatRing.jl b/src/MatRing.jl index a0a1fab9b6..f778d255f7 100644 --- a/src/MatRing.jl +++ b/src/MatRing.jl @@ -66,6 +66,7 @@ end function characteristic(a::MatRing) + iszero(a.n) && return 1 return characteristic(base_ring(a)) end diff --git a/src/generic/MatRing.jl b/src/generic/MatRing.jl index 23c18760ee..4273b04a71 100644 --- a/src/generic/MatRing.jl +++ b/src/generic/MatRing.jl @@ -211,6 +211,7 @@ end function matrix_ring(R::AbstractAlgebra.NCRing, n::Int; cached::Bool = true) # TODO: the 'cached' argument is ignored and mainly here for backwards compatibility # (and perhaps future compatibility, in case we need it again) + @req n >= 0 "n must be a non-negative integer" T = elem_type(R) return MatRing{T}(R, n) end diff --git a/test/generic/MatRing-test.jl b/test/generic/MatRing-test.jl index cc726de152..e8bbe18c6f 100644 --- a/test/generic/MatRing-test.jl +++ b/test/generic/MatRing-test.jl @@ -1,5 +1,7 @@ @testset "Generic.MatAlg.constructors" begin R, t = polynomial_ring(QQ, "t") + @test_throws ArgumentError matrix_ring(R, -1) + S = matrix_ring(R, 3) @test S === matrix_ring(R, 3) @@ -177,6 +179,8 @@ end @test is_zero_column(M, 1) @test degree(M) == 2 + + @test characteristic(matrix_ring(R, 0)) == 1 end @testset "Generic.MatAlg.size/axes" begin