Skip to content

Commit

Permalink
Merge pull request #228 from markuswntr/quaternion/sync
Browse files Browse the repository at this point in the history
Sync latest package changes with `Quaternions` branch
  • Loading branch information
stephentyrone authored Jun 20, 2022
2 parents 3aaab70 + 4f97344 commit 5750897
Show file tree
Hide file tree
Showing 67 changed files with 4,417 additions and 1,587 deletions.
15 changes: 0 additions & 15 deletions .github/workflows/macos.yml

This file was deleted.

5 changes: 0 additions & 5 deletions .xcodesamplecode.plist

This file was deleted.

107 changes: 87 additions & 20 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// swift-tools-version:5.0
// swift-tools-version:5.4
//===--- Package.swift ----------------------------------------*- swift -*-===//
//
// This source file is part of the Swift Numerics open source project
//
// Copyright (c) 2019 Apple Inc. and the Swift Numerics project authors
// 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
Expand All @@ -12,6 +12,8 @@

import PackageDescription

let excludedFilenames = ["CMakeLists.txt", "README.md"]

let package = Package(

name: "swift-numerics",
Expand All @@ -23,23 +25,88 @@ let package = Package(
],

targets: [
// User-facing modules
.target(name: "ComplexModule", dependencies: ["RealModule"]),
.target(name: "Numerics", dependencies: ["ComplexModule", "QuaternionModule", "RealModule"]),
.target(name: "QuaternionModule", dependencies: ["RealModule"]),
.target(name: "RealModule", dependencies: ["_NumericsShims"]),

// Implementation details
.target(name: "_NumericsShims", dependencies: []),
.target(name: "_TestSupport", dependencies: ["Numerics"]),

// Unit test bundles
.testTarget(name: "ComplexTests", dependencies: ["_TestSupport"]),
.testTarget(name: "QuaternionTests", dependencies: ["_TestSupport"]),
.testTarget(name: "RealTests", dependencies: ["_TestSupport"]),

// Test executables
.target(name: "ComplexLog", dependencies: ["Numerics", "_TestSupport"], path: "Tests/Executable/ComplexLog"),
.target(name: "ComplexLog1p", dependencies: ["Numerics", "_TestSupport"], path: "Tests/Executable/ComplexLog1p")
// MARK: - Public API
.target(
name: "ComplexModule",
dependencies: ["RealModule"],
exclude: excludedFilenames
),

.target(
name: "IntegerUtilities",
dependencies: [],
exclude: excludedFilenames
),

.target(
name: "Numerics",
dependencies: [
"ComplexModule", "IntegerUtilities",
"QuaternionModule", "RealModule"
],
exclude: excludedFilenames
),

.target(
name: "QuaternionModule",
dependencies: ["RealModule"],
exclude: ["README.md", "Transformation.md"]
),

.target(
name: "RealModule",
dependencies: ["_NumericsShims"],
exclude: excludedFilenames
),

// MARK: - Implementation details
.target(
name: "_NumericsShims",
exclude: excludedFilenames,
linkerSettings: [.linkedLibrary("m", .when(platforms: [.linux, .android]))]
),

.target(
name: "_TestSupport",
dependencies: ["Numerics"],
exclude: ["CMakeLists.txt"]
),

// MARK: - Unit test bundles
.testTarget(
name: "ComplexTests",
dependencies: ["_TestSupport"],
exclude: ["CMakeLists.txt"]
),

.testTarget(
name: "IntegerUtilitiesTests",
dependencies: ["IntegerUtilities", "_TestSupport"],
exclude: ["CMakeLists.txt"]
),

.testTarget(
name: "QuaternionTests",
dependencies: ["_TestSupport"]
),

.testTarget(
name: "RealTests",
dependencies: ["_TestSupport"],
exclude: ["CMakeLists.txt"]
),

// MARK: - Test executables
.executableTarget(
name: "ComplexLog",
dependencies: ["Numerics", "_TestSupport"],
path: "Tests/Executable/ComplexLog"
),

.executableTarget(
name: "ComplexLog1p",
dependencies: ["Numerics", "_TestSupport"],
path: "Tests/Executable/ComplexLog1p"
)
]
)
71 changes: 43 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ These modules fall broadly into two categories:
There is some overlap between these two categories, and an API that begins in the first category may migrate into the second as it matures and new uses are discovered.

Swift Numerics modules are fine-grained.
For example, if you need support for Complex numbers, you can import ComplexModule¹ as a standalone module:
For example, if you need support for Complex numbers, you can import ComplexModule[^1] as a standalone module:

