Skip to content

Commit 17eafaf

Browse files
authored
[AutoDiff] [stdlib] Fix a bug in _jvpMultiply in SIMDDifferentiation.swift.gyb (#32963)
1 parent 1a81573 commit 17eafaf

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

stdlib/public/Differentiation/SIMDDifferentiation.swift.gyb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ where
189189
)
190190
{
191191
return (lhs * rhs, { ltan, rtan in
192-
return lhs * ltan + rtan * rhs
192+
return lhs * rtan + ltan * rhs
193193
})
194194
}
195195

test/AutoDiff/validation-test/forward_mode.swift

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1537,15 +1537,17 @@ ForwardModeTests.test("Subtraction") {
15371537

15381538
ForwardModeTests.test("Multiplication") {
15391539
let a = SIMD4<Float>(1, 2, 3, 4)
1540+
let a2 = SIMD4<Float>(4, 3, 2, 1)
15401541
let g = SIMD4<Float>(1, 1, 1, 1)
1542+
let g2 = SIMD4<Float>(0, 2, 1, 3)
15411543

15421544
// SIMD * SIMD
15431545
func foo1(x: SIMD4<Float>, y: SIMD4<Float>) -> SIMD4<Float> {
15441546
return x * y
15451547
}
1546-
let (val1, df1) = valueWithDifferential(at: a, a, in: foo1)
1547-
expectEqual(a * a, val1)
1548-
expectEqual(a * g + g * a, df1(g, g))
1548+
let (val1, df1) = valueWithDifferential(at: a, a2, in: foo1)
1549+
expectEqual(a * a2, val1)
1550+
expectEqual(a * g2 + g * a2, df1(g, g2))
15491551

15501552
// SIMD * Scalar
15511553
func foo2(x: SIMD4<Float>, y: Float) -> SIMD4<Float> {

0 commit comments

Comments
 (0)