Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
nrontsis committed Dec 24, 2022
1 parent cbb24ef commit 4b0bb8e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
6 changes: 5 additions & 1 deletion src/array_interface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,11 @@ Base.@propagate_inbounds Base.maybeview(x::ComponentArray, idx...) = _getindex(B
inds = map(i -> i.idx, ci)
axs = map(i -> i.ax, ci)
axs = remove_nulls(axs...)
return :(ComponentArray(index_fun(getdata(x), $inds...), $axs...))
if isa(axs, Tuple{})
return :(index_fun(getdata(x), $inds...))
else
return :(ComponentArray(index_fun(getdata(x), $inds...), $axs...))
end
end

@generated function _setindex!(x::ComponentArray, v, idx...)
Expand Down
4 changes: 2 additions & 2 deletions src/axis.jl
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ function Base.getindex(ax::AbstractAxis, syms::Union{NTuple{N,Symbol}, <:Abstrac
_maybe_view_axis(first_index:last_index, ax)
end
new_ax = Axis(NamedTuple(syms .=> new_axs))
return ComponentIndex(reduce(vcat, inds), new_ax)
return ComponentIndex(vcat(inds...), new_ax)
end

_maybe_view_axis(inds, ax::Axis) = ViewAxis(inds, ax)
Expand Down Expand Up @@ -202,4 +202,4 @@ Base.getindex(ax::CombinedAxis, i::AbstractArray) = _array_axis(ax)[i]

Base.length(ax::CombinedAxis) = lastindex(ax) - firstindex(ax) + 1

Base.CartesianIndices(ax::Tuple{Vararg{CombinedAxis}}) = CartesianIndices(_array_axis.(ax))
Base.CartesianIndices(ax::Tuple{Vararg{CombinedAxis}}) = CartesianIndices(_array_axis.(ax))
5 changes: 4 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,10 @@ end
@test ca.c == ComponentArray(c)
@test ca2.b[1].a.a == 20.0

@test ca[:a] == ca["a"] == ca.a
@test ca[:a] == ca["a"] == ca.a == ca[[:a]][1]
@test ca[[:a]] isa ComponentVector # Issue 175
@test ca[Symbol[]] == Float64[] # Issue 174
@test length(ca[()]) == 0 # Issue #174
@test ca[:b] == ca["b"] == ca.b
@test ca[:c] == ca["c"] == ca.c

Expand Down

0 comments on commit 4b0bb8e

Please sign in to comment.