Skip to content

Bad error message for empty arrays of symbolic indexes #396

@BenChung

Description

@BenChung

Describe the bug 🐞
If you index into a result array with an idxs=[] you get the following error message:

> sol(ts, idxs=SymbolicUtils.BasicSymbolic{Real}[])
ERROR: LoadError: Indexing with parameters is deprecated. Use `getp(A, SymbolicUtils.BasicSymbolic{Real}[])` for parameter indexing.
Stacktrace:
  [1] _getindex
    @ C:\Users\benchung\.julia\packages\RecursiveArrayTools\VAOZn\src\vector_of_array.jl:374 [inlined]
....

This is very undesirable, since it does not accurately communicate the problem. Simply returning an empty vector would be the preferred result. The version with a literal empty array is even worse:

julia> sol([0.5], idxs=[])
ERROR: MethodError: no method matching _getindex(::RecursiveArrayTools.DiffEqArray{…}, ::SymbolicIndexingInterface.NotSymbolic, ::Vector{…})

Closest candidates are:
  _getindex(::RecursiveArrayTools.AbstractVectorOfArray{T, N}, ::SymbolicIndexingInterface.NotSymbolic, ::Colon...) where {T<:Number, N}
   @ RecursiveArrayTools C:\Users\benchung\.julia\packages\RecursiveArrayTools\VAOZn\src\vector_of_array.jl:309
  _getindex(::RecursiveArrayTools.AbstractVectorOfArray{T, N}, ::SymbolicIndexingInterface.NotSymbolic, ::Colon...) where {T, N}
   @ RecursiveArrayTools C:\Users\benchung\.julia\packages\RecursiveArrayTools\VAOZn\src\vector_of_array.jl:298
  _getindex(::RecursiveArrayTools.AbstractVectorOfArray{T, N}, ::SymbolicIndexingInterface.NotSymbolic, ::AbstractArray{Bool}, Colon...) where {T, N}
   @ RecursiveArrayTools C:\Users\benchung\.julia\packages\RecursiveArrayTools\VAOZn\src\vector_of_array.jl:315

Expected behavior

Returning an empty array of results.

Minimal Reproducible Example 👇

using ModelingToolkit, ModelingToolkitStandardLibrary, ModelingToolkitStandardLibrary.Mechanical.TranslationalPosition, OrdinaryDiffEq
sol = solve(ODEProblem(structural_simplify(Mass(m=1.0,name=:m)), [], (0.0, 1.0)), Tsit5())
# error 1
sol(ts, idxs=SymbolicUtils.BasicSymbolic{Real}[])
# error 2
sol([0.5], idxs=[])

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions