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