is there any function in ROOT to compare element by element two different arrays and check that their values are close enough (within a certain epsilon) or identical?
For example numpy has isclose and allclose that will check if element-wise the values are similar and will return a corresponding array of booleans or a single boolean (true if all values close).
I found nothing in TArrayD or in TVector, and I do not think TH1D has such feature.
Any other class I could use?
I am writing some automatic tests and I want to check the values in a histogram that I produce during the test against a reference histogram I have saved.
Hi @cosimoNigro,
I don’t think ROOT has such an helper function (@moneta can confirm/deny), but if you are writing tests you can define it in 3 lines, e.g. with gtest:
void allclose(const std::vector<double> &v1, const std::vector<double> &v2) {
const auto s = v1.size();
ASSERT_EQ(s, v2.size());
for (auto i = 0u; i < s; ++i)
EXPECT_NEAR(v1[i], v2[i]);
}
We would also be glad to accept an IsClose or AllClose implementation for RVec if you ended up implementing one anyway and felt like contributing it upstream.