-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #430 from JuliaArrays/aos_to_soa_ReverseDiff
Specialize Array of Structs to Struct of Array for ReverseDiff
- Loading branch information
Showing
4 changed files
with
56 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
module ArrayInterfaceReverseDiffExt | ||
|
||
if isdefined(Base, :get_extension) | ||
using ArrayInterface | ||
import ReverseDiff | ||
else | ||
using ..ArrayInterface | ||
import ..ReverseDiff | ||
end | ||
|
||
ArrayInterface.ismutable(::Type{<:ReverseDiff.TrackedArray}) = false | ||
ArrayInterface.ismutable(T::Type{<:ReverseDiff.TrackedReal}) = false | ||
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 | ||
reduce(vcat,x) | ||
else | ||
@show "here?" | ||
reduce(vcat,[x[1],x[1]])[1:1] | ||
end | ||
end | ||
|
||
end # module |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using ArrayInterface, ReverseDiff, Tracker, Test | ||
x = ReverseDiff.track([4.0]) | ||
@test ArrayInterface.aos_to_soa(x) isa ReverseDiff.TrackedArray | ||
x = reduce(vcat, ReverseDiff.track([4.0,4.0])) | ||
@test ArrayInterface.aos_to_soa(x) isa ReverseDiff.TrackedArray | ||
x = [ReverseDiff.track([4.0])[1]] | ||
@test ArrayInterface.aos_to_soa(x) isa ReverseDiff.TrackedArray | ||
x = reduce(vcat, ReverseDiff.track([4.0,4.0])) | ||
x = [x[1],x[2]] | ||
@test ArrayInterface.aos_to_soa(x) isa ReverseDiff.TrackedArray | ||
|
||
x = Tracker.TrackedArray([4.0]) | ||
@test ArrayInterface.aos_to_soa(x) isa Tracker.TrackedArray | ||
x = [Tracker.TrackedArray([4.0])[1]] | ||
@test ArrayInterface.aos_to_soa(x) isa Tracker.TrackedArray | ||
x = Tracker.TrackedArray([4.0,4.0]) | ||
@test ArrayInterface.aos_to_soa(x) isa Tracker.TrackedArray | ||
x = reduce(vcat, Tracker.TrackedArray([4.0,4.0])) | ||
x = [x[1],x[2]] | ||
@test ArrayInterface.aos_to_soa(x) isa Tracker.TrackedArray |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters