Skip to content

Commit

Permalink
Merge pull request #39 from kalmarek/mk/AbstractPermutations
Browse files Browse the repository at this point in the history
update to AbstractPermutations-0.3
  • Loading branch information
Marek Kaluba committed Dec 17, 2023
2 parents 06cea66 + dc97436 commit 68d302c
Show file tree
Hide file tree
Showing 9 changed files with 82 additions and 150 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/format.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
- uses: actions/checkout@v2
- name: Install JuliaFormatter and format
run: |
julia -e 'using Pkg; Pkg.add(PackageSpec(name="JuliaFormatter", version="1.0.9"))'
julia -e 'using Pkg; Pkg.add(PackageSpec(name="JuliaFormatter", version="1.0.45"))'
julia -e 'using JuliaFormatter; format(["./src", "./test"], verbose=true)'
- name: Format check
run: |
Expand Down
9 changes: 4 additions & 5 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "PermutationGroups"
uuid = "8bc5a954-2dfc-11e9-10e6-cd969bffa420"
authors = ["Marek Kaluba <kalmar@amu.edu.pl>", "tweisser <tillmann.weisser@web.de>"]
version = "0.5.0"
version = "0.6.0"

[deps]
AbstractPermutations = "36d08e8a-54dd-435f-8c9e-38a475050b11"
Expand All @@ -10,16 +10,15 @@ PrecompileTools = "aea7be01-6a6a-4083-8856-8a6e6704d82a"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"

[compat]
AbstractPermutations = "0.2"
GroupsCore = "0.4"
AbstractPermutations = "0.3"
GroupsCore = "0.5"
PrecompileTools = "1"
julia = "1.6"

[extras]
AbstractAlgebra = "c3fe647b-3220-5bb0-a1ea-a7954cac585d"
BenchmarkTools = "6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["Test", "Random", "BenchmarkTools", "AbstractAlgebra"]
test = ["Test", "Random", "BenchmarkTools"]
56 changes: 26 additions & 30 deletions src/Perms/perm_images.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,13 @@
inv::Perm{T}
cycles::AP.CycleDecomposition{T}

function Perm{T}(
images::AbstractVector{<:Integer},
check::Bool = true,
) where {T}
function Perm{T}(images::Vector{T}; check::Bool = true) where {T}
if check && !isperm(images)
throw(ArgumentError("Provided images are not permutation!"))
end
deg = __degree(images)
if deg == length(images)
return new{T}(images)
else
# for future: use @time one(Perm{Int})
# to check if julia can elide the creation of view
return new{T}(@view images[Base.OneTo(deg)])
end
resize!(images, deg)
return new{T}(images)
end
end
else
Expand All @@ -27,31 +19,34 @@ else
@atomic inv::Perm{T}
@atomic cycles::AP.CycleDecomposition{T}

function Perm{T}(
images::AbstractVector{<:Integer},
check::Bool = true,
) where {T}
function Perm{T}(images::Vector{T}; check::Bool = true) where {T}
if check && !isperm(images)
throw(ArgumentError("Provided images are not permutation!"))
end
li = lastindex(images)
deg =
iszero(li) ? li :
@inbounds images[li] li ? li : __degree(images)
if deg == length(images)
return new{T}(images)
else
# for future: use @time one(Perm{Int})
# to check if julia can elide the creation of view
return new{T}(@view images[Base.OneTo(deg)])
end
resize!(images, deg)
return new{T}(images)
end
end
end

function Perm{T}(
images::AbstractVector{<:Integer};
check::Bool = true,
) where {T}
deg = __degree(images)
return Perm{T}(
convert(Vector{T}, @view images[Base.OneTo(deg)]);
check = check,
)
end

# convienience constructor: inttype(::Type{<:AbstractPermutation}) defaults to UInt32
function Perm(images::AbstractVector{<:Integer}, check = true)
return Perm{AP.inttype(Perm)}(images, check)
function Perm(images::AbstractVector{<:Integer}; check = true)
return Perm{AP.inttype(Perm)}(images; check = check)
end

# ## Interface of AbstractPermutation
Expand All @@ -62,14 +57,15 @@ AP.degree(σ::Perm) = length(σ.images)
# inttype must be T (UInt16 by default) since we store it in e.g. cycles
AP.inttype(::Type{Perm{T}}) where {T} = T
AP.inttype(::Type{Perm}) = UInt16
AP.__unsafe_image(n::Integer, σ::Perm) = oftype(n, @inbounds σ.images[n])

