Commit 5d1b434b authored by Ludovic Courtès's avatar Ludovic Courtès

core: data_storage: 'save_data_as_binary' writes confidence interval data.

parent ec4494d2
......@@ -288,8 +288,10 @@ void alta::save_data_as_binary(std::ostream &out, const alta::data& data)
{
using namespace alta;
// TODO: Support writing the confidence interval.
auto kind = vertical_segment::NO_CONFIDENCE_INTERVAL;
auto maybe_vs = dynamic_cast<const vertical_segment*>(&data);
auto kind = maybe_vs != NULL
? maybe_vs->confidence_interval_kind()
: vertical_segment::NO_CONFIDENCE_INTERVAL;
out << "#DIM " << data.parametrization().dimX() << " " << data.parametrization().dimY() << std::endl;
out << "#PARAM_IN "
......@@ -315,14 +317,27 @@ void alta::save_data_as_binary(std::ostream &out, const alta::data& data)
out << "#BEGIN_STREAM" << std::endl;
for(int i=0; i < data.size(); ++i)
if (kind == vertical_segment::NO_CONFIDENCE_INTERVAL)
{
// No confidence interval to be saved.
for(int i=0; i < data.size(); ++i)
{
vec sample = data.get(i);
const double *numbers = sample.data();
assert(sample.size() == data.parametrization().dimX() + data.parametrization().dimY());
out.write((const char *)numbers, sample.size() * sizeof(*numbers));
}
}
else
{
// FIXME: Currently we are not saving the confidence interval here.
vec sample = data.get(i);
const double *numbers = sample.data();
// Saving data along with the confidence interval.
auto matrix = maybe_vs->matrix_view();
auto byte_count = matrix.cols() * matrix.rows() * sizeof(double);
assert(sample.size() == data.parametrization().dimX() + data.parametrization().dimY());
out.write((const char *)numbers, sample.size() * sizeof(*numbers));
// MATRIX has no stride so we can access the underlying storage
// directly.
out.write((const char *)matrix.data(), byte_count);
}
out << std::endl << "#END_STREAM" << std::endl;
......
......@@ -153,6 +153,24 @@ int main(int argc, char** argv)
TEST_ASSERT(sample1->max() == sample2->max());
TEST_ASSERT(sample1->min() == sample3->min());
TEST_ASSERT(sample1->max() == sample3->max());
// Make sure confidence interval data was preserved.
auto vs_sample1 = dynamic_pointer_cast<vertical_segment>(sample1);
auto vs_sample2 = dynamic_pointer_cast<vertical_segment>(sample2);
auto vs_sample3 = dynamic_pointer_cast<vertical_segment>(sample3);
TEST_ASSERT(vs_sample1 && vs_sample2 && vs_sample3);
TEST_ASSERT(vs_sample1->confidence_interval_kind()
== vertical_segment::ASYMMETRICAL_CONFIDENCE_INTERVAL);
TEST_ASSERT(vs_sample2->confidence_interval_kind()
== vertical_segment::ASYMMETRICAL_CONFIDENCE_INTERVAL);
TEST_ASSERT(vs_sample3->confidence_interval_kind()
== vertical_segment::ASYMMETRICAL_CONFIDENCE_INTERVAL);
// Compare the full "matrix views", which contains both X, Y, and the
// confidence interval on Y.
TEST_ASSERT(vs_sample1->matrix_view() == vs_sample2->matrix_view());
TEST_ASSERT(vs_sample1->matrix_view() == vs_sample3->matrix_view());
}
CATCH_FILE_IO_ERROR(input_file);
......
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