pub struct Tensor { /* private fields */ }Expand description
An owned, device-aware tensor (docs/EAGER.md §3).
Owns the DeviceBuffer that holds its elements and the EP that must free
it. On Phase-1 CPU the buffer is a host allocation, so Tensor::as_bytes
and the typed accessors read it directly.
Implementations§
Source§impl Tensor
impl Tensor
Sourcepub fn from_raw_in(
allocator: Arc<dyn ExecutionProvider>,
dtype: DataType,
shape: Vec<usize>,
bytes: &[u8],
) -> Result<Self>
pub fn from_raw_in( allocator: Arc<dyn ExecutionProvider>, dtype: DataType, shape: Vec<usize>, bytes: &[u8], ) -> Result<Self>
Allocate a tensor from raw little-endian element bytes using allocator.
bytes must hold exactly storage_bytes(numel) bytes for dtype and
shape.
Sourcepub fn zeros_in(
allocator: Arc<dyn ExecutionProvider>,
dtype: DataType,
shape: Vec<usize>,
) -> Result<Self>
pub fn zeros_in( allocator: Arc<dyn ExecutionProvider>, dtype: DataType, shape: Vec<usize>, ) -> Result<Self>
Allocate a zero-initialized tensor of shape/dtype using allocator.
Used by dispatch to materialise output tensors before kernel execution
(docs/EAGER.md §10.1 step 6).
Sourcepub fn from_raw(
dtype: DataType,
shape: Vec<usize>,
bytes: &[u8],
) -> Result<Self>
pub fn from_raw( dtype: DataType, shape: Vec<usize>, bytes: &[u8], ) -> Result<Self>
Build a tensor from raw little-endian bytes on the shared CPU device.
Sourcepub fn zeros(dtype: DataType, shape: Vec<usize>) -> Result<Self>
pub fn zeros(dtype: DataType, shape: Vec<usize>) -> Result<Self>
Build a zero-initialized tensor on the shared CPU device.
Sourcepub fn from_f32(shape: &[usize], data: &[f32]) -> Result<Self>
pub fn from_f32(shape: &[usize], data: &[f32]) -> Result<Self>
Build an f32 tensor from a dense row-major slice on the CPU device.
Sourcepub fn from_i64(shape: &[usize], data: &[i64]) -> Result<Self>
pub fn from_i64(shape: &[usize], data: &[i64]) -> Result<Self>
Build an i64 tensor from a dense row-major slice on the CPU device.
Sourcepub fn layout(&self) -> &TensorLayout
pub fn layout(&self) -> &TensorLayout
The physical layout (row-major contiguous for tensors this crate produces).
Sourcepub fn as_bytes(&self) -> &[u8] ⓘ
pub fn as_bytes(&self) -> &[u8] ⓘ
Borrow the raw little-endian element bytes (host tensors only).
Sourcepub fn to_vec_f32(&self) -> Vec<f32>
pub fn to_vec_f32(&self) -> Vec<f32>
Copy out the elements as f32. Panics if the dtype is not Float32.
Sourcepub fn to_vec_i64(&self) -> Vec<i64>
pub fn to_vec_i64(&self) -> Vec<i64>
Copy out the elements as i64. Panics if the dtype is not Int64.
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
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>
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>
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