Skip to content

Commit

Permalink
Add base_ring_type for MatrixElem; fix it for MatSpace (#1705)
Browse files Browse the repository at this point in the history
This is a useful "inverse" for `dense_matrix_type`.
  • Loading branch information
fingolfin authored May 15, 2024
1 parent 17bc758 commit a2e601d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/Matrix.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions test/generic/Matrix-test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit a2e601d

Please sign in to comment.