Skip to content
Merged
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
6 changes: 6 additions & 0 deletions stdlib/public/Differentiation/OptionalDifferentiation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,17 @@ extension Optional: Differentiable where Wrapped: Differentiable {

public var value: Wrapped.TangentVector?

@inlinable
public init(_ value: Wrapped.TangentVector?) {
self.value = value
}

@inlinable
public static var zero: Self {
return Self(.zero)
}

@inlinable
public static func + (lhs: Self, rhs: Self) -> Self {
switch (lhs.value, rhs.value) {
case (nil, nil): return Self(nil)
Expand All @@ -36,6 +39,7 @@ extension Optional: Differentiable where Wrapped: Differentiable {
}
}

@inlinable
public static func - (lhs: Self, rhs: Self) -> Self {
switch (lhs.value, rhs.value) {
case (nil, nil): return Self(nil)
Expand All @@ -45,13 +49,15 @@ extension Optional: Differentiable where Wrapped: Differentiable {
}
}

@inlinable
public mutating func move(by offset: TangentVector) {
if let value = offset.value {
self.value?.move(by: value)
}
}
}

@inlinable
public mutating func move(by offset: TangentVector) {
if let value = offset.value {
self?.move(by: value)
Expand Down