Skip to content

Commit 7db5280

Browse files
committed
Revise type_param delegation
For elements, use type plus parent. For rings, default to just the type.
1 parent 3f7ceb6 commit 7db5280

File tree

6 files changed

+23
-30
lines changed

6 files changed

+23
-30
lines changed

experimental/LieAlgebras/src/serialization.jl

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,6 @@ end
127127
@register_serialization_type LinearLieAlgebraElem
128128
@register_serialization_type DirectSumLieAlgebraElem
129129

130-
type_params(x::T) where {T<:LieAlgebraElem} = TypeParams(T, parent(x))
131-
132130
function save_object(s::SerializerState, x::LieAlgebraElem)
133131
save_object(s, coefficients(x))
134132
end
@@ -222,8 +220,6 @@ end
222220

223221
@register_serialization_type LieAlgebraModuleElem
224222

225-
type_params(x::T) where {T<:LieAlgebraModuleElem} = TypeParams(T, parent(x))
226-
227223
function save_object(s::SerializerState, x::LieAlgebraModuleElem)
228224
save_object(s, coefficients(x))
229225
end

src/Serialization/Algebras.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
# Free associative algebra serialization
55
@register_serialization_type FreeAssociativeAlgebra uses_id
66

7+
type_params(R::T) where T <: FreeAssociativeAlgebra = TypeParams(T, coefficient_ring(R))
8+
79
function save_object(s::SerializerState, A::FreeAssociativeAlgebra)
810
save_data_dict(s) do
911
save_object(s, symbols(A), :symbols)

src/Serialization/Fields.jl

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,6 @@
55
################################################################################
66
# field of rationals (singleton type)
77
@register_serialization_type QQField
8-
# exclude from ring union definition
9-
type_params(::QQField) = TypeParams(QQField, nothing)
10-
type_params(::QQFieldElem) = TypeParams(QQFieldElem, nothing)
11-
type_params(::fpField) = TypeParams(fpField, nothing)
12-
type_params(::FpField) = TypeParams(FpField, nothing)
13-
type_params(::QQBarField) = TypeParams(QQBarField, nothing)
14-
type_params(::PadicField) = TypeParams(PadicField, nothing)
158

169
################################################################################
1710
# type_params for field extension types
@@ -244,6 +237,8 @@ end
244237

245238
@register_serialization_type FracField uses_id
246239

240+
type_params(R::T) where T <: FracField = TypeParams(T, base_ring(R))
241+
247242
const FracUnionTypes = Union{MPolyRingElem, PolyRingElem, UniversalPolyRingElem}
248243
# we use the union to prevent QQField from using these save methods
249244

@@ -282,6 +277,8 @@ end
282277

283278
@register_serialization_type AbstractAlgebra.Generic.RationalFunctionField "RationalFunctionField" uses_id
284279

280+
type_params(R::T) where T <: AbstractAlgebra.Generic.RationalFunctionField = TypeParams(T, base_ring(R))
281+
285282
function save_object(s::SerializerState,
286283
RF::AbstractAlgebra.Generic.RationalFunctionField{<: FieldElem, <: MPolyRingElem})
287284
save_data_dict(s) do

src/Serialization/Groups.jl

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,6 @@ using Oscar: GAPGroup, _coeff
9090
# `GAPGroupElem` objects get serialized together with their parents.
9191
const GrpElemUnionType = Union{GAPGroupElem, FinGenAbGroupElem}
9292

