-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_main.cpp
More file actions
105 lines (76 loc) · 2.22 KB
/
test_main.cpp
File metadata and controls
105 lines (76 loc) · 2.22 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
#include <cmd.h>
#include <rfbp.hpp>
#if (defined __clang__ || (!defined __clang__ && __GNUC__ > 4)) && defined WITH_SCORER
#define USE_SCORER
#include <scorer.h>
#endif
int main (int argc, char *argv[])
{
bool bin;
int nth;
std :: string patternsfile,
del,
weight_file,
output_file;
parse_test_args(argc,
argv,
patternsfile,
del,
bin,
weight_file,
output_file,
nth);
Patterns patterns(patternsfile, bin, del);
Cavity_Message < MagP64 > messages(weight_file, bin);
long int ** bin_weights = messages.get_weights();
long int * predicted_labels = nullptr;
std :: unique_ptr < int[] > temp_labels( new int [patterns.Nrow] );
std :: unique_ptr < int[] > temp_predict( new int [patterns.Nrow] );
#ifdef USE_SCORER
scorer score;
#endif
#ifdef _OPENMP
#ifdef USE_SCORER
#pragma omp parallel shared (score) num_threads (nth)
#else
#pragma omp parallel num_threads (nth)
#endif
{
#endif
predicted_labels = nonbayes_test(bin_weights, patterns, messages.K);
#ifdef _OPENMP
#pragma omp sections
{
#endif
#ifdef _OPENMP
#pragma omp section
#endif
std :: transform( patterns.output, patterns.output + patterns.Nrow,
temp_labels.get(), [](const long int & p){return static_cast < int >(p);});
#ifdef _OPENMP
#pragma omp section
#endif
std :: transform( predicted_labels, predicted_labels + patterns.Nrow,
temp_predict.get(), [](const long int & p){return static_cast < int >(p);});
#ifdef _OPENMP
}
#endif
#ifdef USE_SCORER
score.compute_score( temp_labels.get(), temp_predict.get(), patterns.Nrow, patterns.Nrow);
#endif
#ifdef _OPENMP
}
#endif
#ifdef USE_SCORER
if ( !output_file.empty() ) score.dump(output_file);
else score.print();
#else
std :: cout << "true_label\tpredict_label" << std :: endl;
for (long int i = 0L; i < patterns.Nrow; ++i)
std :: cout << patterns.output[i] << "\t" << temp_predict[i] << std :: endl;
#endif
for (long int i = 0L; i < messages.K; ++i) delete[] bin_weights[i];
delete[] bin_weights;
delete[] predicted_labels;
return 0;
}