rstsr_core/storage/
creation.rs

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