Skip to content

Commit

Permalink
StaticInt support for ntuple (#65)
Browse files Browse the repository at this point in the history
* StaticInt support for ntuple

* Update src/Static.jl

Co-authored-by: Chris Elrod <[email protected]>

Co-authored-by: Chris Elrod <[email protected]>
  • Loading branch information
Tokazama and chriselrod authored Jun 16, 2022
1 parent eb4ba62 commit f319fb6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "Static"
uuid = "aedffcd0-7271-4cad-89d0-dc628f76c6d3"
authors = ["chriselrod", "ChrisRackauckas", "Tokazama"]
version = "0.7"
version = "0.7.1"

[deps]
IfElse = "615f187c-cbe4-4ef1-ba3b-2fcf58d6d173"
Expand Down
13 changes: 12 additions & 1 deletion src/Static.jl
Original file line number Diff line number Diff line change
Expand Up @@ -481,8 +481,19 @@ Base.:(^)(x::Integer, y::True) = x
Base.:(^)(x::BigInt, y::False) = one(x)
Base.:(^)(x::BigInt, y::True) = x

@inline function Base.ntuple(f::F, ::StaticInt{N}) where {F,N}
(N >= 0) || throw(ArgumentError(string("tuple length should be ≥ 0, got ", N)))
if @generated
quote
Base.Cartesian.@ntuple $N i -> f(i)
end
else
Tuple(f(i) for i = 1:N)
end
end

@inline function invariant_permutation(@nospecialize(x::Tuple), @nospecialize(y::Tuple))
if y === x === nstatic(Val(nfields(x)))
if y === x === ntuple(static, StaticInt(nfields(x)))
return True()
else
return False()
Expand Down

2 comments on commit f319fb6

@Tokazama
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/62456

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.7.1 -m "<description of version>" f319fb6c49a41243ce03b3176bfdeb805f159e2b
git push origin v0.7.1

Please sign in to comment.