pub struct Tensor {
pub data: Vec<f32>,
pub shape: Vec<usize>,
}Expand description
N-dimensional tensor with f32 data and a shape vector. Layout: row-major (C order), last dimension varies fastest.
Fields§
§data: Vec<f32>§shape: Vec<usize>Implementations§
Source§impl Tensor
impl Tensor
Sourcepub fn new(data: Vec<f32>, shape: Vec<usize>) -> Tensor
pub fn new(data: Vec<f32>, shape: Vec<usize>) -> Tensor
Create a tensor from owned data and a shape vector.
Panics (debug-only) if data.len() != shape.product().
Sourcepub fn scalar(val: f32) -> Tensor
pub fn scalar(val: f32) -> Tensor
Create a scalar tensor (shape [1]) containing a single value.
Sourcepub fn reshape(&self, new_shape: &[usize]) -> Tensor
pub fn reshape(&self, new_shape: &[usize]) -> Tensor
Return a new tensor with the same data but a different shape. Panics if the element count changes.
Source§impl Tensor
impl Tensor
Sourcepub fn view(&self) -> TensorView<'_>
pub fn view(&self) -> TensorView<'_>
Create a contiguous view of this tensor.
Sourcepub fn transpose_view(&self, perm: &[usize]) -> TensorView<'_>
pub fn transpose_view(&self, perm: &[usize]) -> TensorView<'_>
Create a transposed view without copying data.
Sourcepub fn slice_view(
&self,
axis: usize,
start: usize,
end: usize,
) -> TensorView<'_>
pub fn slice_view( &self, axis: usize, start: usize, end: usize, ) -> TensorView<'_>
Create a sliced view without copying data.
Source§impl Tensor
impl Tensor
Sourcepub fn broadcast_iter<'a>(
&'a self,
other: &'a Tensor,
) -> Option<BroadcastIter<'a>>
pub fn broadcast_iter<'a>( &'a self, other: &'a Tensor, ) -> Option<BroadcastIter<'a>>
Create a broadcast iterator pairing this tensor with another.
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more