Created
December 22, 2014 21:18
-
-
Save ryanfb/217acaf8d14c2dcab412 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git classify/trainingsampleset.cpp classify/trainingsampleset.cpp | |
index afbf3f4..6121395 100644 | |
--- classify/trainingsampleset.cpp | |
+++ classify/trainingsampleset.cpp | |
@@ -693,6 +693,8 @@ void TrainingSampleSet::ComputeCanonicalSamples(const IntFeatureMap& map, | |
fcinfo.canonical_sample = fcinfo.samples[0]; | |
fcinfo.canonical_dist = 0.0f; | |
for (int i = 0; i < fcinfo.samples.size(); ++i) { | |
+ #pragma omp parallel | |
+ { | |
int s1 = fcinfo.samples[i]; | |
const GenericVector<int>& features1 = samples_[s1]->indexed_features(); | |
f_table.Set(features1, features1.size(), true); | |
@@ -701,6 +703,7 @@ void TrainingSampleSet::ComputeCanonicalSamples(const IntFeatureMap& map, | |
// reasonably fast because f_table.FeatureDistance is fast, but we | |
// may have to reconsider if we start playing with too many samples | |
// of a single char/font. | |
+ #pragma omp for | |
for (int j = 0; j < fcinfo.samples.size(); ++j) { | |
int s2 = fcinfo.samples[j]; | |
if (samples_[s2]->class_id() != c || | |
@@ -709,11 +712,14 @@ void TrainingSampleSet::ComputeCanonicalSamples(const IntFeatureMap& map, | |
continue; | |
GenericVector<int> features2 = samples_[s2]->indexed_features(); | |
double dist = f_table.FeatureDistance(features2); | |
- if (dist > max_dist) { | |
- max_dist = dist; | |
- if (dist > max_max_dist) { | |
- max_s1 = s1; | |
- max_s2 = s2; | |
+ #pragma omp critical(inner_comparison) | |
+ { | |
+ if (dist > max_dist) { | |
+ max_dist = dist; | |
+ if (dist > max_max_dist) { | |
+ max_s1 = s1; | |
+ max_s2 = s2; | |
+ } | |
} | |
} | |
} | |
@@ -727,6 +733,7 @@ void TrainingSampleSet::ComputeCanonicalSamples(const IntFeatureMap& map, | |
fcinfo.canonical_dist = max_dist; | |
} | |
UpdateRange(max_dist, &min_max_dist, &max_max_dist); | |
+ } | |
} | |
if (max_max_dist > global_worst_dist) { | |
// Keep a record of the worst pair over all characters/fonts too. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment