pub enum CpuBuf {
F32(Vec<f32>),
F16(Vec<f16>),
U32(Vec<u32>),
I32(Vec<i32>),
I8(Vec<i8>),
}Expand description
CPU-side typed buffer. Variants per dtype keep storage typed (no
unsafe bytemuck casting, no alignment concerns). Compared to a
(Vec<u8>, Dtype, n) triple this trades 16 bytes of discriminant
for type safety on a non-hot-path (CPU is the slow path; if you
care about throughput here, switch backends).
Variants§
Implementations§
Source§impl CpuBuf
impl CpuBuf
pub fn alloc(dtype: Dtype, n: usize) -> Self
pub fn dtype(&self) -> Dtype
pub fn len(&self) -> usize
pub fn is_empty(&self) -> bool
Sourcepub fn as_f32(&self) -> &[f32]
pub fn as_f32(&self) -> &[f32]
Typed accessor — panics on dtype mismatch. Catches the silent
type-tunnel bugs the old from_slice_i32 route would have
papered over.
pub fn as_f32_mut(&mut self) -> &mut [f32]
pub fn as_f16(&self) -> &[f16]
pub fn as_u32(&self) -> &[u32]
pub fn as_u32_mut(&mut self) -> &mut [u32]
pub fn as_i32(&self) -> &[i32]
pub fn as_i32_mut(&mut self) -> &mut [i32]
pub fn as_i8(&self) -> &[i8]
pub fn from_f32(data: Vec<f32>) -> Self
pub fn from_u32(data: Vec<u32>) -> Self
pub fn from_i32(data: Vec<i32>) -> Self
Auto Trait Implementations§
impl Freeze for CpuBuf
impl RefUnwindSafe for CpuBuf
impl Send for CpuBuf
impl Sync for CpuBuf
impl Unpin for CpuBuf
impl UnsafeUnpin for CpuBuf
impl UnwindSafe for CpuBuf
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