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

Create vsum #496

Merged
merged 3 commits into from
May 22, 2023
Merged

Create vsum #496

merged 3 commits into from
May 22, 2023

Conversation

MilesCranmer
Copy link
Contributor

@MilesCranmer MilesCranmer commented May 21, 2023

This creates a vectorized version of sum, as has been done with vmapreduce and vreduce already. The implementation is just an alias:

@inline vsum(f::F, A::AbstractArray{T}) where {F,T<:NativeTypes} = vmapreduce(f, +, A)
@inline vsum(A::AbstractArray{T}) where {T<:NativeTypes} = vsum(identity, A)

(There is a vsum in VectorizationBase.jl; that one is I think (?) an internal utility, as it doesn't take normal arrays.)

For example:

julia> using LoopVectorization, BenchmarkTools

julia> x = rand(127);

julia> @btime vsum(hypot, $x)
  12.095 ns (0 allocations: 0 bytes)
66.65246070098374

julia> @btime sum(hypot, $x)
  16.992 ns (0 allocations: 0 bytes)
66.65246070098372

@codecov
Copy link

codecov bot commented May 21, 2023

Codecov Report

Patch coverage: 100.00% and project coverage change: -1.13 ⚠️

Comparison is base (d0c61d3) 86.78% compared to head (1063410) 85.65%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #496      +/-   ##
==========================================
- Coverage   86.78%   85.65%   -1.13%     
==========================================
  Files          39       39              
  Lines        9524     9524              
==========================================
- Hits         8265     8158     -107     
- Misses       1259     1366     +107     
Impacted Files Coverage Δ
src/LoopVectorization.jl 100.00% <ø> (ø)
src/simdfunctionals/mapreduce.jl 92.63% <100.00%> (+0.15%) ⬆️

... and 5 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

Copy link
Member

@chriselrod chriselrod left a comment

Choose a reason for hiding this comment

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

@chriselrod
Copy link
Member

You need to export vsum if you're testing that it is exported.
The oftype failures on nightly are unrelated to this PR.

@MilesCranmer
Copy link
Contributor Author

Fixed, thanks.

That package looks super useful, I didn’t know about it. It might be a good idea to ask and try to bring it under the JuliaSIMD organization, for consistency and long term support. I think having it seem like a more “official” package would make me more likely to use it.

@MilesCranmer
Copy link
Contributor Author

Oh I didn’t know about VectorizedStatistics! Should I close this PR?

@chriselrod chriselrod merged commit ab24678 into JuliaSIMD:main May 22, 2023
@chriselrod
Copy link
Member

vsum is simple enough so that it's fine. But maybe we shouldn't export it if they do.

@andrewjradcliffe you're welcome to move your package to JuliaSIMD if you'd like.

@MilesCranmer MilesCranmer deleted the create-vsum branch May 22, 2023 12:25
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants