From c7c738a1e64f34f5935c11d6bcacfa57ca964b7f Mon Sep 17 00:00:00 2001 From: Stefan Weil Date: Sun, 25 Mar 2018 21:04:15 +0200 Subject: [PATCH] lstm: Small code optimisation (#1426) Replace float compare operation by integer compare operation and avoid float division if it is not needed. Signed-off-by: Stefan Weil --- lstm/input.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lstm/input.cpp b/lstm/input.cpp index daa4687f..6411800a 100644 --- a/lstm/input.cpp +++ b/lstm/input.cpp @@ -138,10 +138,9 @@ void Input::PreparePixInput(const StaticShape& shape, const Pix* pix, int height = pixGetHeight(normed_pix); int target_height = shape.height(); if (target_height == 1) target_height = shape.depth(); - if (target_height == 0) target_height = height; - float im_factor = static_cast(target_height) / height; - if (im_factor != 1.0f) { + if (target_height != 0 && target_height != height) { // Get the scaled image. + float im_factor = static_cast(target_height) / height; Pix* scaled_pix = pixScale(normed_pix, im_factor, im_factor); pixDestroy(&normed_pix); normed_pix = scaled_pix;