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

core: vertical_segment: Factorize min/max computation.

parent c5b7e506
......@@ -56,14 +56,6 @@ alta::data* alta::load_data_from_text(std::istream& input,
std::cout << "<<DEBUG>> data will remove outside of " << ymin << " -> " << ymax << " y-interval" << std::endl;
#endif
vec result_min(dim.first), result_max(dim.first);
for(int k=0; k<dim.first; ++k)
{
result_min[k] = std::numeric_limits<double>::max();
result_max[k] = -std::numeric_limits<double>::max();
}
int vs_value = header.get_int("VS");
std::vector<vec> content;
......@@ -193,28 +185,18 @@ alta::data* alta::load_data_from_text(std::istream& input,
#endif
}
// Update min and max
for(int k=0; k<dim.first; ++k)
{
result_min[k] = std::min(result_min[k], v[k]);
result_max[k] = std::max(result_max[k], v[k]);
}
content.push_back(std::move(v));
}
}
std::cout << "<<INFO>> loaded input stream" << std::endl ;
std::cout << "<<INFO>> data inside " << result_min << " ... "
<< result_max << std::endl ;
std::cout << "<<INFO>> loading data input of R^"
<< dim.first
<< " -> R^" << dim.second << std::endl ;
std::cout << "<<INFO>> " << content.size() << " elements to fit" << std::endl ;
parameters param(dim.first, dim.second, in_param, out_param);
data* result = new vertical_segment(param, std::move(content),
result_min, result_max);
data* result = new vertical_segment(param, std::move(content));
if(args.is_defined("data-correct-cosine"))
result->save("/tmp/data-corrected.dat");
......@@ -308,15 +290,6 @@ alta::data* alta::load_data_from_binary(std::istream& in, const alta::arguments&
std::cerr << "<<ERROR>> Uncorrect or not samples count in the header, please check \'SAMPLE_COUNT\'" << std::endl;
}
// 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: Arrange to use mmap and make it zero-alloc and zero-copy.
std::vector<vec> content(sample_count);
for (int i = 0; i < sample_count; i++)
......@@ -333,18 +306,11 @@ alta::data* alta::load_data_from_binary(std::istream& in, const alta::arguments&
}
content[i] = 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]);
}
}
parameters param(dim.first, dim.second,
params::parse_input(header["PARAM_IN"]),
params::parse_output(header["PARAM_OUT"]));
return new alta::vertical_segment(param, std::move(content), min, max);
return new alta::vertical_segment(param, std::move(content));
}
......@@ -23,17 +23,55 @@ using namespace alta;
//#define RELATIVE_ERROR
vertical_segment::vertical_segment(const parameters& params,
std::vector<vec>&& input_data)
: data(params), _data(input_data), _is_absolute(true), _dt(0.1)
// Note: For some reason returning an rvalue here doesn't work, so let's hope
// RVO comes into play.
static vec data_min(unsigned int size, const std::vector<vec>& data)
{
vec min(size);
for(int k = 0; k < size; ++k)
{
min[k] = std::numeric_limits<double>::max();
}
for (auto&& item: data)
{
for (int k = 0; k < size; ++k)
{
min[k] = std::min(min[k], item[k]);
}
}
return min;
}
static vec data_max(unsigned int size, const std::vector<vec>& data)
{
vec max(size);
for(int k = 0; k < size; ++k)
{
max[k] = -std::numeric_limits<double>::max();
}
for (auto&& item: data)
{
for (int k = 0; k < size; ++k)
{
max[k] = std::max(max[k], item[k]);
}
}
return max;
}
vertical_segment::vertical_segment(const parameters& params,
std::vector<vec>&& input_data,
const vec& min, const vec& max)
: data(params, min, max), _data(input_data),
_is_absolute(true), _dt(0.1)
std::vector<vec>&& input_data)
: data(params,
data_min(params.dimX(), input_data),
data_max(params.dimX(), input_data)),
_data(input_data), _is_absolute(true), _dt(0.1)
{
}
......
......@@ -83,9 +83,6 @@ class vertical_segment : public data
vertical_segment(const parameters& params,
std::vector<vec>&& data);
vertical_segment(const parameters& params,
std::vector<vec>&& data,
const vec& min, const vec& max);
vertical_segment(const parameters& params, unsigned int size);
......
......@@ -79,8 +79,7 @@ bool rational_fitter_parallel::fit_data(const ptr<data>& dat, ptr<function>& fit
}
ptr<vertical_segment> vs(new vertical_segment(dat->parametrization(),
std::move(content),
dat->min(), dat->max()));
std::move(content)));
d = vs;
}
......
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