Skip to content

Commit f319fb6

Browse files
Tokazamachriselrod
andauthored
StaticInt support for ntuple (#65)
* StaticInt support for ntuple * Update src/Static.jl Co-authored-by: Chris Elrod <[email protected]> Co-authored-by: Chris Elrod <[email protected]>
1 parent eb4ba62 commit f319fb6

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "Static"
22
uuid = "aedffcd0-7271-4cad-89d0-dc628f76c6d3"
33
authors = ["chriselrod", "ChrisRackauckas", "Tokazama"]
4-
version = "0.7"
4+
version = "0.7.1"
55

66
[deps]
77
IfElse = "615f187c-cbe4-4ef1-ba3b-2fcf58d6d173"

src/Static.jl

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -481,8 +481,19 @@ Base.:(^)(x::Integer, y::True) = x
481481
Base.:(^)(x::BigInt, y::False) = one(x)
482482
Base.:(^)(x::BigInt, y::True) = x
483483

484+
@inline function Base.ntuple(f::F, ::StaticInt{N}) where {F,N}
485+
(N >= 0) || throw(ArgumentError(string("tuple length should be ≥ 0, got ", N)))
486+
if @generated
487+
quote
488+
Base.Cartesian.@ntuple $N i -> f(i)
489+
end
490+
else
491+
Tuple(f(i) for i = 1:N)
492+
end
493+
end
494+
484495
@inline function invariant_permutation(@nospecialize(x::Tuple), @nospecialize(y::Tuple))
485-
if y === x === nstatic(Val(nfields(x)))
496+
if y === x === ntuple(static, StaticInt(nfields(x)))
486497
return True()
487498
else
488499
return False()

0 commit comments

Comments
 (0)