Design principles¶
- Batch is dim 0, sequence is dim 1. Every
*_along_batchand*_along_seqfunction is fixed to these dimensions. Data laid out as(seq, batch, ...)must be transposed first. - Nested functions apply the tensor function with
recursive_apply. Dicts, lists and tuples are traversed and the tensor function is applied to eachtorch.Tensorleaf. The container type is preserved. - Non-tensor leaves are returned unchanged by pointwise and reduction
functions that go through
recursive_apply. - Joining and slicing (
cat_*,stack_*,chunk_*,split_*) accept a flatdictof tensors. - Named-tuple results (
max,min,median,sort) keep theirtorch.return_types.*type in the nested output. - Views versus copies.
slice,select,chunkandsplitreturn views that share memory with the input. Most other functions return new tensors. - Argument errors raise
ValueError. - numpy is only needed for
from_numpyandto_numpy.