Skip to content

Commit c2abc16

Browse files
Add a missing dispatch (#204)
1 parent 02c95fe commit c2abc16

File tree

4 files changed

+9
-1
lines changed

4 files changed

+9
-1
lines changed

Project.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ ArrayInterface = "4fba245c-0d91-5ea0-9b3e-6abc04ee57a9"
88
ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"
99
ConstructionBase = "187b0558-2788-49d3-abe0-74a17ed4e7c9"
1010
ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"
11+
Functors = "d9f16b24-f501-4c13-a1f2-28368ffc5196"
1112
GPUArrays = "0c68f7d7-f131-5f86-a1c3-88cf8149b2d7"
1213
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
1314
RecursiveArrayTools = "731186ca-8d62-57ce-b412-fbd966d074cd"
@@ -23,6 +24,7 @@ ChainRulesCore = "0.8, 0.9, 0.10, 1"
2324
ConstructionBase = "1"
2425
GPUArrays = "8"
2526
ForwardDiff = "0.10"
27+
Functors = "0.4.4"
2628
Requires = "1"
2729
ReverseDiff = "1"
2830
RecursiveArrayTools = "2"

src/ComponentArrays.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module ComponentArrays
22

33
import ChainRulesCore
4-
import StaticArrayInterface, ArrayInterface
4+
import StaticArrayInterface, ArrayInterface, Functors
55

66
using LinearAlgebra
77

src/compat/chainrulescore.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,8 @@ function ChainRulesCore.ProjectTo(ca::ComponentArray)
1717
end
1818

1919
(p::ChainRulesCore.ProjectTo{ComponentArray})(dx::AbstractArray) = ComponentArray(p.project(dx), p.axes)
20+
21+
function (p::ChainRulesCore.ProjectTo{ComponentArray})(t::ChainRulesCore.Tangent{A, <:NamedTuple}) where {A}
22+
nt = Functors.fmap(ChainRulesCore.backing, ChainRulesCore.backing(t))
23+
return ComponentArray(nt)
24+
end

test/Project.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
ArrayInterfaceCore = "30b0a656-2188-435a-8636-2ec0e6a096e2"
33
FiniteDiff = "6a86dc24-6348-571c-b903-95158fe2bd41"
44
ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"
5+
Functors = "d9f16b24-f501-4c13-a1f2-28368ffc5196"
56
InvertedIndices = "41ab1584-1d38-5bbf-9106-f11c6c58b48f"
67
JLArrays = "27aeb0d3-9eb9-45fb-866b-73c2ecf80fcb"
78
LabelledArrays = "2ee39098-c373-598a-b85f-a56591580800"

0 commit comments

Comments
 (0)