|
1 | | -__precompile__(true) |
| 1 | +""" |
| 2 | +Type stable methods for small tuples |
| 3 | +""" |
2 | 4 | module TupleTools |
3 | 5 |
|
4 | 6 | using Base: tuple_type_head, tuple_type_tail, tuple_type_cons, tail, front, setindex |
@@ -26,12 +28,7 @@ Base.@pure StaticLength(N::Int) = StaticLength{N}() |
26 | 28 | Base.@pure Base.:+(::StaticLength{N₁}, ::StaticLength{N₂}) where {N₁,N₂} = StaticLength(N₁+N₂) |
27 | 29 | Base.@pure Base.:-(::StaticLength{N₁}, ::StaticLength{N₂}) where {N₁,N₂} = StaticLength(max(0,N₁-N₂)) |
28 | 30 |
|
29 | | -if VERSION < v"0.7.0-DEV.843" |
30 | | - @inline Base.ntuple(f, ::StaticLength{N}) where {N} = ntuple(f, Val{N}) |
31 | | -else |
32 | | - @inline Base.ntuple(f, ::StaticLength{N}) where {N} = ntuple(f, Val{N}()) |
33 | | -end |
34 | | - |
| 31 | +@inline Base.ntuple(f, ::StaticLength{N}) where {N} = ntuple(f, Val{N}()) |
35 | 32 | @inline argtail2(a, b, c...) = c |
36 | 33 |
|
37 | 34 | """ |
@@ -327,4 +324,13 @@ Inverse permutation of a permutation `p`. |
327 | 324 | """ |
328 | 325 | invperm(p::Tuple{Vararg{Int}}) = sortperm(p) |
329 | 326 |
|
| 327 | +""" |
| 328 | + diff(v::Tuple) -> Tuple |
| 329 | +
|
| 330 | +Finite difference operator of tuple `v`. |
| 331 | +""" |
| 332 | +diff(v::Tuple{}) = () # similar to diff([]) |
| 333 | +diff(v::Tuple{Any}) = () |
| 334 | +diff(v::Tuple) = (v[2]-v[1], diff(Base.tail(v))...) |
| 335 | + |
330 | 336 | end # module |
0 commit comments