pub struct Tensor {
pub shape: Vec<usize>,
pub strides: Vec<usize>,
/* private fields */
}Expand description
A general N-D f32 tensor: an Arc-shared device buffer viewed through (shape, strides, offset).
Fields§
§shape: Vec<usize>§strides: Vec<usize>Implementations§
Source§impl Tensor
impl Tensor
pub fn numel(&self) -> usize
pub fn rank(&self) -> usize
pub fn is_contiguous(&self) -> bool
pub fn from_vec(ctx: &Arc<Context>, data: &[f32], shape: &[usize]) -> Tensor
pub fn zeros(ctx: &Arc<Context>, shape: &[usize]) -> Tensor
Sourcepub async fn to_vec(&self) -> Vec<f32>
pub async fn to_vec(&self) -> Vec<f32>
Materialize (contiguous) and read back to host in logical row-major order.
pub fn reshape(&self, shape: &[usize]) -> Tensor
pub fn permute(&self, perm: &[usize]) -> Tensor
pub fn transpose(&self, a: usize, b: usize) -> Tensor
Sourcepub fn broadcast_to(&self, shape: &[usize]) -> Tensor
pub fn broadcast_to(&self, shape: &[usize]) -> Tensor
Broadcast to a larger shape (right-aligned); broadcast dims get stride 0.
Sourcepub fn contiguous(&self) -> Tensor
pub fn contiguous(&self) -> Tensor
Materialize a (possibly strided/broadcast) view into a fresh contiguous buffer.
pub fn add(&self, o: &Tensor) -> Tensor
pub fn sub(&self, o: &Tensor) -> Tensor
pub fn mul(&self, o: &Tensor) -> Tensor
pub fn div(&self, o: &Tensor) -> Tensor
pub fn maximum(&self, o: &Tensor) -> Tensor
pub fn exp(&self) -> Tensor
pub fn neg(&self) -> Tensor
pub fn relu(&self) -> Tensor
pub fn sqrt(&self) -> Tensor
pub fn relu_mask(&self) -> Tensor
pub fn sum(&self, axes: &[usize], keepdim: bool) -> Tensor
pub fn max(&self, axes: &[usize], keepdim: bool) -> Tensor
pub fn mean(&self, axes: &[usize], keepdim: bool) -> Tensor
pub fn matmul(&self, other: &Tensor) -> Tensor
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for Tensor
impl !UnwindSafe for Tensor
impl Freeze for Tensor
impl Send for Tensor
impl Sync for Tensor
impl Unpin for Tensor
impl UnsafeUnpin 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