hpt_dataloader/utils.rs
1use hpt_common::{error::base::TensorError, shape::shape::Shape};
2
3/// A trait defines empty function for Tensor that will allocate memory on CPU.
4pub trait CPUTensorCreator {
5 /// the output type of the creator
6 type Output;
7 /// the meta type of the tensor
8 type Meta;
9
10 /// Creates a tensor with uninitialized elements of the specified shape.
11 ///
12 /// This function allocates memory for a tensor in CPU of the given shape, but the values are uninitialized, meaning they may contain random data.
13 ///
14 /// # Arguments
15 ///
16 /// * `shape` - The desired shape of the tensor. The type `S` must implement `Into<Shape>`.
17 ///
18 /// # Returns
19 ///
20 /// * A tensor with the specified shape, but with uninitialized data.
21 ///
22 /// # Panics
23 ///
24 /// * This function may panic if the requested shape is invalid or too large for available memory.
25 #[track_caller]
26 fn empty<S: Into<Shape>>(shape: S) -> Result<Self::Output, TensorError>;
27}
28
29/// A trait defines conversion to DataLoader
30pub trait ToDataLoader {
31 /// the output type of the conversion
32 type Output;
33 /// convert to DataLoader
34 fn to_dataloader(self) -> Self::Output;
35}