Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
A rearrangement is a generalisation of transposition, where the dimensions are arbitrarily permuted.
Synopsis
- rearrangeShape :: [Int] -> [a] -> [a]
- rearrangeInverse :: [Int] -> [Int]
- rearrangeReach :: [Int] -> Int
- rearrangeCompose :: [Int] -> [Int] -> [Int]
- isPermutationOf :: Eq a => [a] -> [a] -> Maybe [Int]
- transposeIndex :: Int -> Int -> [a] -> [a]
- isMapTranspose :: [Int] -> Maybe (Int, Int, Int)
Documentation
rearrangeShape :: [Int] -> [a] -> [a] Source #
Calculate the given permutation of the list. It is an error if the permutation goes out of bounds.
rearrangeInverse :: [Int] -> [Int] Source #
Produce the inverse permutation.
rearrangeReach :: [Int] -> Int Source #
Return the first dimension not affected by the permutation. For
example, the permutation [1,0,2]
would return 2
.
rearrangeCompose :: [Int] -> [Int] -> [Int] Source #
Compose two permutations, with the second given permutation being applied first.
isPermutationOf :: Eq a => [a] -> [a] -> Maybe [Int] Source #
Check whether the first list is a permutation of the second, and if so, return the permutation. This will also find identity permutations (i.e. the lists are the same) The implementation is naive and slow.
transposeIndex :: Int -> Int -> [a] -> [a] Source #
If l
is an index into the array a
, then transposeIndex k n
l
is an index to the same element in the array transposeArray k n
a
.
isMapTranspose :: [Int] -> Maybe (Int, Int, Int) Source #
If perm
is conceptually a map of a transposition,
isMapTranspose perm
returns the number of dimensions being mapped
and the number dimension being transposed. For example, we can
consider the permutation [0,1,4,5,2,3]
as a map of a transpose,
by considering dimensions [0,1]
, [4,5]
, and [2,3]
as single
dimensions each.
If the input is not a valid permutation, then the result is undefined.