Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Batch observed function eval if possible #368

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/vector_of_array.jl
Original file line number Diff line number Diff line change
Expand Up @@ -406,13 +406,20 @@ Base.@propagate_inbounds function _getindex(
if all(x -> is_parameter(A, x), sym)
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)]
return A[sym, eachindex(A.t)]
end
end

Base.@propagate_inbounds function _getindex(
A::AbstractDiffEqArray, ::ScalarSymbolic, sym::Union{Tuple, AbstractArray}, args...)
return reduce(vcat, map(s -> A[s, args...]', sym))
u = A.u[args...]
t = A.t[args...]
observed_fn = observed(A, sym)
if t isa AbstractArray
return observed_fn.(u, (parameter_values(A),), t)
else
return observed_fn(u, parameter_values(A), t)
end
end

Base.@propagate_inbounds function _getindex(A::AbstractDiffEqArray, ::ScalarSymbolic,
Expand Down
2 changes: 1 addition & 1 deletion test/downstream/symbol_indexing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ sol_new = DiffEqArray(sol.u[1:10],
@test_throws Exception sol_new[τ]

gs, = Zygote.gradient(sol) do sol
sum(sol[fol_separate.x])
sum(sol[fol_separate.x])
end

@test "Symbolic Indexing ADjoint" all(all.(isone, gs.u))
Expand Down
Loading