Commit b2bbc793 authored by Paal Kvamme's avatar Paal Kvamme
Browse files

If statistics not available set min > max.

parent 59ad4229
......@@ -1156,7 +1156,8 @@ public:
// If this is the first write then these steps are no-ops
// 1. Clear the statistics because it is out of date.
this->_meta_rw->ih().setstats(0,0,0,0,0);
constexpr double inf{std::numeric_limits<double>::infinity()};
this->_meta_rw->ih().setstats(0,0,0,inf,-inf);
// 2. Clear the histogram, except that we have already started
// deciding the histogram range to use as the range of all
......@@ -1286,8 +1287,7 @@ public:
// this and many similar places need to be updated.
this->_meta_rw->ih().setstats
(scaled_stats.getcnt(), scaled_stats.getsum(), scaled_stats.getssq(),
static_cast<float>(scaled_stats.getmin()),
static_cast<float>(scaled_stats.getmax()));
scaled_stats.getmin(), scaled_stats.getmax());
this->_meta_rw->hh().sethisto(scaled_histo.getmin(), scaled_histo.getmax(),
scaled_histo.getbins(), scaled_histo.getsize());
if (false)
......
......@@ -861,7 +861,7 @@ public:
virtual const std::vector<std::int64_t>& brickoffsets() const override { return _cached_brickoffsets; }
// Write support.
virtual void setstats(std::int64_t scnt, double ssum, double sssq,
float smin, float smax)
double smin, double smax)
{
throw OpenZGY::Errors::ZgyInternalError("Writing InfoHeader is only supported for the latest version.");
}
......@@ -1015,13 +1015,14 @@ public:
virtual const std::vector<std::int64_t>& alphaoffsets() const override { return _cached_alphaoffsets; }
virtual const std::vector<std::int64_t>& brickoffsets() const override { return _cached_brickoffsets; }
virtual void setstats(std::int64_t scnt, double ssum, double sssq,
float smin, float smax)
double smin, double smax)
{
_pod._scnt = scnt;
_pod._ssum = ssum;
_pod._sssq = sssq;
_pod._smin = smin;
_pod._smax = smax;
// TODO-Low: After the next ZGY version the casts must be removed.
_pod._smin = static_cast<float>(smin);
_pod._smax = static_cast<float>(smax);
}
};
......
......@@ -333,7 +333,7 @@ public:
virtual double defaultvalue() const = 0;
// Write support.
virtual void setstats(std::int64_t scnt, double ssum, double sssq,
float smin, float smax) = 0;
double smin, double smax) = 0;
};
/////////////////////////////////////////////////////////////////////////////
......
......@@ -713,8 +713,8 @@ do_test_finalize(int mode)
TEST_CHECK(stat.cnt == 0);
TEST_CHECK(stat.sum == 0);
TEST_CHECK(stat.ssq == 0);
TEST_CHECK(stat.min == 0);
TEST_CHECK(stat.max == 0);
TEST_CHECK(stat.min == std::numeric_limits<double>::infinity());
TEST_CHECK(stat.max == -std::numeric_limits<double>::infinity());
TEST_CHECK(hist.samplecount == 0);
TEST_CHECK_(hist.minvalue == 42, "minvalue expect 42 got %lg", hist.minvalue);
TEST_CHECK_(hist.maxvalue == 42, "maxvalue expect 42 got %lg", hist.maxvalue);
......
......@@ -315,6 +315,8 @@ do_test_reopen(const std::string& filename, TestTwiceFlags flags)
return (flags & f) != TestTwiceFlags::nothing;
};
constexpr double inf{std::numeric_limits<double>::infinity()};
// If not finalized on the last close there will be no lowres, stats, histo.
const int expect_nlods =
(flagset(TestTwiceFlags::step2_finalize) ? 5 :
......@@ -413,7 +415,7 @@ do_test_reopen(const std::string& filename, TestTwiceFlags flags)
(expect_15 * -15 * -15.0) +
(expect_10 * -10 * -10.0);
const double expect_stat_min = !expect_finalized ? 0.0 :
const double expect_stat_min = !expect_finalized ? inf :
(expect_15 + expect_10 == 0 ? 0.0 : -15.0);
// Note the quirk with incremental finalize. If there were ever
......@@ -421,7 +423,7 @@ do_test_reopen(const std::string& filename, TestTwiceFlags flags)
// range even if those samples were removed later.
// Unless of course the caller asked for an incremental finalize
// but didn't get it because step 1 did not finalize.
const double expect_stat_max = !expect_finalized ? 0 :
const double expect_stat_max = !expect_finalized ? -inf :
(flagset(TestTwiceFlags::step1_write) &&
flagset(TestTwiceFlags::step1_finalize) &&
flagset(TestTwiceFlags::step2_replace) &&
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment