Skip to content
Draft
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
71 changes: 71 additions & 0 deletions src/Serialization/SparseModules.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
########################################################################
# Serialization of `FreeMod`s and their elements
########################################################################

@register_serialization_type FreeMod uses_id

type_params(F::T) where {T <: FreeMod} = TypeParams(T, base_ring(F))

function save_object(s::SerializerState, F::FreeMod)
save_data_dict(s) do
#save_object(s, ngens(F), :rank)
save_object(s, symbols(F), :symbols)
end
end

function load_object(s::DeserializerState, ::Type{<:FreeMod}, params::Ring)
R = params
symbs = load_object(s, Vector{Symbol}, :symbols)
#rk = load_object(s, Int, :rank)
return FreeMod(R, symbs)
end

@register_serialization_type FreeModElem

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

save_object(s::SerializerState, v::FreeModElem) = save_object(s, coordinates(v))

function load_object(s::DeserializerState, ::Type{<:FreeModElem}, parent::FreeMod)
P = base_ring(parent)
RET = elem_type(P)
r = load_object(s, SRow, P)
return FreeModElem(r, parent)
end

########################################################################
# Serialization of `SubquoModule`s and their elements
########################################################################

@register_serialization_type SubquoModule uses_id

type_params(M::T) where {T <: SubquoModule} = TypeParams(T, ambient_free_module(M))

function save_object(s::SerializerState, M::SubquoModule)
save_data_dict(s) do
save_object(s, ambient_representatives_generators(M), :sub)
save_object(s, relations(M), :quo)
end
end

function load_object(s::DeserializerState, ::Type{<:SubquoModule}, params::FreeMod)
F = params
R = base_ring(F)
I = Oscar.SubModuleOfFreeModule(F, load_object(s, Vector{FreeModElem{elem_type(R)}}, F, :sub))
N = Oscar.SubModuleOfFreeModule(F, load_object(s, Vector{FreeModElem{elem_type(R)}}, F, :quo))
return SubquoModule(I, N)
end

@register_serialization_type SubquoModuleElem

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

save_object(s::SerializerState, v::SubquoModuleElem) = save_object(s, coordinates(v))

function load_object(s::DeserializerState, ::Type{<:SubquoModuleElem}, parent::SubquoModule)
P = base_ring(parent)
RET = elem_type(P)
r = load_object(s, SRow, P)
return SubquoModuleElem(r, parent)
end

11 changes: 11 additions & 0 deletions src/Serialization/containers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,17 @@ function type_params(obj::S) where {T, S <:MatVecType{T}}
return TypeParams(S, params[1])
end

function type_params(obj::SRow{T, Vector{T}}) where T
if isempty(obj)
return TypeParams(SRow, TypeParams(T, nothing))
end

params = map(x -> type_params(x[2]), obj)
@req params_all_equal(params) "Not all params of Vector or Matrix entries are the same, consider using a Tuple for serialization"
return TypeParams(SRow, params[1])
end


function type_params(obj::S) where {N, T, S <:Array{T, N}}
if isempty(obj)
return TypeParams(S, :subtype_params => TypeParams(T, nothing), :dims => N)
Expand Down
1 change: 1 addition & 0 deletions src/Serialization/main.jl
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,7 @@ include("QuadForm.jl")
include("GAP.jl")
include("Groups.jl")
include("LieTheory.jl")
include("SparseModules.jl")

include("Upgrades/main.jl")
include("parallel.jl")
Expand Down
27 changes: 27 additions & 0 deletions test/Serialization/SparseModules.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
@testset "Serialization of sparse modules" begin
mktempdir() do path
R, (x, y) = QQ[:x, :y]

F = FreeMod(R, 2)
test_save_load_roundtrip(path, F) do loaded
#@test symbols(F) == symbols(loaded)
@test F === loaded
end
v = x*F[1]
test_save_load_roundtrip(path, v) do loaded
@test v == loaded
end

I = ideal(R, [x, y])
II, inc = I*F
test_save_load_roundtrip(path, II) do loaded
#@test symbols(F) == symbols(loaded)
@test II === loaded
end
v = x*II[1]
test_save_load_roundtrip(path, v) do loaded
@test v == loaded
end
end
end

Loading