StaticPermutations

Base.PermutedDimsArrays.PermutedDimsArrayMethod
PermutedDimsArray(A, perm::AbstractPermutation) -> B

Alternative PermutedDimsArray constructor taking a static permutation.

In contrast to the base constructors, the returned type is fully inferred here.

source
Core.TupleMethod
Tuple(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
source
StaticPermutations.NoPermutationType
NoPermutation <: AbstractPermutation

Represents an identity permutation.

It is functionally equivalent to Permutation(1, 2, 3, ...), and is included for convenience.

source
StaticPermutations.PermutationType
Permutation{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))
source
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)
source
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)
source
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
source
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.

source
Base.invMethod
inv(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
source
Base.ispermMethod
isperm(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
source
Base.lengthMethod
length(perm::AbstractPermutation)

Returns length of permutation.

For NoPermutation, returns nothing.

Examples

julia> length(Permutation(3, 2, 1))
3

julia> length(NoPermutation()) === nothing
true
source
StaticPermutations.appendMethod
append(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()
source
StaticPermutations.isidentityMethod
isidentity(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
source
StaticPermutations.prependMethod
prepend(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()
source