You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[AutoDiff] [stdlib] Add a top-level 'withoutDerivative(at:in:)' API. (#25552)
The existing `withoutDerivative()` method on `Differentiable` is not general enough to support generic algorithms that are conditionally differentiable, for example:
```swift
@differentiable(where T: Differentiable)
func foo<T: Numeric>(x: T) -> T {
2 * x.withoutDerivative()
}
// Error: 'x' does not conform to 'Differentiable'.
```
We add a top-level function that makes this possible.
```swift
@differentiable(where T: Differentiable)
func foo<T: Numeric>(x: T) -> T {
withoutDerivative(at: x) { x in
2 * x
} // Okay!
}
```
0 commit comments