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: aos_to_soa for all singleton dims #457

Merged
merged 2 commits into from
Nov 18, 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
7 changes: 2 additions & 5 deletions ext/ArrayInterfaceReverseDiffExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,8 @@
ArrayInterface.can_setindex(::Type{<:ReverseDiff.TrackedArray}) = false
ArrayInterface.fast_scalar_indexing(::Type{<:ReverseDiff.TrackedArray}) = false
function ArrayInterface.aos_to_soa(x::AbstractArray{<:ReverseDiff.TrackedReal, N}) where {N}
if length(x) > 1
return reshape(reduce(vcat, x), size(x))
else
return reduce(vcat,[x[1], x[1]])[1:1]
end
y = length(x) > 1 ? reduce(vcat, x) : reduce(vcat, [x[1], x[1]])[1:1]
return reshape(y, size(x))

Check warning on line 12 in ext/ArrayInterfaceReverseDiffExt.jl

View check run for this annotation

Codecov / codecov/patch

ext/ArrayInterfaceReverseDiffExt.jl#L11-L12

Added lines #L11 - L12 were not covered by tests
end

function ArrayInterface.restructure(x::Array, y::ReverseDiff.TrackedArray)
Expand Down
3 changes: 3 additions & 0 deletions test/ad.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
using ArrayInterface, ReverseDiff, Tracker, Test
x = ReverseDiff.track([4.0])
@test ArrayInterface.aos_to_soa(x) isa ReverseDiff.TrackedArray
x = reshape([ReverseDiff.track(rand(1, 1, 1))[1]], 1, 1, 1)
@test ArrayInterface.aos_to_soa(x) isa ReverseDiff.TrackedArray
@test ndims(ArrayInterface.aos_to_soa(x)) == 3
x = reduce(vcat, ReverseDiff.track([4.0,4.0]))
@test ArrayInterface.aos_to_soa(x) isa ReverseDiff.TrackedArray
x = [ReverseDiff.track([4.0])[1]]
Expand Down
Loading