StaticPermutations
Base.PermutedDimsArrays.PermutedDimsArray
Core.Tuple
StaticPermutations.AbstractPermutation
StaticPermutations.NoPermutation
StaticPermutations.Permutation
Base.:*
Base.:*
Base.:/
Base.:\
Base.inv
Base.isperm
Base.length
StaticPermutations.append
StaticPermutations.identity_permutation
StaticPermutations.isidentity
StaticPermutations.prepend
Base.PermutedDimsArrays.PermutedDimsArray
— MethodPermutedDimsArray(A, perm::AbstractPermutation) -> B
Alternative PermutedDimsArray
constructor taking a static permutation.
In contrast to the base constructors, the returned type is fully inferred here.
Core.Tuple
— MethodTuple(perm::Permutation)
Extract tuple representation of Permutation.
The result can be passed to permutedims
and PermutedDimsArray
.
Returns nothing
if perm
is a NoPermutation
.
Examples
julia> Tuple(Permutation(3, 2, 1))
(3, 2, 1)
julia> Tuple(NoPermutation()) === nothing
true
StaticPermutations.AbstractPermutation
— TypeAbstractPermutation
Abstract type representing a compile-time permutation.
Subtypes are Permutation
and NoPermutation
.
StaticPermutations.NoPermutation
— TypeNoPermutation <: AbstractPermutation
Represents an identity permutation.
It is functionally equivalent to Permutation(1, 2, 3, ...)
, and is included for convenience.
StaticPermutations.Permutation
— TypePermutation{p} <: AbstractPermutation
Describes a compile-time dimension permutation.
The type parameter p
should be a valid permutation such as (3, 1, 2)
.
Permutation(perm::Vararg{Int})
Permutation(perm::NTuple{N,Int})
Constructs a Permutation
.
Example
Both are equivalent:
p1 = Permutation(3, 4)
p2 = Permutation((3, 4))
Base.:*
— Method*(p::AbstractPermutation, collection)
Apply permutation to the given collection.
The collection may be a Tuple
or a CartesianIndex
to be reordered. If p
is a Permutation
, the collection must have the same length as p
.
Examples
julia> p = Permutation(2, 3, 1);
julia> p * (36, 42, 14)
(42, 14, 36)
julia> p * CartesianIndex(36, 42, 14)
CartesianIndex(42, 14, 36)
Base.:*
— Method*(p::AbstractPermutation, q::AbstractPermutation)
Compose two permutations: apply permutation p
to permutation q
.
Note that permutation composition is non-commutative.
Examples
julia> p = Permutation(2, 3, 1);
julia> q = Permutation(1, 3, 2);
julia> p * q
Permutation(3, 2, 1)
julia> q * p
Permutation(2, 1, 3)
julia> p * inv(p)
Permutation(1, 2, 3)
julia> inv(p) * p
Permutation(1, 2, 3)
Base.:/
— Method/(y::AbstractPermutation, x::AbstractPermutation)
Get relative permutation needed to get from x
to y
. That is, the permutation p
such that p * x == y
.
Examples
julia> x = Permutation(3, 1, 2);
julia> y = Permutation(2, 1, 3);
julia> p = y / x
Permutation(3, 2, 1)
julia> p * x == y
true
Base.:\
— Method\(p::AbstractPermutation, x)
Undo permutation p
from permuted collection x
.
In other words, apply inverse of permutation p
to x
. This is effectively equivalent to inv(p) * x
.
Base.inv
— Methodinv(p::Permutation)
invperm(p::Permutation)
Returns the inverse permutation of p
.
Functionally equivalent to Julia's invperm
, with the advantage that the result is a compile time constant.
See also /
.
Examples
julia> p = Permutation(2, 3, 1);
julia> q = inv(p)
Permutation(3, 1, 2)
julia> t_orig = (36, 42, 14);
julia> t_perm = p * t_orig
(42, 14, 36)
julia> q * t_perm === t_orig
true
Base.isperm
— Methodisperm(perm::AbstractPermutation) -> Bool
Returns true
if perm
is a valid permutation, false
otherwise.
The result is known at compile time.
Examples
julia> isperm(Permutation(3, 1, 2))
true
julia> isperm(Permutation(4, 1, 2))
false
julia> isperm(NoPermutation())
true
Base.length
— Methodlength(perm::AbstractPermutation)
Returns length of permutation.
For NoPermutation
, returns nothing
.
Examples
julia> length(Permutation(3, 2, 1))
3
julia> length(NoPermutation()) === nothing
true
StaticPermutations.append
— Methodappend(p::Permutation, ::Val{M})
Append M
non-permuted dimensions to the given permutation.
Examples
julia> append(Permutation(2, 3, 1), Val(2))
Permutation(2, 3, 1, 4, 5)
julia> append(NoPermutation(), Val(2))
NoPermutation()
StaticPermutations.identity_permutation
— Methodidentity_permutation(::Val{N})
identity_permutation(A::AbstractArray{T,N})
Returns the identity permutation Permutation(1, 2, ..., N)
.
StaticPermutations.isidentity
— Methodisidentity(p::Permutation)
Returns true
if p
is an identity permutation, i.e. if it is equivalent to (1, 2, 3, ...)
.
julia> isidentity(Permutation(1, 2, 3))
true
julia> isidentity(Permutation(1, 3, 2))
false
julia> isidentity(NoPermutation())
true
StaticPermutations.prepend
— Methodprepend(p::Permutation, ::Val{M})
Prepend M
non-permuted dimensions to the given permutation.
Examples
julia> prepend(Permutation(2, 3, 1), Val(2))
Permutation(1, 2, 4, 5, 3)
julia> prepend(NoPermutation(), Val(2))
NoPermutation()