From e4c5fac060602d208a103ae98d71ecd838f84360 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C5=91rinc=20Serf=C5=91z=C5=91?= Date: Wed, 2 Sep 2026 16:44:56 +0200 Subject: [PATCH] normalize.py: Use `count_nonzero` in place of the reduction kernels in --- httomolibgpu/prep/normalize.py | 24 ++---------------------- 1 file changed, 2 insertions(+), 22 deletions(-) diff --git a/httomolibgpu/prep/normalize.py b/httomolibgpu/prep/normalize.py index cd8a82bc..ad0401f6 100644 --- a/httomolibgpu/prep/normalize.py +++ b/httomolibgpu/prep/normalize.py @@ -152,26 +152,6 @@ def dark_flat_field_correction( no_return=True, ) - count_greater_kernel = cp.ReductionKernel( - in_params="T data, raw float32 upper_bound", - out_params="int32 out", - map_expr="data >= upper_bound ? 1 : 0", # map each element → 1 or 0 - reduce_expr="a + b", # sum them - post_map_expr="out = a", # final result - identity="0", - name="count_greater", - ) - - count_smaller_kernel = cp.ReductionKernel( - in_params="T data, raw float32 lower_bound", - out_params="int32 out", - map_expr="data <= lower_bound ? 1 : 0", # map each element → 1 or 0 - reduce_expr="a + b", # sum them - post_map_expr="out = a", # final result - identity="0", - name="count_smaller", - ) - normalisation_kernel(data, flat0, dark0, upper_bound, lower_bound, out) if clipping_warning: @@ -180,9 +160,9 @@ def dark_flat_field_correction( 50.0 # warning if more clipped values than given percentage ) - clipped_total_up = int(count_greater_kernel(out, float32(upper_bound))) + clipped_total_up = cp.count_nonzero(out >= upper_bound) clipped_up_percent = clipped_total_up / data_elements_num * 100 - clipped_total_lower = int(count_smaller_kernel(out, float32(lower_bound))) + clipped_total_lower = cp.count_nonzero(out <= lower_bound) clipped_down_percent = clipped_total_lower / data_elements_num * 100 if clipped_up_percent >= clipped_percentage_warning: