Skip to content

Feat: Support for symbolic indexing of solution objects #367

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

Merged
merged 4 commits into from
Apr 29, 2024
Merged
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
8 changes: 6 additions & 2 deletions ext/RecursiveArrayToolsZygoteExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,12 @@ end

function (p::ChainRulesCore.ProjectTo{VectorOfArray})(x::Union{
AbstractArray, AbstractVectorOfArray})
arr = reshape(x, p.sz)
return VectorOfArray([arr[:, i] for i in 1:p.sz[end]])
if eltype(x) <: Number
arr = reshape(x, p.sz)
return VectorOfArray([arr[:, i] for i in 1:p.sz[end]])
elseif eltype(x) <: AbstractArray
return VectorOfArray(x)
end
end

@adjoint function Broadcast.broadcasted(::typeof(+), x::AbstractVectorOfArray,
Expand Down
6 changes: 6 additions & 0 deletions test/downstream/symbol_indexing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ sol_new = DiffEqArray(sol.u[1:10],
@test_throws Exception sol[τ]
@test_throws Exception sol_new[τ]

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

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

# Tables interface
test_tables_interface(sol_new, [:timestamp, Symbol("x(t)")], hcat(sol_new[t], sol_new[x]))

Expand Down