Skip to content
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

Define mapfoldl/foldl for static arrays #750

Merged
merged 2 commits into from
Mar 3, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Link to specialization tips in the Julia manual
  • Loading branch information
tkf committed Mar 3, 2020
commit cf9a19014dcc01f34f37b13b384486f71fed1a55
6 changes: 5 additions & 1 deletion src/mapreduce.jl
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,11 @@ reduce(::typeof(hcat), A::StaticArray{<:Tuple,<:StaticVecOrMatLike}) =
## (map)foldl ##
################

@inline mapfoldl(f, op::R, a::StaticArray; init = _InitialValue()) where {R} =
# Using `where {R}` to force specialization. See:
# https://docs.julialang.org/en/v1.5-dev/manual/performance-tips/#Be-aware-of-when-Julia-avoids-specializing-1
# https://github.com/JuliaLang/julia/pull/33917

@inline mapfoldl(f::F, op::R, a::StaticArray; init = _InitialValue()) where {F,R} =
_mapfoldl(f, op, :, init, Size(a), a)
@inline foldl(op::R, a::StaticArray; init = _InitialValue()) where {R} =
_foldl(op, a, :, init)
Expand Down