Skip to main content

rstsr_core/storage/
creation.rs

1use crate::prelude_dev::*;
2
3pub trait DeviceCreationAnyAPI<T>: DeviceRawAPI<T> {
4    /// # Safety
5    ///
6    /// This function is unsafe because it does not initialize the memory.
7    unsafe fn empty_impl(&self, len: usize) -> Result<Storage<DataOwned<Self::Raw>, T, Self>>;
8    fn full_impl(&self, len: usize, fill: T) -> Result<Storage<DataOwned<Self::Raw>, T, Self>>
9    where
10        T: Clone;
11    fn outof_cpu_vec(&self, vec: Vec<T>) -> Result<Storage<DataOwned<Self::Raw>, T, Self>>;
12    #[allow(clippy::wrong_self_convention)]
13    fn from_cpu_vec(&self, vec: &[T]) -> Result<Storage<DataOwned<Self::Raw>, T, Self>>
14    where
15        T: Clone;
16
17    #[allow(clippy::type_complexity)]
18    fn uninit_impl(
19        &self,
20        len: usize,
21    ) -> Result<Storage<DataOwned<<Self as DeviceRawAPI<MaybeUninit<T>>>::Raw>, MaybeUninit<T>, Self>>
22    where
23        Self: DeviceRawAPI<MaybeUninit<T>>;
24
25    /// # Safety
26    ///
27    /// This function is unsafe because it assumes that the input storage is fully initialized.
28    #[allow(clippy::type_complexity)]
29    unsafe fn assume_init_impl(
30        storage: Storage<DataOwned<<Self as DeviceRawAPI<MaybeUninit<T>>>::Raw>, MaybeUninit<T>, Self>,
31    ) -> Result<Storage<DataOwned<<Self as DeviceRawAPI<T>>::Raw>, T, Self>>
32    where
33        Self: DeviceRawAPI<MaybeUninit<T>>;
34}
35
36pub trait DeviceCreationNumAPI<T>: DeviceRawAPI<T> {
37    fn zeros_impl(&self, len: usize) -> Result<Storage<DataOwned<Self::Raw>, T, Self>>;
38    fn ones_impl(&self, len: usize) -> Result<Storage<DataOwned<Self::Raw>, T, Self>>;
39}
40
41pub trait DeviceCreationComplexFloatAPI<T>: DeviceRawAPI<T> {
42    fn linspace_impl(
43        &self,
44        start: T,
45        end: T,
46        n: usize,
47        endpoint: bool,
48    ) -> Result<Storage<DataOwned<Self::Raw>, T, Self>>;
49}
50
51pub trait DeviceCreationArangeAPI<T>: DeviceRawAPI<T> {
52    fn arange_impl(&self, start: T, end: T, step: T) -> Result<Storage<DataOwned<Self::Raw>, T, Self>>;
53}
54
55pub trait DeviceCreationTriAPI<T>: DeviceRawAPI<T> {
56    fn tril_impl<D>(&self, raw: &mut Self::Raw, layout: &Layout<D>, k: isize) -> Result<()>
57    where
58        D: DimAPI;
59    fn triu_impl<D>(&self, raw: &mut Self::Raw, layout: &Layout<D>, k: isize) -> Result<()>
60    where
61        D: DimAPI;
62}