Skip to content
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
16 changes: 12 additions & 4 deletions DifferentiationInterface/src/first_order/pullback.jl
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,9 @@ function _pullback_via_pushforward(
dy,
contexts::Vararg{Context,C},
) where {F,C}
dx = map(CartesianIndices(x)) do j
ind = CartesianIndices(x)
T = typeof(similar(x, eltype(ind)))
dx = map(x, T(ind)) do xj, j
a = only(pushforward(f, pushforward_prep, backend, x, (basis(x, j),), contexts...))
dot(a, dy)
end
Expand All @@ -362,7 +364,9 @@ function _pullback_via_pushforward(
dy,
contexts::Vararg{Context,C},
) where {F,C}
dx = map(CartesianIndices(x)) do j
ind = CartesianIndices(x)
T = typeof(similar(x, eltype(ind)))
dx = map(x, T(ind)) do xj, j
a = only(pushforward(f, pushforward_prep, backend, x, (basis(x, j),), contexts...))
b = only(
pushforward(f, pushforward_prep, backend, x, (im * basis(x, j),), contexts...),
Expand Down Expand Up @@ -472,7 +476,9 @@ function _pullback_via_pushforward(
dy,
contexts::Vararg{Context,C},
) where {F,C}
dx = map(CartesianIndices(x)) do j # preserve shape
ind = CartesianIndices(x)
T = typeof(similar(x, eltype(ind)))
dx = map(x, T(ind)) do xj, j # preserve shape
a = only(pushforward(f!, y, pushforward_prep, backend, x, (basis(x, j),), contexts...))
dot(a, dy)
end
Expand All @@ -488,7 +494,9 @@ function _pullback_via_pushforward(
dy,
contexts::Vararg{Context,C},
) where {F,C}
dx = map(CartesianIndices(x)) do j # preserve shape
ind = CartesianIndices(x)
T = typeof(similar(x, eltype(ind)))
dx = map(x, T(ind)) do xj, j # preserve shape
a = only(pushforward(f!, y, pushforward_prep, backend, x, (basis(x, j),), contexts...))
b = only(
pushforward(
Expand Down
16 changes: 12 additions & 4 deletions DifferentiationInterface/src/first_order/pushforward.jl
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,9 @@ function _pushforward_via_pullback(
dx,
contexts::Vararg{Context,C},
) where {F,C}
dy = map(CartesianIndices(y)) do i
ind = CartesianIndices(y)
T = typeof(similar(y, eltype(ind)))
dy = map(y, T(ind)) do yi, i
a = only(pullback(f, pullback_prep, backend, x, (basis(y, i),), contexts...))
dot(a, dx)
end
Expand All @@ -367,7 +369,9 @@ function _pushforward_via_pullback(
dx,
contexts::Vararg{Context,C},
) where {F,C}
dy = map(CartesianIndices(y)) do i
ind = CartesianIndices(y)
T = typeof(similar(y, eltype(ind)))
dy = map(y, T(ind)) do yi, i
a = only(pullback(f, pullback_prep, backend, x, (basis(y, i),), contexts...))
b = only(pullback(f, pullback_prep, backend, x, (im * basis(y, i),), contexts...))
real(dot(a, dx)) + im * real(dot(b, dx))
Expand Down Expand Up @@ -444,7 +448,9 @@ function _pushforward_via_pullback(
dx,
contexts::Vararg{Context,C},
) where {F,C}
dy = map(CartesianIndices(y)) do i # preserve shape
ind = CartesianIndices(y)
T = typeof(similar(y, eltype(ind)))
dy = map(y, T(ind)) do yi, i # preserve shape
a = only(pullback(f!, y, pullback_prep, backend, x, (basis(y, i),), contexts...))
dot(a, dx)
end
Expand All @@ -460,7 +466,9 @@ function _pushforward_via_pullback(
dx,
contexts::Vararg{Context,C},
) where {F,C}
dy = map(CartesianIndices(y)) do i # preserve shape
ind = CartesianIndices(y)
T = typeof(similar(y, eltype(ind)))
dy = map(y, T(ind)) do yi, i # preserve shape
a = only(pullback(f!, y, pullback_prep, backend, x, (basis(y, i),), contexts...))
b = only(
pullback(f!, y, pullback_prep, backend, x, (im * basis(y, i),), contexts...)
Expand Down
Loading