-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmatrix_print.hpp
84 lines (77 loc) · 2.29 KB
/
matrix_print.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
#include <iostream>
#include <sstream>
#include <string>
inline void print_matrix_numpy_style(float* thematrix, unsigned int zeilen, unsigned int spalten, std::string name)
{
/* zeilen starts at */
std::cout << name << " = ";
std::cout << "np.array([";
for (unsigned int zeilennummer = 0; zeilennummer < zeilen; zeilennummer++)
{
std::cout << "[";
for (unsigned int spaltennummer = 0; spaltennummer < spalten; spaltennummer++)
{
std::cout << thematrix[spaltennummer * zeilen + zeilennummer] << ", ";
// std::cout << spaltennummer * zeilen + zeilennummer << ", ";
}
std::cout << "]";
if (zeilennummer != zeilen - 1)
{
std::cout << ","; // Add a sepeartion commma but don't do it for the last element so there are no trailing commas
}
std::cout << std::endl;
}
std::cout << "])\n";
}
inline void print_error(float* host_error, int number_of_inputs, int* SHAPE, int NUM_LAYERS_TOTAL)
{
std::stringstream ss;
int offset = 0;
for (int layer = 1; layer < NUM_LAYERS_TOTAL; layer++)
{
ss.str("");
ss.clear();
ss << "error" << layer;
print_matrix_numpy_style(host_error + offset, SHAPE[layer], number_of_inputs, ss.str());
offset += SHAPE[layer] * number_of_inputs;
}
}
inline void print_activations(float* host_activations, int number_of_inputs, int* SHAPE, int NUM_LAYERS_TOTAL)
{
std::stringstream ss;
int offset = 0;
for (int layer = 0; layer < NUM_LAYERS_TOTAL; layer++)
{
ss.str("");
ss.clear();
ss << "activation" << layer;
print_matrix_numpy_style(host_activations + offset, SHAPE[layer], number_of_inputs, ss.str());
offset += SHAPE[layer] * number_of_inputs;
}
}
inline void print_weight_matrix_numpy_style(float *the_matrix, const int shape[], int length)
{
int offset = 0;
std::stringstream ss;
for (int i = 0; i < length - 1; i++)
{
ss.str("");
ss.clear();
ss << "weight_matrix" << i;
print_matrix_numpy_style(the_matrix + offset, shape[i + 1], shape[i], ss.str());
offset += shape[i] * shape[i + 1];
}
}
inline void print_bias_matrix_numpy_style(float *the_matrix, const int shape[], int shape_length)
{
int offset = 0;
std::stringstream ss;
for (int i = 0; i < shape_length - 1; i++)
{
ss.str("");
ss.clear();
ss << "bias_layer" << i;
print_matrix_numpy_style(the_matrix + offset, shape[i + 1], 1, ss.str());
offset += shape[i + 1];
}
}