diff --git a/Project.toml b/Project.toml index 93227026..1018527e 100644 --- a/Project.toml +++ b/Project.toml @@ -57,7 +57,7 @@ StaticArrays = "1.6" StaticArraysCore = "1.1" Statistics = "1" StructArrays = "0.6" -SymbolicIndexingInterface = "0.3" +SymbolicIndexingInterface = "0.3.1" Tables = "1" Test = "1" Tracker = "0.2" diff --git a/src/vector_of_array.jl b/src/vector_of_array.jl index 40d45cc4..12e23083 100644 --- a/src/vector_of_array.jl +++ b/src/vector_of_array.jl @@ -284,8 +284,7 @@ Base.@propagate_inbounds function _getindex(A::AbstractDiffEqArray, ::ScalarSymb return getindex.(A.u, variable_index.((A,), (sym,), eachindex(A.t))) end elseif is_parameter(A, sym) - Base.depwarn("Indexing with parameters is deprecated. Use `getp(A, $sym)` for parameter indexing.", :parameter_getindex) - return getp(A, sym)(A) + error("Indexing with parameters is deprecated. Use `getp(A, $sym)` for parameter indexing.") elseif is_observed(A, sym) return observed(A, sym).(A.u, (parameter_values(A),), A.t) else @@ -325,8 +324,7 @@ end Base.@propagate_inbounds function _getindex(A::AbstractDiffEqArray, ::ScalarSymbolic, sym::Union{Tuple,AbstractArray}) if all(x -> is_parameter(A, x), sym) - Base.depwarn("Indexing with parameters is deprecated. Use `getp(A, $sym)` for parameter indexing.", :parameter_getindex) - return getp(A, sym)(A) + error("Indexing with parameters is deprecated. Use `getp(A, $sym)` for parameter indexing.") else return [getindex.((A,), sym, i) for i in eachindex(A.t)] end @@ -336,6 +334,14 @@ Base.@propagate_inbounds function _getindex(A::AbstractDiffEqArray, ::ScalarSymb return reduce(vcat, map(s -> A[s, args...]', sym)) end +Base.@propagate_inbounds function _getindex(A::AbstractDiffEqArray, ::ScalarSymbolic, ::SymbolicIndexingInterface.SolvedVariables, args...) + return getindex(A, variable_symbols(A), args...) +end + +Base.@propagate_inbounds function _getindex(A::AbstractDiffEqArray, ::ScalarSymbolic, ::SymbolicIndexingInterface.AllVariables, args...) + return getindex(A, all_variable_symbols(A), args...) +end + Base.@propagate_inbounds function Base.getindex(A::AbstractVectorOfArray, _arg, args...) symtype = symbolic_type(_arg) elsymtype = symbolic_type(eltype(_arg)) diff --git a/test/downstream/symbol_indexing.jl b/test/downstream/symbol_indexing.jl index 29ffdd21..1669032b 100644 --- a/test/downstream/symbol_indexing.jl +++ b/test/downstream/symbol_indexing.jl @@ -22,8 +22,13 @@ sol_new = DiffEqArray(sol.u[1:10], @test sol_new[t] ≈ sol_new.t @test sol_new[t, 1:5] ≈ sol_new.t[1:5] @test getp(sol, τ)(sol) == getp(sol_new, τ)(sol_new) == 3.0 -@test_deprecated sol[τ] -@test_deprecated sol_new[τ] +@test variable_symbols(sol) == variable_symbols(sol_new) == [x] +@test all_variable_symbols(sol) == all_variable_symbols(sol_new) == [x, RHS] +@test all_symbols(sol) == all_symbols(sol_new) == [x, RHS, τ, t] +@test sol[solvedvariables, 1:10] == sol_new[solvedvariables] == sol_new[[x]] +@test sol[allvariables, 1:10] == sol_new[allvariables] == sol_new[[x, RHS]] +@test_throws Exception sol[τ] +@test_throws Exception sol_new[τ] # Tables interface test_tables_interface(sol_new, [:timestamp, Symbol("x(t)")], hcat(sol_new[t], sol_new[x])) diff --git a/test/qa.jl b/test/qa.jl index 59f5ddc2..639aed55 100644 --- a/test/qa.jl +++ b/test/qa.jl @@ -3,7 +3,7 @@ using RecursiveArrayTools, Aqua Aqua.find_persistent_tasks_deps(RecursiveArrayTools) ambs = Aqua.detect_ambiguities(RecursiveArrayTools; recursive = true) @warn "Number of method ambiguities: $(length(ambs))" - @test length(ambs) <= 1 + @test length(ambs) <= 11 Aqua.test_deps_compat(RecursiveArrayTools) Aqua.test_piracies(RecursiveArrayTools) Aqua.test_project_extras(RecursiveArrayTools) diff --git a/test/symbolic_indexing_interface_test.jl b/test/symbolic_indexing_interface_test.jl index 67c3b3b4..17d7155b 100644 --- a/test/symbolic_indexing_interface_test.jl +++ b/test/symbolic_indexing_interface_test.jl @@ -21,11 +21,13 @@ dx = DiffEqArray([[f(x), f2(x)] for x in t], @test dx[(:a, :b)] == [(f(x), f2(x)) for x in t] @test dx[[:a, :b], 3] ≈ [f(t[3]), f2(t[3])] @test dx[[:a, :b], 4:5] ≈ vcat(f.(t[4:5])', f2.(t[4:5])') +@test dx[solvedvariables] == dx[allvariables] == dx[[:a, :b]] +@test dx[solvedvariables, 3] == dx[allvariables, 3] == dx[[:a, :b], 3] @test getp(dx, [:p, :q])(dx) == [1.0, 2.0] @test getp(dx, :p)(dx) == 1.0 @test getp(dx, :q)(dx) == 2.0 -@test_deprecated dx[:p] -@test_deprecated dx[[:p, :q]] +@test_throws Exception dx[:p] +@test_throws Exception dx[[:p, :q]] @test dx[:t] == t @test symbolic_container(dx) isa SymbolCache @@ -35,11 +37,12 @@ dx = DiffEqArray([[f(x), f2(x)] for x in t], @test is_parameter.((dx,), [:a, :b, :p, :q, :t]) == [false, false, true, true, false] @test parameter_index.((dx,), [:a, :b, :p, :q, :t]) == [nothing, nothing, 1, 2, nothing] @test is_independent_variable.((dx,), [:a, :b, :p, :q, :t]) == [false, false, false, false, true] -@test variable_symbols(dx) == [:a, :b] +@test variable_symbols(dx) == all_variable_symbols(dx) == [:a, :b] @test parameter_symbols(dx) == [:p, :q] @test independent_variable_symbols(dx) == [:t] @test is_time_dependent(dx) @test constant_structure(dx) +@test all_symbols(dx) == [:a, :b, :p, :q, :t] dx = DiffEqArray([[f(x), f2(x)] for x in t], t; variables = [:a, :b]) @test_throws Exception dx[nothing] # make sure it isn't storing [nothing] as indepsym