From 800ff26433ae463518caf79bcc0fb225f2c68ab6 Mon Sep 17 00:00:00 2001 From: David Date: Mon, 13 Feb 2017 12:55:16 -0600 Subject: [PATCH] simplified conditionals for gradient calculation --- stim/cuda/templates/gradient.cuh | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/stim/cuda/templates/gradient.cuh b/stim/cuda/templates/gradient.cuh index 88dd259..febd57b 100644 --- a/stim/cuda/templates/gradient.cuh +++ b/stim/cuda/templates/gradient.cuh @@ -32,20 +32,16 @@ namespace stim{ //use forward differences if a coordinate is zero if(xi == 0) out[i * 2 + 0] = in[i_xp] - in[i]; - if(yi == 0) - out[i * 2 + 1] = in[i_yp] - in[i]; - - //use backward differences if the coordinate is at the maximum edge - if(xi == x-1) + else if (xi == x - 1) out[i * 2 + 0] = in[i] - in[i_xn]; - if(yi == y-1) - out[i * 2 + 1] = in[i] - in[i_yn]; - - //otherwise use central differences - if(xi > 0 && xi < x-1) + else out[i * 2 + 0] = (in[i_xp] - in[i_xn]) / 2; - if(yi > 0 && yi < y-1) + if(yi == 0) + out[i * 2 + 1] = in[i_yp] - in[i]; + else if(yi == y-1) + out[i * 2 + 1] = in[i] - in[i_yn]; + else out[i * 2 + 1] = (in[i_yp] - in[i_yn]) / 2; } -- libgit2 0.21.4