Skip to content

Commit 824ab19

Browse files
committed
docs: add missing funcdocs
1 parent ae8af85 commit 824ab19

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

Sources/Differentiation/ArrayDifferentiableView+Collection.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,31 +10,42 @@ extension Array.DifferentiableView:
1010
@retroactive BidirectionalCollection,
1111
@retroactive MutableCollection
1212
where Element: Differentiable {
13+
/// The type being stored
1314
public typealias Element = Array.Element
15+
16+
/// The type used as an index into the Array
1417
public typealias Index = Array.Index
18+
19+
/// A contiguous sequence of values from within the Array
1520
public typealias SubSequence = Array.SubSequence
1621

22+
/// Return or set the ``Element`` at the given index
1723
@inlinable
1824
public subscript(position: Index) -> Element {
1925
_read { yield base[position] }
2026
set(newValue) { base[position] = newValue }
2127
}
2228

29+
/// Return or set the ``SubSequence`` at the given range of indices
2330
@inlinable
2431
public subscript(bounds: Range<Index>) -> SubSequence {
2532
get { base[bounds] }
2633
set(newValue) { base[bounds] = newValue }
2734
}
2835

36+
/// The first index of the Array
2937
@inlinable
3038
public var startIndex: Index { base.startIndex }
3139

40+
/// The last index of the Array
3241
@inlinable
3342
public var endIndex: Index { base.endIndex }
3443

44+
/// Create a new ``Array.DifferentiableView``
3545
@inlinable
3646
public init() { self.init(Array<Element>()) }
3747

48+
/// Replace the elements at a range of indices with the values from another ``Collection``
3849
@inlinable
3950
public mutating func replaceSubrange<C>(_ subrange: Range<Self.Index>, with newElements: C)
4051
where C: Collection, Self.Element == C.Element {

Sources/Differentiation/Dictionary+Differentiation.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@ import _Differentiation
88
// https://bugs.swift.org/browse/TF-1193
99

1010
extension Dictionary: @retroactive Differentiable where Value: Differentiable {
11+
/// Tangent Vectors for each key-value pair
1112
public typealias TangentVector = [Key: Value.TangentVector]
13+
14+
/// Shift the dictionary by the given ``TangentVector``
15+
/// All keys in the given shift vectar must exist in the dictionary
1216
public mutating func move(by direction: TangentVector) {
1317
for (componentKey, componentDirection) in direction {
1418
func fatalMissingComponent() -> Value {
@@ -18,6 +22,7 @@ extension Dictionary: @retroactive Differentiable where Value: Differentiable {
1822
}
1923
}
2024

25+
/// Create a zero tangent vector for every key
2126
public var zeroTangentVectorInitializer: () -> TangentVector {
2227
let listOfKeys = keys // capturing only what's needed, not the entire self, in order to not waste memory
2328
func initializer() -> Self.TangentVector {
@@ -29,14 +34,17 @@ extension Dictionary: @retroactive Differentiable where Value: Differentiable {
2934

3035
/// Implements the `AdditiveArithmetic` requirements.
3136
extension Dictionary: @retroactive AdditiveArithmetic where Value: AdditiveArithmetic {
37+
/// Combine two dictionaries by adding their keys
3238
public static func + (_ lhs: Self, _ rhs: Self) -> Self {
3339
lhs.merging(rhs, uniquingKeysWith: +)
3440
}
3541

42+
/// Combine two dictionaries by subtracting their keys
3643
public static func - (_ lhs: Self, _ rhs: Self) -> Self {
3744
lhs.merging(rhs.mapValues { .zero - $0 }, uniquingKeysWith: +)
3845
}
3946

47+
/// Return an empty dictionary
4048
public static var zero: Self { [:] }
4149
}
4250

Sources/Differentiation/Optional+DifferentiableMap.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import _Differentiation
44

55
extension Optional where Wrapped: Differentiable {
6+
/// Apply a differentiable closure to the wrapped value
67
@inlinable
78
@differentiable(reverse,wrt: self)
89
public func differentiableMap<Result: Differentiable>(

0 commit comments

Comments
 (0)