FiniteDifferences.jl icon indicating copy to clipboard operation
FiniteDifferences.jl copied to clipboard

make `to_vec(::Integer)` an empty vector

Open mzgubic opened this issue 4 years ago • 4 comments

Closes #188

breaks a few rules in ChainRules, need to take a look at that before merging

mzgubic avatar Aug 04 '21 10:08 mzgubic

#191 closed in favour of this PR.

@mzgubic what's the status of this? Any chance we could push it through?

willtebbutt avatar Sep 27 '21 13:09 willtebbutt

I tackled this before leaving for holidays but didn't have time to continue when I came back. I do remember it was kind of annoying as some weird things were popping up (one symptom is the _int2zero bandaid)

(feel free to take over)

mzgubic avatar Sep 27 '21 13:09 mzgubic

I think the underlying problem is related to Example 2 from this CRTU issue. Need to confirm by working through the things that are breaking though.

willtebbutt avatar Sep 27 '21 14:09 willtebbutt

I think the underlying problem is related to Example 2 from this CRTU issue. Need to confirm by working through the things that are breaking though.

I did a bit more digging into what it would take to implement this. It turns out that we're also missing a way to say "treat t as a tangent for x and convert it to a vector of reals". This functionality is needed in j′vp The distinction is most plain for integers:

to_vec(5) should clearly return an empty vector because integers are non-differentiable, however, if we have a function tangent_to_vec(primal, tangent) where tangent is a tangent for primal, tangent_to_vec(1.0, 5) should return a length 1 vector containing 5.

Similarly, while to_vec(primal::Diagonal) should return a length size(primal, 1) vector (if we're treating things structurally), tangent_to_vec(primal::Matrix{Float64}, tangent::Diagonal{Float64}) should return a length length(primal) vector.

Very doable, just requires some work.

willtebbutt avatar Sep 28 '21 10:09 willtebbutt