differentiable-swift/swift-differentiation
[](https://swiftpackageindex.com/differentiable-swift/swift-differentiation) [](https://swiftpackageindex.com/differentiable-swift/swift-differentiation)
Overview
Currently this package provides the following functionality:
- Differentiable support for the
Dictionarytype. - Extensions to the
Arraytype to be able to make writes to a given index differentiable (update(at:with:)) since using the subscript setter is currently not supported due to missing coroutine support. Collectionconformances for theArray.DifferentiableViewtype to make it easier to work with directly.- Some missing derivatives of standard library Swift functions like,
min(::),max(::),abs(:),atan2(:_:),Sequence.min()andSequence.max() - Provides a
differentiableMap(_:)function for the Optional type.
Differentiable Swift
The goal of the Differentiable Swift language feature is to provide first-class, language-integrated support for differentiable programming, making Swift the first general-purpose, statically typed programming language to have automatic differentiation built in. Originally developed as part of the Swift for TensorFlow project, teams at PassiveLogic and elsewhere are currently working on it. Differentiable Swift is purely a language feature and isn't tied to any specific machine learning framework or platform.
Getting Started
Differentiable Swift is present as an experimental language feature in Swift toolchains. Due to the incompleteness of its implementation, for best results we recommend using the newest release Swift toolchain from swift.org. Or if you want to be on the bleeding edge to download one of the newest nightly toolchains. These tend to be more unstable however in terms of crashing.
In order to enable Differentiable Swift no special compiler flags are needed, but you do need to place the following:
import _Differentiationin any file where differentiation will be used. The compiler will warn you about this if you do forget to add the above and try to use any differentiable Swift capabilities.
When using this package and its methods you only need to add the following:
import DifferentiationSince the package also exports the _Differentiation module. Make sure to add the package to your dependencies however:
dependencies: [
.package(url: "https://github.com/differentiable-swift/swift-differentiation", from: "0.0.1")
]And then adding the product to any target that needs access to the library:
.product(name: "Differentiation", package: "swift-differentiation"),Contributing
If you're missing functionality or something is broken please file an issue! If you find something Differentiable Swift related that's not working but isn't directly related to this library please report it in an issue in our swift-differentiation-testing repo. Here we try to provide an easy way for people to report and track incorrect behaviour of the Differentiable Swift language feature. If you have code that reproduces your issue please add it to the issue so that we can more easily debug or help with the problem you're running into.
Code Formatting
This package makes use of SwiftFormat, which you can install from homebrew.
To apply formatting rules to all files, which you should do before submitting a PR, run from the root of the repository:
swiftformat .Formatting is validated with the --strict flag on every PR
Differentiable Swift resources
If you want to learn more about differentiable Swift, there are a variety of resources out there. The API has changed over time, so some older documentation may provide great background on the feature but not fully reflect code as it is written today.
- Differentiable programming for gradient-based machine learning
- The Intro to Differentiable Swift series:
- Part 0: Why Automatic Differentiation is Awesome - Part 1: Gradient Descent - Part 2: Differentiable Swift - Part 3: Differentiable API Introduction - Part 4: Differentiable Swift API Details
- Differentiable Programming Manifesto (note: slightly out of date)
- The Swift for TensorFlow project explored the use of differentiable Swift paired with machine learning frameworks:
- Overview of Swift for TensorFlow - Main Swift for TensorFlow GitHub repository - Swift for TensorFlow machine learning APIs - Machine learning models and libraries
License
This library is released under the Apache 2.0 license. See LICENSE for details.
Package Metadata
Repository: differentiable-swift/swift-differentiation
Stars: 10
Forks: 3
Open issues: 3
Default branch: main
Primary language: swift
License: Apache-2.0
README: README.md