Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change MatRing & MatRingElem to wrap a "native" matrix, not a Matrix{T} #1955

Open
fingolfin opened this issue Jan 13, 2025 · 0 comments
Open

Comments

@fingolfin
Copy link
Member

I think we should change the implementation of Generic.MatRingElem from

struct MatRingElem{T <: NCRingElement} <: AbstractAlgebra.MatRingElem{T}
   base_ring::NCRing
   entries::Matrix{T}

   function MatRingElem{T}(R::NCRing, A::Matrix{T}) where T <: NCRingElement
      @assert elem_type(R) === T
      return new{T}(R, A)
   end
end

to something more like this (untested, but I hope at least the principle idea gets across)

struct MatRingElem{T <: NCRingElement} <: AbstractAlgebra.MatRingElem{T}
   data::MatElem{T}

   function MatRingElem{T}(A::MatElem{T}) where T <: NCRingElement
      @assert A isa dense_matrix_type(T)
      return new{T}(A)
   end
end

function data(M::MatRingElem{T}) where T
  return M.data::dense_matrix_type(T)
end

This way those MatRingElem are less useless / more efficient. After a quick glance a bunch of code should actually become simpler. And some code that currently is implement for Generic.MatRingElem and Generic.Mat simultaneously needs to be untangled, but that's fine, e.g.

number_of_rows(a::Union{Mat, MatRingElem}) = size(a.entries, 1)

number_of_columns(a::Union{Mat,MatRingElem}) = size(a.entries, 2)

Base.@propagate_inbounds getindex(a::Union{Mat, MatRingElem}, r::Int, c::Int) = a.entries[r, c]

Base.@propagate_inbounds function setindex!(a::Union{Mat, MatRingElem}, d::NCRingElement,
                                            r::Int, c::Int)
    a.entries[r, c] = base_ring(a)(d)
end

Base.isassigned(a::Union{Mat,MatRingElem}, i, j) = isassigned(a.entries, i, j)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant