pub struct Tensor<'data> { /* private fields */ }Expand description
Tensor, can own, or borrow the underlying tensor
Implementations§
Source§impl<'data> Tensor<'data>
impl<'data> Tensor<'data>
Sourcepub fn shape(&self) -> &[usize]
pub fn shape(&self) -> &[usize]
The shape of the tensor
use smelte-rs::cpu::f32::Tensor;
let tensor = Tensor::zeros(vec![2, 2]);
assert_eq!(tensor.shape(), vec![2, 2]);Sourcepub fn data(&self) -> &[f32]
pub fn data(&self) -> &[f32]
A slice to the underlying tensor data
use smelte-rs::cpu::f32::Tensor;
let tensor = Tensor::zeros(vec![2, 2]);
assert_eq!(tensor.data(), vec![0.0; 4]);Sourcepub fn data_mut(&mut self) -> &mut [f32]
pub fn data_mut(&mut self) -> &mut [f32]
A mutable slice to the underlying tensor data
use smelte-rs::cpu::f32::Tensor;
let mut tensor = Tensor::zeros(vec![2, 2]);
tensor.data_mut().iter_mut().for_each(|v| *v += 1.0);
assert_eq!(tensor.data(), vec![1.0; 4]);Sourcepub fn zeros(shape: Vec<usize>) -> Self
pub fn zeros(shape: Vec<usize>) -> Self
Creates a new nulled tensor with given shape
use smelte-rs::cpu::f32::Tensor;
let tensor = Tensor::zeros(vec![2, 2]);Sourcepub fn borrowed(
data: &'data [f32],
shape: Vec<usize>,
) -> Result<Self, TensorError>
pub fn borrowed( data: &'data [f32], shape: Vec<usize>, ) -> Result<Self, TensorError>
Creates a new borrowed tensor with given shape. Can fail if data doesn’t match the shape
use smelte-rs::cpu::f32::Tensor;
let data = [1.0, 2.0, 3.0, 4.0];
let tensor = Tensor::borrowed(&data, vec![2, 2]).unwrap();Trait Implementations§
Source§impl<'a> TensorAttention<Tensor<'a>> for Tensor<'a>
impl<'a> TensorAttention<Tensor<'a>> for Tensor<'a>
Source§impl<'a> TensorGelu<Tensor<'a>> for Tensor<'a>
impl<'a> TensorGelu<Tensor<'a>> for Tensor<'a>
Source§impl<'a> TensorMatmul<Tensor<'a>> for Tensor<'a>
impl<'a> TensorMatmul<Tensor<'a>> for Tensor<'a>
Source§impl<'a> TensorMatmulT<Tensor<'a>> for Tensor<'a>
impl<'a> TensorMatmulT<Tensor<'a>> for Tensor<'a>
Source§impl<'a> TensorNormalize<Tensor<'a>> for Tensor<'a>
impl<'a> TensorNormalize<Tensor<'a>> for Tensor<'a>
Source§impl<'a> TensorSelect<Tensor<'a>> for Tensor<'a>
impl<'a> TensorSelect<Tensor<'a>> for Tensor<'a>
Source§impl<'a> TensorSoftmax<Tensor<'a>> for Tensor<'a>
impl<'a> TensorSoftmax<Tensor<'a>> for Tensor<'a>
Source§impl<'a> TensorTanh<Tensor<'a>> for Tensor<'a>
impl<'a> TensorTanh<Tensor<'a>> for Tensor<'a>
impl<'a> BertOps<Tensor<'a>> for Tensor<'a>
impl<'a> TensorOps<Tensor<'a>> for Tensor<'a>
Auto Trait Implementations§
impl<'data> Freeze for Tensor<'data>
impl<'data> RefUnwindSafe for Tensor<'data>
impl<'data> Send for Tensor<'data>
impl<'data> Sync for Tensor<'data>
impl<'data> Unpin for Tensor<'data>
impl<'data> UnwindSafe for Tensor<'data>
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