Skip to content

Commit 2aedf0e

Browse files
authored
---
yaml --- r: 340967 b: refs/heads/rxwei-patch-1 c: 925c768 h: refs/heads/master i: 340965: 3cc1868 340963: cc112c8 340959: 900c641
1 parent fefb3c1 commit 2aedf0e

File tree

3 files changed

+9
-24
lines changed

3 files changed

+9
-24
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1015,7 +1015,7 @@ refs/tags/swift-DEVELOPMENT-SNAPSHOT-2018-08-18-a: b10b1fce14385faa6d44f6b933e95
10151015
refs/heads/rdar-43033749-fix-batch-mode-no-diags-swift-5.0-branch: a14e64eaad30de89f0f5f0b2a782eed7ecdcb255
10161016
refs/heads/revert-19006-error-bridging-integer-type: 8a9065a3696535305ea53fe9b71f91cbe6702019
10171017
refs/heads/revert-19050-revert-19006-error-bridging-integer-type: ecf752d54b05dd0a20f510f0bfa54a3fec3bcaca
1018-
refs/heads/rxwei-patch-1: 8dac116bdcf115e47765b252395cd5eb8c7cf999
1018+
refs/heads/rxwei-patch-1: 925c7685d4ed1a395bb286de6784846478471d0a
10191019
refs/heads/shahmishal-patch-1: e58ec0f7488258d42bef51bc3e6d7b3dc74d7b2a
10201020
refs/heads/typelist-existential: 4046359efd541fb5c72d69a92eefc0a784df8f5e
10211021
refs/tags/swift-4.2-DEVELOPMENT-SNAPSHOT-2018-08-20-a: 4319ba09e4fb8650ee86061075c74a016b6baab9

branches/rxwei-patch-1/stdlib/public/core/AutoDiff.swift

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -248,13 +248,13 @@ public func differentiableFunction<T, U, R>(
248248
}
249249

250250
public extension Differentiable {
251-
@differentiable(wrt: self, vjp: _vjpWithGrad)
252-
func withGradient(_ body: @escaping (inout TangentVector) -> Void) -> Self {
251+
@differentiable(wrt: self, vjp: _vjpWithDerivative)
252+
func withDerivative(_ body: @escaping (inout TangentVector) -> Void) -> Self {
253253
return self
254254
}
255255

256256
@inlinable
257-
internal func _vjpWithGrad(
257+
internal func _vjpWithDerivative(
258258
_ body: @escaping (inout TangentVector) -> Void
259259
) -> (Self, (TangentVector) -> TangentVector) {
260260
return (self, { grad in
@@ -263,21 +263,6 @@ public extension Differentiable {
263263
return grad
264264
})
265265
}
266-
267-
@differentiable(wrt: self, vjp: _vjpWithGrad)
268-
func withGradient(_ body: @escaping (TangentVector) -> Void) -> Self {
269-
return self
270-
}
271-
272-
@inlinable
273-
internal func _vjpWithGrad(
274-
_ body: @escaping (TangentVector) -> Void
275-
) -> (Self, (TangentVector) -> TangentVector) {
276-
return (self, { grad in
277-
body(grad)
278-
return grad
279-
})
280-
}
281266
}
282267

283268
/// Make a function be recomputed in its pullback, known as "checkpointing" in

branches/rxwei-patch-1/test/AutoDiff/custom_derivatives.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,18 +72,18 @@ CustomDerivativesTests.test("Checkpointing") {
7272

7373
CustomDerivativesTests.test("SumOfGradPieces") {
7474
var grad: Float = 0
75-
let addToGrad = { grad += $0 }
75+
func addToGrad(_ x: inout Float) { grad += x }
7676
_ = gradient(at: 4) { (x: Float) in
77-
x.withGradient(addToGrad)
78-
* x.withGradient(addToGrad)
79-
* x.withGradient(addToGrad)
77+
x.withDerivative(addToGrad)
78+
* x.withDerivative(addToGrad)
79+
* x.withDerivative(addToGrad)
8080
}
8181
expectEqual(48, grad)
8282
}
8383

8484
CustomDerivativesTests.test("ModifyGradientOfSum") {
8585
expectEqual(30, gradient(at: 4) { (x: Float) in
86-
x.withGradient { $0 *= 10 } + x.withGradient { $0 *= 20 }
86+
x.withDerivative { $0 *= 10 } + x.withDerivative { $0 *= 20 }
8787
})
8888
}
8989

0 commit comments

Comments
 (0)