Commit e2be5f02 authored by Ludovic Courtès's avatar Ludovic Courtès

data_storage: Initialize '_min' and '_max' in 'load_data_from_binary'.

parent 5e8cf8d2
......@@ -280,6 +280,15 @@ void load_data_from_binary(std::istream& in, const header& header, data& data)
int sample_count = header["SAMPLE_COUNT"];
// Initialize the mininum and maximum values.
vec min(dim.first), max(dim.first);
for(int k = 0; k < dim.first; k++)
{
min[k] = std::numeric_limits<double>::max();
max[k] = -std::numeric_limits<double>::max();
}
// TODO: Arrage to use mmap and make it zero-alloc and zero-copy.
for (int i = 0; i < sample_count; i++)
{
......@@ -294,7 +303,16 @@ void load_data_from_binary(std::istream& in, const header& header, data& data)
}
data.set(row);
// Update min and max.
for(int k = 0; k < dim.first; k++)
{
min[k] = std::min(min[k], row[k]);
max[k] = std::max(max[k], row[k]);
}
}
// TODO: Factorize this in data::set.
data.setMin(min);
data.setMax(max);
}
......@@ -151,5 +151,13 @@ int main(int argc, char** argv)
TEST_ASSERT(files_are_equal(temp_file1, temp_file2));
TEST_ASSERT(sample2.equals(sample3));
TEST_ASSERT(sample1.min().size() == sample1.dimX());
TEST_ASSERT(sample1.max().size() == sample1.dimX());
TEST_ASSERT(sample1.min() == sample2.min());
TEST_ASSERT(sample1.max() == sample2.max());
TEST_ASSERT(sample1.min() == sample3.min());
TEST_ASSERT(sample1.max() == sample3.max());
return EXIT_SUCCESS;
}
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