Commit 800ff26433ae463518caf79bcc0fb225f2c68ab6

Authored by David Mayerich
1 parent 48966d30

simplified conditionals for gradient calculation

Showing 1 changed file with 7 additions and 11 deletions   Show diff stats
stim/cuda/templates/gradient.cuh
... ... @@ -32,20 +32,16 @@ namespace stim{
32 32 //use forward differences if a coordinate is zero
33 33 if(xi == 0)
34 34 out[i * 2 + 0] = in[i_xp] - in[i];
35   - if(yi == 0)
36   - out[i * 2 + 1] = in[i_yp] - in[i];
37   -
38   - //use backward differences if the coordinate is at the maximum edge
39   - if(xi == x-1)
  35 + else if (xi == x - 1)
40 36 out[i * 2 + 0] = in[i] - in[i_xn];
41   - if(yi == y-1)
42   - out[i * 2 + 1] = in[i] - in[i_yn];
43   -
44   - //otherwise use central differences
45   - if(xi > 0 && xi < x-1)
  37 + else
46 38 out[i * 2 + 0] = (in[i_xp] - in[i_xn]) / 2;
47 39  
48   - if(yi > 0 && yi < y-1)
  40 + if(yi == 0)
  41 + out[i * 2 + 1] = in[i_yp] - in[i];
  42 + else if(yi == y-1)
  43 + out[i * 2 + 1] = in[i] - in[i_yn];
  44 + else
49 45 out[i * 2 + 1] = (in[i_yp] - in[i_yn]) / 2;
50 46  
51 47 }
... ...