```swift
import ComplexModule
Expand Down Expand Up @@ -42,7 +42,7 @@ To use Swift Numerics in a SwiftPM project:
1. Add the following line to the dependencies in your `Package.swift` file:

```swift
.package(url: "https://github.com/apple/swift-numerics", from: "0.0.7"),
.package(url: "https://github.com/apple/swift-numerics", from: "1.0.0"),
```

2. Add `Numerics` as a dependency for your target:
Expand All @@ -56,6 +56,22 @@ To use Swift Numerics in a SwiftPM project:

3. Add `import Numerics` in your source code.

## 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.
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.
The definitions therein may therefore change at whim, and the entire module may be removed in any new release.
If you have a use case that requires underscored operations, please raise an issue to request that they be made public API.

Future minor versions of the package may introduce changes to these rules as needed.

We'd like this package to quickly embrace Swift language and toolchain improvements that are relevant to its mandate.
Accordingly, from time to time, we expect that new versions of this package will require clients to upgrade to a more recent Swift toolchain release.
Requiring a new Swift release will only require a minor version bump.

## Contributing to Swift Numerics

Swift Numerics is a standalone library that is separate from the core Swift project, but it will sometimes act as a staging ground for APIs that will later be incorporated into the Swift Standard Library.
Expand Down Expand Up @@ -89,7 +105,8 @@ Questions about how to use Swift Numerics modules, or issues that are not clearl

1. [`RealModule`](Sources/RealModule/README.md)
2. [`ComplexModule`](Sources/ComplexModule/README.md)
3. [`QuaternionModule`](Sources/QuaternionModule/README.md)
3. [`IntegerUtilities`](Sources/IntegerUtilties/README.md) (on main only, not yet present in a released tag)
4. [`QuaternionModule`](Sources/QuaternionModule/README.md)

## Future expansion

Expand All @@ -98,28 +115,26 @@ Questions about how to use Swift Numerics modules, or issues that are not clearl
3. [Shaped Arrays](https://github.com/apple/swift-numerics/issues/6)
4. [Decimal Floating-point](https://github.com/apple/swift-numerics/issues/7)

## Notes

¹ Swift is currently unable to use the fully-qualified name for types when a type and module have the same name (discussion here: https://forums.swift.org/t/pitch-fully-qualified-name-syntax/28482).
This would prevent users of Swift Numerics who don't need generic types from doing things such as:

```swift
import Complex
// I know I only ever want Complex<Double>, so I shouldn't need the generic parameter.
typealias Complex = Complex.Complex<Double> // This doesn't work, because name lookup fails.
```

For this reason, modules that would have this ambiguity are suffixed with `Module` within Swift Numerics:

```swift
import ComplexModule
// I know I only ever want Complex<Double>, so I shouldn't need the generic parameter.
typealias Complex = ComplexModule.Complex<Double>
// But I can still refer to the generic type by qualifying the name if I need it occasionally:
let a = ComplexModule.Complex<Float>
```

The `Real` module does not contain a `Real` type, but does contain a `Real` protocol.
Users may want to define their own `Real` type (and possibly re-export the `Real` module)--that is why the suffix is also applied there.
New modules have to evaluate this decision carefully, but can err on the side of adding the suffix.
It's expected that most users will simply `import Numerics`, so this isn't an issue for them.
[^1]: The module is named `ComplexModule` instead of `Complex` because Swift is currently unable to use the fully-qualified name for types when a type and module have the same name (discussion here: https://forums.swift.org/t/pitch-fully-qualified-name-syntax/28482).
This would prevent users of Swift Numerics who don't need generic types from doing things such as:

```swift
import Complex
// I know I only ever want Complex<Double>, so I shouldn't need the generic parameter.
typealias Complex = Complex.Complex<Double> // This doesn't work, because name lookup fails.
```

For this reason, modules that would have this ambiguity are suffixed with `Module` within Swift Numerics:

```swift
import ComplexModule
// I know I only ever want Complex<Double>, so I shouldn't need the generic parameter.
typealias Complex = ComplexModule.Complex<Double>
// But I can still refer to the generic type by qualifying the name if I need it occasionally:
let a = ComplexModule.Complex<Float>
```

The `Real` module does not contain a `Real` type, but does contain a `Real` protocol.
Users may want to define their own `Real` type (and possibly re-export the `Real` module)--that is why the suffix is also applied there.
New modules have to evaluate this decision carefully, but can err on the side of adding the suffix.
It's expected that most users will simply `import Numerics`, so this isn't an issue for them.
3 changes: 2 additions & 1 deletion Sources/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
#[[
This source file is part of the Swift Numerics open source project
Copyright (c) 2019 Apple Inc. and the Swift Numerics project authors
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
#]]

add_subdirectory(_NumericsShims)
add_subdirectory(ComplexModule)
add_subdirectory(IntegerUtilities)
add_subdirectory(Numerics)
add_subdirectory(RealModule)
if(BUILD_TESTING)
Expand Down
13 changes: 10 additions & 3 deletions Sources/ComplexModule/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,17 @@ See https://swift.org/LICENSE.txt for license information
#]]

add_library(ComplexModule
Arithmetic.swift
Complex.swift
Differentiable.swift
ElementaryFunctions.swift)
Complex+AdditiveArithmetic.swift
Complex+AlgebraicField.swift
Complex+Codable.swift
Complex+ElementaryFunctions.swift
Complex+Hashable.swift
Complex+IntegerLiteral.swift
Complex+Numeric.swift
Complex+StringConvertible.swift
Polar.swift
Scale.swift)
set_target_properties(ComplexModule PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY})
target_link_libraries(ComplexModule PUBLIC
Expand Down
42 changes: 42 additions & 0 deletions Sources/ComplexModule/Complex+AdditiveArithmetic.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
//===--- Complex+AdditiveArithmetic.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
//
//===----------------------------------------------------------------------===//

import RealModule

extension Complex: AdditiveArithmetic {
/// The additive identity, with real and imaginary parts both zero.
///
/// See also: `one`, `i`, `infinity`
@_transparent
public static var zero: Complex {
Complex(0, 0)
}

@_transparent
public static func +(z: Complex, w: Complex) -> Complex {
return Complex(z.x + w.x, z.y + w.y)
}

@_transparent
public static func -(z: Complex, w: Complex) -> Complex {
return Complex(z.x - w.x, z.y - w.y)
}

@_transparent
public static func +=(z: inout Complex, w: Complex) {
z = z + w
}

@_transparent
public static func -=(z: inout Complex, w: Complex) {
z = z - w
}
}
Loading

0 comments on commit 5750897

Please sign in to comment.