@@ -68,6 +68,22 @@ ControlFlowTests.test("Conditionals") {
68
68
expectEqual ( ( - 20 , 2 ) , valueWithGradient ( at: - 10 , in: cond_tuple) )
69
69
expectEqual ( ( - 2674 , 2 ) , valueWithGradient ( at: - 1337 , in: cond_tuple) )
70
70
71
+ func cond_tuple2( _ x: Float ) -> Float {
72
+ // Convoluted function returning `x + x`.
73
+ let y : ( Float , Float ) = ( x, x)
74
+ let y0 = y. 0
75
+ if x > 0 {
76
+ let y1 = y. 1
77
+ return y0 + y1
78
+ }
79
+ let y0_double = y0 + y. 0
80
+ let y1 = y. 1
81
+ return y0_double - y1 + y. 0
82
+ }
83
+ expectEqual ( ( 8 , 2 ) , valueWithGradient ( at: 4 , in: cond_tuple2) )
84
+ expectEqual ( ( - 20 , 2 ) , valueWithGradient ( at: - 10 , in: cond_tuple2) )
85
+ expectEqual ( ( - 2674 , 2 ) , valueWithGradient ( at: - 1337 , in: cond_tuple2) )
86
+
71
87
func cond_tuple_var( _ x: Float ) -> Float {
72
88
// Convoluted function returning `x + x`.
73
89
var y : ( Float , Float ) = ( x, x)
@@ -135,6 +151,22 @@ ControlFlowTests.test("Conditionals") {
135
151
expectEqual ( ( - 20 , 2 ) , valueWithGradient ( at: - 10 , in: cond_struct) )
136
152
expectEqual ( ( - 2674 , 2 ) , valueWithGradient ( at: - 1337 , in: cond_struct) )
137
153
154
+ func cond_struct2( _ x: Float ) -> Float {
155
+ // Convoluted function returning `x + x`.
156
+ let y = FloatPair ( x, x)
157
+ let y0 = y. first
158
+ if x > 0 {
159
+ let y1 = y. second
160
+ return y0 + y1
161
+ }
162
+ let y0_double = y0 + y. first
163
+ let y1 = y. second
164
+ return y0_double - y1 + y. first
165
+ }
166
+ expectEqual ( ( 8 , 2 ) , valueWithGradient ( at: 4 , in: cond_struct2) )
167
+ expectEqual ( ( - 20 , 2 ) , valueWithGradient ( at: - 10 , in: cond_struct2) )
168
+ expectEqual ( ( - 2674 , 2 ) , valueWithGradient ( at: - 1337 , in: cond_struct2) )
169
+
138
170
func cond_struct_var( _ x: Float ) -> Float {
139
171
// Convoluted function returning `x + x`.
140
172
var y = FloatPair ( x, x)
0 commit comments