1
1
// RUN: %target-run-simple-swift
2
2
// REQUIRES: executable_test
3
3
4
- // Would fail due to unavailability of swift_autoDiffCreateLinearMapContext.
5
- // UNSUPPORTED: use_os_stdlib
6
- // UNSUPPORTED: back_deployment_runtime
7
-
8
4
import StdlibUnittest
9
5
import _Differentiation
10
6
@@ -43,19 +39,8 @@ InoutControlFlowTests.test("MutatingBeforeControlFlow") {
43
39
}
44
40
45
41
// SR-14053
46
- protocol NumericDifferentiable : Numeric , Differentiable {
47
- @differentiable ( reverse) static func * ( lhs: Self , rhs: Self ) -> Self
48
- }
49
-
50
- extension Float : NumericDifferentiable { }
51
-
52
- struct Model2 < T: NumericDifferentiable > : Differentiable {
53
- var first : T
54
- var second : T
55
- }
56
-
57
42
@differentiable ( reverse)
58
- func adjust< T : NumericDifferentiable > ( model: inout Model2 < T > , multiplier: T ) {
43
+ func adjust( model: inout Model , multiplier: Float ) {
59
44
model. first = model. second * multiplier
60
45
61
46
// Dummy no-op if block, required to introduce control flow.
@@ -64,21 +49,21 @@ func adjust<T: NumericDifferentiable>(model: inout Model2<T>, multiplier: T) {
64
49
}
65
50
66
51
@differentiable ( reverse)
67
- func loss2( model: Model2 < Float > , multiplier: Float ) -> Float {
52
+ func loss2( model: Model , multiplier: Float ) -> Float {
68
53
var model = model
69
54
adjust ( model: & model, multiplier: multiplier)
70
55
return model. first
71
56
}
72
57
73
58
InoutControlFlowTests . test ( " InoutParameterWithControlFlow " ) {
74
- var model = Model2 < Float > ( first: 1 , second: 3 )
59
+ var model = Model ( first: 1 , second: 3 )
75
60
let grad = gradient ( at: model, 5.0 , of: loss2)
76
61
expectEqual ( 0 , grad. 0 . first)
77
62
expectEqual ( 5 , grad. 0 . second)
78
63
}
79
64
80
65
@differentiable ( reverse)
81
- func adjust2< T : NumericDifferentiable > ( multiplier: T , model: inout Model2 < T > ) {
66
+ func adjust2( multiplier: Float , model: inout Model ) {
82
67
model. first = model. second * multiplier
83
68
84
69
// Dummy no-op if block, required to introduce control flow.
@@ -87,14 +72,14 @@ func adjust2<T: NumericDifferentiable>(multiplier: T, model: inout Model2<T>) {
87
72
}
88
73
89
74
@differentiable ( reverse)
90
- func loss3( model: Model2 < Float > , multiplier: Float ) -> Float {
75
+ func loss3( model: Model , multiplier: Float ) -> Float {
91
76
var model = model
92
77
adjust2 ( multiplier: multiplier, model: & model)
93
78
return model. first
94
79
}
95
80
96
81
InoutControlFlowTests . test ( " LaterInoutParameterWithControlFlow " ) {
97
- var model = Model2 < Float > ( first: 1 , second: 3 )
82
+ var model = Model ( first: 1 , second: 3 )
98
83
let grad = gradient ( at: model, 5.0 , of: loss3)
99
84
expectEqual ( 0 , grad. 0 . first)
100
85
expectEqual ( 5 , grad. 0 . second)
0 commit comments