[libcamera-devel,v3,5/5] ipa: ipu3: af: Simplify accumulations of y_items
diff mbox series

Message ID 20220325092555.1799897-6-kieran.bingham@ideasonboard.com
State Accepted
Headers show
Series
  • ipa: ipu3: af: Small improvements
Related show

Commit Message

Kieran Bingham March 25, 2022, 9:25 a.m. UTC
Simplify the accumulation of the total and variance with a ternary
operator.

Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 src/ipa/ipu3/algorithms/af.cpp | 14 ++++----------
 1 file changed, 4 insertions(+), 10 deletions(-)

Comments

Jean-Michel Hautbois March 29, 2022, 5:57 a.m. UTC | #1
Hi Kieran,

Thanks for the patch !

On 25/03/2022 10:25, Kieran Bingham wrote:
> Simplify the accumulation of the total and variance with a ternary
> operator.
> 
> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

Reviewed-by: Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com>

> ---
>   src/ipa/ipu3/algorithms/af.cpp | 14 ++++----------
>   1 file changed, 4 insertions(+), 10 deletions(-)
> 
> diff --git a/src/ipa/ipu3/algorithms/af.cpp b/src/ipa/ipu3/algorithms/af.cpp
> index c0f2d34368cb..6c25d02ec7f0 100644
> --- a/src/ipa/ipu3/algorithms/af.cpp
> +++ b/src/ipa/ipu3/algorithms/af.cpp
> @@ -341,20 +341,14 @@ double Af::afEstimateVariance(Span<const y_table_item_t> y_items, bool isY1)
>   	double mean;
>   	double var_sum = 0;
>   
> -	for (auto y : y_items) {
> -		if (isY1)
> -			total += y.y1_avg;
> -		else
> -			total += y.y2_avg;
> -	}
> +	for (auto y : y_items)
> +		total += isY1 ? y.y1_avg : y.y2_avg;
>   
>   	mean = total / y_items.size();
>   
>   	for (auto y : y_items) {
> -		if (isY1)
> -			var_sum += pow(y.y1_avg - mean, 2);
> -		else
> -			var_sum += pow(y.y2_avg - mean, 2);
> +		double avg = isY1 ? y.y1_avg : y.y2_avg;
> +		var_sum += pow(avg - mean, 2);
>   	}
>   
>   	return var_sum / y_items.size();

Patch
diff mbox series

diff --git a/src/ipa/ipu3/algorithms/af.cpp b/src/ipa/ipu3/algorithms/af.cpp
index c0f2d34368cb..6c25d02ec7f0 100644
--- a/src/ipa/ipu3/algorithms/af.cpp
+++ b/src/ipa/ipu3/algorithms/af.cpp
@@ -341,20 +341,14 @@  double Af::afEstimateVariance(Span<const y_table_item_t> y_items, bool isY1)
 	double mean;
 	double var_sum = 0;
 
-	for (auto y : y_items) {
-		if (isY1)
-			total += y.y1_avg;
-		else
-			total += y.y2_avg;
-	}
+	for (auto y : y_items)
+		total += isY1 ? y.y1_avg : y.y2_avg;
 
 	mean = total / y_items.size();
 
 	for (auto y : y_items) {
-		if (isY1)
-			var_sum += pow(y.y1_avg - mean, 2);
-		else
-			var_sum += pow(y.y2_avg - mean, 2);
+		double avg = isY1 ? y.y1_avg : y.y2_avg;
+		var_sum += pow(avg - mean, 2);
 	}
 
 	return var_sum / y_items.size();