remove threaded wlmetric_ball

* the threaded version was hardly faster
* there was a memory leak (?) that was gone with -t 1
* simplifies the whole thing
This commit is contained in:
Marek Kaluba 2023-03-22 21:41:37 +01:00
parent 8bd3f7ede6
commit 1f1e51917a
No known key found for this signature in database
GPG Key ID: 8BF1A3855328FC15
4 changed files with 26 additions and 58 deletions

View File

@ -1,20 +1,19 @@
name = "Groups" name = "Groups"
uuid = "5d8bd718-bd84-11e8-3b40-ad14f4a32557" uuid = "5d8bd718-bd84-11e8-3b40-ad14f4a32557"
authors = ["Marek Kaluba <kalmar@amu.edu.pl>"] authors = ["Marek Kaluba <kalmar@amu.edu.pl>"]
version = "0.7.5" version = "0.7.6"
[deps] [deps]
Folds = "41a02a25-b8f0-4f67-bc48-60067656b558"
GroupsCore = "d5909c97-4eac-4ecc-a3dc-fdd0858a4120" GroupsCore = "d5909c97-4eac-4ecc-a3dc-fdd0858a4120"
KnuthBendix = "c2604015-7b3d-4a30-8a26-9074551ec60a" KnuthBendix = "c2604015-7b3d-4a30-8a26-9074551ec60a"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Logging = "56ddb016-857b-54e1-b83d-db4d58db5568" Logging = "56ddb016-857b-54e1-b83d-db4d58db5568"
OrderedCollections = "bac558e1-5e72-5ebc-8fee-abe8a469f55d" OrderedCollections = "bac558e1-5e72-5ebc-8fee-abe8a469f55d"
PermutationGroups = "8bc5a954-2dfc-11e9-10e6-cd969bffa420" PermutationGroups = "8bc5a954-2dfc-11e9-10e6-cd969bffa420"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182" StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
[compat] [compat]
Folds = "0.2.7"
GroupsCore = "0.4" GroupsCore = "0.4"
KnuthBendix = "0.4" KnuthBendix = "0.4"
OrderedCollections = "1" OrderedCollections = "1"

View File

@ -1,12 +1,9 @@
module Groups module Groups
import Folds
import Logging import Logging
using GroupsCore using GroupsCore
import GroupsCore.Random import Random
import OrderedCollections: OrderedSet
import KnuthBendix import KnuthBendix
import KnuthBendix: AbstractWord, Alphabet, Word import KnuthBendix: AbstractWord, Alphabet, Word

View File

@ -1,3 +1,5 @@
import OrderedCollections: OrderedSet
mutable struct FPGroupIter{S,T,GEl} mutable struct FPGroupIter{S,T,GEl}
seen::S seen::S
seen_iter_state::T seen_iter_state::T

View File

@ -1,6 +1,6 @@
""" """
wlmetric_ball(S::AbstractVector{<:GroupElem} wlmetric_ball(S::AbstractVector{<:GroupElem}
[, center=one(first(S)); radius=2, op=*, threading=true]) [, center=one(first(S)); radius=2, op=*])
Compute metric ball as a list of elements of non-decreasing length, given the Compute metric ball as a list of elements of non-decreasing length, given the
word-length metric on the group generated by `S`. The ball is centered at `center` word-length metric on the group generated by `S`. The ball is centered at `center`
(by default: the identity element). `radius` and `op` keywords specify the (by default: the identity element). `radius` and `op` keywords specify the
@ -11,57 +11,27 @@ function wlmetric_ball(
center::T = one(first(S)); center::T = one(first(S));
radius = 2, radius = 2,
op = *, op = *,
threading = true,
) where {T} ) where {T}
threading && return wlmetric_ball_thr(S, center; radius = radius, op = op) ball = [center]
return wlmetric_ball_serial(S, center; radius = radius, op = op) sizes = [1]
end if radius 0
return ball, sizes[2:end]
function wlmetric_ball_serial( else
S::AbstractVector{T}, ball = union!(ball, [center * s for s in S])
center::T = one(first(S)); push!(sizes, length(ball))
radius = 2, if radius == 1
op = *, return ball, sizes[2:end]
) where {T} else
@assert radius >= 1 for _ in 2:radius
old = union!(OrderedSet([center]), [center * s for s in S]) new = collect(
sizes = [1, length(old)] op(o, s) for o in @view(ball[sizes[end-1]:end]) for s in S
for _ in 2:radius )
new = collect( append!(ball, new)
op(o, s) for o in @view(old.dict.keys[sizes[end-1]:end]) for s in S unique!(ball)
) push!(sizes, length(ball))
union!(old, new) end
push!(sizes, length(old))
end
return old.dict.keys, sizes[2:end]
end
function wlmetric_ball_thr(
S::AbstractVector{T},
center::T = one(first(S));
radius = 2,
op = *,
) where {T}
@assert radius >= 1
old = union!([center], [center * s for s in S])
return _wlmetric_ball(S, old, radius, op, Folds.collect, Folds.unique)
end
function _wlmetric_ball(S, old, radius, op, collect, unique)
sizes = [1, length(old)]
for _ in 2:radius
old = let old = old, S = S
new = collect(
(g = op(o, s);
normalform!(g);
hash(g);
g) for o in @view(old[sizes[end-1]:end]) for s in S
)
append!(old, new)
unique(old)
end end
push!(sizes, length(old)) return ball, sizes[2:end]
end end
return old, sizes[2:end] # return wlmetric_ball_serial(S, center; radius = radius, op = op)
end end