Skip to content

Commit

Permalink
Cache module orderings elsewhere and introduce shortcut. (#4116)
Browse files Browse the repository at this point in the history
  • Loading branch information
HechtiDerLachs authored Sep 19, 2024
1 parent b5d0b43 commit 6a7407f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/Modules/ModuleTypes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ option is set in suitable functions.
n::Int
S::Vector{Symbol}
d::Union{Vector{FinGenAbGroupElem}, Nothing}
default_ordering::ModuleOrdering

# We register the incoming and outgoing natural morphisms.
# This must be done in a way that objects can be collected by the
Expand Down
10 changes: 7 additions & 3 deletions src/Modules/UngradedModules/Methods.jl
Original file line number Diff line number Diff line change
Expand Up @@ -229,10 +229,14 @@ ring_map(f::SubQuoHom{<:AbstractFreeMod, <:ModuleFP, Nothing}) = nothing
ring_map(f::SubQuoHom) = f.ring_map

function default_ordering(F::FreeMod)
if iszero(F)
return default_ordering(base_ring(F))*ModuleOrdering(F, Orderings.ModOrdering(Vector{Int}(), :lex))
if !isdefined(F, :default_ordering)
if iszero(F)
F.default_ordering = default_ordering(base_ring(F))*ModuleOrdering(F, Orderings.ModOrdering(Vector{Int}(), :lex))
else
F.default_ordering = default_ordering(base_ring(F))*lex(gens(F))
end
end
return default_ordering(base_ring(F))*lex(gens(F))
return F.default_ordering::ModuleOrdering{typeof(F)}
end

##############################
Expand Down
10 changes: 9 additions & 1 deletion src/Modules/UngradedModules/SubModuleOfFreeModule.jl
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ end
Get the default ordering of `M`.
"""
function default_ordering(M::SubModuleOfFreeModule)
return default_ordering(ambient_free_module(M))
if !isdefined(M, :default_ordering)
ord = default_ordering(ambient_free_module(M))
set_default_ordering!(M, ord)
Expand All @@ -166,7 +167,14 @@ end
Compute a standard basis of `submod` with respect to the given `odering``.
The return type is `ModuleGens`.
"""
function standard_basis(submod::SubModuleOfFreeModule; ordering::ModuleOrdering = default_ordering(submod))
function standard_basis(submod::SubModuleOfFreeModule; ordering::Union{ModuleOrdering, Nothing} = default_ordering(submod))
# This is to circumvent hashing of the ordering in the obviously avoidable cases
if ordering===default_ordering(submod)
for (ord, gb) in submod.groebner_basis
ord === ordering && return gb
end
end

@req is_exact_type(elem_type(base_ring(submod))) "This functionality is only supported over exact fields."
gb = get!(submod.groebner_basis, ordering) do
return compute_standard_basis(submod, ordering)
Expand Down

0 comments on commit 6a7407f

Please sign in to comment.