-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdriver.cpp
69 lines (60 loc) · 1.87 KB
/
driver.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include <functional>
#include <iomanip>
#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>
constexpr unsigned INPUT_NUM = 1;
constexpr unsigned MAX_ARG_NUM = 50;
template <typename T,
std::enable_if_t<std::is_floating_point<T>::value, bool> = true>
std::vector<std::vector<T>> &inputs() {
static auto v = []() {
std::vector<std::vector<T>> v;
for (unsigned i = 0; i < MAX_ARG_NUM; i++) {
std::vector<T> a;
for (unsigned i = 0; i < INPUT_NUM; i++) {
a.push_back(((T)(rand())) / 1000);
}
v.push_back(a);
}
return v;
}();
return v;
}
template <typename T, std::enable_if_t<std::is_integral<T>::value, bool> = true>
std::vector<std::vector<T>> &inputs() {
static auto v = []() {
std::vector<std::vector<T>> v;
for (unsigned i = 0; i < MAX_ARG_NUM; i++) {
std::vector<T> a;
for (unsigned i = 0; i < INPUT_NUM; i++) {
a.push_back(((T)rand()) % 100 + 1);
}
v.push_back(a);
}
return v;
}();
return v;
}
template <typename t>
void run(std::function<t()> f, const char *name, std::string argstr, unsigned i) {
std::cout << name << "(" << (i == 0 ? "" : argstr.c_str() + 2) << ") = " << std::setprecision(15) << f()
<< std::endl;
}
template <typename t, typename arg, typename... args>
void run(std::function<t(arg, args...)> f, const char *name,
std::string argstr, unsigned argno) {
for (arg i : inputs<arg>()[argno]) {
run(std::function<t(args...)>([=](args... a) { return f(i, a...); }), name,
argstr + ", " + std::to_string(i), argno + 1);
}
}
template <typename t, typename... args>
__attribute__((noinline)) void run2(t (*f)(args...), const char *name) {
run(std::function<t(args...)>(f), name, "", 0);
printf("\n");
}
void init() { srand(1); }
void cleanup() {}
#define RUN(arg) run2(arg, #arg)