-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
to_vec doesn't preserve equality #132
Comments
I also suspect that this change would make it much safer to rely on recursive definitions of |
Would be solved if we just entirely stopped using Lets keep exporting it though, it is part of the public API, in that users are expected to extend it. |
The other thing to say here is that the present design means that In particular, Again, this isn't to say that what we're presently doing in |
Also, regarding the above plan, @sethaxen what are your thoughts on it in light of our adjoint-adventures the other day? I'm nervous that if I start changing things, things will start breaking in strange ways. |
I agree in general with your comments. I need to formalize my thinking here, but I think what we have been doing so far is using We need a different function to handle (co)tangents. Because we randomize the (co)tangents, the map here doesn't really matter all that much (though maybe it should). The important requirements are 1) it produces a real vector with the same dimension as the primal and 2) all valid equivalent representations for the same (co)tangent vector should map to the same real vector. So e.g.
We could always set up a ChainRules integration test, since arguably ChainRules's test suite puts this package through its paces more than our test suite can. |
I'm also still trying to figure out what I think about this whole thing, but I agree that we should really do this at the very least. |
I'll get on it |
Firstly, I'm very fond of
to_vec
-- it's served us well over the last couple of years. We know it has some shortcomings though, that we will need to address at some point.Presently we have implementations of
to_vec
like this instead of implementations that look like this.IIRC the reason for this is that if you define things in the latter fashion then you'll find if you do something like
then
A_vec == At_vec
. My suspicion is that at some point in time, we were trying to compare the equality of two things based on theirto_vec
representation and it came up that things weren't being compared properly. We do a similar thing withDiagonal
etc.Unfortunately, it seems quite straightforward to construct examples which don't admit such a straightforward resolution as we employed for
Adjoint
,Transpose
, andDiagonal
. For a trivial example, consider thatHowever, since
to_vec(::Tuple)
simply concatenatesto_vec
of each of the fields, we'll find thatThis leads me to believe that it's likely not possible to define
to_vec
such that equality is preserved.As such, I propose that we
to_vec(x)[1] == to_vec(y)[1]
in general tells you nothing about whetherx == y
, and vice versa. We should point this out to explicitly warn people away from trying to check whether two things are equal based on theirto_vec
representation.Tranpose
andAdjoint
) to use the struct representation, which is more computationally efficient.to_vec
should purely be thought of as a way to makeFiniteDifferences
' life easier. We might even consider ceasing to export it.Now that @oxinabox has added some new approximate equality checking to
ChainRulesTestUtils
, this ought to be less of a problem anyway, because it's now more straightforward to check whether things are approximately equal.Of course, if anyone can see a different path forward, I'm all ears.
The text was updated successfully, but these errors were encountered: