Skip to content

Commit 80ab32a

Browse files
committed
fix: remove init vjp due to compiler issue
This can be reactivated in Swift 6.3
1 parent 82e8971 commit 80ab32a

File tree

2 files changed

+39
-33
lines changed

2 files changed

+39
-33
lines changed

Sources/Differentiation/InlineArray+Differentiation.swift

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,23 @@ extension InlineArray: @retroactive Differentiable where Element: Differentiable
1313
}
1414
}
1515

16-
@derivative(of: init)
17-
@_alwaysEmitIntoClient
18-
public static func _vjpInit(repeating value: Element) -> (value: Self, pullback: (TangentVector) -> Element.TangentVector) {
19-
(
20-
value: Self(repeating: value),
21-
pullback: { v in
22-
var result: Element.TangentVector = .zero
23-
for i in v.indices {
24-
result += v[i]
25-
}
26-
return result
27-
}
28-
)
29-
}
16+
// not available yet due to a compiler issue. This is in main as of 2025/05/25. Part of Swift 6.3
17+
/*
18+
@derivative(of: init)
19+
@_alwaysEmitIntoClient
20+
public static func _vjpInit(repeating value: Element) -> (value: Self, pullback: (TangentVector) -> Element.TangentVector) {
21+
(
22+
value: Self(repeating: value),
23+
pullback: { v in
24+
var result: Element.TangentVector = .zero
25+
for i in v.indices {
26+
result += v[i]
27+
}
28+
return result
29+
}
30+
)
31+
}
32+
*/
3033

3134
@inlinable
3235
public func read(_ i: Index) -> Element {

Tests/DifferentiationTests/InlineArrayTests.swift

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -28,26 +28,29 @@ struct InlineArrayTests {
2828
#expect(diff[1] == 1.5)
2929
}
3030

31-
// Test differentiable init(repeating:)
32-
@Test("vjp of init(repeating:) aggregates tangent inputs correctly")
33-
@available(macOS 26, *)
34-
func testVJPInitRepeating() {
35-
// For differentiable init(repeating:), the pullback should sum all elements of the tangent vector
36-
let repeated = InlineArray<2, Double>(repeating: 4.0)
37-
// forward run
38-
// Now test pullback: apply VJP
39-
// The API for using VJP: call `valueWithPullback` or similar
40-
let (value, pullback) = valueWithPullback(at: 4.0, of: { value in InlineArray<2, Double>(repeating: value) })
41-
// value should equal what init(repeating:) produces
42-
#expect(value == repeated)
31+
// disabled until Swift 6.3 as we can't register derivative for methods marked @_alwaysEmitIntoClient for now.
32+
/*
33+
// Test differentiable init(repeating:)
34+
@Test("vjp of init(repeating:) aggregates tangent inputs correctly")
35+
@available(macOS 26, *)
36+
func testVJPInitRepeating() {
37+
// For differentiable init(repeating:), the pullback should sum all elements of the tangent vector
38+
let repeated = InlineArray<2, Double>(repeating: 4.0)
39+
// forward run
40+
// Now test pullback: apply VJP
41+
// The API for using VJP: call `valueWithPullback` or similar
42+
let (value, pullback) = valueWithPullback(at: 4.0, of: { value in InlineArray<2, Double>(repeating: value) })
43+
// value should equal what init(repeating:) produces
44+
#expect(value == repeated)
4345

44-
// construct some tangent vector
45-
let tv: InlineArray<2, Double> = [10.0, 20.0]
46-
// apply pullback
47-
let back = pullback(tv)
48-
// Should equal sum of elements, i.e. 10 + 20 == 30, as Double’s tangent
49-
#expect(back == 30.0)
50-
}
46+
// construct some tangent vector
47+
let tv: InlineArray<2, Double> = [10.0, 20.0]
48+
// apply pullback
49+
let back = pullback(tv)
50+
// Should equal sum of elements, i.e. 10 + 20 == 30, as Double’s tangent
51+
#expect(back == 30.0)
52+
}
53+
*/
5154

5255
@Test("vjp of read is correct")
5356
@available(macOS 26, *)

0 commit comments

Comments
 (0)