Commit adcb106f authored by Bednárek David RNDr. Ph.D.'s avatar Bednárek David RNDr. Ph.D.
Browse files

comparison to gold

parent c90e10e5
......@@ -36,7 +36,7 @@ namespace fmwkng {
class abstract_element;
using element_ptr = std::unique_ptr< abstract_element>;
using element_observer = const abstract_element *;
using element_observer = const abstract_element*;
enum class element_sense { OPEN, CLOSE };
......@@ -60,6 +60,7 @@ namespace fmwkng {
virtual void make_code(std::ostream& os) const = 0;
virtual std::size_t data_size() const = 0;
virtual void data_text(std::ostream& os, std::size_t i) const = 0;
virtual void gold_comparison_text(std::ostream& os, const abstract_element* gold) const = 0;
virtual void metadata_marker(std::ostream& os) const = 0;
virtual bool useful() const = 0;
virtual bool reducible() const = 0;
......@@ -137,6 +138,23 @@ namespace fmwkng {
}
}
}
void gold_comparison_text(std::ostream& os, element_list_view gold) const
{
std::size_t s = 0;
auto git = gold.begin();
for (auto it = begin(); it != end(); ++it)
{
if ((*it)->sense() == element_sense::CLOSE)
{
if (s)
os << "\t";
(*it)->gold_comparison_text(os, &**git);
++s;
++git;
}
}
}
void metadata_text(std::ostream& os) const
{
std::size_t s = 0;
......@@ -230,9 +248,13 @@ namespace fmwkng {
{
element_list_view(*this).data_text(os);
}
void gold_comparison_text(std::ostream& os, const element_list & gold) const
{
element_list_view(*this).gold_comparison_text(os, element_list_view(gold));
}
void metadata_text(std::ostream& os) const
{
element_list_view(*this).metadata_text( os);
element_list_view(*this).metadata_text(os);
}
bool has_paired() const
......@@ -337,7 +359,7 @@ namespace fmwkng {
element_list reduced_children;
};
inline reducer_list view_to_list(element_const_iterator & b, element_const_iterator e)
inline reducer_list view_to_list(element_const_iterator& b, element_const_iterator e)
{
reducer_list rl;
......@@ -368,7 +390,7 @@ namespace fmwkng {
os << std::endl;
print_list(os, a.children, indent + "\t");
os << indent;
(*(a.source_range.end()-1))->metadata_marker(os);
(*(a.source_range.end() - 1))->metadata_marker(os);
os << std::endl;
}
}
......@@ -391,7 +413,7 @@ namespace fmwkng {
return m;
}
inline void reduce_list(reduced_list& nl, const reducer_list &rl)
inline void reduce_list(reduced_list& nl, const reducer_list& rl)
{
std::unordered_map< std::string, element_list> reduction_map;
std::vector< std::unordered_map< std::string, element_list>::pointer> reduction_order;
......@@ -413,7 +435,7 @@ namespace fmwkng {
auto sz = src.size();
for (std::size_t i = 0; i < sz; ++i)
{
rv.first->second.push_back( src[i]->aggregate_init());
rv.first->second.push_back(src[i]->aggregate_init());
}
}
else
......@@ -458,15 +480,58 @@ namespace fmwkng {
{
rn.reduced_children.push_back(std::move(a));
}
rn.reduced_children.push_back((*(rn.source_range.end()-1))->clone());
rn.reduced_children.push_back((*(rn.source_range.end() - 1))->clone());
//std::cout << "\t";
//print_list(rn.reduced_children);
}
}
struct element_list_hash {
std::size_t operator()(const element_list& el) const
{
std::ostringstream os;
el.metadata_text(os);
os << "\t";
el.data_text(os);
return hash_(os.str());
}
private:
std::hash<std::string> hash_;
};
}
struct gold_pair;
struct gold_data {
gold_data()
{}
gold_data(const gold_data& b);
gold_data(gold_data&& b) noexcept = default;
gold_data& operator=(const gold_data& b);
gold_data & operator=(gold_data&& b) noexcept = default;
~gold_data() noexcept = default;
const impl::element_list* find(const impl::element_list& key) const
{
auto it = dm.find(key);
return it == dm.end() ? nullptr : &it->second;
}
gold_data(std::initializer_list<gold_pair> il);
using data_map = std::unordered_map< impl::element_list, impl::element_list, impl::element_list_hash>;
data_map dm;
};
namespace impl {
using element_observer_vector = std::vector<element_observer>;
inline void print_node(const reducer_node& rn, std::size_t depth,
inline void print_node(const gold_data& gd,
const reducer_node& rn,
std::size_t depth,
const element_observer_vector & openers = {},
const element_observer_vector & closers = {})
{
......@@ -480,12 +545,25 @@ namespace fmwkng {
c2.push_back(&**(rn.source_range.end()-1));
for (auto&& a : rn.children)
{
print_node(a, depth - 1, o2, c2);
print_node(gd, a, depth - 1, o2, c2);
}
}
}
else
{
element_list key;
for (auto&& a : openers)
{
key.push_back(a->clone());
}
for (auto&& a : rn.reduced_children)
{
if (a->sense() == element_sense::OPEN)
key.push_back(a->clone());
}
auto gold_value = gd.find(key);
for (auto&& a : openers)
{
a->metadata_marker(std::cout);
......@@ -504,6 +582,13 @@ namespace fmwkng {
std::cout << '\t';
rn.reduced_children.data_text(std::cout);
}
if (!!gold_value && gold_value->data_size())
{
std::cout << '\t';
rn.reduced_children.gold_comparison_text(std::cout, *gold_value);
}
std::cout << std::endl;
}
}
......@@ -594,7 +679,7 @@ namespace fmwkng {
return root;
}
inline void print_all(element_list_view el, element_list_view prefix = {})
inline void print_all(const gold_data & gd, element_list_view el, element_list_view prefix = {})
{
//print_list(el, prefix);
auto root = reduce_list(el);
......@@ -610,11 +695,16 @@ namespace fmwkng {
--d;
for (auto&& a : root)
{
print_node(a, d, openers);
print_node(gd, a, d, openers);
}
}
}
inline void print_all(element_list_view el, element_list_view prefix = {})
{
print_all(gold_data(), el, prefix);
}
inline void print_all_code(std::ostream & os, element_list_view el)
{
auto root = reduce_list(el);
......@@ -656,6 +746,12 @@ namespace fmwkng {
assert(i == 0);
my_traits::data_text(os, d_);
}
virtual void gold_comparison_text(std::ostream& os, const abstract_element* gold) const override
{
auto p = dynamic_cast<const self_*>(gold);
assert(!!p);
my_traits::gold_comparison_text(os, d_, p->d_);
}
virtual void metadata_marker(std::ostream& os) const override
{
my_traits::metadata_marker(os);
......@@ -723,6 +819,9 @@ namespace fmwkng {
{
assert(false);
}
virtual void gold_comparison_text(std::ostream& os, const abstract_element* gold) const override
{
}
virtual void metadata_marker(std::ostream& os) const override
{
my_traits::metadata_marker(os);
......@@ -812,6 +911,12 @@ namespace fmwkng {
assert(i == 0);
my_traits::data_text(os, d_);
}
virtual void gold_comparison_text(std::ostream& os, const abstract_element* gold) const override
{
auto p = dynamic_cast<const self_*>(gold);
assert(!!p);
my_traits::gold_comparison_text(os, d_, p->d_);
}
virtual void metadata_marker(std::ostream& os) const override
{
my_traits::metadata_marker_open(os);
......@@ -880,6 +985,9 @@ namespace fmwkng {
{
assert(false);
}
virtual void gold_comparison_text(std::ostream& os, const abstract_element* gold) const override
{
}
virtual void metadata_marker(std::ostream& os) const override
{
my_traits::metadata_marker_close(os);
......@@ -942,6 +1050,9 @@ namespace fmwkng {
{
assert(false);
}
virtual void gold_comparison_text(std::ostream& os, const abstract_element* gold) const override
{
}
virtual void metadata_marker(std::ostream& os) const override
{
my_traits::metadata_marker_open(os);
......@@ -1010,6 +1121,12 @@ namespace fmwkng {
assert(i == 0);
my_traits::data_text(os, d_);
}
virtual void gold_comparison_text(std::ostream& os, const abstract_element* gold) const override
{
auto p = dynamic_cast<const self_*>(gold);
assert(!!p);
my_traits::gold_comparison_text(os, d_, p->d_);
}
virtual void metadata_marker(std::ostream& os) const override
{
my_traits::metadata_marker_close(os);
......@@ -1653,7 +1770,8 @@ namespace fmwkng {
private:
using self_ = root_data_holder< config_t>;
public:
root_data_holder(int argc, char** argv)
root_data_holder(int argc, char** argv, const gold_data& gd = gold_data{})
: gd_(gd)
{
std::fill(platform_enablers_.begin(), platform_enablers_.end(), true);
process_arguments(std::vector< std::string>(argv + 1, argv + argc));
......@@ -1802,6 +1920,7 @@ namespace fmwkng {
mutable element_list el_;
mutable element_list all_el_;
std::string code_fn_;
gold_data gd_;
void print_elements() const
{
......@@ -1819,7 +1938,7 @@ namespace fmwkng {
void print_all_elements() const
{
print_all(all_el_);
print_all(gd_, all_el_);
}
void process_arguments(const std::vector< std::string>& arg)
......@@ -1943,6 +2062,10 @@ namespace fmwkng {
{
os << platform_tag::name();
}
static void gold_comparison_text(std::ostream& os, const data_type& d, const data_type& gold_d)
{
assert(0);
}
static void code_data(std::ostream& os, const data_type&)
{
os << "std::monostate{}";
......@@ -2028,6 +2151,10 @@ namespace fmwkng {
{
os << d.first;
}
static void gold_comparison_text(std::ostream& os, const data_type& d, const data_type& gold_d)
{
assert(0);
}
static void code_data(std::ostream& os, const data_type& d)
{
os << "std::make_pair("
......@@ -2080,6 +2207,10 @@ namespace fmwkng {
{
os << "all";
}
static void gold_comparison_text(std::ostream& os, const data_type& d, const data_type& gold_d)
{
assert(0);
}
static void code_data(std::ostream& os, const data_type& d)
{
os << "std::monostate()";
......@@ -2112,6 +2243,10 @@ namespace fmwkng {
{
os << "all";
}
static void gold_comparison_text(std::ostream& os, const data_type& d, const data_type& gold_d)
{
assert(0);
}
static void code_data(std::ostream& os, const data_type& d)
{
os << "std::monostate()";
......@@ -2144,6 +2279,10 @@ namespace fmwkng {
{
d.data_text(os);
}
static void gold_comparison_text(std::ostream& os, const data_type& d, const data_type& gold_d)
{
assert(0);
}
static void code_data(std::ostream& os, const data_type& d)
{
d.code_data(os);
......@@ -2263,6 +2402,10 @@ namespace fmwkng {
{
os << d;
}
static void gold_comparison_text(std::ostream& os, const data_type& d, const data_type& gold_d)
{
assert(0);
}
static void code_data(std::ostream& os, const data_type& d)
{
os << d;
......@@ -2482,6 +2625,11 @@ namespace fmwkng {
{
os << d.count();
}
static void gold_comparison_text(std::ostream& os, const data_type& d, const data_type& gold_d)
{
auto ratio = (double)d.count() / gold_d.count();
os << ratio;
}
static void code_data(std::ostream& os, const data_type& d)
{
os << "std::clock::duration("
......@@ -2611,6 +2759,13 @@ namespace fmwkng {
{
os << d;
}
static void gold_comparison_text(std::ostream& os, const data_type& d, const data_type& gold_d)
{
if (d == gold_d)
os << "OK";
else
os << "MISMATCH";
}
static void code_data(std::ostream& os, const data_type& d)
{
os << d;
......@@ -2788,6 +2943,11 @@ namespace fmwkng {
{
os << d;
}
static void gold_comparison_text(std::ostream& os, const data_type& d, const data_type& gold_d)
{
auto ratio = d / gold_d;
os << (ratio*100) << "%";
}
static void code_data(std::ostream& os, const data_type& d)
{
os << d;
......@@ -2825,6 +2985,11 @@ namespace fmwkng {
{
os << std::exp(d.first / d.second);
}
static void gold_comparison_text(std::ostream& os, const data_type& d, const data_type& gold_d)
{
auto logratio = (d.first / d.second) - (gold_d.first / gold_d.second);
os << (std::exp(logratio)*100) << "%";
}
static void code_data(std::ostream& os, const data_type& d)
{
os << "std::make_pair("
......@@ -3654,34 +3819,29 @@ namespace fmwkng {
impl::element_list value;
};
namespace impl {
struct element_list_hash {
std::size_t operator()(const element_list& el) const
{
std::ostringstream os;
el.metadata_text(os);
os << "\t";
el.data_text(os);
return hash_(os.str());
}
private:
std::hash<std::string> hash_;
};
inline gold_data::gold_data(std::initializer_list<gold_pair> il)
{
for (auto&& a : il)
{
auto rv = dm.emplace(a.key.clone(), a.value.clone());
assert(rv.second);
}
}
struct gold_data {
gold_data(std::initializer_list<gold_pair> il)
inline gold_data::gold_data(const gold_data& b)
{
for (auto&& a : b.dm)
{
for (auto&& a : il)
{
auto rv = dm.emplace(a.key.clone(), a.value.clone());
assert(rv.second);
}
auto rv = dm.emplace(a.first.clone(), a.second.clone());
assert(rv.second);
}
using data_map = std::unordered_map< impl::element_list, impl::element_list, impl::element_list_hash>;
data_map dm;
};
}
inline gold_data& gold_data::operator=(const gold_data& b)
{
return operator=(gold_data(b));
}
#pragma endregion
}
......
......@@ -100,7 +100,7 @@ namespace macromain {
int main(int argc, char** argv)
{
using namespace fmwkng;
root<macromain::root_config> ctx1(argc, argv);
root<macromain::root_config> ctx1(argc, argv, macromain::gold_results());
//std::cout << "Running..." << std::endl;
for_platforms(ctx1, macromain::run_platform_ftor());
//std::cout << "Done." << std::endl;
......
Supports Markdown
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