ai_dataloader/collate/torch_collate/
reference.rs

1use super::TorchCollate;
2use crate::collate::Collate;
3
4/// We think it makes no sense to but a bench of reference into a Tensor. That's why if the dataset yield reference and they
5/// we clone their value.
6/// It is useful for having a non-consuming `Iterator` over the `Dataloader`.
7impl<T> Collate<&T> for TorchCollate
8where
9    T: Clone,
10    Self: Collate<T>,
11{
12    type Output = <Self as Collate<T>>::Output;
13    fn collate(&self, batch: Vec<&T>) -> Self::Output {
14        TorchCollate.collate(batch.into_iter().cloned().collect())
15    }
16}