Skip to content

Commit bb57241

Browse files
committed
Add indirect ExpressibleByArrayLiteral test.
No activity analysis test added because activity info for the `array.uninitialized_intrinsic` application is the same.
1 parent 05122fb commit bb57241

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

test/AutoDiff/array.swift

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,28 @@ ArrayAutoDiffTests.test("ArrayLiteralIndirect") {
5656
expectEqual(Float(2), gradY)
5757
}
5858

59+
ArrayAutoDiffTests.test("ExpressibleByArrayLiteralIndirect") {
60+
struct Indirect<T: Differentiable>: Differentiable & ExpressibleByArrayLiteral {
61+
var x: T
62+
63+
typealias ArrayLiteralElement = T
64+
init(arrayLiteral: T...) {
65+
assert(arrayLiteral.count > 1)
66+
self.x = arrayLiteral[0]
67+
}
68+
}
69+
70+
func testArrayUninitializedIntrinsic<T>(_ x: T, _ y: T) -> Indirect<T> {
71+
return [x, y]
72+
}
73+
74+
let (gradX, gradY) = pullback(at: Float(1), Float(1), in: {
75+
x, y in testArrayUninitializedIntrinsic(x, y)
76+
})(Indirect<Float>.TangentVector(x: 1))
77+
expectEqual(1, gradX)
78+
expectEqual(0, gradY)
79+
}
80+
5981
ArrayAutoDiffTests.test("ArrayConcat") {
6082
struct TwoArrays : Differentiable {
6183
var a: [Float]

0 commit comments

Comments
 (0)