scheinerman / Permutations.jl

Permutations class for Julia.
Other
51 stars 14 forks source link

Is it possible to get permutation length in the compile time? #15

Closed adamryczkowski closed 6 years ago

adamryczkowski commented 6 years ago

I would like to have a specilized functions for different permutation sizes (I work with axes permutations, and I would like to treat 2D and 3D case specifically).

Is it possible to write an equivalent of

function foo(p::Permutations.AbstractPermutation{3})
    @info("p is a permutation of length 3")
end

That would allow having a similar interface to AbstractArray{T, N}.

scheinerman commented 6 years ago

Adam, I'm not understanding what you'd like. This package only does permutations of finite sets of the form {1,2,...,n}.

adamryczkowski commented 6 years ago

I am asking, whether the length of the permutation can be accessed at the compile time. I guess it cannot - it seems to be only a runtime feature because the Permutation itself is implemented as an Array of size length, and length of the Arrays are runtime (as opposed to the dimensionality of them).

I can wrap your Permutation with a parametric type like this

struct MyPermutation{N}
   p::Permutations.AbstractPermutation
end

...but after a second thought, I am not sure this is worth the trouble. The code that I am implementing does not need to be fast and I can break my function into multiple definitions like this: Break functions into multiple definitions