[cctbxbb] Trapping NaN or not trapping NaN
luc_j_bourhis at mac.com
Mon Apr 11 01:24:54 PDT 2016
> On 11 Apr 2016, at 10:11, Graeme.Winter at diamond.ac.uk wrote:
> Will also help with graphics programs etc too! Often get crashes in matplotlib from this...
This is indeed another very good point. We’ve had issues with wxPython as well and I remember having to sandwich some call calling into wxPython with an enabling/disabling of traps. Note that I did write a long time ago a nice utility which can be used both in C++ and Python:
In Python, it uses a context:
>>> import boost.python
>>> from scitbx.array_family import flex
>>> a = flex.double((0, 0, 0))
>>> with boost.python.trapping(division_by_zero=False):
>>> b = 1/a
(inf, inf, inf)
... CRASH ...
In C++, it uses the guard pattern:
exception_trapping guard(exception_trapping::division_by_zero | exception_trapping::invalid);
// the computations in this scope will now trap division-by-zero and NaN
// when leaving the scope, trapping will go back to what it was before entering the scope
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the cctbxbb