[Numpy-discussion] problem with float64's str()
Fri Apr 4 15:40:08 CDT 2008
On Fri, Apr 4, 2008 at 12:47 PM, Robert Kern <firstname.lastname@example.org> wrote:
> On Fri, Apr 4, 2008 at 9:56 AM, Will Lee <email@example.com> wrote:
> > I understand the implication for the floating point comparison and the
> > for allclose. However, I think in a doctest context, this behavior
> > the doc much harder to read.
> Tabling the issue of the fact that we changed behavior for a moment,
> this is a fundamental problem with using doctests as unit tests for
> numerical code. The floating point results that you get *will* be
> different on different machines, but the code will still be correct.
> Using allclose() and similar techniques are the best tools available
> (although they still suck). Relying on visual representations of these
> results is simply an untenable strategy.
That is sometimes, but not always the case. Why? Because most of the time
that one ends up with simple values, one is starting with arbitrary floating
point values and doing at most simple operations on them. Thus a strategy
that helps many of my unit tests look better and function reliably is to
choose values that can be represented exactly in floating point. If the
original value here had been 0.00125 rather than .0012, there would be no
problem here. Well almost, you still are vulnerable to the rules for zero
padding and what no getting changed and so forth, but in general it's more
reliable and prettier.
Of course this isn't always a solution. But I've found it's helpful for a
Note that the string
> representation of NaNs and Infs are completely different across
> That said, str(float_numpy_scalar) really should have the same rules
> as str(some_python_float).
> Robert Kern
> "I have come to believe that the whole world is an enigma, a harmless
> enigma that is made terrible by our own mad attempt to interpret it as
> though it had an underlying truth."
> -- Umberto Eco
> Numpy-discussion mailing list
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Numpy-discussion