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

@inbounds for array rounding #22

Closed
milankl opened this issue Dec 1, 2021 · 1 comment
Closed

@inbounds for array rounding #22

milankl opened this issue Dec 1, 2021 · 1 comment

Comments

@milankl
Copy link
Owner

milankl commented Dec 1, 2021

function Base.round(X::AbstractArray{Float32},nsb::Integer)

@inbounds is missing in these loops which shaves off about 2x of benchmarks

julia> @btime round(A,5);
  11.977 ms (2 allocations: 38.15 MiB)

julia> @btime round2(A,5);
  5.447 ms (2 allocations: 38.15 MiB)

with round2 being

function round2(X::AbstractArray{Float32},nsb::Integer)
           semask = setmask32(nsb)
           s = shift32(nsb)
           shmask = ~mask32(nsb)

           Y = similar(X)                              # preallocate
           @inbounds for i in eachindex(X)
               Y[i] = round(X[i],semask,s,shmask)
           end
           
           return Y
       end
@milankl
Copy link
Owner Author

milankl commented Dec 7, 2021

adressed with #23

@milankl milankl closed this as completed Dec 8, 2021
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

No branches or pull requests

1 participant