@static if VERSION < v"1.7"
function Base.copy(p::Perm)
imgs = copy(p.images)
q = typeof(p)(imgs, false)
q = typeof(p)(imgs; check = false)
if isdefined(p, :inv)
inv_imgs = copy(p.inv.images)
q⁻¹ = typeof(p)(inv_imgs, false)
q⁻¹ = typeof(p)(inv_imgs; check = false)
q.inv = q⁻¹
q⁻¹.inv = q
end
Expand All @@ -78,7 +74,7 @@ AP.inttype(::Type{Perm}) = UInt16

function Base.inv::Perm)
if !isdefined(σ, :inv)
σ⁻¹ = typeof(σ)(invperm.images), false)
σ⁻¹ = typeof(σ)(invperm.images); check = false)
σ.inv = σ⁻¹
σ⁻¹.inv = σ
end
Expand All @@ -95,10 +91,10 @@ AP.inttype(::Type{Perm}) = UInt16
else
function Base.copy(p::Perm)
imgs = copy(p.images)
q = typeof(p)(imgs, false)
q = typeof(p)(imgs; check = false)
if isdefined(p, :inv, :sequentially_consistent)
inv_imgs = copy(@atomic(p.inv).images)
q⁻¹ = typeof(p)(inv_imgs, false)
q⁻¹ = typeof(p)(inv_imgs; check = false)
@atomic q.inv = q⁻¹
@atomic q⁻¹.inv = q
end
Expand All @@ -110,7 +106,7 @@ else
if isone(σ)
@atomic σ.inv = σ
else
σ⁻¹ = typeof(σ)(invperm.images), false)
σ⁻¹ = typeof(σ)(invperm.images); check = false)
# we don't want to end up with two copies of inverse σ floating around
if !isdefined(σ, :inv, :sequentially_consistent)
@atomic σ.inv = σ⁻¹
Expand Down
3 changes: 2 additions & 1 deletion src/Perms/perm_static.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ struct SPerm{N} <: AP.AbstractPermutation
end

function SPerm{N}(
images::AbstractVector{<:Integer},
images::AbstractVector{<:Integer};
check::Bool = true,
) where {N}
@assert length(images) N "vector too large for SPerm"
Expand All @@ -37,6 +37,7 @@ function Base.:^(n::Integer, σ::SPerm)
end
AP.degree::SPerm) = σ.degree
AP.inttype(::Type{<:SPerm}) = UInt8
AP.__unsafe_image(n::Integer, σ::SPerm) = oftype(n, @inbounds σ.images[n])

function Base.inv::SPerm{N}) where {N}
return SPerm{N}(invperm.images), AP.degree(σ))
Expand Down
8 changes: 8 additions & 0 deletions src/group_interface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ else
end
GroupsCore.gens(G::PermGroup) = Permutation.(G.__gens_raw, Ref(G))

function Random.Sampler(
RNG::Type{<:Random.AbstractRNG},
G::AbstractPermutationGroup,
repetition::Random.Repetition = Val(Inf),
)
return Random.SamplerTrivial(G)
end

function Base.rand(
rng::Random.AbstractRNG,
rs::Random.SamplerTrivial{Gr},
Expand Down
2 changes: 1 addition & 1 deletion src/perm_group.jl
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ function Base.:^(σ::Permutation{P}, τ::AbstractPermutation) where {P}
img[i^τ] = (i^σ)^τ
end

res = P(img, false)
res = P(img; check = false)
@assert res in parent(σ)
return Permutation(res, parent(σ))
end
Expand Down
83 changes: 0 additions & 83 deletions test/AbstractPerm_interface.jl

This file was deleted.

Loading

2 comments on commit 68d302c

@kalmarek
Copy link
Owner

@kalmarek kalmarek commented on 68d302c Dec 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator register

Breaking changes

  • AbstractPermutations-0.3 which require kwarg check::Bool in the interface permutation-from-images constructor

Features

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/97283

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.6.0 -m "<description of version>" 68d302ceb18940cef84c0624508fc6813cd7a1f4
git push origin v0.6.0

Please sign in to comment.