-
-
Notifications
You must be signed in to change notification settings - Fork 21
Open
Description
Is there a way to make this work? The important part is the preallocation of the mixed tuples in the array.
- DiffCache doesn't work, and
- GeneralLazyBufferCache [don't know if it is the right approach instead]
using ForwardDiff
using PreallocationTools
using StaticArrays
ar_alloc = [(; a=1.0, b=2.0, c=SVector(0.0)), (; a=1.0, b=2.0, c=SVector(0.0))]
function fxy(x, ar_alloc, y)
for i in 1:2
a = x + 1
b = x * x + 2
c = SVector(x * x * x + 3 + a)
ar_alloc[i] = (; a, b, c)
end
ŷ = [ar_alloc[1].a + ar_alloc[1].c[1], ar_alloc[2].a + +ar_alloc[2].c[1]]
return sum(abs.(ŷ .- y))
end
y = [2.3, 5.0]
loss(x) = fxy(x, ar_alloc, y)
loss(0.5)
ForwardDiff.gradient(loss, [0.2, 0.5, 0.6])Metadata
Metadata
Assignees
Labels
No labels