-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathfixture.hpp
More file actions
160 lines (125 loc) · 4.39 KB
/
Copy pathfixture.hpp
File metadata and controls
160 lines (125 loc) · 4.39 KB
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
#pragma once
#include <gtest/gtest.h>
#include <algorithm>
#include <random>
#include <string>
#include <vector>
#include "layers/Layer.hpp"
using namespace it_lab_ai;
class BaseTestFixture : public ::testing::Test {
public:
void SetUp() override {
defaultOptions.backend = Backend::kNaive;
defaultOptions.parallel = false;
defaultOptions.par_backend = ParBackend::kSeq;
}
static RuntimeOptions setTBBOptions() {
RuntimeOptions options;
options.backend = Backend::kNaive;
options.parallel = true;
options.par_backend = ParBackend::kTbb;
return options;
}
static RuntimeOptions setSeqOptions() {
RuntimeOptions options;
options.backend = Backend::kNaive;
options.parallel = true;
options.par_backend = ParBackend::kSeq;
return options;
}
static RuntimeOptions setSTLOptions() {
RuntimeOptions options;
options.backend = Backend::kNaive;
options.parallel = true;
options.par_backend = ParBackend::kThreads;
return options;
}
static RuntimeOptions setKokkosOptions() {
RuntimeOptions options;
options.backend = Backend::kNaive;
options.parallel = true;
options.par_backend = ParBackend::kKokkos;
return options;
}
static RuntimeOptions setOmpOptions() {
RuntimeOptions options;
options.backend = Backend::kNaive;
options.parallel = true;
options.par_backend = ParBackend::kOmp;
return options;
}
static RuntimeOptions createOptionsWithBackend(ParBackend backend) {
RuntimeOptions options;
options.backend = Backend::kNaive;
options.parallel = (backend != ParBackend::kSeq);
options.par_backend = backend;
return options;
}
static std::vector<float> basic1DData() {
return {9.0f, 8.0f, 7.0f, 6.0f, 5.0f, 4.0f, 3.0f, 2.0f};
}
static Shape basic1DShape() { return {8}; }
static std::vector<float> basic2DData4x4() {
return {9.0f, 8.0f, 7.0f, 6.0f, 5.0f, 4.0f, 3.0f, 2.0f,
2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f};
}
static Shape basic2DShape4x4() { return {4, 4}; }
static std::vector<float> basic2DData3x3() {
return {9.0f, 8.0f, 7.0f, 5.0f, 4.0f, 3.0f, 2.0f, 3.0f, 4.0f};
}
static Shape basic2DShape3x3() { return {3, 3}; }
static std::vector<float> activationTestData() {
return {-3.0f, -2.0f, -1.0f, 0.0f, 1.0f, 2.0f, 3.0f};
}
static std::vector<float> reluExpected() {
return {0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 2.0f, 3.0f};
}
static std::vector<float> sigmoidExpected() {
return {0.0474f, 0.1192f, 0.2689f, 0.5f, 0.7311f, 0.8808f, 0.9526f};
}
static std::vector<float> get1DAverageExpected() {
return {8.0f, 6.0f, 4.0f};
}
static std::vector<float> get2DAverageStride1Expected() {
return {6.5f, 5.5f, 4.5f, 3.5f, 3.5f, 3.5f, 4.5f, 5.5f, 6.5f};
}
static std::vector<float> ascending1DData() {
return {1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f};
}
static Shape ascending1DShape() { return {10}; }
static std::vector<float> descending1DData() {
return {10.0f, 9.0f, 8.0f, 7.0f, 6.0f, 5.0f, 4.0f, 3.0f, 2.0f, 1.0f};
}
static std::vector<float> mixed1DData() {
return {-5.0f, -3.0f, 0.0f, 2.0f, 4.0f, -1.0f, 3.0f, 1.0f, -2.0f, 5.0f};
}
static std::vector<float> small2DData2x2() {
return {1.0f, 2.0f, 3.0f, 4.0f};
}
static Shape small2DShape2x2() { return {2, 2}; }
static std::vector<float> medium2DData5x5() {
return {1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f,
10.0f, 11.0f, 12.0f, 13.0f, 14.0f, 15.0f, 16.0f, 17.0f, 18.0f,
19.0f, 20.0f, 21.0f, 22.0f, 23.0f, 24.0f, 25.0f};
}
static Shape medium2DShape5x5() { return {5, 5}; }
static std::vector<float> zero2DData3x3() {
return {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f};
}
static Shape zero2DShape3x3() { return {3, 3}; }
static std::vector<float> constant2DData4x4(float value = 5.0f) {
return std::vector<float>(16, value);
}
static Shape constant2DShape4x4() { return {4, 4}; }
template <typename T>
static void expectVectorsNear(const std::vector<T>& actual,
const std::vector<T>& expected,
T tolerance = static_cast<T>(1e-5)) {
ASSERT_EQ(actual.size(), expected.size());
for (size_t i = 0; i < actual.size(); ++i) {
EXPECT_NEAR(actual[i], expected[i], tolerance) << "at index " << i;
}
}
protected:
RuntimeOptions defaultOptions;
};