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

Remove unnecessary splatting from the code fo adjoint of [hv]cat #504

Closed
wants to merge 1 commit into from

Conversation

AzamatB
Copy link
Contributor

@AzamatB AzamatB commented Feb 7, 2020

No description provided.

@oxinabox
Copy link
Member

oxinabox commented Feb 8, 2020

If we are going to microoptimize, I suggest we do it a bit more heavily:

Benchmarking:

julia> const xs = (ones(4,4), ones(5,5), ones(8,7));

julia> f(x) = cumsum(collect(size.(x,1)))
f (generic function with 1 method)

julia> g(x) = cumsum([size.(x,1)...])
g (generic function with 1 method)

julia> function h(x)
       r = collect(size.(x,1))
       cumsum!(r,r)
       end
h (generic function with 1 method)

julia> function i(x)
       k = Ref(0)
       ntuple(length(x)) do i
       @inbounds k[]+=size(x[i],1)
       end
       end
i (generic function with 1 method)
julia> @btime f($xs)
  60.529 ns (2 allocations: 224 bytes)

julia> @btime g($xs)
  59.682 ns (2 allocations: 224 bytes)

julia> @btime h($xs)
  36.109 ns (1 allocation: 112 bytes);

julia> @btime i($xs);
  1.251 ns (0 allocations: 0 bytes)

@mcabbott
Copy link
Member

mcabbott commented Feb 8, 2020

Sounds like a use case for JuliaLang/julia#34654.

@CarloLucibello
Copy link
Member

closing as stale

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.

4 participants