yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
f94b2f7a3
master
1//DIAGNOSTIC_TEST:SIMPLE: 2 3float nonDiff(float x) 4{ 5 return x; 6} 7 8[ForwardDifferentiable] 9float f(float x) 10{ 11 float val = 0; 12 if (x > 5) 13 val = x + 1; 14 else 15 val = nonDiff(x * 2.0f); 16 // Not all path propagates derivatives through. 17 return val; 18} 19 20// error: function does not return a differentiable value. 21[ForwardDifferentiable] 22void g(float x) 23{ 24 float val = 0; 25 if (x > 5) 26 val = x + 1; 27 28 for (int i = 0; i < 5; i++) // Not ok, we can't infer the loop iterations because the body modifies induction var. 29 { 30 i = (int)x; 31 no_diff debugBreak(); 32 } 33 return; 34} 35 36 37[ForwardDifferentiable] 38float h(float x) 39{ 40 float val = 0; 41 // no diagnostic by clarifying intention. 42 val = no_diff(nonDiff(x * 2.0f)); 43 return val; 44}