From c004b6f540b28fadce3bab78a290e25ea3308095 Mon Sep 17 00:00:00 2001 From: Gregory Lee Date: Wed, 21 Aug 2024 20:59:22 -0400 Subject: [PATCH] chan_vese: pass all constants to `_fused_variance_kernel2` as device scalars (#764) This change avoids an issue with an internal `numpy.can_cast` call in CuPy's kernel fusion code when using NumPy 2.0. With this change all cuCIM tests passed using NumPy 2.0.1 and the CuPy 13.3dev branch. Fixes https://github.com/rapidsai/cucim/issues/742 Authors: - Gregory Lee (https://github.com/grlee77) Approvers: - https://github.com/jakirkham - Gigon Bae (https://github.com/gigony) URL: https://github.com/rapidsai/cucim/pull/764 --- python/cucim/src/cucim/skimage/segmentation/_chan_vese.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/python/cucim/src/cucim/skimage/segmentation/_chan_vese.py b/python/cucim/src/cucim/skimage/segmentation/_chan_vese.py index ea33f26b5..6827eebdd 100644 --- a/python/cucim/src/cucim/skimage/segmentation/_chan_vese.py +++ b/python/cucim/src/cucim/skimage/segmentation/_chan_vese.py @@ -65,7 +65,9 @@ def _fused_variance_kernel2( difference_term += term2 new_phi = phi + (dt * delta_phi) * (mu * K + difference_term) - out = new_phi / (1 + mu * dt * delta_phi * Csum) + out_denom = mu * dt * delta_phi * Csum + out_denom += out_denom.dtype.type(1) + out = new_phi / out_denom return out @@ -430,6 +432,9 @@ def chan_vese( phivar = tol + 1 dt = cp.asarray(dt, dtype=float_dtype) + mu = cp.asarray(mu, dtype=float_dtype) + lambda1 = cp.asarray(lambda1, dtype=float_dtype) + lambda2 = cp.asarray(lambda2, dtype=float_dtype) while phivar > tol and i < max_num_iter: # Save old level set values oldphi = phi