@@ -2,7 +2,7 @@ module ComponentArraysReverseDiffExt
22
33using ComponentArrays, ReverseDiff
44
5- const TrackedComponentArray{V, D, N, DA, A, Ax} = ReverseDiff. TrackedArray{V,D,N,ComponentArray{V,N,A,Ax},DA}
5+ const TrackedComponentArray{V,D,N, DA,A, Ax} = ReverseDiff. TrackedArray{V,D,N,ComponentArray{V,N,A,Ax},DA}
66
77maybe_tracked_array (val:: AbstractArray , der, tape, inds, origin) = ReverseDiff. TrackedArray (val, der, tape)
88function maybe_tracked_array (val:: Real , der, tape, inds, origin:: AbstractVector )
@@ -12,10 +12,10 @@ function maybe_tracked_array(val::Real, der, tape, inds, origin::AbstractVector)
1212end
1313
1414for f in [:getindex , :view ]
15- @eval function Base. $f (tca:: TrackedComponentArray , inds:: Union{Symbol, Val} ...)
16- val = $ f (ReverseDiff. value (tca), inds... )
17- der = Base. maybeview (ReverseDiff. deriv (tca), inds... )
18- t = ReverseDiff. tape (tca)
15+ @eval function Base. $f (tca:: TrackedComponentArray , inds:: Union{Symbol,Val} ...)
16+ val = $ f (ReverseDiff. value (tca), inds... )
17+ der = Base. maybeview (ReverseDiff. deriv (tca), inds... )
18+ t = ReverseDiff. tape (tca)
1919 return maybe_tracked_array (val, der, t, inds, tca)
2020 end
2121end
@@ -31,4 +31,17 @@ function Base.getproperty(tca::TrackedComponentArray, s::Symbol)
3131 end
3232end
3333
34+ function Base. propertynames (:: TrackedComponentArray{V,D,N,DA,A,Tuple{Ax}} ) where {V,D,N,DA,A,Ax<: ComponentArrays.AbstractAxis }
35+ return propertynames (ComponentArrays. indexmap (Ax))
36+ end
37+
38+ function Base. NamedTuple (tca:: TrackedComponentArray )
39+ props = propertynames (tca)
40+ return NamedTuple {props} (getproperty (tca, p) for p in props)
41+ end
42+
43+ @inline ComponentArrays. __value (x:: AbstractArray{<:ReverseDiff.TrackedReal} ) = ReverseDiff. value .(x)
44+ @inline ComponentArrays. __value (x:: ReverseDiff.TrackedArray ) = ReverseDiff. value (x)
45+ @inline ComponentArrays. __value (x:: TrackedComponentArray ) = ComponentArray (ComponentArrays. __value (getdata (x)), getaxes (x))
46+
3447end
0 commit comments