Can anyone explain the DataBunch used to automatically batch examples, from nb03 of SwiftAI repo? Here’s the relevant code. In particular, can anyone explain this line, and how the indices were derived:
self.yb = Labels.init(_handles: _handles[xEnd..<_handles.endIndex])
The full code snippet can be seen here, for reference:
public struct DataBatch<Inputs: Differentiable & TensorGroup, Labels: TensorGroup>: TensorGroup {
public var xb: Inputs
public var yb: Labels
public init(xb: Inputs, yb: Labels){ (self.xb,self.yb) = (xb,yb) }
public var _tensorHandles: [_AnyTensorHandle] {
xb._tensorHandles + yb._tensorHandles
}
public init<C: RandomAccessCollection>(_handles: C) where C.Element: _AnyTensorHandle {
let xStart = _handles.startIndex
let xEnd = _handles.index(
xStart, offsetBy: Int(Inputs._tensorHandleCount))
self.xb = Inputs.init(_handles: _handles[xStart..<xEnd])
self.yb = Labels.init(_handles: _handles[xEnd..<_handles.endIndex])
}
}