Skip to content

Fix RaggedEnd in range and returning DiffEqArray#527

Merged
ChrisRackauckas merged 5 commits intoSciML:masterfrom
JoshuaLampert:fix-range-raggedend
Jan 21, 2026
Merged

Fix RaggedEnd in range and returning DiffEqArray#527
ChrisRackauckas merged 5 commits intoSciML:masterfrom
JoshuaLampert:fix-range-raggedend

Conversation

@JoshuaLampert
Copy link
Contributor

Checklist

  • Appropriate tests were added
  • Any code changes were done in a way that does not break public API
  • All documentation related to code changes were updated
  • The new code follows the
    contributor guidelines, in particular the SciML Style Guide and
    COLPRAC.
  • Any new documentation only uses public API

Additional context

This fixes two issues:

  1. Indexing with a range, which has a start including an end fails (noticed by @iago-lito on Zulip):
    on master:
julia> u = VectorOfArray([[1.0, 2.0, 3.0], [4.0, 5.0, 6.0], [7.0, 8.0, 9.0]])
VectorOfArray{Float64,2}:
3-element Vector{Vector{Float64}}:
 [1.0, 2.0, 3.0]
 [4.0, 5.0, 6.0]
 [7.0, 8.0, 9.0]

julia> u[:, end-1:end]
ERROR: MethodError: no method matching isless(::RecursiveArrayTools.RaggedEnd, ::RecursiveArrayTools.RaggedEnd)
The function `isless` exists, but no method is defined for this combination of argument types.

Closest candidates are:
  isless(::Missing, ::Any)
   @ Base missing.jl:87
  isless(::Any, ::Missing)
   @ Base missing.jl:88
  isless(::Pkg.Resolve.VersionWeight, ::Pkg.Resolve.VersionWeight)
   @ Pkg ~/.julia/juliaup/julia-1.12.4+0.x64.linux.gnu/share/julia/stdlib/v1.12/Pkg/src/Resolve/versionweights.jl:28
  ...

Stacktrace:
 [1] <(x::RecursiveArrayTools.RaggedEnd, y::RecursiveArrayTools.RaggedEnd)
   @ Base ./operators.jl:399
 [2] <=(x::RecursiveArrayTools.RaggedEnd, y::RecursiveArrayTools.RaggedEnd)
   @ Base ./operators.jl:448
 [3] >=(x::RecursiveArrayTools.RaggedEnd, y::RecursiveArrayTools.RaggedEnd)
   @ Base ./operators.jl:472
 [4] (::Colon)(start::RecursiveArrayTools.RaggedEnd, stop::RecursiveArrayTools.RaggedEnd)
   @ Base ./range.jl:7
 [5] top-level scope
   @ REPL[6]:1

This PR:

julia> u = VectorOfArray([[1.0, 2.0, 3.0], [4.0, 5.0, 6.0], [7.0, 8.0, 9.0]])
VectorOfArray{Float64,2}:
3-element Vector{Vector{Float64}}:
 [1.0, 2.0, 3.0]
 [4.0, 5.0, 6.0]
 [7.0, 8.0, 9.0]

julia> u[:, end-1:end]
VectorOfArray{Float64,2}:
2-element Vector{Vector{Float64}}:
 [4.0, 5.0, 6.0]
 [7.0, 8.0, 9.0]
  1. Indexing a DiffEqArray with a range returned a VectorOfArray instead of a DiffEqArray:
    on master:
julia> u = DiffEqArray([[1.0, 2.0, 3.0], [4.0, 5.0, 6.0], [7.0, 8.0, 9.0]], 1:3)
t: 1:3
u: 3-element Vector{Vector{Float64}}:
 [1.0, 2.0, 3.0]
 [4.0, 5.0, 6.0]
 [7.0, 8.0, 9.0]

julia> u[:, 2:end]
VectorOfArray{Float64,2}:
2-element Vector{Vector{Float64}}:
 [4.0, 5.0, 6.0]
 [7.0, 8.0, 9.0]

This PR:

julia> u = DiffEqArray([[1.0, 2.0, 3.0], [4.0, 5.0, 6.0], [7.0, 8.0, 9.0]], 1:3)
t: 1:3
u: 3-element Vector{Vector{Float64}}:
 [1.0, 2.0, 3.0]
 [4.0, 5.0, 6.0]
 [7.0, 8.0, 9.0]

julia> u[:, 2:end]
t: 2:1:3
u: 2-element Vector{Vector{Float64}}:
 [4.0, 5.0, 6.0]
 [7.0, 8.0, 9.0]

function Base.:(:)(start::RaggedEnd, stop::RaggedEnd)
return RaggedRange(stop.dim, start.offset, 1, stop.offset)
end
function Base.:(:)(start::RaggedEnd, step::Integer, stop::RaggedEnd)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're missing start with raggedend and stop with integer?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, right. That's also possible. I'll add that in a minute.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be fixed. Thanks for catching that!

@test diffeq.u == recs
@test diffeq[:, end] == testa[:, end]
@test diffeq[:, 2:end] == DiffEqArray([recs[i] for i in 2:length(recs)], t)
@test diffeq[:, 2:end] == DiffEqArray([recs[i] for i in 2:length(recs)], t[2:end])
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was actually pretty confusing because in the previous test t of the left hand side is not the same as the t on the right hand side, but it is not caught because of

.

@JoshuaLampert
Copy link
Contributor Author

Can this be merged, @ChrisRackauckas?

@ChrisRackauckas ChrisRackauckas merged commit ecd6794 into SciML:master Jan 21, 2026
23 of 27 checks passed
@JoshuaLampert JoshuaLampert deleted the fix-range-raggedend branch January 21, 2026 09:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants