On Sun, Jun 14, 2020 at 7:49 PM Oscar Benjamin <oscar.j.benja...@gmail.com>
wrote:

> > > I've had occasion to use math.isclose(), np.isclose(), and
> np.allclose()
> > > quite often.
> > Can you elaborate a bit on the kinds of things you use them for?
>
> I can't elaborate on David's use but in my own experience these
> functions are mostly useful for interactive checking or for something
> like unit tests. They can be used extensively in the testing code for
> projects with a lot of floating point functions.


At times I have computations which *should be* the same mathematically, but
are carried out through a different sequence of specific computations.  One
common example is in parallel frameworks where the order of computation is
indeterminate because multiple workers/threads/processes are each
calculating portions to aggregate.

Another related case is when I call some library to do an operation, but I
did not write the library, nor do I understand its guts well.  For example,
the tensor libraries used in neural networks that will calculate a loss
function.  Occasionally I'd like to be able to replicate (within a
tolerance) a computation the library performs using something more general
like NumPy.  Having a few ulps difference is typical, but counts as
validating the "same" answer.

Another occasion I encounter it is with data measurements.  Some sort of
instrument collects measurements with a small jitter.  Two measurements
that cannot be distinguished based on the precision of the instrument might
nonetheless be stored as different floating point numbers.  In that case, I
probably want to be able to tweak the tolerances for the specific case.

-- 
The dead increasingly dominate and strangle both the living and the
not-yet born.  Vampiric capital and undead corporate persons abuse
the lives and control the thoughts of homo faber. Ideas, once born,
become abortifacients against new conceptions.
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/VJSIJ3VHKVJQUZ6ZSXWY7VCBRXSOQKVJ/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to