Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Sources/Differentiation/Dictionary+Differentiation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import _Differentiation

extension Dictionary: @retroactive Differentiable where Value: Differentiable {
public typealias TangentVector = [Key: Value.TangentVector]

@inlinable
public mutating func move(by direction: TangentVector) {
for (componentKey, componentDirection) in direction {
func fatalMissingComponent() -> Value {
Expand All @@ -21,14 +23,17 @@ extension Dictionary: @retroactive Differentiable where Value: Differentiable {

/// Implements the `AdditiveArithmetic` requirements.
extension Dictionary: @retroactive AdditiveArithmetic where Value: AdditiveArithmetic {
@inlinable
public static func + (_ lhs: Self, _ rhs: Self) -> Self {
lhs.merging(rhs, uniquingKeysWith: +)
}

@inlinable
public static func - (_ lhs: Self, _ rhs: Self) -> Self {
lhs.merging(rhs.mapValues { .zero - $0 }, uniquingKeysWith: +)
}

@inlinable
public static var zero: Self { [:] }
}

Expand Down
1 change: 1 addition & 0 deletions Sources/Differentiation/Foundation+VJPs.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import Foundation

/// Differentiation of ``atan2``
@derivative(of: atan2(_:_:))
@inlinable
public func _vjpAtan2(
y: Double, x: Double
) -> (value: Double, pullback: (Double) -> (Double, Double)) {
Expand Down
2 changes: 2 additions & 0 deletions Sources/Differentiation/Sequence+MinMaxVJPs.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ extension Sequence where
// level is because of the DocC crash: https://github.com/swiftlang/swift/issues/75258
/// To differentiate ``Swift/Sequence/max``
@derivative(of: max)
@inlinable
public func _vjpMax() -> (
value: Element?,
pullback: (Element?.TangentVector) -> (Self.TangentVector)
Expand Down Expand Up @@ -51,6 +52,7 @@ extension Sequence where
// level is because of the DocC crash: https://github.com/swiftlang/swift/issues/75258
/// To differentiate ``Swift/Sequence/min``
@derivative(of: min)
@inlinable
public func _vjpMin() -> (
value: Element?,
pullback: (Element?.TangentVector) -> (Self.TangentVector)
Expand Down