Skip to content

Commit 3f06912

Browse files
committed
[AutoDiff] Enable forward-mode differentiation tests.
Resolves TF-1237 TODO comments.
1 parent 2f50c85 commit 3f06912

File tree

2 files changed

+11
-34
lines changed

2 files changed

+11
-34
lines changed

test/AutoDiff/stdlib/floating_point.swift.gyb

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-run-simple-swiftgyb
1+
// RUN: %target-run-simple-swiftgyb(-Xfrontend -enable-experimental-forward-mode-differentiation)
22
// REQUIRES: executable_test
33

44
#if (arch(i386) || arch(x86_64)) && !os(Windows)
@@ -38,33 +38,24 @@ FloatingPointDerivativeTests.test("${Self}.+") {
3838
expectEqual((1, 1), gradient(at: ${Self}(4), ${Self}(5), in: +))
3939
expectEqual((10, 10), pullback(at: ${Self}(4), ${Self}(5), in: +)(${Self}(10)))
4040

41-
// TODO(TF-1237): Upstream forward-mode differentiation.
42-
expectCrash {
43-
expectEqual(2, derivative(at: ${Self}(4), ${Self}(5), in: +))
44-
expectEqual(20, differential(at: ${Self}(4), ${Self}(5), in: +)(${Self}(10), ${Self}(10)))
45-
}
41+
expectEqual(2, derivative(at: ${Self}(4), ${Self}(5), in: +))
42+
expectEqual(20, differential(at: ${Self}(4), ${Self}(5), in: +)(${Self}(10), ${Self}(10)))
4643
}
4744

4845
FloatingPointDerivativeTests.test("${Self}.-") {
4946
expectEqual((1, -1), gradient(at: ${Self}(4), ${Self}(5), in: -))
5047
expectEqual((10, -10), pullback(at: ${Self}(4), ${Self}(5), in: -)(${Self}(10)))
5148

52-
// TODO(TF-1237): Upstream forward-mode differentiation.
53-
expectCrash {
54-
expectEqual(0, derivative(at: ${Self}(4), ${Self}(5), in: -))
55-
expectEqual(-5, differential(at: ${Self}(4), ${Self}(5), in: -)(${Self}(5), ${Self}(10)))
56-
}
49+
expectEqual(0, derivative(at: ${Self}(4), ${Self}(5), in: -))
50+
expectEqual(-5, differential(at: ${Self}(4), ${Self}(5), in: -)(${Self}(5), ${Self}(10)))
5751
}
5852

5953
FloatingPointDerivativeTests.test("${Self}.*") {
6054
expectEqual((5, 4), gradient(at: ${Self}(4), ${Self}(5), in: *))
6155
expectEqual((50, 40), pullback(at: ${Self}(4), ${Self}(5), in: *)(${Self}(10)))
6256

63-
// TODO(TF-1237): Upstream forward-mode differentiation.
64-
expectCrash {
65-
expectEqual(9, derivative(at: ${Self}(4), ${Self}(5), in: *))
66-
expectEqual(90, differential(at: ${Self}(4), ${Self}(5), in: *)(${Self}(10), ${Self}(10)))
67-
}
57+
expectEqual(9, derivative(at: ${Self}(4), ${Self}(5), in: *))
58+
expectEqual(90, differential(at: ${Self}(4), ${Self}(5), in: *)(${Self}(10), ${Self}(10)))
6859
}
6960

7061
FloatingPointDerivativeTests.test("${Self}./") {
@@ -79,11 +70,8 @@ FloatingPointDerivativeTests.test("${Self}./") {
7970
expectEqualWithTolerance(-1.6, dy)
8071
}
8172

82-
// TODO(TF-1237): Upstream forward-mode differentiation.
83-
expectCrash {
84-
expectEqualWithTolerance(0.04, derivative(at: ${Self}(4), ${Self}(5), in: /))
85-
expectEqual(90, differential(at: ${Self}(4), ${Self}(5), in: *)(${Self}(10), ${Self}(10)))
86-
}
73+
expectEqualWithTolerance(0.04, derivative(at: ${Self}(4), ${Self}(5), in: /))
74+
expectEqual(90, differential(at: ${Self}(4), ${Self}(5), in: *)(${Self}(10), ${Self}(10)))
8775
}
8876

8977
FloatingPointDerivativeTests.test("${Self}.squareRoot") {

test/AutoDiff/stdlib/tgmath_derivatives.swift.gyb

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-run-simple-swiftgyb
1+
// RUN: %target-run-simple-swiftgyb(-Xfrontend -enable-experimental-forward-mode-differentiation)
22
// REQUIRES: executable_test
33

44
#if os(macOS) || os(iOS) || os(tvOS) || os(watchOS)
@@ -55,10 +55,6 @@ where T == T.TangentVector {
5555
%for T in ['Float', 'Float80']:
5656

5757
DerivativeTests.test("${op}_${T}") {
58-
%if op == 'derivative':
59-
// TODO(TF-1237): Upstream forward-mode differentiation and uncomment the next line.
60-
expectCrash {
61-
%end
6258
expectEqualWithTolerance(7.3890560989306502274, ${op}(at: 2 as ${T}, in: exp))
6359
expectEqualWithTolerance(2.772588722239781145, ${op}(at: 2 as ${T}, in: exp2))
6460
expectEqualWithTolerance(7.3890560989306502274, ${op}(at: 2 as ${T}, in: expm1))
@@ -86,10 +82,6 @@ DerivativeTests.test("${op}_${T}") {
8682
expectEqualWithTolerance(0, ${op}(at: 2 as ${T}, in: { round($0) }))
8783
expectEqualWithTolerance(0, ${op}(at: 2 as ${T}, in: { trunc($0) }))
8884

89-
%if op == 'derivative':
90-
} // `expectCrash` for forward-mode differentiation
91-
%end
92-
9385
// Differential operator specific tests.
9486

9587
// fma
@@ -99,10 +91,7 @@ DerivativeTests.test("${op}_${T}") {
9991
expectEqualWithTolerance(4, dfma.1)
10092
expectEqualWithTolerance(1, dfma.2)
10193
%else: # if op == 'derivative'
102-
// TODO(TF-1237): Upstream forward-mode differentiation.
103-
expectCrash {
104-
expectEqualWithTolerance(10, dfma)
105-
}
94+
expectEqualWithTolerance(10, dfma)
10695
%end
10796

10897
// remainder, fmod

0 commit comments

Comments
 (0)