Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

serialize ZZModRing (note the capital ZZ) #2750

Merged
merged 1 commit into from
Sep 1, 2023
Merged
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
21 changes: 15 additions & 6 deletions src/Serialization/Rings.jl
Original file line number Diff line number Diff line change
Expand Up @@ -63,27 +63,36 @@ end
@register_serialization_type ZZRing

################################################################################
# non simpleton base rings
# Mod Rings
@register_serialization_type Nemo.zzModRing
@register_serialization_type Nemo.ZZModRing
const ModRingUnion = Union{Nemo.zzModRing, Nemo.ZZModRing}

function save_object(s::SerializerState, R::Nemo.zzModRing)
save_object(s, string(modulus(R)))
function save_object(s::SerializerState, R::T) where T <: ModRingUnion
save_object(s, modulus(R))
end

function load_object(s::DeserializerState, ::Type{Nemo.zzModRing}, str::String)
modulus = parse(UInt64, str)
return Nemo.zzModRing(modulus)
end

function load_object(s::DeserializerState, ::Type{Nemo.ZZModRing}, str::String)
modulus = ZZRingElem(str)
return Nemo.ZZModRing(modulus)
end

#elements
@register_serialization_type zzModRingElem uses_params
@register_serialization_type ZZModRingElem uses_params
const ModRingElemUnion = Union{zzModRingElem, ZZModRingElem}

function save_object(s::SerializerState, x::zzModRingElem)
function save_object(s::SerializerState, x::ModRingElemUnion)
save_data_basic(s, string(x))
end

function load_object(s::DeserializerState, ::Type{zzModRingElem},
str::String, parent_ring::Nemo.zzModRing)
function load_object(s::DeserializerState, ::Type{<:ModRingElemUnion},
str::String, parent_ring::T) where T <: ModRingUnion
antonydellavecchia marked this conversation as resolved.
Show resolved Hide resolved
return parent_ring(ZZRingElem(str))
end

Expand Down
83 changes: 42 additions & 41 deletions test/Serialization/basic_types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -42,49 +42,50 @@ function test_save_load_roundtrip(func, path, original::T; params=nothing) where
end

@testset "basic_types" begin

mktempdir() do path
@testset "Testing (de)serialization of $(T)" for T in
(
UInt, UInt8, UInt16, UInt32, UInt64, UInt128,
Int, Int8, Int16, Int32, Int64, Int128,
Float16, Float32, Float64,
BigInt,
ZZRingElem,
QQFieldElem,
residue_ring(ZZ, ZZ(6)),
residue_ring(ZZ, 6),
Nemo.fpField(UInt(7)),
Nemo.FpField(ZZRingElem(7)),
#PadicField(7, 30),
#TropicalSemiring()
)
original = T(1)
test_save_load_roundtrip(path, original) do loaded
@test loaded == original
end
end

mktempdir() do path
@testset "Testing (de)serialization of $(T)" for T in
(
UInt, UInt8, UInt16, UInt32, UInt64, UInt128,
Int, Int8, Int16, Int32, Int64, Int128,
Float16, Float32, Float64,
BigInt,
ZZRingElem,
QQFieldElem,
residue_ring(ZZ, 6),
Nemo.fpField(UInt(7)),
Nemo.FpField(ZZRingElem(7)),
#PadicField(7, 30),
#TropicalSemiring()
)
original = T(1)
test_save_load_roundtrip(path, original) do loaded
@test loaded == original
end
end

@testset "String" begin
original = "original"
test_save_load_roundtrip(path, original) do loaded
@test loaded == original
end
end
@testset "String" begin
original = "original"
test_save_load_roundtrip(path, original) do loaded
@test loaded == original
end
end

@testset "Symbol" begin
original = :original
test_save_load_roundtrip(path, original) do loaded
@test loaded == original
end
end
@testset "Symbol" begin
original = :original
test_save_load_roundtrip(path, original) do loaded
@test loaded == original
end
end

@testset "Singleton types" begin
test_save_load_roundtrip(path, ZZ) do loaded
@test loaded === ZZ
end
test_save_load_roundtrip(path, QQ) do loaded
@test loaded === QQ
end
end
@testset "Singleton types" begin
test_save_load_roundtrip(path, ZZ) do loaded
@test loaded === ZZ
end
test_save_load_roundtrip(path, QQ) do loaded
@test loaded === QQ
end
end
end
end
Loading