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

fix: respect array type in wrong-mode pushforward/pullback #620

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
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: 4 additions & 4 deletions DifferentiationInterface/src/first_order/pullback.jl
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,9 @@ function _pullback_via_pushforward(
dy,
contexts::Vararg{Context,C},
) where {F,C}
dx = map(CartesianIndices(x)) do j
dx = map(CartesianIndices(x)) do xj, j
t1 = pushforward(f, pushforward_prep, backend, x, (basis(x, j),), contexts...)
dot(only(t1), dy)
convert(eltype(x), dot(only(t1), dy))
end
return dx
end
Expand Down Expand Up @@ -254,9 +254,9 @@ function _pullback_via_pushforward(
dy,
contexts::Vararg{Context,C},
) where {F,C}
dx = map(CartesianIndices(x)) do j # preserve shape
dx = map(CartesianIndices(x)) do xj, j # preserve shape
t1 = pushforward(f!, y, pushforward_prep, backend, x, (basis(x, j),), contexts...)
dot(only(t1), dy)
convert(eltype(x), dot(only(t1), dy))
end
return dx
end
Expand Down
8 changes: 4 additions & 4 deletions DifferentiationInterface/src/first_order/pushforward.jl
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,9 @@ function _pushforward_via_pullback(
dx,
contexts::Vararg{Context,C},
) where {F,C}
dy = map(CartesianIndices(y)) do i
dy = map(y, CartesianIndices(y)) do yi, i
t1 = pullback(f, pullback_prep, backend, x, (basis(y, i),), contexts...)
dot(only(t1), dx)
convert(eltype(y), dot(only(t1), dx))
end
return dy
end
Expand Down Expand Up @@ -243,9 +243,9 @@ function _pushforward_via_pullback(
dx,
contexts::Vararg{Context,C},
) where {F,C}
dy = map(CartesianIndices(y)) do i # preserve shape
dy = map(CartesianIndices(y)) do yi, i # preserve shape
t1 = pullback(f!, y, pullback_prep, backend, x, (basis(y, i),), contexts...)
dot(only(t1), dx)
convert(eltype(y), dot(only(t1), dx))
end
return dy
end
Expand Down
Loading