- slice-tensor tensor start lengthprocedure
Extracts a slice of a tensor along the first dimension. Gradients flow back to the matching positions of the original tensor.
- tensor
- input tensor with shape (n, ...)
- start
- starting index (0-based)
- length
- number of elements to extract
Returns a tensor with shape (length, ...).
;; Slice a batch of data (define batch-data (make-tensor32 (make-f32vector 100) '(10 10))) (define mini-batch (slice-tensor batch-data 2 5)) ; Shape: (5, 10) ;; Gradients flow back to the original positions (backward! (sum-tensor mini-batch)) (tensor-grad batch-data) ; Only rows 2-6 have non-zero gradients