pub struct Tensor {
pub dtype: DataType,
pub shape: Vec<usize>,
pub layout: TensorLayout,
/* private fields */
}Expand description
An owned, host-resident, device-aware tensor (§5, §20.2).
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; the design leaves room for
non-host devices (the accessors gate on host accessibility).
Fields§
§dtype: DataTypeElement type.
shape: Vec<usize>Logical shape (static dims).
layout: TensorLayoutPhysical layout of Tensor::buffer. Row-major contiguous for tensors
this crate produces.
Implementations§
Source§impl Tensor
impl Tensor
Sourcepub fn from_raw(
dtype: DataType,
shape: Vec<usize>,
bytes: &[u8],
) -> Result<Self, SessionError>
pub fn from_raw( dtype: DataType, shape: Vec<usize>, bytes: &[u8], ) -> Result<Self, SessionError>
Build a tensor from raw little-endian bytes on the shared CPU device.
Sourcepub fn from_f32(shape: &[usize], data: &[f32]) -> Result<Self, SessionError>
pub fn from_f32(shape: &[usize], data: &[f32]) -> Result<Self, SessionError>
Build an f32 tensor from a dense row-major slice.
Sourcepub fn from_i64(shape: &[usize], data: &[i64]) -> Result<Self, SessionError>
pub fn from_i64(shape: &[usize], data: &[i64]) -> Result<Self, SessionError>
Build an i64 tensor from a dense row-major slice.
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.