93-
type_params(p::T) where T <: GrpElemUnionType = TypeParams(T, parent(p))
94-
9593
#############################################################################
9694
# attributes handling
9795
const GAPGroup_attributes = [

src/Serialization/LieTheory.jl

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,6 @@ end
7474

7575
@register_serialization_type WeightLatticeElem
7676

77-
type_params(w::WeightLatticeElem) = TypeParams(WeightLatticeElem, parent(w))
78-
7977
function save_object(s::SerializerState, w::WeightLatticeElem)
8078
save_object(s, _vec(coefficients(w)))
8179
end
@@ -107,8 +105,6 @@ end
107105

108106
@register_serialization_type WeylGroupElem
109107

110-
type_params(w::WeylGroupElem) = TypeParams(WeylGroupElem, parent(w))
111-
112108
function save_object(s::SerializerState, x::WeylGroupElem)
113109
save_object(s, word(x))
114110
end

src/Serialization/Rings.jl

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
################################################################################
22
# Common union types
33

4-
const RingMatElemUnion = Union{NCRingElem, MatElem, SMat}
5-
const RingMatSpaceUnion = Union{NCRing, MatSpace, SMatSpace}
64
const ModRingUnion = Union{zzModRing, ZZModRing}
75
const ModRingElemUnion = Union{zzModRingElem, ZZModRingElem}
86

@@ -31,14 +29,18 @@ const LaurentUnionType = Union{Generic.LaurentSeriesRing,
3129
################################################################################
3230
# type_params functions
3331

34-
type_params(x::T) where T <: RingMatElemUnion = TypeParams(T, parent(x))
35-
type_params(R::T) where T <: RingMatSpaceUnion = TypeParams(T, base_ring(R))
32+
# element types by default use their parent as reference object
33+
type_params(x::T) where T <: SetElem = TypeParams(T, parent(x))
34+
type_params(x::T) where T <: SMat = TypeParams(T, parent(x))
35+
36+
# rings, groups etc. default have no reference object
37+
type_params(R::T) where T <: AbstractAlgebra.Set = TypeParams(T, nothing)
38+
39+
# ideals and matrix spaces have their base ring as reference object
3640
type_params(x::T) where T <: Ideal = TypeParams(T, base_ring(x))
37-
# exclude from ring union
38-
type_params(::ZZRing) = TypeParams(ZZRing, nothing)
39-
type_params(::ZZRingElem) = TypeParams(ZZRingElem, nothing)
40-
type_params(R::T) where T <: PolyRingUnionType = TypeParams(T, coefficient_ring(R))
41-
type_params(R::T) where T <: ModRingUnion = TypeParams(T, nothing)
41+
type_params(x::T) where T <: MatSpace = TypeParams(T, base_ring(x))
42+
type_params(x::T) where T <: SMatSpace = TypeParams(T, base_ring(x))
43+
4244

4345
################################################################################
4446
# ring of integers (singleton type)
@@ -85,6 +87,9 @@ end
8587
@register_serialization_type MPolyDecRing uses_id
8688
@register_serialization_type AbstractAlgebra.Generic.LaurentMPolyWrapRing uses_id
8789

90+
# polynomial-like rings use their coefficient ring as reference object
91+
type_params(R::T) where T <: PolyRingUnionType = TypeParams(T, coefficient_ring(R))
92+
8893
function save_object(s::SerializerState, R::PolyRingUnionType)
8994
save_data_dict(s) do
9095
save_object(s, symbols(R), :symbols)
@@ -378,6 +383,7 @@ end
378383
# Power Series
379384
@register_serialization_type SeriesRing uses_id
380385

386+
type_params(R::T) where T <: SeriesRing = TypeParams(T, base_ring(R))
381387

382388
function save_object(s::SerializerState, R::RelPowerSeriesUnionType)
383389
save_data_dict(s) do
@@ -497,6 +503,8 @@ end
497503
@register_serialization_type Generic.LaurentSeriesField "LaurentSeriesField" uses_id
498504
@register_serialization_type ZZLaurentSeriesRing uses_id
499505

506+
type_params(R::T) where T <: LaurentUnionType = TypeParams(T, base_ring(R))
507+
500508
function save_object(s::SerializerState, R::LaurentUnionType)
501509
save_data_dict(s) do
502510
save_object(s, var(R), :var)
@@ -702,8 +710,6 @@ end
702710

703711
@register_serialization_type MPolyLocRingElem
704712

705-
type_params(a::MPolyLocRingElem) = TypeParams(MPolyLocRingElem, parent(a))
706-
707713
function save_object(s::SerializerState, a::MPolyLocRingElem)
708714
# `save_type_params` will store the output of type_params
709715
# in this case the parent ring
@@ -742,8 +748,6 @@ end
742748

743749
@register_serialization_type MPolyQuoLocRingElem
744750

745-
type_params(a::T) where {T<:MPolyQuoLocRingElem} = TypeParams(T, parent(a))
746-
747751
function save_object(s::SerializerState, a::MPolyQuoLocRingElem)
748752
save_object(s, [lifted_numerator(a), lifted_denominator(a)])
749753
end

0 commit comments

Comments
 (0)