JuliaArrays / JuliaArrays/AxisArrays.jl

Axes are copied when taking a view

Open
#147 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Julia
Stars
207
Forks
41
PR merge metrics
No merged PRs in 30d

Description

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.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with src/indexing.jl around line 80 and reproduce the allocation shown in the issue using the DateTime AxisArray example. Determine whether view should preserve the original axes, then verify the intended behavior and allocation impact with the provided BenchmarkTools expression.

Written by the indexing model from the issue text.

Assessment

Tech stack
julia
Domain
data
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.