Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions experimental/LieAlgebras/src/serialization.jl
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,6 @@ end
@register_serialization_type LinearLieAlgebraElem
@register_serialization_type DirectSumLieAlgebraElem

type_params(x::T) where {T<:LieAlgebraElem} = TypeParams(T, parent(x))

function save_object(s::SerializerState, x::LieAlgebraElem)
save_object(s, coefficients(x))
end
Expand Down Expand Up @@ -222,8 +220,6 @@ end

@register_serialization_type LieAlgebraModuleElem

type_params(x::T) where {T<:LieAlgebraModuleElem} = TypeParams(T, parent(x))

function save_object(s::SerializerState, x::LieAlgebraModuleElem)
save_object(s, coefficients(x))
end
Expand Down
2 changes: 2 additions & 0 deletions src/Serialization/Algebras.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
# Free associative algebra serialization
@register_serialization_type FreeAssociativeAlgebra uses_id

type_params(R::T) where T <: FreeAssociativeAlgebra = TypeParams(T, coefficient_ring(R))

function save_object(s::SerializerState, A::FreeAssociativeAlgebra)
save_data_dict(s) do
save_object(s, symbols(A), :symbols)
Expand Down
11 changes: 4 additions & 7 deletions src/Serialization/Fields.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,6 @@
################################################################################
# field of rationals (singleton type)
@register_serialization_type QQField
# exclude from ring union definition
type_params(::QQField) = TypeParams(QQField, nothing)
Copy link
Collaborator

@antonydellavecchia antonydellavecchia Oct 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am a little confused what's happening with QQ now that this has been removed. For example

julia> Oscar.Serialization.type_params(QQ)
Type parameters for QQField ZZ

The printing could be improved... but the point is the return is ZZ and not nothing because of

type_params(R::T) where T <: FracField = TypeParams(T, base_ring(R))

However, QQField still seems to serialize properly including examples when QQField is a parameter.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah okay, there is a catch on line 234 of main.jl

type_params(::QQFieldElem) = TypeParams(QQFieldElem, nothing)
type_params(::fpField) = TypeParams(fpField, nothing)
type_params(::FpField) = TypeParams(FpField, nothing)
type_params(::QQBarField) = TypeParams(QQBarField, nothing)
type_params(::PadicField) = TypeParams(PadicField, nothing)

################################################################################
# type_params for field extension types
Expand Down Expand Up @@ -244,6 +237,8 @@ end

@register_serialization_type FracField uses_id

type_params(R::T) where T <: FracField = TypeParams(T, base_ring(R))

const FracUnionTypes = Union{MPolyRingElem, PolyRingElem, UniversalPolyRingElem}
# we use the union to prevent QQField from using these save methods

Expand Down Expand Up @@ -282,6 +277,8 @@ end

@register_serialization_type AbstractAlgebra.Generic.RationalFunctionField "RationalFunctionField" uses_id

type_params(R::T) where T <: AbstractAlgebra.Generic.RationalFunctionField = TypeParams(T, base_ring(R))

function save_object(s::SerializerState,
RF::AbstractAlgebra.Generic.RationalFunctionField{<: FieldElem, <: MPolyRingElem})
save_data_dict(s) do
Expand Down
2 changes: 0 additions & 2 deletions src/Serialization/Groups.jl
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,6 @@ using Oscar: GAPGroup, _coeff
# `GAPGroupElem` objects get serialized together with their parents.
const GrpElemUnionType = Union{GAPGroupElem, FinGenAbGroupElem}

type_params(p::T) where T <: GrpElemUnionType = TypeParams(T, parent(p))

