mirror of
https://github.com/kalmarek/Groups.jl.git
synced 2024-11-19 06:30:29 +01:00
rework DirectProdIter to the new iteration protocol
This commit is contained in:
parent
e28c296bce
commit
0750a47853
@ -118,7 +118,7 @@ parent(g::DirectProductGroupElem) =
|
|||||||
#
|
#
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
|
||||||
Base.size(g::DirectProductGroupElem) = size(g.elts)
|
size(g::DirectProductGroupElem) = size(g.elts)
|
||||||
Base.IndexStyle(::Type{DirectProductGroupElem}) = Base.LinearFast()
|
Base.IndexStyle(::Type{DirectProductGroupElem}) = Base.LinearFast()
|
||||||
Base.getindex(g::DirectProductGroupElem, i::Int) = g.elts[i]
|
Base.getindex(g::DirectProductGroupElem, i::Int) = g.elts[i]
|
||||||
|
|
||||||
@ -276,10 +276,7 @@ end
|
|||||||
#
|
#
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
|
||||||
import Base: size, length, start, next, done, eltype
|
struct DirectPowerIter{GrEl<:AbstractAlgebra.GroupElem}
|
||||||
|
|
||||||
struct DirectPowerIter{Gr<:AbstractAlgebra.Group, GrEl<:AbstractAlgebra.GroupElem}
|
|
||||||
G::Gr
|
|
||||||
N::Int
|
N::Int
|
||||||
elts::Vector{GrEl}
|
elts::Vector{GrEl}
|
||||||
totalorder::Int
|
totalorder::Int
|
||||||
@ -287,27 +284,20 @@ struct DirectPowerIter{Gr<:AbstractAlgebra.Group, GrEl<:AbstractAlgebra.GroupEle
|
|||||||
end
|
end
|
||||||
|
|
||||||
function DirectPowerIter(G::Gr, N::Integer) where {Gr<:AbstractAlgebra.Group}
|
function DirectPowerIter(G::Gr, N::Integer) where {Gr<:AbstractAlgebra.Group}
|
||||||
return DirectPowerIter{Gr, elem_type(G)}(
|
return DirectPowerIter{elem_type(G)}(N, collect(G), order(G)^N, order(G))
|
||||||
G,
|
|
||||||
N,
|
|
||||||
vec(collect(elements(G))),
|
|
||||||
Int(order(G))^N,
|
|
||||||
Int(order(G))
|
|
||||||
)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
Base.size(DPIter::DirectPowerIter) = ntuple(i -> DPIter.orderG, DPIter.N)
|
length(DPIter::DirectPowerIter) = DPIter.totalorder
|
||||||
Base.length(DPIter::DirectPowerIter) = DPIter.totalorder
|
|
||||||
Base.start(::DirectPowerIter) = 0
|
|
||||||
|
|
||||||
function Base.next(DPIter::DirectPowerIter, state)
|
function iterate(DPIter::DirectPowerIter, state=0)
|
||||||
idx = ind2sub(size(DPIter), state+1)
|
if state >= DPIter.totalorder
|
||||||
|
return nothing
|
||||||
|
end
|
||||||
|
idx = Tuple(CartesianIndices(ntuple(i -> DPIter.orderG, DPIter.N))[state+1])
|
||||||
return DirectProductGroupElem([DPIter.elts[i] for i in idx]), state+1
|
return DirectProductGroupElem([DPIter.elts[i] for i in idx]), state+1
|
||||||
end
|
end
|
||||||
|
|
||||||
Base.done(DPIter::DirectPowerIter, state) = DPIter.totalorder <= state
|
eltype(::Type{DirectPowerIter{GrEl}}) where {GrEl} = DirectProductGroupElem{GrEl}
|
||||||
|
|
||||||
Base.eltype(::Type{DirectPowerIter{Gr, GrEl}}) where {Gr, GrEl} = DirectProductGroupElem{GrEl}
|
|
||||||
|
|
||||||
@doc doc"""
|
@doc doc"""
|
||||||
elements(G::DirectProductGroup)
|
elements(G::DirectProductGroup)
|
||||||
|
@ -4,9 +4,9 @@ module Groups
|
|||||||
using AbstractAlgebra
|
using AbstractAlgebra
|
||||||
import AbstractAlgebra: Group, GroupElem, Ring
|
import AbstractAlgebra: Group, GroupElem, Ring
|
||||||
import AbstractAlgebra: parent, parent_type, elem_type
|
import AbstractAlgebra: parent, parent_type, elem_type
|
||||||
import AbstractAlgebra: elements, order, gens, matrix_repr
|
import AbstractAlgebra: order, gens, matrix_repr
|
||||||
|
|
||||||
import Base: length, ==, hash, show, convert
|
import Base: length, ==, hash, show, convert, eltype, iterate
|
||||||
import Base: inv, reduce, *, ^, power_by_squaring
|
import Base: inv, reduce, *, ^, power_by_squaring
|
||||||
import Base: findfirst, findnext
|
import Base: findfirst, findnext
|
||||||
import Base: deepcopy_internal
|
import Base: deepcopy_internal
|
||||||
|
Loading…
Reference in New Issue
Block a user