module data
Typed data entry: build a tensor from a slice, with the element type
naming the dtype. Half-precision elements ride bit-carrier newtypes
(F16, BF16); the payload stays at the runtime's dtype end to
end, and any numeric conversion runs through the runtime
(f_tensor_to_dtype), never through host float math.
Three entry forms: Api::tensor_from_slice COPIES the slice in (the
tensor owns its memory from then on); Api::f_tensor_from_blob /
Api::f_tensor_from_blob_strided BORROW the slice as a view (no copy;
the tensor cannot outlive the &mut borrow); and
Api::f_tensor_from_blob_owned ADOPTS a Vec (no copy; the runtime
drops it when the last reference goes away); the blob forms come as an
f_ Result primary plus a panicking twin. The write half is
Api::f_tensor_copy_from: host data into an existing tensor.
let x = api.tensor_from_slice(&[1.0f32, 2.0, 3.0, 4.0], &[2, 2])?;
let mut buf = [1.0f32; 8];
let view = api.f_tensor_from_blob(&mut buf, &[8])?; // addresses buf, no copy
BF16 (struct)
A bfloat16, carried as its bit pattern.
Implements: Clone, Copy, Debug, Element, Eq, PartialEq, StructuralPartialEq
F16 (struct)
A 16-bit IEEE-754 half, carried as its bit pattern.
Implements: Clone, Copy, Debug, Element, Eq, PartialEq, StructuralPartialEq
Element (trait)
An element type a slice can enter the tensor world as. DTYPE is the
runtime dtype the bits are read at.
Safety
An implementation asserts that Self's in-memory representation is
exactly DTYPE's element encoding, densely packed; the runtime reads
the slice's bytes at that dtype.