#############################################################################
# attributes handling
const GAPGroup_attributes = [
Expand Down
4 changes: 0 additions & 4 deletions src/Serialization/LieTheory.jl
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,6 @@ end

@register_serialization_type WeightLatticeElem

type_params(w::WeightLatticeElem) = TypeParams(WeightLatticeElem, parent(w))

function save_object(s::SerializerState, w::WeightLatticeElem)
save_object(s, _vec(coefficients(w)))
end
Expand Down Expand Up @@ -107,8 +105,6 @@ end

@register_serialization_type WeylGroupElem

type_params(w::WeylGroupElem) = TypeParams(WeylGroupElem, parent(w))

function save_object(s::SerializerState, x::WeylGroupElem)
save_object(s, word(x))
end
Expand Down
30 changes: 17 additions & 13 deletions src/Serialization/Rings.jl
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
################################################################################
# Common union types

const RingMatElemUnion = Union{NCRingElem, MatElem, SMat}
const RingMatSpaceUnion = Union{NCRing, MatSpace, SMatSpace}
const ModRingUnion = Union{zzModRing, ZZModRing}
const ModRingElemUnion = Union{zzModRingElem, ZZModRingElem}

Expand Down Expand Up @@ -31,14 +29,18 @@ const LaurentUnionType = Union{Generic.LaurentSeriesRing,
################################################################################
# type_params functions

type_params(x::T) where T <: RingMatElemUnion = TypeParams(T, parent(x))
type_params(R::T) where T <: RingMatSpaceUnion = TypeParams(T, base_ring(R))
# element types by default use their parent as reference object
type_params(x::T) where T <: SetElem = TypeParams(T, parent(x))
type_params(x::T) where T <: SMat = TypeParams(T, parent(x))

# rings, groups etc. default have no reference object
type_params(R::T) where T <: AbstractAlgebra.Set = TypeParams(T, nothing)

# ideals and matrix spaces have their base ring as reference object
type_params(x::T) where T <: Ideal = TypeParams(T, base_ring(x))
# exclude from ring union
type_params(::ZZRing) = TypeParams(ZZRing, nothing)
type_params(::ZZRingElem) = TypeParams(ZZRingElem, nothing)
type_params(R::T) where T <: PolyRingUnionType = TypeParams(T, coefficient_ring(R))
type_params(R::T) where T <: ModRingUnion = TypeParams(T, nothing)
type_params(x::T) where T <: MatSpace = TypeParams(T, base_ring(x))
type_params(x::T) where T <: SMatSpace = TypeParams(T, base_ring(x))


################################################################################
# ring of integers (singleton type)
Expand Down Expand Up @@ -85,6 +87,9 @@ end
@register_serialization_type MPolyDecRing uses_id
@register_serialization_type AbstractAlgebra.Generic.LaurentMPolyWrapRing uses_id

# polynomial-like rings use their coefficient ring as reference object
type_params(R::T) where T <: PolyRingUnionType = TypeParams(T, coefficient_ring(R))

function save_object(s::SerializerState, R::PolyRingUnionType)
save_data_dict(s) do
save_object(s, symbols(R), :symbols)
Expand Down Expand Up @@ -378,6 +383,7 @@ end
# Power Series
@register_serialization_type SeriesRing uses_id

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

function save_object(s::SerializerState, R::RelPowerSeriesUnionType)
save_data_dict(s) do
Expand Down Expand Up @@ -497,6 +503,8 @@ end
@register_serialization_type Generic.LaurentSeriesField "LaurentSeriesField" uses_id
@register_serialization_type ZZLaurentSeriesRing uses_id

type_params(R::T) where T <: LaurentUnionType = TypeParams(T, base_ring(R))

function save_object(s::SerializerState, R::LaurentUnionType)
save_data_dict(s) do
save_object(s, var(R), :var)
Expand Down Expand Up @@ -702,8 +710,6 @@ end

@register_serialization_type MPolyLocRingElem

type_params(a::MPolyLocRingElem) = TypeParams(MPolyLocRingElem, parent(a))

function save_object(s::SerializerState, a::MPolyLocRingElem)
# `save_type_params` will store the output of type_params
# in this case the parent ring
Expand Down Expand Up @@ -742,8 +748,6 @@ end

@register_serialization_type MPolyQuoLocRingElem

type_params(a::T) where {T<:MPolyQuoLocRingElem} = TypeParams(T, parent(a))

function save_object(s::SerializerState, a::MPolyQuoLocRingElem)
save_object(s, [lifted_numerator(a), lifted_denominator(a)])
end
Expand Down
15 changes: 10 additions & 5 deletions src/Serialization/main.jl
Original file line number Diff line number Diff line change
Expand Up @@ -167,12 +167,17 @@ struct TypeParams{T, S}
type::Type{T}
params::S

function TypeParams(T::Type, args::Pair...)
return new{T, typeof(args)}(T, args)
function TypeParams(T::Type, params)
if Base.issingletontype(T)
return new{T, Nothing}(T, nothing)
else
return new{T, typeof(params)}(T, params)
end
end
TypeParams(T::Type, obj) = new{T, typeof(obj)}(T, obj)
end

TypeParams(T::Type, args::Pair...) = TypeParams(T, args)

params(tp::TypeParams) = tp.params
type(tp::TypeParams) = tp.type

Expand Down Expand Up @@ -419,7 +424,7 @@ function load_typed_object(s::DeserializerState, key::Symbol; override_params::A
end

# The load mechanism first checks if the type needs to load necessary
# parameters before loading it's data, if so a type tree is traversed
# parameters before loading its data, if so a type tree is traversed
function load_typed_object(s::DeserializerState; override_params::Any = nothing)
T = decode_type(s)
Base.issingletontype(T) && return T()
Expand Down Expand Up @@ -702,7 +707,7 @@ Load the object stored in the given io stream
respectively in the file `filename`.

If `params` is specified, then the root object of the loaded data
either will attempt a load using these parameters. In the case of Rings this
either will attempt a load using these parameters. In the case of rings this
results in setting its parent, or in the case of a container of ring types such as
`Vector` or `Tuple`, then the parent of the entries will be set using their
`params`.
Expand Down
Loading