From a2e601db066a486140a00a4a732ea050bde2d185 Mon Sep 17 00:00:00 2001 From: Max Horn Date: Wed, 15 May 2024 22:36:36 +0200 Subject: [PATCH] Add base_ring_type for MatrixElem; fix it for MatSpace (#1705) This is a useful "inverse" for `dense_matrix_type`. --- src/Matrix.jl | 4 +++- test/generic/Matrix-test.jl | 6 ++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/Matrix.jl b/src/Matrix.jl index 960c2ad6e5..9f4761e7fd 100644 --- a/src/Matrix.jl +++ b/src/Matrix.jl @@ -10,10 +10,12 @@ # ############################################################################### -base_ring_type(::Type{MatSpace{T}}) where T <: NCRingElement = parent_type(T) +base_ring_type(::Type{<:MatSpace{T}}) where T <: NCRingElement = parent_type(T) base_ring(a::MatSpace{T}) where {T <: NCRingElement} = a.base_ring::parent_type(T) +base_ring_type(::Type{<:MatrixElem{T}}) where T <: NCRingElement = parent_type(T) + base_ring(a::MatrixElem{T}) where {T <: NCRingElement} = a.base_ring::parent_type(T) function check_parent(a::MatElem, b::MatElem, throw::Bool = true) diff --git a/test/generic/Matrix-test.jl b/test/generic/Matrix-test.jl index 567a063c62..08a1c6dba7 100644 --- a/test/generic/Matrix-test.jl +++ b/test/generic/Matrix-test.jl @@ -122,6 +122,9 @@ end @test elem_type(S) == Generic.MatSpaceElem{elem_type(R)} @test elem_type(Generic.MatSpace{elem_type(R)}) == Generic.MatSpaceElem{elem_type(R)} @test parent_type(Generic.MatSpaceElem{elem_type(R)}) == Generic.MatSpace{elem_type(R)} + @test base_ring_type(Generic.MatSpace{elem_type(R)}) == typeof(R) + @test base_ring_type(Generic.MatSpaceElem{elem_type(R)}) == typeof(R) + @test base_ring_type(S) == typeof(R) @test base_ring(S) == R @test nrows(S) == 3 @test ncols(S) == 3 @@ -132,6 +135,7 @@ end @test isa(f, MatElem) @test parent_type(f) == typeof(S) + @test base_ring_type(f) == typeof(R) g = S(2) @@ -348,6 +352,8 @@ end @test dense_matrix_type(typeof(R)) == elem_type(S) @test dense_matrix_type(typeof(R(1))) == elem_type(S) + @test base_ring_type(dense_matrix_type(R)) == typeof(R) + @test isa(S(), MatElem) @test isa(S(ZZ(1)), MatElem) @test isa(S(one(R)), MatElem)