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

data: Add 'equals' method.

parent c85f0997
......@@ -9,6 +9,7 @@
file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include <iostream>
#include <cmath>
#include "data.h"
#include "data_storage.h"
......@@ -24,3 +25,31 @@ void data::save(const std::string& filename) const
file.close();
}
bool data::equals(const data& data, double epsilon)
{
if (size() != data.size()
|| dimX() != data.dimX() || dimY() != data.dimY()
|| input_parametrization() != data.input_parametrization()
|| output_parametrization() != data.output_parametrization())
return false;
for(int i = 0; i < data.size(); i++)
{
vec other = data.get(i);
vec self = get(i);
if (self.size() != other.size()) // should not happen
return false;
for (int j = 0; j < self.size(); j++)
{
double diff = std::abs(self[j] - other[j]);
if (diff > epsilon)
return false;
}
}
return true;
}
......@@ -74,6 +74,10 @@ class data : public parametrized
// Get data size, e.g. the number of samples to fit
virtual int size() const = 0 ;
//! \brief Return true if this object is equal to DATA ±ε.
virtual bool equals(const data& data,
double epsilon = std::numeric_limits<float>::min());
protected: // data
} ;
......
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