Skip to content

Commit

Permalink
Avoid some float / double conversions in class Classify
Browse files Browse the repository at this point in the history
This also fixes several compiler warnings ([-Wimplicit-float-conversion],
[-Wdouble-promotion]).

Signed-off-by: Stefan Weil <[email protected]>
  • Loading branch information
stweil committed May 20, 2024
1 parent d0b3d09 commit 0366613
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/classify/normmatch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,17 @@ struct NORM_PROTOS {
* normalization adjustment. The equation that represents the transform is:
* 1 / (1 + (NormAdj / midpoint) ^ curl)
*/
static double NormEvidenceOf(double NormAdj) {
NormAdj /= classify_norm_adj_midpoint;
static float NormEvidenceOf(float NormAdj) {
NormAdj /= static_cast<float>(classify_norm_adj_midpoint);

if (classify_norm_adj_curl == 3) {
NormAdj = NormAdj * NormAdj * NormAdj;
} else if (classify_norm_adj_curl == 2) {
NormAdj = NormAdj * NormAdj;
} else {
NormAdj = pow(NormAdj, classify_norm_adj_curl);
NormAdj = std::pow(NormAdj, static_cast<float>(classify_norm_adj_curl));
}
return (1.0 / (1.0 + NormAdj));
return (1 / (1 + NormAdj));
}

/*----------------------------------------------------------------------------
Expand All @@ -73,7 +73,7 @@ static double NormEvidenceOf(double NormAdj) {
double_VAR(classify_norm_adj_midpoint, 32.0, "Norm adjust midpoint ...");
double_VAR(classify_norm_adj_curl, 2.0, "Norm adjust curl ...");
/** Weight of width variance against height and vertical position. */
const double kWidthErrorWeighting = 0.125;
const float kWidthErrorWeighting = 0.125f;

/*----------------------------------------------------------------------------
Public Code
Expand Down Expand Up @@ -102,7 +102,7 @@ float Classify::ComputeNormMatch(CLASS_ID ClassId, const FEATURE_STRUCT &feature
float Match = (feature.Params[CharNormLength] * feature.Params[CharNormLength] * 500.0f +
feature.Params[CharNormRx] * feature.Params[CharNormRx] * 8000.0f +
feature.Params[CharNormRy] * feature.Params[CharNormRy] * 8000.0f);
return (1.0f - NormEvidenceOf(Match));
return (1 - NormEvidenceOf(Match));
}

float BestMatch = FLT_MAX;
Expand Down Expand Up @@ -145,7 +145,7 @@ float Classify::ComputeNormMatch(CLASS_ID ClassId, const FEATURE_STRUCT &feature
BestMatch = Match;
}
}
return 1.0 - NormEvidenceOf(BestMatch);
return 1 - NormEvidenceOf(BestMatch);
} /* ComputeNormMatch */

void Classify::FreeNormProtos() {
Expand Down

0 comments on commit 0366613

Please sign in to comment.