blob: 21dd9f76c366b6d3bbbb167d83c8105f358947b4 (
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
|
//DIAGNOSTIC_TEST:SIMPLE:
struct DiffT : IDifferentiable
{
float f;
}
struct NoDiffField
{
DiffT fp;
}
[BackwardDifferentiable]
float g(float x)
{
NoDiffField obj;
obj.fp.f = x * x; // Error, this location cannot hold derivative.
return obj.fp.f;
}
[BackwardDifferentiable]
void diffOut(inout float x)
{
x = 2;
}
float noDiffFunc(float x)
{
return 0.0;
}
[BackwardDifferentiable]
float h(float x)
{
NoDiffField obj;
obj.fp.f = detach(x * x); // OK.
obj.fp.f = noDiffFunc(x); // OK.
diffOut(obj.fp.f); // Error.
return obj.fp.f;
}
|