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