-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.cpp
138 lines (112 loc) · 2.59 KB
/
test.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
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
#include "mnist.h"
// Right now the tests are validated by visual inspection
// Can be binded to a unit testing framework for automation
extern int c;
extern int cc;
extern int d;
// Print tensor
template <typename T>
void pt(const Tensor2D<T>& t)
{
for(size_t i = 0; i < t.rows(); i++) {
for(size_t j = 0; j < t.cols(); j++)
cout << t[i][j] << " ";
cout << endl;
}
}
//Print dimension
template <typename T>
void pd(const Tensor2D<T>& t)
{
cout << t.rows() << "x" << t.cols() << endl;
}
pair<Tensor2D<precision>, Tensor2D<precision>>
getmock() {
Tensor2D<precision> t1(2, 3);
Tensor2D<precision> t2(3, 2);
t1[0][0] = 1;
t1[0][1] = 2;
t1[0][2] = 3;
t1[1][0] = 4;
t1[1][1] = 5;
t1[1][2] = 6;
t2[0][0] = 9;
t2[0][1] = 10;
t2[1][0] = 11;
t2[1][1] = 12;
t2[2][0] = 13;
t2[2][1] = 15;
return pair<Tensor2D<precision>, Tensor2D<precision>>(t1, t2);
}
pair<Tensor2D<precision>, Tensor2D<precision>>
getmock2() {
Tensor2D<precision> t1(2, 2);
Tensor2D<precision> t2(2, 2);
t1[0][0] = 1;
t1[0][1] = 2;
t1[1][0] = 3;
t1[1][1] = 4;
t2[0][0] = 5;
t2[0][1] = 6;
t2[1][0] = 7;
t2[1][1] = 8;
return pair<Tensor2D<precision>, Tensor2D<precision>>(t1, t2);
}
void test_tensor() {
cout << "test_tensor" << endl;
Tensor2D<precision> t(2, 3);
t[0][0] = 1.0;
pt(t);
}
void test_dot() {
cout << "test_dot" << endl;
auto p = getmock();
pt(dot(p.first, p.second));
}
void test_add() {
cout << "test_add" << endl;
auto p = getmock2();
pt(add(p.first, p.second));
}
void test_sub() {
cout << "test_sub" << endl;
auto p = getmock2();
pt(sub(p.first, p.second));
}
void test_mul() {
cout << "test_mul" << endl;
auto p = getmock2();
pt(mul(p.first, 1.1));
}
void test_transpose() {
cout << "test_transpose" << endl;
auto p = getmock();
pt(transpose(p.first));
}
void test_softmax() {
cout << "test_softmax" << endl;
auto p = getmock();
pt(softmax(p.first));
}
void test_memory() {
cout << "test_memory" << endl;
for(size_t i = 0; i < 10; ++i) {
Tensor2D<float> t1(10000, 10000);
Tensor2D<float> t2(10000, 10000);
Tensor2D<float> t3 = t1;
Tensor2D<float> t4(10000, 10000);
//t4 = add(dot(t1, t2), t3);
}
}
int main()
{
test_tensor();
test_dot();
test_add();
test_sub();
test_mul();
test_transpose();
test_softmax();
test_memory();
return 0;
}