aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTatWai Chong <tatwai.chong@arm.com>2023-08-31 16:58:27 -0700
committerEric Kunze <eric.kunze@arm.com>2023-09-13 18:44:56 +0000
commitfb879821119c93109198a576e7b93e80b3dc0616 (patch)
tree330eceb5d54add4c1e2ccdfdbac7f277573d0a57
parent76c6a556c7396ee6468780b57676e5821c55b1e4 (diff)
downloadreference_model-fb879821119c93109198a576e7b93e80b3dc0616.tar.gz
Add integer divide with floor for coordinate calculation
Align with the change in the spec. Define idiv_floor to give equivalent behavior to the floating-point floor function for image coordinate calculation. Change-Id: Ice06d354d58b1bb0dfedab55c9cc9eac1598b50c Signed-off-by: TatWai Chong <tatwai.chong@arm.com>
-rw-r--r--reference_model/src/graph_node.cc13
-rw-r--r--reference_model/src/graph_node.h1
-rw-r--r--reference_model/src/ops/image.cc9
3 files changed, 17 insertions, 6 deletions
diff --git a/reference_model/src/graph_node.cc b/reference_model/src/graph_node.cc
index 1781e40..791ed45 100644
--- a/reference_model/src/graph_node.cc
+++ b/reference_model/src/graph_node.cc
@@ -229,3 +229,16 @@ int GraphNode::idiv_check(int input1, int input2, int& result)
result = input1 / input2;
return 0;
}
+
+// perform an integer division with rounding towards minus infinity
+int GraphNode::idiv_floor(int input1, int input2)
+{
+ ERROR_IF(input2 == 0, "idiv_floor: input2 must not be zero");
+ int result = input1 / input2;
+
+ if (result * input2 > input1)
+ {
+ result--;
+ }
+ return result;
+}
diff --git a/reference_model/src/graph_node.h b/reference_model/src/graph_node.h
index 900f4b8..440ca04 100644
--- a/reference_model/src/graph_node.h
+++ b/reference_model/src/graph_node.h
@@ -256,6 +256,7 @@ public:
// Helper functions.
int idiv_check(int input1, int input2, int& result);
+ int idiv_floor(int input1, int input2);
protected:
// Print out a node validation error
diff --git a/reference_model/src/ops/image.cc b/reference_model/src/ops/image.cc
index cf2b60a..b1b762f 100644
--- a/reference_model/src/ops/image.cc
+++ b/reference_model/src/ops/image.cc
@@ -159,16 +159,15 @@ int OpResize<InDtype, OutDtype, resize_t>::eval()
int32_t y = oy * scale_y_d + offset_y;
int32_t x = ox * scale_x_d + offset_x;
- int32_t iy;
- int32_t ix;
+ int16_t iy = idiv_floor(y, scale_y_n);
+ int16_t ix = idiv_floor(x, scale_x_n);
+
resize_t dy;
resize_t dx;
if (std::is_same<resize_t, double>::value)
{
const double fy_double = static_cast<double>(y) / static_cast<double>(scale_y_n);
const double fx_double = static_cast<double>(x) / static_cast<double>(scale_x_n);
- iy = floor(fy_double);
- ix = floor(fx_double);
dy = (resize_t)(fy_double - iy);
dx = (resize_t)(fx_double - ix);
@@ -177,8 +176,6 @@ int OpResize<InDtype, OutDtype, resize_t>::eval()
{
const float fy = static_cast<float>(y) / static_cast<float>(scale_y_n);
const float fx = static_cast<float>(x) / static_cast<float>(scale_x_n);
- iy = floor(fy);
- ix = floor(fx);
if (std::is_floating_point<resize_t>::value || (typeid(resize_t) == typeid(Eigen::bfloat16)) ||
(typeid(resize_t) == typeid(half_float::half)))