ai_dataloader/collate/default_collate/reference.rs
1use super::DefaultCollate;
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 a
5/// we clone them them.
6/// It is useful for having a non-consuming `Iterator` over the `Dataloader`.
7impl<T> Collate<&T> for DefaultCollate
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 DefaultCollate.collate(batch.into_iter().cloned().collect())
15 }
16}