Skip to content

Commit

Permalink
let reindex ViewAxis reuse previous axis
Browse files Browse the repository at this point in the history
instead of just indexmap, fixes jonniedie#134
  • Loading branch information
bgctw committed Jun 1, 2022
1 parent 5a81362 commit ed03b81
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/axis.jl
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ Base.keys(ax::AbstractAxis) = keys(indexmap(ax))
reindex(i, offset) = i .+ offset
reindex(ax::FlatAxis, _) = ax
reindex(ax::Axis, offset) = Axis(map(x->reindex(x, offset), indexmap(ax)))
reindex(ax::ViewAxis, offset) = ViewAxis(viewindex(ax) .+ offset, indexmap(ax))
reindex(ax::ViewAxis, offset) = ViewAxis(viewindex(ax) .+ offset, ax.ax)

# Get AbstractAxis index
@inline Base.getindex(::AbstractAxis, idx) = ComponentIndex(idx)
Expand Down
7 changes: 7 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,13 @@ end
# Issue #100
chol = cholesky(cmat + I)
@test convert(Cholesky{Float32,Matrix{Float32}}, chol).factors isa Matrix{Float32}

# Issue #134
boid = ComponentArray(pos=zeros(2), vel=zeros(2))
u0 = ComponentArray(boids=repeat([boid], 2))
u0.boids
tmp = u0[KeepIndex(:boids)]
@test tmp.boids == u0.boids
end

@testset "Autodiff" begin
Expand Down

0 comments on commit ed03b81

Please sign in to comment.