From dc4564e0ad74e5d6ab11486c230077d9a7b927b7 Mon Sep 17 00:00:00 2001 From: Matt Wala Date: Mon, 2 Jan 2017 09:53:02 -0600 Subject: [PATCH] E2P: Hoist assignment of "kernel_scaling" out of the inner loop. This caused a problem when the inner loop was empty, leaving this variable uninitialized. If you were unluckly, the uninitialized kernel_scaling would have a NaN bit pattern which would inadvertently poison the output with NaNs. --- sumpy/e2p.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/sumpy/e2p.py b/sumpy/e2p.py index c7f82175..b2e0e585 100644 --- a/sumpy/e2p.py +++ b/sumpy/e2p.py @@ -104,15 +104,15 @@ class E2PBase(KernelCacheWrapper): complex_dtype=np.complex128 # FIXME ) + return loopy_insns, result_names + + def get_kernel_scaling_assignment(self): from pymbolic.interop.sympy import SympyToPymbolicMapper sympy_conv = SympyToPymbolicMapper() - loopy_insns.append( - lp.Assignment(id=None, + return [lp.Assignment(id=None, assignee="kernel_scaling", expression=sympy_conv(self.expansion.kernel.get_scaling()), - temp_var_type=lp.auto)) - - return loopy_insns, result_names + temp_var_type=lp.auto)] def get_cache_key(self): return (type(self).__name__, self.expansion, tuple(self.kernels)) @@ -135,7 +135,8 @@ class E2PFromSingleBox(E2PBase): "{[itgt_box]: 0<=itgt_box tgt_ibox = target_boxes[itgt_box] <> itgt_start = box_target_starts[tgt_ibox] @@ -229,7 +230,8 @@ class E2PFromCSR(E2PBase): "{[isrc_box]: isrc_box_start<=isrc_box tgt_ibox = target_boxes[itgt_box] <> itgt_start = box_target_starts[tgt_ibox] -- GitLab