From 75ad3c84a12db1577e18a2537e3b39c00c6663a2 Mon Sep 17 00:00:00 2001 From: Stefan Klug Date: Fri, 13 Jun 2025 12:09:39 +0200 Subject: [PATCH] libipa: pwl: Fix single point Pwl Fix the eval() function for Pwls that contain only a single point. Remove the should_fail from the corresponding test case. Signed-off-by: Stefan Klug Reviewed-by: Kieran Bingham --- src/ipa/libipa/pwl.cpp | 4 ++++ test/ipa/libipa/meson.build | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/ipa/libipa/pwl.cpp b/src/ipa/libipa/pwl.cpp index 3d218817..69a93341 100644 --- a/src/ipa/libipa/pwl.cpp +++ b/src/ipa/libipa/pwl.cpp @@ -210,6 +210,10 @@ double Pwl::eval(double x, int *span, bool updateSpan) const : points_.size() / 2 - 1); if (span && updateSpan) *span = index; + + if (points_.size() == 1) + return points_[0].y(); + return points_[index].y() + (x - points_[index].x()) * (points_[index + 1].y() - points_[index].y()) / (points_[index + 1].x() - points_[index].x()); diff --git a/test/ipa/libipa/meson.build b/test/ipa/libipa/meson.build index c553366a..2070bed7 100644 --- a/test/ipa/libipa/meson.build +++ b/test/ipa/libipa/meson.build @@ -4,7 +4,7 @@ libipa_test = [ {'name': 'fixedpoint', 'sources': ['fixedpoint.cpp']}, {'name': 'histogram', 'sources': ['histogram.cpp']}, {'name': 'interpolator', 'sources': ['interpolator.cpp']}, - {'name': 'pwl', 'sources': ['pwl.cpp'], 'should_fail': true }, + {'name': 'pwl', 'sources': ['pwl.cpp'] }, ] foreach test : libipa_test