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

Dropdims is surprisingly slow #85

Open
mcabbott opened this issue Nov 23, 2019 · 2 comments
Open

Dropdims is surprisingly slow #85

mcabbott opened this issue Nov 23, 2019 · 2 comments
Labels
help wanted Extra attention is needed

Comments

@mcabbott
Copy link
Collaborator

mcabbott commented Nov 23, 2019

I don’t have a solution, but notice this:

julia> r = rand(10,1,10);

julia> @btime dropdims($r, dims=2);
  529.307 ns (9 allocations: 224 bytes)

julia> nda = NamedDimsArray(r, (:x, :_, :y));

julia> @btime dropdims($nda, dims=:_);
  7.647 μs (18 allocations: 672 bytes)

julia> @btime (() -> dropdims($nda, dims=2))();
  7.533 μs (18 allocations: 672 bytes)

julia> @btime NamedDims.remaining_dimnames_after_dropping((:x, :_, :y), 2)
  1.419 ns (0 allocations: 0 bytes)
(:x, :y)

Not really related, but also notice that dropdims doesn’t match repeated names, perhaps it should?

julia> ndb = NamedDimsArray(ones(2,1,2,1), (:x, :_, :y, :_));

julia> dropdims(ndb, dims=:_)
2×2×1 NamedDimsArray{(:x, :y, :_),Float64,3,Array{Float64,3}}:
[:, :, 1] =
 1.0  1.0
 1.0  1.0

julia> dropdims(dropdims(ndb, dims=:_), dims=:_)
2×2 NamedDimsArray{(:x, :y),Float64,2,Array{Float64,2}}:
 1.0  1.0
 1.0  1.0
@nickrobinson251
Copy link
Contributor

dropdims doesn’t match repeated names, perhaps it should?

I'm less worried about that one, since we treat operations on duplicate names as undefined behaviour.

@mcabbott
Copy link
Collaborator Author

Oh I don’t claim that’s a bug, sorry if that wasn’t clear, just something to think about. But at some point the behaviour is defined by how it behaves (or should be made an error if it’s never to be used). Anyway perhaps an orthogonal issue to the title.

@nickrobinson251 nickrobinson251 added the help wanted Extra attention is needed label Jul 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants