pub struct Tensor { /* private fields */ }Expand description
A contiguous, row-major tensor on a specific device.
Implementations§
Source§impl Tensor
impl Tensor
pub fn from_f32( data: &[f32], shape: impl Into<Shape>, device: &Device, ) -> Result<Tensor>
pub fn from_u32( data: &[u32], shape: impl Into<Shape>, device: &Device, ) -> Result<Tensor>
pub fn zeros(shape: impl Into<Shape>, device: &Device) -> Result<Tensor>
pub fn shape(&self) -> &Shape
pub fn dtype(&self) -> DType
pub fn device(&self) -> Device
Sourcepub fn to_vec_f32(&self) -> Result<Vec<f32>>
pub fn to_vec_f32(&self) -> Result<Vec<f32>>
Copy the tensor contents to a host Vec<f32>. Sync facade: on wasm32
only CPU tensors can be read synchronously (roadmap v4, pitfall 14) —
use Tensor::to_vec_f32_async for WebGPU tensors there.
pub fn to_vec_u32(&self) -> Result<Vec<u32>>
Sourcepub async fn to_vec_f32_async(&self) -> Result<Vec<f32>>
pub async fn to_vec_f32_async(&self) -> Result<Vec<f32>>
Async readback — the primary form (identical result to to_vec_f32);
on wasm the browser event loop drives the buffer mapping.
Sourcepub async fn to_vec_f32_batch(tensors: &[Tensor]) -> Result<Vec<Vec<f32>>>
pub async fn to_vec_f32_batch(tensors: &[Tensor]) -> Result<Vec<Vec<f32>>>
Read several f32 tensors back in one GPU round trip, in the order given.
Tensor::to_vec_f32_async is a submit and a fence wait per call, so
a step that wants several small tensors — the attention probe reads
n_layer + 1 per generated token — pays for the round trips, not the
bytes. Every tensor must be on the same device.
pub async fn to_vec_u32_async(&self) -> Result<Vec<u32>>
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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