ai_dataloader/collate/
default_collate.rs

1/// Default Collate function that mimic the [`default_collate` function](https://pytorch.org/docs/stable/data.html#automatic-batching-default) from ``PyTorch``.
2///
3/// As they are no such lib with the same functionality as `PyTorch` tensor in Rust,
4/// data is collated inside `ndarray`. Ndarray is the rust equivalent of `numpy.ndarray` with
5/// almost the same capabilities. Nevertheless, they can't run on the GPU.
6///
7///
8/// Basic transformation implemented for the default Collate :
9///
10/// - `Vec<Scalar>` -> `ndarray<scalar>`
11/// - `Vec<tuple>` -> `tuple(ndarray)`
12/// - `Vec<HashMap<Key, Value>>` -> `HasMap<Key, DefaultCollate::default().collate(Vec<Value>)`
13/// - `Vec<Array>` -> `Vec<Stack Array>`
14/// - `Vec[V1_i, V2_i, ...]` -> `Vec[DefaultCollate::default().collate([V1_1, V1_2, ...]), DefaultCollate::default().collate([V2_1, V2_2, ...]), ...]`
15///
16///
17/// Like for `PyTorch` version, `String` and `u8` aren't changed by the collation (No Op).
18///
19/// - `Vec<String>` -> `Vec<String>`
20/// - `Vec<&str>` -> `Vec<&str>`
21/// - `Vec<u8>` -> `Vec<u8>`
22///
23///
24#[derive(Default, Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
25pub struct DefaultCollate;
26
27mod array;
28mod map;
29mod ndarray;
30mod nonzero;
31mod primitive;
32mod reference;
33mod sequence;
34mod string;
35mod tuple;