Skip to content

Axes are copied when taking a view #147

Open
@kcajf

Description

@kcajf

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions