diff --git a/Sources/ComplexModule/Differentiable.swift b/Sources/ComplexModule/Differentiable.swift index 443a1d5a..5e2f3042 100644 --- a/Sources/ComplexModule/Differentiable.swift +++ b/Sources/ComplexModule/Differentiable.swift @@ -15,6 +15,11 @@ import _Differentiation extension Complex: Differentiable where RealType: Differentiable, RealType.TangentVector == RealType { public typealias TangentVector = Self + + @inlinable + public var zeroTangentVectorInitializer: () -> Self { + { Complex.zero } + } } extension Complex diff --git a/Tests/ComplexTests/DifferentiableTests.swift b/Tests/ComplexTests/DifferentiableTests.swift index 4ade368c..31759ac7 100644 --- a/Tests/ComplexTests/DifferentiableTests.swift +++ b/Tests/ComplexTests/DifferentiableTests.swift @@ -57,6 +57,10 @@ final class DifferentiableTests: XCTestCase { XCTAssertEqual(φDivide(Complex(1, 0)), Complex(0.25, -0.25)) XCTAssertEqual(φDivide(Complex(0, 1)), Complex(0.25, 0.25)) } + + func testZeroTangentVectorInitializer() { + XCTAssertEqual(Complex(-5, 5).zeroTangentVector, Complex(0, 0)) + } } #endif