On Thu, Oct 9, 2014 at 2:36 PM, Brendan Tracey <
tracey....@gmail.com> wrote:
>
> I understand == for NaNs returns false. The question is if two NaN values
> should be "Deep Equals" each other.
As the DeepEqual doc says, "[i]t uses normal == equality where
possible." For values of type float32 or float64 normal == equality
is possible, and that is exactly what DeepEqual does.
> As far as testing for idempotency is concerned, these two structures are
> equal. However, DeepEquals returns false because the Gradient field contains
> NaN values. How can I perform a test for deep equality where NaN values are
> considered equal?
If you want something that is mostly like == but for which NaN's are
==, you'll have to write your own function. You can't use
reflect.DeepEqual.
Look at it this way: for DeepEqual, we have to decide how to handle
NaNs. There are two choices: like ==, or always treat NaN as equal.
Different people have different needs for DeepEqual, and there is no
obvious reason to make either choice. So we make it like ==, because
that is simpler to understand and easy to justify.
Ian