Skip to content

Commit

Permalink
Avoid some unnecessary conversions from float to double
Browse files Browse the repository at this point in the history
Signed-off-by: Stefan Weil <sw@weilnetz.de>
  • Loading branch information
stweil committed Nov 28, 2021
1 parent 5e8d877 commit a1f40ca
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/classify/adaptmatch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1301,7 +1301,7 @@ int Classify::CharNormTrainingSample(bool pruner_only, int keep_this, const Trai
std::vector<uint8_t> char_norm_array(unicharset.size());
auto num_pruner_classes = std::max(static_cast<unsigned>(unicharset.size()), PreTrainedTemplates->NumClasses);
std::vector<uint8_t> pruner_norm_array(num_pruner_classes);
adapt_results->BlobLength = static_cast<int>(ActualOutlineLength(norm_feature) * 20 + 0.5);
adapt_results->BlobLength = static_cast<int>(ActualOutlineLength(norm_feature) * 20 + 0.5f);
ComputeCharNormArrays(norm_feature, PreTrainedTemplates, &char_norm_array[0], &pruner_norm_array[0]);

PruneClasses(PreTrainedTemplates, num_features, keep_this, sample.features(), &pruner_norm_array[0],
Expand Down Expand Up @@ -1347,7 +1347,7 @@ int Classify::CharNormTrainingSample(bool pruner_only, int keep_this, const Trai
void Classify::ClassifyAsNoise(ADAPT_RESULTS *results) {
float rating = results->BlobLength / matcher_avg_noise_size;
rating *= rating;
rating /= 1.0 + rating;
rating /= 1 + rating;

AddNewResult(UnicharRating(UNICHAR_SPACE, 1.0f - rating), results);
} /* ClassifyAsNoise */
Expand Down Expand Up @@ -1783,8 +1783,8 @@ PROTO_ID Classify::MakeNewTempProtos(FEATURE_SET Features, int NumBadFeat, FEATU
A2 = F2->Params[PicoFeatDir];

AngleDelta = std::fabs(A1 - A2);
if (AngleDelta > 0.5) {
AngleDelta = 1.0 - AngleDelta;
if (AngleDelta > 0.5f) {
AngleDelta = 1 - AngleDelta;
}

if (AngleDelta > matcher_clustering_max_angle_delta || std::fabs(X1 - X2) > SegmentLength ||
Expand All @@ -1811,8 +1811,8 @@ PROTO_ID Classify::MakeNewTempProtos(FEATURE_SET Features, int NumBadFeat, FEATU
instead of the -0.25 to 0.75 used in baseline normalization */
Proto->Length = SegmentLength;
Proto->Angle = A1;
Proto->X = (X1 + X2) / 2.0;
Proto->Y = (Y1 + Y2) / 2.0 - Y_DIM_OFFSET;
Proto->X = (X1 + X2) / 2;
Proto->Y = (Y1 + Y2) / 2 - Y_DIM_OFFSET;
FillABC(Proto);

TempProto->ProtoId = Pid;
Expand Down Expand Up @@ -2045,7 +2045,7 @@ void Classify::RemoveExtraPuncs(ADAPT_RESULTS *Results) {
* - matcher_good_threshold default good match rating
*/
void Classify::SetAdaptiveThreshold(float Threshold) {
Threshold = (Threshold == matcher_good_threshold) ? 0.9 : (1.0 - Threshold);
Threshold = (Threshold == matcher_good_threshold) ? 0.9f : (1 - Threshold);
classify_adapt_proto_threshold.set_value(ClipToRange<int>(255 * Threshold, 0, 255));
classify_adapt_feature_threshold.set_value(ClipToRange<int>(255 * Threshold, 0, 255));
} /* SetAdaptiveThreshold */
Expand Down

0 comments on commit a1f40ca

Please sign in to comment.