jipolanco / StaticPermutations.jl

Fast dimension permutations of Julia arrays

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

StaticPermutations

Stable Dev Build Status Coverage

Tools for dealing with compile-time dimension permutations of Julia arrays.

This package defines a Permutation type describing a permutation of dimensions. Permutations can be composed, inverted, applied to collections and reverted, among other operations. All these operations have zero runtime cost, since they are performed using the static information encoded in the Permutation type. See the documentation for a list of implemented methods.

Quick start

julia> using StaticPermutations

julia> perm = Permutation(2, 3, 1)
Permutation(2, 3, 1)

julia> typeof(perm)
Permutation{(2, 3, 1),3}

Permutations can be inverted and composed. The resulting permutation is always fully inferred.

julia> inv(perm)  # same as invperm(perm)
Permutation(3, 1, 2)

julia> q = Permutation(3, 2, 1);

# Composition is performed using the `*` operator.
julia> perm * q
Permutation(2, 1, 3)

# Note that composition is non-commutative.
julia> q * perm
Permutation(1, 3, 2)

Permutations are applied to collections using the * operator:

julia> x = (42, 12, 32)  # these may be array indices, for instance
(42, 12, 32)

julia> y = perm * x
(12, 32, 42)

Permutations may be reverted using the \ operator:

julia> x′ = perm \ y  # same as inv(perm) * y
(42, 12, 32)

julia> x′ == x
true

About

Fast dimension permutations of Julia arrays

License:MIT License


Languages

Language:Julia 100.0%