Skip to content

Commit c634b5d

Browse files
Merge pull request #121 from dan-zheng/complex-differentiable
Define `Complex.zeroTangentVectorInitializer`.
2 parents 593946d + 86f0b33 commit c634b5d

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

Sources/ComplexModule/Differentiable.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ import _Differentiation
1515
extension Complex: Differentiable
1616
where RealType: Differentiable, RealType.TangentVector == RealType {
1717
public typealias TangentVector = Self
18+
19+
@inlinable
20+
public var zeroTangentVectorInitializer: () -> Self {
21+
{ Complex.zero }
22+
}
1823
}
1924

2025
extension Complex

Tests/ComplexTests/DifferentiableTests.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ final class DifferentiableTests: XCTestCase {
5757
XCTAssertEqual(φDivide(Complex(1, 0)), Complex(0.25, -0.25))
5858
XCTAssertEqual(φDivide(Complex(0, 1)), Complex(0.25, 0.25))
5959
}
60+
61+
func testZeroTangentVectorInitializer() {
62+
XCTAssertEqual(Complex<Float>(-5, 5).zeroTangentVector, Complex(0, 0))
63+
}
6064
}
6165

6266
#endif

0 commit comments

Comments
 (0)