pub struct Tensor<T, const N: usize> { /* private fields */ }
Expand description
Implementations§
Source§impl<const N: usize> Tensor<usize, N>
impl<const N: usize> Tensor<usize, N>
Sourcepub fn new(dt: DigitLayout, shape: [usize; N]) -> Self
pub fn new(dt: DigitLayout, shape: [usize; N]) -> Self
创建使用指定数据类型 dt
和形状 shape
的张量,张量的“数据”是连续存储其数据占用的字节数。
传入的 shape
应为张量中的数值的数量。
在底层存储中,可能将多个数值捆绑为一个数据组。
获取张量的形状时,将返回作为 N 维数组的形状,其连续维度除去了组的规模。
例如,对于将 32 个数字绑定为一组的数据类型,shape
为 [7, 1024]
时,产生的张量的形状是 [7, 32]
。
// 定义一个数据类型,以 32 个 8 位无符号数为一组。
digit_layout::layout!(GROUP u(8); 32);
let tensor = Tensor::new(GROUP, [7, 1024]);
assert_eq!(tensor.dt(), GROUP);
assert_eq!(tensor.shape(), [7, 32]);
assert_eq!(tensor.take(), 7 * 32 * 32);
pub fn from_dim_slice(dt: DigitLayout, shape: impl AsRef<[usize]>) -> Self
Source§impl<T, const N: usize> Tensor<T, N>
impl<T, const N: usize> Tensor<T, N>
pub const fn dt(&self) -> DigitLayout
pub const fn layout(&self) -> &ArrayLayout<N>
pub fn shape(&self) -> &[usize]
pub fn strides(&self) -> &[isize]
pub fn offset(&self) -> isize
pub const fn get(&self) -> &T
pub fn get_mut(&mut self) -> &mut T
pub fn take(self) -> T
pub const fn from_raw_parts( dt: DigitLayout, layout: ArrayLayout<N>, item: T, ) -> Self
pub fn into_raw_parts(self) -> (DigitLayout, ArrayLayout<N>, T)
pub fn use_info(&self) -> Tensor<usize, N>
pub fn is_contiguous(&self) -> bool
Source§impl<T, const N: usize> Tensor<T, N>
impl<T, const N: usize> Tensor<T, N>
pub fn as_ref(&self) -> Tensor<&T, N>
pub fn as_mut(&mut self) -> Tensor<&mut T, N>
pub fn transform(self, f: impl FnOnce(ArrayLayout<N>) -> ArrayLayout<N>) -> Self
pub fn map<U>(self, f: impl FnOnce(T) -> U) -> Tensor<U, N>
pub fn replace<U>(self, u: U) -> (T, Tensor<U, N>)
Trait Implementations§
Auto Trait Implementations§
impl<T, const N: usize> Freeze for Tensor<T, N>where
T: Freeze,
impl<T, const N: usize> RefUnwindSafe for Tensor<T, N>where
T: RefUnwindSafe,
impl<T, const N: usize> Send for Tensor<T, N>where
T: Send,
impl<T, const N: usize> Sync for Tensor<T, N>where
T: Sync,
impl<T, const N: usize> Unpin for Tensor<T, N>where
T: Unpin,
impl<T, const N: usize> UnwindSafe for Tensor<T, N>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more