Skip to content

Commit

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

function MatSpaceElem{T}(R::NCRing, ::UndefInitializer, r::Int, c::Int) where T <: NCRingElement
return MatSpaceElem{T}(R, Matrix{T}(undef, r, c))
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 3ed3ea9

Please # to comment.