From ceb50016bce33a27c9fcbae4f575e0cbada31526 Mon Sep 17 00:00:00 2001 From: Graeme Winter Date: Mon, 18 May 2020 10:38:36 +0100 Subject: [PATCH 1/2] Fix treatment of NaN in histogram Includes test to assert this behaviour. Means histogram behaves as expected for #478 however issues with min() and max() remain --- scitbx/array_family/boost_python/tst_flex.py | 5 +++++ scitbx/histogram.h | 4 +++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/scitbx/array_family/boost_python/tst_flex.py b/scitbx/array_family/boost_python/tst_flex.py index bc3b1c2808..63558b5411 100644 --- a/scitbx/array_family/boost_python/tst_flex.py +++ b/scitbx/array_family/boost_python/tst_flex.py @@ -2097,6 +2097,11 @@ def exercise_histogram(): assert not show_diff(t.getvalue(), s.getvalue()) assert l.n_out_of_slot_range() == 17 + # treatment of data with NaN in - cctbx/cctbx_project#478 + d = flex.log10(flex.double(range(-10, 100)) + 0.5) + h = flex.histogram(d, data_min=-10, data_max=10, n_slots=20) + assert h.slots()[0] == 0 + def exercise_weighted_histogram(): x = flex.double(range(20)) w = 0.5 * flex.double(range(20)) diff --git a/scitbx/histogram.h b/scitbx/histogram.h index 0513b6d4be..1a37847c0f 100644 --- a/scitbx/histogram.h +++ b/scitbx/histogram.h @@ -169,7 +169,9 @@ namespace scitbx { void assign_to_slot(ValueType const& d) { - slots_[get_i_slot(d)]++; + if (!std::isnan(d)) { + slots_[get_i_slot(d)]++; + } } template From b050b89c58baee5da0c83c4682df882bfbcb008d Mon Sep 17 00:00:00 2001 From: Graeme Winter Date: Wed, 3 Jun 2020 11:23:29 +0100 Subject: [PATCH 2/2] Tab->spaces --- scitbx/histogram.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scitbx/histogram.h b/scitbx/histogram.h index 1a37847c0f..0eedd2b5bc 100644 --- a/scitbx/histogram.h +++ b/scitbx/histogram.h @@ -169,9 +169,9 @@ namespace scitbx { void assign_to_slot(ValueType const& d) { - if (!std::isnan(d)) { - slots_[get_i_slot(d)]++; - } + if (!std::isnan(d)) { + slots_[get_i_slot(d)]++; + } } template