Skip to content

Commit 36cf566

Browse files
committed
fixing up some tests and turning off SIMD extension which uses @_alwaysEmitIntoClient since that's not supported yet.
1 parent b72aca9 commit 36cf566

File tree

5 files changed

+67
-59
lines changed

5 files changed

+67
-59
lines changed

stdlib/public/Differentiation/SIMDVectorTypesDerivatives.swift.gyb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,9 @@ extension SIMD
174174
}
175175
}
176176

177+
// FIXME(TF-1103): Derivative registration does not yet support
178+
// `@_alwaysEmitIntoClient` original functions.
179+
/*
177180
extension SIMD
178181
where Self : Differentiable,
179182
TangentVector : SIMD,
@@ -186,6 +189,7 @@ extension SIMD
186189
return (sum(), { v in Self(repeating: Scalar(v)) })
187190
}
188191
}
192+
*/
189193

190194
extension SIMD
191195
where Self : Differentiable,

test/AutoDiff/stdlib/array.swift

Lines changed: 56 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
// RUN: %target-run-simple-swift
22

33
import StdlibUnittest
4-
import DifferentiationUnittest
4+
import _Differentiation
55

66
var ArrayAutoDiffTests = TestSuite("ArrayAutoDiff")
77

88
typealias FloatArrayTan = Array<Float>.TangentVector
9-
typealias TrackedFloatArrayTan = Array<Tracked<Float>>.TangentVector
109

