mirror of
https://github.com/kalmarek/Groups.jl.git
synced 2024-12-25 02:05:30 +01:00
more economical generate_balls using Base.product
This commit is contained in:
parent
d6befc7990
commit
78881e1d79
@ -378,28 +378,12 @@ end
|
|||||||
#
|
#
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
|
||||||
function products{T<:GroupElem}(X::AbstractVector{T}, Y::AbstractVector{T}, op=*)
|
function generate_balls{T<:GroupElem}(S::Vector{T}, Id::T=parent(first(S))(); radius=2, op=*)
|
||||||
result = Vector{T}()
|
sizes = Int[]
|
||||||
seen = Set{T}()
|
|
||||||
for x in X
|
|
||||||
for y in Y
|
|
||||||
z = op(x,y)
|
|
||||||
if !in(z, seen)
|
|
||||||
push!(seen, z)
|
|
||||||
push!(result, z)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
return result
|
|
||||||
end
|
|
||||||
|
|
||||||
function generate_balls{T<:GroupElem}(S::Vector{T}, Id::T; radius=2, op=*)
|
|
||||||
sizes = Vector{Int}()
|
|
||||||
S = deepcopy(S)
|
|
||||||
S = unshift!(S, Id)
|
|
||||||
B = [Id]
|
B = [Id]
|
||||||
for i in 1:radius
|
for i in 1:radius
|
||||||
B = products(B, S, op);
|
BB = [op(i,j) for (i,j) in Base.product(B,S)]
|
||||||
|
B = unique([B; vec(BB)])
|
||||||
push!(sizes, length(B))
|
push!(sizes, length(B))
|
||||||
end
|
end
|
||||||
return B, sizes
|
return B, sizes
|
||||||
|
Loading…
Reference in New Issue
Block a user