-
-
Notifications
You must be signed in to change notification settings - Fork 5.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add specialized reverse
implementation for NTuple
#50113
Conversation
This adds a specialized version of `reverse` for NTuple using a simple constructor. 1.9: ``` julia> a = tuple(rand(Int, 256)...); julia> @benchmark reverse($a) BenchmarkTools.Trial: 7099 samples with 1 evaluation. Range (min … max): 611.280 μs … 5.698 ms ┊ GC (min … max): 0.00% … 0.00% Time (median): 670.392 μs ┊ GC (median): 0.00% Time (mean ± σ): 700.950 μs ± 144.952 μs ┊ GC (mean ± σ): 1.37% ± 5.70% ▃▄██▇▆▆▆▆▄▂ ▂ ▇███████████▇▇▆▄▇█▅▅▅▃▄▁▁▁▁▃▄▄▁▁▁▃▁▃▁▁▄▃▄▅▆▅▆▆▅▅▆▇▆▆▇▇▇█▇▆▇▇▆ █ 611 μs Histogram: log(frequency) by time 1.33 ms < Memory estimate: 794.42 KiB, allocs estimate: 33663. ``` This commit: ``` julia> @benchmark reverse($a) BenchmarkTools.Trial: 10000 samples with 995 evaluations. Range (min … max): 26.252 ns … 52.545 ns ┊ GC (min … max): 0.00% … 0.00% Time (median): 26.285 ns ┊ GC (median): 0.00% Time (mean ± σ): 26.578 ns ± 0.940 ns ┊ GC (mean ± σ): 0.00% ± 0.00% █▆▂ ▁ ▁ ████▆▅▆▅▄▄▄▂▃▄███▇▆▆▆▅▆▄▅▅▆█▇▆▄▅▆▆▅▆██▅▅▅▄▅▅▄▅▄▅▅▅▄▅▃▅▂▄▄██ █ 26.3 ns Histogram: log(frequency) by time 30.2 ns < Memory estimate: 0 bytes, allocs estimate: 0. ```
reverse
implementation for NTuplereverse
implementation for NTuple
reverse
implementation for NTuplereverse
implementation for NTuple
Many other tuple functions have a limit size for when they stop specialising. Shouldn't that be the case here too? |
Yes, that happens automatically with the non- |
The other |
|
||
# Specialized extensions for NTuple | ||
function reverse(t::NTuple{N}) where N | ||
ntuple(Val{N}()) do i |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is better than Val(N)
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It doesn't matter. Usually Val(N)
is preferred as it is more concise, but it desugars to effectively the same thing.
This adds a specialized version of
reverse
for NTupleusing a simple constructor.
1.9:
This commit: