Commit Graph

9 Commits

Author SHA1 Message Date
Jaap Wijnen
84c30b5c86 mark move @inlinable to better signal intent (#78944)
Co-authored-by: Jaap Wijnen <jaap@passivelogic.com>
2025-02-20 15:03:36 -08:00
Richard Wei
8bc6143a4c [AutoDiff] Rename 'move(along:)' to 'move(by:)'.
Rename `move(along:)` to `move(by:)` based on the proposal feedback. The main argument for the change is that tangent vectors specify both a direction and a magnitude, whereas `along:` does not indicate that `self` is being moved by the specified magnitude.
2021-02-23 21:45:01 -05:00
Richard Wei
e3db926e0c [AutoDiff] Remove '_Differentiable.zeroTangentVectorInitializer'. (#35329)
Remove `_Differentiable.zeroTangentVectorInitializer` to address the feedback on the [proposal thread](https://forums.swift.org/t/differentiable-programming-for-gradient-based-machine-learning/42147). The corresponding change has already been made in the [proposal](https://github.com/rxwei/swift-evolution/blob/autodiff/proposals/0000-differentiable-programming.md).

Removed components:
- `zeroTangentVectorInitializer` and `zeroTangentVector` in `Differentiable`, `Array`, `Optional`, `Float`, `Double`, `Float80`, and SIMD types.
- `zeroTangentVectorInitializer` synthesis logic in `Differentiable` derived conformances.
2021-01-20 10:45:03 -08:00
Dan Zheng
f9c5d7ae6c [AutoDiff] Derive Differentiable.zeroTangentVectorInitializer. (#31823)
`Differentiable` conformance derivation now supports
`Differentiable.zeroTangentVectorInitializer`.

There are two potential cases:
1. Memberwise derivation: done when `TangentVector` can be initialized memberwise.
2. `{ TangentVector.zero }` derivation: done as a fallback.

`zeroTangentVectorInitializer` is a closure that produces a zero tangent vector,
capturing minimal necessary information from `self`.

It is an instance property, unlike the static property `AdditiveArithmetic.zero`,
and should be used by the differentiation transform for correctness.

Remove `Differentiable.zeroTangentVectorInitializer` dummy default implementation.

Update stdlib `Differentiable` conformances and tests.
Clean up DerivedConformanceDifferentiable.cpp cruft.

Resolves TF-1007.
Progress towards TF-1008: differentiation correctness for projection operations.
2020-05-29 01:59:52 -07:00
Dan Zheng
65ab642b1a [AutoDiff upstream] Add Differentiable.zeroTangentVector.
Add `Differentiable.zeroTangentVectorInitializer` protocol requirement and
`Differentiable.zeroTangentVector` default implementation.
2020-04-09 11:15:18 -07:00
Dan Zheng
2c112141dd [AutoDiff upstream] Deduplicate floating-point Differentiable conformances.
Move `Differentiable` conformances out of Differentiable.swift.
All `Differentiable` conformances exist in separate files.
2020-04-08 02:49:21 -07:00
Richard Wei
57d228b39e [AutoDiff upstream] Add differential operators and some utilities.
* Add all [differential operators](https://github.com/apple/swift/blob/master/docs/DifferentiableProgramming.md#list-of-differential-operators).
* Add `withoutDerivative(at:)`, used for efficiently stopping the derivative propagation at a value and causing the derivative at the value to be zero.
* Add utility `differentiableFunction(from:)`, used for creating a `@differentiable` function from an original function and a derivative function.

Mostly work done by @marcrasi and @dan-zheng.
Partially resolves TF-843.

TODO:
* Add `AnyDerivative`.
* Add `Array.differentiableMap(_:)` and `differentiableReduce(_:_:)`.
2020-03-30 14:15:35 -07:00
Dan Zheng
8aac6f9a1a [AutoDiff upstream] Conform floating-point types to Differentiable. (#28718)
Add `Differentiable` conformances for floating-point types to the
`_Differentiation` module. The `TangentVector` associated type for
floating-point types is `Self`.

This design adheres to the differentiable programming manifesto:
docs/DifferentiableProgramming.md.

Partially resolves TF-1052.
2019-12-11 18:43:09 -08:00
Dan Zheng
53e61a9587 [AutoDiff upstream] Add the _Differentiation module. (#27511)
The `_Differentiation` module is the experimental support library for
differentiable programming. It is built when the build-script flag
`--enable-experimental-differentiable-programming` is enabled.

The `Differentiable` protocol generalizes all types that work with
differentiation. It is a core piece of the differentiable programming
project. Other parts depending on the `Differentiable` protocol will
be upstreamed piece by piece.

The `Differentiable` protocol is compiler-known and will be used during
type-checking, SILGen, and the SIL differentiation transform.
2019-11-06 11:31:12 -08:00