File tree Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -56,6 +56,28 @@ ArrayAutoDiffTests.test("ArrayLiteralIndirect") {
56
56
expectEqual ( Float ( 2 ) , gradY)
57
57
}
58
58
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
+
59
81
ArrayAutoDiffTests . test ( " ArrayConcat " ) {
60
82
struct TwoArrays : Differentiable {
61
83
var a : [ Float ]
You can’t perform that action at this time.
0 commit comments