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

Dispatch to efficient methods for map(func, AbDimArray) and reduce(..., dims=:) #14

Merged
merged 1 commit into from
Oct 18, 2019

Conversation

ivirshup
Copy link
Contributor

Adding a couple more methods I found that are slower than they could be. Using this setup:

using DimensionalData
using DimensionalData: X, Y
using SparseArrays
using BenchmarkTools

s = sprand(1000, 1000, .1)
sd = DimensionalArray(s, (X <| 1:1000, Y <| 1:1000))

On 9a6b121:

julia> @btime map(sin, $s);
  944.490 μs (6 allocations: 1.54 MiB)

julia> @btime map(sin, $sd);
  3.355 s (10 allocations: 3.07 MiB)

julia> @btime reduce(+, $s);
  19.714 μs (1 allocation: 48 bytes)

julia> @btime reduce(+, $sd);
  11.689 ms (8 allocations: 160 bytes)

In this PR:

julia> @btime map(sin, $s);
  941.790 μs (6 allocations: 1.54 MiB)

julia> @btime map(sin, $sd);
  941.316 μs (7 allocations: 1.54 MiB)

julia> @btime reduce(+, $s);
  19.799 μs (1 allocation: 48 bytes)

julia> @btime reduce(+, $sd);
  19.812 μs (1 allocation: 48 bytes)

This doesn't cover the case of map(f, ::Varargs{<:AbDimArray, N}) since I wasn't sure what to do if the dimensions don't match.

@rafaqz rafaqz merged commit d9546f0 into rafaqz:master Oct 18, 2019
@rafaqz
Copy link
Owner

rafaqz commented Oct 18, 2019

Thanks!

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