1110
ArrayAutoDiffTests.test("ArrayIdentity") {
1211
func arrayIdentity(_ x: [Float]) -> [Float] {
@@ -24,48 +23,48 @@ ArrayAutoDiffTests.test("ArraySubscript") {
2423
return array[0] + array[1] + array[2]
2524
}
2625

27-
expectEqual(
26+
expectEqual(
2827
FloatArrayTan([1, 1, 1, 0, 0, 0]),
2928
gradient(at: [2, 3, 4, 5, 6, 7], in: sumFirstThree))
3029
}
3130

32-
ArrayAutoDiffTests.testWithLeakChecking("ArrayLiteral") {
31+
ArrayAutoDiffTests.test("ArrayLiteral") {
3332
do {
34-
func twoElementLiteral(_ x: Tracked<Float>, _ y: Tracked<Float>) -> [Tracked<Float>] {
33+
func twoElementLiteral(_ x: Float, _ y: Float) -> [Float] {
3534
return [x, y]
3635
}
3736
let pb = pullback(at: 1, 1, in: twoElementLiteral)
38-
expectEqual((1, 2), pb(TrackedFloatArrayTan([Tracked<Float>(1), Tracked<Float>(2)])))
37+
expectEqual((1, 2), pb(FloatArrayTan([Float(1), Float(2)])))
3938
}
4039

4140
do {
4241
// TF-952: Test array literal initialized from an address (e.g. `var`).
43-
func twoElementLiteralAddress(_ x: Tracked<Float>, _ y: Tracked<Float>) -> [Tracked<Float>] {
42+
func twoElementLiteralAddress(_ x: Float, _ y: Float) -> [Float] {
4443
var result = x
4544
result = result * y
4645
return [result, result]
4746
}
4847
let pb = pullback(at: 3, 4, in: twoElementLiteralAddress)
49-
expectEqual((8, 6), pb(TrackedFloatArrayTan([1, 1])))
48+
expectEqual((8, 6), pb(FloatArrayTan([1, 1])))
5049
}
5150

5251
do {
5352
// TF-952: Test array literal initialized with function call results.
54-
func twoElementLiteralFunctionResult(_ x: Tracked<Float>, _ y: Tracked<Float>) -> [Tracked<Float>] {
53+
func twoElementLiteralFunctionResult(_ x: Float, _ y: Float) -> [Float] {
5554
return [x * y, x * y]
5655
}
5756
let pb = pullback(at: 3, 4, in: twoElementLiteralFunctionResult)
58-
expectEqual((8, 6), pb(TrackedFloatArrayTan([1, 1])))
57+
expectEqual((8, 6), pb(FloatArrayTan([1, 1])))
5958
}
6059

6160
do {
6261
// TF-975: Test multiple array literals.
63-
func twoElementLiterals(_ x: Tracked<Float>, _ y: Tracked<Float>) -> [Tracked<Float>] {
62+
func twoElementLiterals(_ x: Float, _ y: Float) -> [Float] {
6463
let array = [x * y, x * y]
6564
return [array[0], array[1]]
6665
}
6766
let pb = pullback(at: 3, 4, in: twoElementLiterals)
68-
expectEqual((8, 6), pb(TrackedFloatArrayTan([1, 1])))
67+
expectEqual((8, 6), pb(FloatArrayTan([1, 1])))
6968
}
7069
}
7170

@@ -96,8 +95,8 @@ struct Struct<T> {
9695
extension Struct: Differentiable where T: Differentiable {}
9796

9897
ArrayAutoDiffTests.test("ArrayLiteralStruct") {
99-
typealias TV = Struct<Tracked<Float>>.TangentVector
100-
let s = Struct<Tracked<Float>>(x: 3, y: 4)
98+
typealias TV = Struct<Float>.TangentVector
99+
let s = Struct<Float>(x: 3, y: 4)
101100

102101
do {
103102
func structElementLiteral<T>(_ s: Struct<T>) -> [T] {
@@ -106,10 +105,10 @@ ArrayAutoDiffTests.test("ArrayLiteralStruct") {
106105
func structGeneric<T>(_ s: Struct<T>) -> T {
107106
return structElementLiteral(s)[0]
108107
}
109-
func structConcrete1(_ s: Struct<Tracked<Float>>) -> Tracked<Float> {
108+
func structConcrete1(_ s: Struct<Float>) -> Float {
110109
return structElementLiteral(s)[0] * structElementLiteral(s)[1]
111110
}
112-
func structConcrete2(_ s: Struct<Tracked<Float>>) -> Tracked<Float> {
111+
func structConcrete2(_ s: Struct<Float>) -> Float {
113112
let array = structElementLiteral(s)
114113
return array[0] * array[1]
115114
}
@@ -126,11 +125,11 @@ ArrayAutoDiffTests.test("ArrayLiteralStruct") {
126125
func structGeneric<T>(_ s: Struct<T>) -> T {
127126
return structElementAddressLiteral(s)[0]
128127
}
129-
func structConcrete1(_ s: Struct<Tracked<Float>>) -> Tracked<Float> {
128+
func structConcrete1(_ s: Struct<Float>) -> Float {
130129
return structElementAddressLiteral(s)[0] *
131130
structElementAddressLiteral(s)[1]
132131
}
133-
func structConcrete2(_ s: Struct<Tracked<Float>>) -> Tracked<Float> {
132+
func structConcrete2(_ s: Struct<Float>) -> Float {
134133
let array = structElementAddressLiteral(s)
135134
return array[0] * array[1]
136135
}
@@ -148,11 +147,11 @@ ArrayAutoDiffTests.test("ArrayLiteralStruct") {
148147
func structGeneric<T>(_ s: Struct<T>) -> T {
149148
return structElementAddressLiteral2(s)[0]
150149
}
151-
func structConcrete1(_ s: Struct<Tracked<Float>>) -> Tracked<Float> {
150+
func structConcrete1(_ s: Struct<Float>) -> Float {
152151
return structElementAddressLiteral2(s)[0] *
153152
structElementAddressLiteral2(s)[1]
154153
}
155-
func structConcrete2(_ s: Struct<Tracked<Float>>) -> Tracked<Float> {
154+
func structConcrete2(_ s: Struct<Float>) -> Float {
156155
let array = structElementAddressLiteral2(s)
157156
return array[0] * array[1]
158157
}
@@ -167,7 +166,7 @@ ArrayAutoDiffTests.test("ArrayLiteralStruct") {
167166
func applyIndirectResult<T>(_ x: T, _ y: T) -> [Struct<T>] {
168167
return [Struct(x: x, y: y), Struct(x: x, y: y)]
169168
}
170-
let pb = pullback(at: Tracked<Float>(3), 4, in: { applyIndirectResult($0, $1) })
169+
let pb = pullback(at: Float(3), 4, in: { applyIndirectResult($0, $1) })
171170
let v = TV(x: 1, y: 1)
172171
expectEqual((2, 2), pb(.init([v, v])))
173172
}
@@ -179,42 +178,42 @@ ArrayAutoDiffTests.test("ArrayLiteralTuple") {
179178
var tuple = (x, y)
180179
return [tuple.0, tuple.1]
181180
}
182-
let pb = pullback(at: Tracked<Float>(3), 4, in: { tupleElementGeneric($0, $1) })
181+
let pb = pullback(at: Float(3), 4, in: { tupleElementGeneric($0, $1) })
183182
// FIXME(TF-977): Fix incorrect derivative for array literal with
184183
// `tuple_element_addr` elements.
185-
// expectEqual((1, 1), pb(TrackedFloatArrayTan([1, 1])))
186-
expectEqual((0, 2), pb(TrackedFloatArrayTan([1, 1])))
184+
// expectEqual((1, 1), pb(FloatArrayTan([1, 1])))
185+
expectEqual((0, 2), pb(FloatArrayTan([1, 1])))
187186
}
188187
}
189188

190-
ArrayAutoDiffTests.testWithLeakChecking("ArrayLiteralNested") {
189+
ArrayAutoDiffTests.test("ArrayLiteralNested") {
191190
do {
192191
func nested0(
193-
_ x: Tracked<Float>, _ y: Tracked<Float>, _ bool: Bool = true
194-
) -> [Tracked<Float>] {
192+
_ x: Float, _ y: Float, _ bool: Bool = true
193+
) -> [Float] {
195194
let result = [[[[x, y]]]]
196195
return result[0][0][0]
197196
}
198197
let pb = pullback(at: 3, 4, in: { nested0($0, $1) })
199-
expectEqual((1, 1), pb(TrackedFloatArrayTan([1, 1, 1, 1])))
198+
expectEqual((1, 1), pb(FloatArrayTan([1, 1, 1, 1])))
200199
}
201200

202201
do {
203202
func nested1(
204-
_ x: Tracked<Float>, _ y: Tracked<Float>, _ bool: Bool = true
205-
) -> [Tracked<Float>] {
203+
_ x: Float, _ y: Float, _ bool: Bool = true
204+
) -> [Float] {
206205
var result = [[x, y], [x, y]]
207206
return result[0] + result[1]
208207
}
209208
let pb = pullback(at: 3, 4, in: { nested1($0, $1) })
210-
expectEqual((2, 2), pb(TrackedFloatArrayTan([1, 1, 1, 1])))
209+
expectEqual((2, 2), pb(FloatArrayTan([1, 1, 1, 1])))
211210
}
212211

213212
do {
214213
// Convoluted function computing `[x + y]`.
215214
func nested2(
216-
_ x: Tracked<Float>, _ y: Tracked<Float>, _ bool: Bool = true
217-
) -> [Tracked<Float>] {
215+
_ x: Float, _ y: Float, _ bool: Bool = true
216+
) -> [Float] {
218217
var result = [[], [x]]
219218
result = result + []
220219
result = result + [[]]
@@ -224,38 +223,38 @@ ArrayAutoDiffTests.testWithLeakChecking("ArrayLiteralNested") {
224223
}
225224
let (value, pb) = valueWithPullback(at: 3, 4, in: { nested2($0, $1) })
226225
expectEqual([3, 4], value)
227-
expectEqual((1, 1), pb(TrackedFloatArrayTan([1, 1])))
226+
expectEqual((1, 1), pb(FloatArrayTan([1, 1])))
228227
}
229228
}
230229

231-
ArrayAutoDiffTests.testWithLeakChecking("ArrayLiteralControlFlow") {
230+
ArrayAutoDiffTests.test("ArrayLiteralControlFlow") {
232231
do {
233232
// TF-922: Test array literal and control flow.
234233
func controlFlow(
235-
_ x: Tracked<Float>, _ y: Tracked<Float>, _ bool: Bool = true
236-
) -> [Tracked<Float>] {
234+
_ x: Float, _ y: Float, _ bool: Bool = true
235+
) -> [Float] {
237236
var result = [x * y, x * y]
238237
let result2 = bool ? result : result
239238
var result3 = bool ? (bool ? result2 : result) : result2
240239
return result3
241240
}
242241
let pb = pullback(at: 3, 4, in: { controlFlow($0, $1) })
243-
expectEqual((8, 6), pb(TrackedFloatArrayTan([1, 1])))
242+
expectEqual((8, 6), pb(FloatArrayTan([1, 1])))
244243
}
245244

246245
do {
247246
// TF-922: Test array literal and control flow.
248247
func controlFlowAddress(
249-
_ x: Tracked<Float>, _ y: Tracked<Float>, _ bool: Bool = true
250-
) -> [Tracked<Float>] {
248+
_ x: Float, _ y: Float, _ bool: Bool = true
249+
) -> [Float] {
251250
var product = x * y // initial value is an address
252251
var result = [product, product]
253252
let result2 = bool ? result : result
254253
var result3 = bool ? (bool ? result2 : result) : result2
255254
return result3
256255
}
257256
let pb = pullback(at: 3, 4, in: { controlFlowAddress($0, $1) })
258-
expectEqual((8, 6), pb(TrackedFloatArrayTan([1, 1])))
257+
expectEqual((8, 6), pb(FloatArrayTan([1, 1])))
259258
}
260259

261260
do {
@@ -266,22 +265,22 @@ ArrayAutoDiffTests.testWithLeakChecking("ArrayLiteralControlFlow") {
266265
var result3 = bool ? (bool ? result2 : result) : result2
267266
return result3
268267
}
269-
let pb = pullback(at: Tracked<Float>(3), 4, in: { controlFlowGeneric($0, $1) })
270-
expectEqual((1, 1), pb(TrackedFloatArrayTan([1, 1])))
268+
let pb = pullback(at: Float(3), 4, in: { controlFlowGeneric($0, $1) })
269+
expectEqual((1, 1), pb(FloatArrayTan([1, 1])))
271270
}
272271

273272
do {
274273
// Test nested array literal and control flow.
275274
func controlFlowNestedLiteral(
276-
_ x: Tracked<Float>, _ y: Tracked<Float>, _ bool: Bool = true
277-
) -> [Tracked<Float>] {
278-
var result: [[Tracked<Float>]] = []
275+
_ x: Float, _ y: Float, _ bool: Bool = true
276+
) -> [Float] {
277+
var result: [[Float]] = []
279278
var result2 = bool ? result + [[x]] : result + [[x]]
280279
var result3 = bool ? (bool ? result2 + [[y]] : result2 + [[y]]) : result2 + [[y]]
281280
return result3[0] + [result3[1][0]]
282281
}
283282
let pb = pullback(at: 3, 4, in: { controlFlowNestedLiteral($0, $1) })
284-
expectEqual((1, 1), pb(TrackedFloatArrayTan([1, 1])))
283+
expectEqual((1, 1), pb(FloatArrayTan([1, 1])))
285284
}
286285
}
287286

@@ -340,38 +339,38 @@ ArrayAutoDiffTests.test("Array.+") {
340339
at: TwoArrays(a: [], b: [0, 0, 0, 0]),
341340
in: sumFirstThreeConcatenated))
342341

343-
func identity(_ array: [Tracked<Float>]) -> [Tracked<Float>] {
344-
var results: [Tracked<Float>] = []
342+
func identity(_ array: [Float]) -> [Float] {
343+
var results: [Float] = []
345344
for i in withoutDerivative(at: array.indices) {
346345
results = results + [array[i]]
347346
}
348347
return results
349348
}
350-
let v = TrackedFloatArrayTan([4, -5, 6])
349+
let v = FloatArrayTan([4, -5, 6])
351350
expectEqual(v, pullback(at: [1, 2, 3], in: identity)(v))
352351
}
353352

354353
ArrayAutoDiffTests.test("Array.append") {
355-
func identity(_ array: [Tracked<Float>]) -> [Tracked<Float>] {
356-
var results: [Tracked<Float>] = []
354+
func identity(_ array: [Float]) -> [Float] {
355+
var results: [Float] = []
357356
for i in withoutDerivative(at: array.indices) {
358357
results.append(array[i])
359358
}
360359
return results
361360
}
362-
let v = TrackedFloatArrayTan([4, -5, 6])
361+
let v = FloatArrayTan([4, -5, 6])
363362
expectEqual(v, pullback(at: [1, 2, 3], in: identity)(v))
364363
}
365364

366-
ArrayAutoDiffTests.testWithLeakChecking("Array.init(repeating:count:)") {
365+
ArrayAutoDiffTests.test("Array.init(repeating:count:)") {
367366
@differentiable
368-
func repeating(_ x: Tracked<Float>) -> [Tracked<Float>] {
367+
func repeating(_ x: Float) -> [Float] {
369368
Array(repeating: x, count: 10)
370369
}
371-
expectEqual(Tracked<Float>(10), gradient(at: .zero) { x in
370+
expectEqual(Float(10), gradient(at: .zero) { x in
372371
repeating(x).differentiableReduce(0, {$0 + $1}).value
373372
})
374-
expectEqual(Tracked<Float>(20), pullback(at: .zero, in: { x in
373+
expectEqual(Float(20), pullback(at: .zero, in: { x in
375374
repeating(x).differentiableReduce(0, {$0 + $1}).value
376375
})(2))
377376
}

test/AutoDiff/stdlib/floating_point.swift.gyb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
// RUN: %target-run-simple-swiftgyb-forward-mode-differentiation
1+
// -*- swift -*-
2+
// RUN: %target-run-simple-swiftgyb
23
// REQUIRES: executable_test
34

45
#if (arch(i386) || arch(x86_64)) && !os(Windows)
@@ -7,6 +8,7 @@
78
typealias TestLiteralType = Double
89
#endif
910

11+
import _Differentiation
1012
import StdlibUnittest
1113

1214
var FloatingPointDerivativeTests = TestSuite("FloatingPointDerivatives")

test/AutoDiff/stdlib/simd.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// RUN: %target-run-simple-swift
22
// REQUIRES: executable_test
33

4+
import _Differentiation
45
import StdlibUnittest
56
#if os(macOS)
67
import Darwin.C

test/AutoDiff/stdlib/tgmathDerivatives.swift.gyb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
// RUN: %target-run-simple-swiftgyb-forward-mode-differentiation
1+
// -*- swift -*-
2+
// RUN: %target-run-simple-swiftgyb
23
// REQUIRES: executable_test
34

45
#if os(macOS) || os(iOS) || os(tvOS) || os(watchOS)
@@ -18,6 +19,7 @@
1819
#endif
1920

2021
import StdlibUnittest
22+
import _Differentiation
2123

2224
let DerivativeTests = TestSuite("TGMath")
2325

0 commit comments

Comments
 (0)