-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathTypes.hpp
117 lines (87 loc) · 3.13 KB
/
Types.hpp
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
/* Copyright(C) ga-developers
*
* Repository: https://github.com/ga-developers/ga-benchmark.git
*
* This file is part of the GA-Benchmark project.
*
* GA-Benchmark is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* GA-Benchmark is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GA-Benchmark. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef __GABM_TYPES_HPP__
#define __GABM_TYPES_HPP__
#include <array>
#include <cstdint>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <random>
#include <vector>
#include <benchmark/benchmark.h>
namespace gabm {
using real_t = std::double_t;
using grade_t = std::int32_t;
using dims_t = std::uint32_t;
using vector_coords_t = std::array<real_t, GABM_N_DIMENSIONS>;
using factors_list_t = std::vector<vector_coords_t>;
class BaseRandomEntries;
namespace detail {
std::default_random_engine random_engine{ GABM_OPERATION }; /*The seed is constant because all solutions must use the same set of random numbers.*/
std::vector<BaseRandomEntries*> random_entries;
}
class BaseRandomEntries {
public:
BaseRandomEntries() {
detail::random_entries.push_back(this);
}
virtual void init() = 0;
};
template<typename RandomEntryGeneratorClass>
class RandomEntries : public BaseRandomEntries {
private:
using Super = BaseRandomEntries;
using entry_type = decltype(RandomEntryGeneratorClass::MakeRandomEntry(detail::random_engine));
using container_type = std::vector<entry_type>;
public:
using size_type = typename container_type::size_type;
using value_type = typename container_type::value_type;
using reference = typename container_type::reference;
using const_reference = typename container_type::const_reference;
RandomEntries() :
Super(),
_entries() {
_entries.resize(GABM_ITERATIONS);
}
void init() override {
for (auto &entry : _entries) {
entry = RandomEntryGeneratorClass::MakeRandomEntry(detail::random_engine);
}
}
GABM_ALWAYS_INLINE size_type size() const {
return _entries.size();
}
GABM_ALWAYS_INLINE reference operator[](size_type ind) {
return _entries[ind];
}
GABM_ALWAYS_INLINE const_reference operator[](size_type ind) const {
return _entries[ind];
}
private:
container_type _entries;
};
void InitializeRandomEntries() {
for (auto ptr : detail::random_entries) {
ptr->init();
}
}
}
#endif // __GABM_TYPES_HPP__