rstsr_core/storage/
creation.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
use crate::prelude_dev::*;
use num::{complex::ComplexFloat, Num};

pub trait DeviceCreationAnyAPI<T>
where
    Self: DeviceRawAPI<T>,
{
    /// # Safety
    ///
    /// This function is unsafe because it does not initialize the memory.
    unsafe fn empty_impl(&self, len: usize) -> Result<Storage<DataOwned<Self::Raw>, T, Self>>;
    fn full_impl(&self, len: usize, fill: T) -> Result<Storage<DataOwned<Self::Raw>, T, Self>>;
    fn outof_cpu_vec(&self, vec: Vec<T>) -> Result<Storage<DataOwned<Self::Raw>, T, Self>>;
    #[allow(clippy::wrong_self_convention)]
    fn from_cpu_vec(&self, vec: &[T]) -> Result<Storage<DataOwned<Self::Raw>, T, Self>>;
}

pub trait DeviceCreationNumAPI<T>
where
    T: Num,
    Self: DeviceRawAPI<T>,
{
    fn zeros_impl(&self, len: usize) -> Result<Storage<DataOwned<Self::Raw>, T, Self>>;
    fn ones_impl(&self, len: usize) -> Result<Storage<DataOwned<Self::Raw>, T, Self>>;
    fn arange_int_impl(&self, len: usize) -> Result<Storage<DataOwned<Self::Raw>, T, Self>>;
}

pub trait DeviceCreationComplexFloatAPI<T>
where
    T: ComplexFloat,
    Self: DeviceRawAPI<T>,
{
    fn linspace_impl(
        &self,
        start: T,
        end: T,
        n: usize,
        endpoint: bool,
    ) -> Result<Storage<DataOwned<Self::Raw>, T, Self>>;
}

pub trait DeviceCreationPartialOrdNumAPI<T>
where
    T: Num + PartialOrd,
    Self: DeviceRawAPI<T>,
{
    fn arange_impl(
        &self,
        start: T,
        end: T,
        step: T,
    ) -> Result<Storage<DataOwned<Self::Raw>, T, Self>>;
}