Skip to content

Commit e72ed73

Browse files
committed
Add unsafe (non-checking) permute
1 parent 1a57b5e commit e72ed73

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/TupleTools.jl

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,8 +259,11 @@ Get the indices `t[i] for i in I`, again as tuple.
259259
260260
Permute the elements of tuple `t` according to the permutation in `p`.
261261
"""
262-
@inline permute(t::NTuple{N,Any}, p::NTuple{N,Int}) where {N} = isperm(p) ? getindices(t, p) : throw(ArgumentError("not a valid permutation: $p"))
263-
@inline permute(t::NTuple{N,Any}, p) where {N} = isperm(p) && length(p) == N ? ntuple(n->t[p[n]], StaticLength(N)) : throw(ArgumentError("not a valid permutation: $p"))
262+
@inline permute(t::NTuple{N,Any}, p::NTuple{N,Int}) where {N} = isperm(p) ? _permute(t, p) : throw(ArgumentError("not a valid permutation: $p"))
263+
@inline permute(t::NTuple{N,Any}, p) where {N} = isperm(p) && length(p) == N ? _permute(t,p) : throw(ArgumentError("not a valid permutation: $p"))
264+
265+
@inline _permute(t::NTuple{N,Any}, p::NTuple{N,Int}) where {N} = getindices(t, p)
266+
@inline _permute(t::NTuple{N,Any}, p) where {N} = ntuple(n->t[p[n]], StaticLength(N))
264267

265268
"""
266269
invperm(p::NTuple{N,Int}) -> ::NTuple{N,Int}

0 commit comments

Comments
 (0)