Skip to content

Commit

Permalink
Improve copy & deepcopy for MatSpaceElem
Browse files Browse the repository at this point in the history
Also add a UndefInitializer constructor for it.
  • Loading branch information
fingolfin committed Nov 10, 2024
1 parent c509f90 commit 6d7d425
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 14 deletions.
5 changes: 5 additions & 0 deletions src/generic/GenericTypes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1068,6 +1068,11 @@ struct MatSpaceElem{T <: NCRingElement} <: Mat{T}
end
end

function MatSpaceElem{T}(R::NCRing, ::UndefInitializer, r::Int, c::Int)
t = Matrix{T}(undef, r, c)
return MatSpaceElem{T}(R, t)
end

function MatSpaceElem{T}(R::NCRing, A::AbstractMatrix{T}) where T <: NCRingElement
return MatSpaceElem{T}(R, Matrix(A))
end
Expand Down
16 changes: 2 additions & 14 deletions src/generic/Matrix.jl
Original file line number Diff line number Diff line change
Expand Up @@ -59,23 +59,11 @@ Base.isassigned(a::Union{Mat,MatRingElem}, i, j) = isassigned(a.entries, i, j)
################################################################################

function copy(d::MatSpaceElem{T}) where T <: NCRingElement
z = similar(d)
for i = 1:nrows(d)
for j = 1:ncols(d)
z[i, j] = d[i, j]
end
end
return z
return MatSpaceElem{T}(base_ring(d), copy(d.entries))
end

function deepcopy_internal(d::MatSpaceElem{T}, dict::IdDict) where T <: NCRingElement
z = similar(d)
for i = 1:nrows(d)
for j = 1:ncols(d)
z[i, j] = deepcopy_internal(d[i, j], dict)
end
end
return z
return MatSpaceElem{T}(base_ring(d), deepcopy_internal(d.entries, dict))
end

function deepcopy_internal(d::MatSpaceView{T}, dict::IdDict) where T <: NCRingElement
Expand Down

0 comments on commit 6d7d425

Please sign in to comment.