Skip to content

Commit c74cbce

Browse files
authored
Fix incorrect derivative (#41423)
1 parent e2012dd commit c74cbce

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed

stdlib/public/Differentiation/FloatingPointDifferentiation.swift.gyb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ where
268268
func _vjpAddingProduct(
269269
_ lhs: Self, _ rhs: Self
270270
) -> (value: Self, pullback: (Self) -> (Self, Self, Self)) {
271-
return (addingProduct(lhs, rhs), { _ in (1, rhs, lhs) })
271+
return (addingProduct(lhs, rhs), { v in (v, v * rhs, v * lhs) })
272272
}
273273

274274
@inlinable // FIXME(sil-serialize-all)

test/AutoDiff/stdlib/floating_point.swift.gyb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ FloatingPointDerivativeTests.test("${Self}.squareRoot") {
8181

8282
FloatingPointDerivativeTests.test("${Self}.addingProduct") {
8383
expectEqual((1, 2, 3), gradient(at: ${Self}(10), 3, 2, of: { $0.addingProduct($1, $2) }))
84+
expectEqual((2, 4, 6), pullback(at: ${Self}(10), 3, 2, of: { $0.addingProduct($1, $2) })(2))
8485
}
8586

8687
FloatingPointDerivativeTests.test("${Self}.minimum") {

0 commit comments

Comments
 (0)