https://github.com/jipolanco/staticpermutations.jl
Fast dimension permutations of Julia arrays
https://github.com/jipolanco/staticpermutations.jl
julia permutations
Last synced: 16 days ago
JSON representation
Fast dimension permutations of Julia arrays
- Host: GitHub
- URL: https://github.com/jipolanco/staticpermutations.jl
- Owner: jipolanco
- License: mit
- Created: 2020-11-05T07:55:11.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2024-10-11T08:07:26.000Z (7 months ago)
- Last Synced: 2025-04-13T16:12:58.620Z (16 days ago)
- Topics: julia, permutations
- Language: Julia
- Homepage:
- Size: 305 KB
- Stars: 6
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# StaticPermutations
[](https://jipolanco.github.io/StaticPermutations.jl/stable) [](https://jipolanco.github.io/StaticPermutations.jl/dev) [](https://github.com/jipolanco/StaticPermutations.jl/actions) [](https://codecov.io/gh/jipolanco/StaticPermutations.jl)
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](https://jipolanco.github.io/StaticPermutations.jl/dev) for a list of implemented methods.## Quick start
```julia
julia> using StaticPermutationsjulia> 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
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
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
julia> x′ = perm \ y # same as inv(perm) * y
(42, 12, 32)julia> x′ == x
true
```