Skip to content

Commit 0cd60e6

Browse files
committed
fix issue 508
1 parent 52e98c9 commit 0cd60e6

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

src/vector_of_array.jl

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -616,6 +616,33 @@ end
616616
end
617617
@inline _has_ragged_end(x, xs...) = _has_ragged_end(x) || _has_ragged_end(xs)
618618

619+
# Helper function to resolve RaggedEnd objects in a tuple of arguments
620+
@inline function _resolve_ragged_end_args(A::AbstractVectorOfArray, args::Tuple)
621+
# Handle empty tuple case
622+
length(args) == 0 && return args
623+
if !_has_ragged_end(args...)
624+
return args
625+
end
626+
# For now, we need to resolve only the last argument if it's RaggedEnd (column selector)
627+
# This handles the common case sol[:x, end] where end gets converted to RaggedEnd(0, lastindex)
628+
if args[end] isa RaggedEnd
629+
resolved_last = _column_indices(A, args[end])
630+
if length(args) == 1
631+
return (resolved_last,)
632+
else
633+
return (Base.front(args)..., resolved_last)
634+
end
635+
elseif args[end] isa RaggedRange
636+
resolved_last = _resolve_ragged_index(args[end], A, 1)
637+
if length(args) == 1
638+
return (resolved_last,)
639+
else
640+
return (Base.front(args)..., resolved_last)
641+
end
642+
end
643+
return args
644+
end
645+
619646
@inline function _ragged_getindex(A::AbstractVectorOfArray, I...)
620647
n = ndims(A)
621648
# Special-case when user provided one fewer index than ndims(A): last index is column selector.
@@ -752,7 +779,9 @@ Base.@propagate_inbounds function Base.getindex(A::AbstractVectorOfArray, _arg,
752779
_getindex(A, symtype, _arg, args...)
753780
end
754781
else
755-
_getindex(A, symtype, elsymtype, _arg, args...)
782+
# Resolve any RaggedEnd objects in args before passing to symbolic indexing
783+
resolved_args = _resolve_ragged_end_args(A, args)
784+
_getindex(A, symtype, elsymtype, _arg, resolved_args...)
756785
end
757786
end
758787

test/downstream/symbol_indexing.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,14 @@ sol_ts = sol(ts)
6363
test_tables_interface(sol_ts, [:timestamp, Symbol("x(t)"), Symbol("y(t)")],
6464
hcat(ts, Array(sol_ts)'))
6565

66+
# Test issue 508: Cannot call `to_index(::RaggedEnd)` with symbolic indexing and end
67+
@testset "Symbolic indexing with end (issue #508)" begin
68+
@test sol[x, end] isa Number
69+
@test sol[y, end] isa Number
70+
@test sol[x, end] == sol[x][end]
71+
@test sol[y, end] == sol[y][end]
72+
end
73+
6674
# Array variables
6775
using LinearAlgebra
6876
sts = @variables x(t)[1:3]=[1, 2, 3.0] y(t)=1.0

0 commit comments

Comments
 (0)