pub struct Tensor { /* private fields */ }Expand description
A multi-dimensional tensor with NHWC layout
Implementations§
Source§impl Tensor
impl Tensor
Sourcepub fn zeros(shape: &[usize]) -> Self
pub fn zeros(shape: &[usize]) -> Self
Create a new tensor with the given shape, initialized to zeros
Sourcepub fn ones(shape: &[usize]) -> Self
pub fn ones(shape: &[usize]) -> Self
Create a new tensor with the given shape, initialized to ones
Sourcepub fn from_data(data: Vec<f32>, shape: &[usize]) -> CnnResult<Self>
pub fn from_data(data: Vec<f32>, shape: &[usize]) -> CnnResult<Self>
Create a tensor from raw data with the given shape
Sourcepub fn get_4d(&self, n: usize, h: usize, w: usize, c: usize) -> f32
pub fn get_4d(&self, n: usize, h: usize, w: usize, c: usize) -> f32
Get element at index (for 4D NHWC tensor)
Sourcepub fn set_4d(&mut self, n: usize, h: usize, w: usize, c: usize, value: f32)
pub fn set_4d(&mut self, n: usize, h: usize, w: usize, c: usize, value: f32)
Set element at index (for 4D NHWC tensor)
Sourcepub fn batch_size(&self) -> usize
pub fn batch_size(&self) -> usize
Get batch size (first dimension)
Sourcepub fn reshape(&self, new_shape: &[usize]) -> CnnResult<Self>
pub fn reshape(&self, new_shape: &[usize]) -> CnnResult<Self>
Reshape the tensor to a new shape
Sourcepub fn view(&self, new_shape: &[usize]) -> CnnResult<Self>
pub fn view(&self, new_shape: &[usize]) -> CnnResult<Self>
Clone with a new shape (must have same numel)
Sourcepub fn slice_batch(&self, start: usize, end: usize) -> CnnResult<Self>
pub fn slice_batch(&self, start: usize, end: usize) -> CnnResult<Self>
Get a slice of the tensor along the batch dimension
Sourcepub fn map_inplace<F>(&mut self, f: F)
pub fn map_inplace<F>(&mut self, f: F)
Apply a function element-wise in place
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Tensor
impl RefUnwindSafe for Tensor
impl Send for Tensor
impl Sync for Tensor
impl Unpin for Tensor
impl UnsafeUnpin for Tensor
impl UnwindSafe for Tensor
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