Skip to content
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
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "ComponentArrays"
uuid = "b0b7db55-cfe3-40fc-9ded-d10e2dbeff66"
authors = ["Jonnie Diegelman <47193959+jonniedie@users.noreply.github.com>"]
version = "0.15.16"
version = "0.15.17"

[deps]
ArrayInterface = "4fba245c-0d91-5ea0-9b3e-6abc04ee57a9"
Expand Down
7 changes: 7 additions & 0 deletions ext/ComponentArraysTrackerExt.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
module ComponentArraysTrackerExt

using ArrayInterface: ArrayInterface
using ComponentArrays, Tracker

function Tracker.param(ca::ComponentArray)
Expand Down Expand Up @@ -34,4 +35,10 @@ end
return ComponentArrays._getindex(Base.getindex, x, v)
end

function ArrayInterface.restructure(x::ComponentVector,
y::ComponentVector{T, <:TrackedArray}) where {T}
getaxes(x) == getaxes(y) || error("Axes must match")
return y
end

end
1 change: 1 addition & 0 deletions test/Project.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[deps]
ArrayInterface = "4fba245c-0d91-5ea0-9b3e-6abc04ee57a9"
ArrayInterfaceCore = "30b0a656-2188-435a-8636-2ec0e6a096e2"
BenchmarkTools = "6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf"
FiniteDiff = "6a86dc24-6348-571c-b903-95158fe2bd41"
Expand Down
7 changes: 6 additions & 1 deletion test/autodiff_tests.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import FiniteDiff, ForwardDiff, ReverseDiff, Tracker, Zygote
using Optimisers
using Optimisers, ArrayInterface
using Test

F(a, x) = sum(abs2, a) * x^3
Expand Down Expand Up @@ -127,3 +127,8 @@ end
@test eltype(getdata(ps_data)) <: Float64
end

@testset "ArrayInterface restructure TrackedArray" begin
ps = ComponentArray(; a = rand(2), b = (; c = rand(2)))
ps_tracked = Tracker.param(ps)
@test ArrayInterface.restructure(ps, ps_tracked) isa ComponentVector{<:Any, <:Tracker.TrackedArray}
end