summaryrefslogtreecommitdiffstats
path: root/tests/diagnostics/autodiff-data-flow-2.slang
blob: 42aee0d01604e6d5dd779ad7cde32fcf651c7052 (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
//DIAGNOSTIC_TEST:SIMPLE:

float nonDiff(float x)
{
    return x;
}

[ForwardDifferentiable]
float f(float x)
{
    return x * x;
}

[BackwardDifferentiable]
float g(float x)
{
    float val = f(x + 1); // Error: f must also be backward-differentiable
    return val;
}

[BackwardDifferentiable]
float h(float x)
{
    float val = 0;
    // no diagnostic by clarifying intention.
    val = no_diff(f(x + 1));

    // error: dynamic loop without [MaxIters] or [ForceUnroll]
    for (int i = 0; i < (int)x; i++)
    {
        no_diff debugBreak();
    }

    return val;
}