Skip to content

Commit d49fe30

Browse files
ThomasBreuerfingolfin
authored andcommitted
support deepcopy_internal for group elements
resolves issue #860
1 parent 072b432 commit d49fe30

File tree

4 files changed

+65
-0
lines changed

4 files changed

+65
-0
lines changed

src/Groups/matrices/MatGrp.jl

+17
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,23 @@ parent_type(::Type{T}) where T<:MatrixGroupElem{RE,S} where {RE,S} = MatrixGroup
125125
parent_type(::T) where T<:MatrixGroupElem{RE,S} where {RE,S} = MatrixGroup{RE,S}
126126

127127

128+
function Base.deepcopy_internal(x::MatrixGroupElem, dict::IdDict)
129+
if isdefined(x, :X)
130+
X = Base.deepcopy_internal(x.X, dict)
131+
if isdefined(x, :elm)
132+
elm = Base.deepcopy_internal(x.elm, dict)
133+
return MatrixGroupElem(x.parent, elm, X)
134+
else
135+
return MatrixGroupElem(x.parent, X)
136+
end
137+
elseif isdefined(x, :elm)
138+
elm = Base.deepcopy_internal(x.elm, dict)
139+
return MatrixGroupElem(x.parent, elm)
140+
end
141+
error("$x has neither :X nor :elm")
142+
end
143+
144+
128145
########################################################################
129146
#
130147
# Basic

src/Groups/types.jl

+5
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@ struct BasicGAPGroupElem{T<:GAPGroup} <: GAPGroupElem{T}
6161
X::GapObj
6262
end
6363

64+
function Base.deepcopy_internal(x::BasicGAPGroupElem, dict::IdDict)
65+
X = Base.deepcopy_internal(x.X, dict)
66+
return BasicGAPGroupElem(x.parent, X)
67+
end
68+
6469
Base.hash(x::GAPGroup, h::UInt) = h # FIXME
6570
Base.hash(x::GAPGroupElem, h::UInt) = h # FIXME
6671

test/Groups/elements.jl

+12
Original file line numberDiff line numberDiff line change
@@ -131,3 +131,15 @@ end
131131
@test_throws ErrorException gen(G, 0)
132132
end
133133

134+
@testset "deepcopy" begin
135+
for g in [symmetric_group(5), free_group(2), small_group(8, 1),
136+
automorphism_group(alternating_group(4))]
137+
m = Oscar.BasicGAPGroupElem(g, gen(g, 1).X)
138+
@test isdefined(m, :X)
139+
c = deepcopy(m);
140+
@test isdefined(c, :X)
141+
@test c.X == m.X
142+
143+
@test deepcopy([one(g)]) == [one(g)]
144+
end
145+
end

test/Groups/matrixgroups.jl

+31
Original file line numberDiff line numberDiff line change
@@ -686,3 +686,34 @@ end
686686
g = -identity_matrix(K, 3)
687687
@test g in G
688688
end
689+
690+
@testset "deepcopy" begin
691+
g = general_linear_group(2, 4)
692+
693+
m = MatrixGroupElem(g, gen(g, 1).X); # do not call `show`!
694+
@test isdefined(m, :X)
695+
@test ! isdefined(m, :elm)
696+
c = deepcopy(m);
697+
@test isdefined(c, :X)
698+
@test ! isdefined(c, :elm)
699+
@test c.X == m.X
700+
701+
m = MatrixGroupElem(g, gen(g, 1).elm, gen(g, 1).X)
702+
@test isdefined(m, :X)
703+
@test isdefined(m, :elm)
704+
c = deepcopy(m);
705+
@test isdefined(c, :X)
706+
@test isdefined(c, :elm)
707+
@test c.X == m.X
708+
@test c.elm == m.elm
709+
710+
m = MatrixGroupElem(g, gen(g, 1).elm)
711+
@test ! isdefined(m, :X)
712+
@test isdefined(m, :elm)
713+
c = deepcopy(m);
714+
@test ! isdefined(c, :X)
715+
@test isdefined(c, :elm)
716+
@test c.elm == m.elm
717+
718+
@test deepcopy([one(g)]) == [one(g)]
719+
end

0 commit comments

Comments
 (0)