Skip to content

Axes are copied when taking a view #147

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

Open
kcajf opened this issue Sep 26, 2018 · 2 comments
Open

Axes are copied when taking a view #147

kcajf opened this issue Sep 26, 2018 · 2 comments

Comments

@kcajf
Copy link

kcajf commented Sep 26, 2018

Having looked at the source code it is clear that when taking a view of an AxisArray, the indexed axes might be copied if _new_axes is called (https://github.com/JuliaArrays/AxisArrays.jl/blob/master/src/indexing.jl#L80). Is this the intended behaviour? It would make more sense to me for views to be taken of the original axes as well, to aid performance.

Example below (there is 16KB of allocation - i.e. the index copy)

using Dates
using AxisArrays
using BenchmarkTools

index = collect(DateTime(2018, 1, 1):Minute(1):DateTime(2018, 1, 10))
B = AxisArray(randn(Float64, (length(index), 10)), index)

@btime view(B, 1000:3000, :)
# 994.800 ns (6 allocations: 15.98 KiB)

If this should be fixed / changed, I'm happy to give a PR a go.

@kcajf
Copy link
Author

kcajf commented Dec 12, 2018

Does anyone strongly oppose this? I think it's important to somehow have the ability to avoid copying the axes, even if not via this syntax.

@timholy
Copy link
Member

timholy commented Dec 12, 2018

In this example, do you need to call collect? If you skip the collect, presumably it's also fast and allocation-free?

But of course there may be cases where you can't use a range, and hence this seems like a reasonable idea. I'll comment over in #148.

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

2 participants