diff --git a/README.md b/README.md index 765aa0d..843b770 100644 --- a/README.md +++ b/README.md @@ -59,7 +59,7 @@ To use Swift Numerics in a SwiftPM project: ## Source stability The Swift Numerics package is source stable; version numbers follow [Semantic Versioning](https://semver.org). -The public API of the `swift-numerics` package consists of non-underscored declarations that are marked either `public` or `usableFromInline` in modules re-exported by the top-level `Numerics` module, *excepting any API that involves a conformance to Differentiable (because Differentiable itself is not stable in Swift)*. +The public API of the `swift-numerics` package consists of non-underscored declarations that are marked either `public` or `usableFromInline` in modules re-exported by the top-level `Numerics` module. Interfaces that aren't part of the public API may continue to change in any release, including patch releases. Note that contents of the `_NumericsShims` and `_TestSupport` modules, as well as contents of the `Tests` directory, explicitly are not public API. diff --git a/Sources/ComplexModule/CMakeLists.txt b/Sources/ComplexModule/CMakeLists.txt index 5c1dd8f..ecc4653 100644 --- a/Sources/ComplexModule/CMakeLists.txt +++ b/Sources/ComplexModule/CMakeLists.txt @@ -12,7 +12,6 @@ add_library(ComplexModule Complex+AdditiveArithmetic.swift Complex+AlgebraicField.swift Complex+Codable.swift - Complex+Differentiable.swift Complex+ElementaryFunctions.swift Complex+Hashable.swift Complex+IntegerLiteral.swift diff --git a/Sources/ComplexModule/Complex+Differentiable.swift b/Sources/ComplexModule/Complex+Differentiable.swift deleted file mode 100644 index eea3816..0000000 --- a/Sources/ComplexModule/Complex+Differentiable.swift +++ /dev/null @@ -1,101 +0,0 @@ -//===--- Differentiable.swift ---------------------------------*- swift -*-===// -// -// This source file is part of the Swift Numerics open source project -// -// Copyright (c) 2019 - 2021 Apple Inc. and the Swift Numerics project authors -// Licensed under Apache License v2.0 with Runtime Library Exception -// -// See https://swift.org/LICENSE.txt for license information -// -//===----------------------------------------------------------------------===// - -// STC April 2022: experimentally remove differentiable conformance to work -// around CI config failure. -#if canImport(_Differentiation) && !os(macOS) -import _Differentiation - -extension Complex: Differentiable -where RealType: Differentiable, RealType.TangentVector == RealType { - public typealias TangentVector = Self - - @inlinable - public var zeroTangentVectorInitializer: () -> Self { - { Complex.zero } - } -} - -extension Complex -where RealType: Differentiable, RealType.TangentVector == RealType { - @derivative(of: init(_:_:)) - @usableFromInline - static func _derivativeInit( - _ real: RealType, - _ imaginary: RealType - ) -> (value: Complex, pullback: (Complex) -> (RealType, RealType)) { - (value: .init(real, imaginary), pullback: { v in - (v.real, v.imaginary) - }) - } - - @derivative(of: real) - @usableFromInline - func _derivativeReal() -> (value: RealType, pullback: (RealType) -> Complex) { - (value: real, pullback: { v in - Complex(v, .zero) - }) - } - - @derivative(of: imaginary) - @usableFromInline - func _derivativeImaginary() -> ( - value: RealType, - pullback: (RealType) -> Complex - ) { - (value: real, pullback: { v in - Complex(.zero, v) - }) - } - - @derivative(of: +) - @usableFromInline - static func _derivativeAdd(lhs: Complex, rhs: Complex) - -> (value: Complex, pullback: (Complex) -> (Complex, Complex)) - { - (lhs + rhs, { v in (v, v) }) - } - - @derivative(of: -) - @usableFromInline - static func _derivativeSubtract(lhs: Complex, rhs: Complex) - -> (value: Complex, pullback: (Complex) -> (Complex, Complex)) - { - (lhs - rhs, { v in (v, -v) }) - } - - @derivative(of: *) - @usableFromInline - static func _derivativeMultiply(lhs: Complex, rhs: Complex) - -> (value: Complex, pullback: (Complex) -> (Complex, Complex)) - { - (lhs * rhs, { v in (rhs * v, lhs * v) }) - } - - @derivative(of: /) - @usableFromInline - static func _derivativeDivide(lhs: Complex, rhs: Complex) - -> (value: Complex, pullback: (Complex) -> (Complex, Complex)) - { - (lhs / rhs, { v in (v / rhs, -lhs / (rhs * rhs) * v) }) - } - - @derivative(of: conjugate) - @usableFromInline - func _derivativeConjugate() -> ( - value: Complex, - pullback: (Complex) -> Complex - ) { - (conjugate, { v in v.conjugate }) - } -} - -#endif diff --git a/Tests/ComplexTests/CMakeLists.txt b/Tests/ComplexTests/CMakeLists.txt index 43d83ab..9b1b698 100644 --- a/Tests/ComplexTests/CMakeLists.txt +++ b/Tests/ComplexTests/CMakeLists.txt @@ -10,7 +10,6 @@ See https://swift.org/LICENSE.txt for license information add_library(ComplexTests ApproximateEqualityTests.swift ArithmeticTests.swift - DifferentiableTests.swift ElementaryFunctionTests.swift PropertyTests.swift) set_target_properties(ComplexTests PROPERTIES diff --git a/Tests/ComplexTests/DifferentiableTests.swift b/Tests/ComplexTests/DifferentiableTests.swift deleted file mode 100644 index 31632bb..0000000 --- a/Tests/ComplexTests/DifferentiableTests.swift +++ /dev/null @@ -1,76 +0,0 @@ -//===--- DifferentiableTests.swift ----------------------------*- swift -*-===// -// -// This source file is part of the Swift Numerics open source project -// -// Copyright (c) 2019 - 2020 Apple Inc. and the Swift Numerics project authors -// Licensed under Apache License v2.0 with Runtime Library Exception -// -// See https://swift.org/LICENSE.txt for license information -// -//===----------------------------------------------------------------------===// - -// STC April 2022: experimentally remove differentiable conformance to work -// around CI config failure. -#if canImport(_Differentiation) && !os(macOS) - -import XCTest -import ComplexModule -import _Differentiation - -final class DifferentiableTests: XCTestCase { - func testComponentGetter() { - XCTAssertEqual( - gradient(at: Complex(5, 5)) { $0.real * 2 }, - Complex(2, 0)) - XCTAssertEqual( - gradient(at: Complex(5, 5)) { $0.imaginary * 2 }, - Complex(0, 2)) - XCTAssertEqual( - gradient(at: Complex(5, 5)) { $0.real * 5 + $0.imaginary * 2 }, - Complex(5, 2)) - } - - func testInitializer() { - let φ1 = pullback(at: 4, -3) { r, i in Complex(r, i) } - let tan1 = φ1(Complex(-1, 2)) - XCTAssertEqual(tan1.0, -1) - XCTAssertEqual(tan1.1, 2) - - let φ2 = pullback(at: 4, -3) { r, i in Complex(r * r, i + i) } - let tan2 = φ2(Complex(-1, 1)) - XCTAssertEqual(tan2.0, -8) - XCTAssertEqual(tan2.1, 2) - } - - func testConjugate() { - let φ = pullback(at: Complex(20, -4)) { x in x.conjugate } - XCTAssertEqual(φ(Complex(1, 0)), Complex(1, 0)) - XCTAssertEqual(φ(Complex(0, 1)), Complex(0, -1)) - XCTAssertEqual(φ(Complex(-1, 1)), Complex(-1, -1)) - } - - func testArithmetics() { - let φAdd = pullback(at: Complex(2, 3)) { x in - x + Complex(5, 6) - } - XCTAssertEqual(φAdd(Complex(1, 1)), Complex(1, 1)) - - let φSubtract = pullback(at: Complex(2, 3)) { x in - Complex(5, 6) - x - } - XCTAssertEqual(φSubtract(Complex(1, 1)), Complex(-1, -1)) - - let φMultiply = pullback(at: Complex(2, 3)) { x in x * x } - XCTAssertEqual(φMultiply(Complex(1, 0)), Complex(4, 6)) - XCTAssertEqual(φMultiply(Complex(0, 1)), Complex(-6, 4)) - XCTAssertEqual(φMultiply(Complex(1, 1)), Complex(-2, 10)) - - let φDivide = pullback(at: Complex(20, -4)) { x in - x / Complex(2, 2) - } - XCTAssertEqual(φDivide(Complex(1, 0)), Complex(0.25, -0.25)) - XCTAssertEqual(φDivide(Complex(0, 1)), Complex(0.25, 0.25)) - } -} - -#endif diff --git a/Tests/WindowsMain.swift b/Tests/WindowsMain.swift index 259a045..5ce400a 100644 --- a/Tests/WindowsMain.swift +++ b/Tests/WindowsMain.swift @@ -161,21 +161,6 @@ var testCases = [ IntegerUtilitiesTests.DoubleWidthTests.all, ] -#if canImport(_Differentiation) -extension DifferentiableTests { - static var all = testCase([ - ("testComponentGetter", DifferentiableTests.testComponentGetter), - ("testInitializer", DifferentiableTests.testInitializer), - ("testConjugate", DifferentiableTests.testConjugate), - ("testArithmetics", DifferentiableTests.testArithmetics), - ]) -} - -testCases += [ - DifferentiableTests.all -] -#endif - XCTMain(testCases) #endif