[v2,4/4] libipa: pwl: Fix single point Pwl
diff mbox series

Message ID 20250613100947.589875-5-stefan.klug@ideasonboard.com
State New
Headers show
Series
  • ipa: pwl: Fixes for single point PWLs
Related show

Commit Message

Stefan Klug June 13, 2025, 10:09 a.m. UTC
Fix the eval() function for Pwls that contain only a single point.
Remove the shouldi_fail from the corresponding test case.

Signed-off-by: Stefan Klug <stefan.klug@ideasonboard.com>
---
 src/ipa/libipa/pwl.cpp      | 4 ++++
 test/ipa/libipa/meson.build | 2 +-
 2 files changed, 5 insertions(+), 1 deletion(-)

Comments

Kieran Bingham June 13, 2025, 10:17 a.m. UTC | #1
Quoting Stefan Klug (2025-06-13 11:09:39)
> Fix the eval() function for Pwls that contain only a single point.
> Remove the shouldi_fail from the corresponding test case.


s/shouldi_fail/should_fail/

> 
> Signed-off-by: Stefan Klug <stefan.klug@ideasonboard.com>
> ---
>  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 3d2188170d83..69a9334112e8 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();

That's far clearer/more readable to me thanks.

Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>

> +
>         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 c553366a7934..2070bed70222 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
> -- 
> 2.48.1
>

Patch
diff mbox series

diff --git a/src/ipa/libipa/pwl.cpp b/src/ipa/libipa/pwl.cpp
index 3d2188170d83..69a9334112e8 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 c553366a7934..2070bed70222 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