pub struct AllocationGroup { /* private fields */ }Expand description
One group of move-only owners and append-only logical descriptors.
§Examples
use tenferro_tensor::AllocationGroup;
let (group, bindings) = AllocationGroup::from_tensors(Vec::new())?;
assert!(bindings.is_empty());
assert!(format!("{group:?}").contains("AllocationGroup"));Implementations§
Source§impl AllocationGroup
impl AllocationGroup
Sourcepub fn from_tensors(
tensors: Vec<Tensor>,
) -> Result<(Self, Box<[DescriptorSlot]>), GroupError>
pub fn from_tensors( tensors: Vec<Tensor>, ) -> Result<(Self, Box<[DescriptorSlot]>), GroupError>
Build one move-only group for detached runtime input ownership.
§Examples
use tenferro_tensor::AllocationGroup;
let (group, bindings) = AllocationGroup::from_tensors(Vec::new())?;
assert!(bindings.is_empty());
assert!(format!("{group:?}").contains("AllocationGroup"));§Errors
Returns GroupError::IndexOverflow when the input count cannot be
represented by a descriptor slot.
Sourcepub fn read_views<'a>(
&'a self,
bindings: &[DescriptorSlot],
) -> Result<Vec<TensorRead<'a>>, GroupError>
pub fn read_views<'a>( &'a self, bindings: &[DescriptorSlot], ) -> Result<Vec<TensorRead<'a>>, GroupError>
Borrow dtype-erased read views for descriptor bindings without materializing or cloning any owner.
§Errors
Returns GroupError::DescriptorSlotOutOfBounds,
GroupError::DescriptorSlotVacant, or GroupError::InvalidDescriptor
when a binding does not identify a valid descriptor.
Sourcepub fn read_view<'a>(
&'a self,
slot: DescriptorSlot,
) -> Result<TensorRead<'a>, GroupError>
pub fn read_view<'a>( &'a self, slot: DescriptorSlot, ) -> Result<TensorRead<'a>, GroupError>
Borrow one dtype-erased read view for a descriptor without materializing or cloning its physical owner.
§Errors
Returns GroupError::DescriptorSlotOutOfBounds,
GroupError::DescriptorSlotVacant, or GroupError::InvalidDescriptor
when slot is not a valid descriptor.
Sourcepub fn append_tensor(
&mut self,
tensor: Tensor,
) -> Result<DescriptorSlot, GroupError>
pub fn append_tensor( &mut self, tensor: Tensor, ) -> Result<DescriptorSlot, GroupError>
Append a tensor owner and return its new descriptor slot without copying.
§Errors
Returns GroupError::IndexOverflow when allocation or descriptor
indices cannot be represented, or GroupError::InvalidDescriptor
when the consumed tensor descriptor is invalid.
Sourcepub fn append_group(
&mut self,
source: AllocationGroup,
source_slot: DescriptorSlot,
) -> Result<DescriptorSlot, GroupError>
pub fn append_group( &mut self, source: AllocationGroup, source_slot: DescriptorSlot, ) -> Result<DescriptorSlot, GroupError>
Append one descriptor and all of its physical owners without copying.
§Errors
Returns GroupError::IndexOverflow when group indices overflow or
GroupError::InvalidDescriptor when source_slot is invalid.
Sourcepub fn take_tensor(
&mut self,
slot: DescriptorSlot,
) -> Result<Tensor, GroupError>
pub fn take_tensor( &mut self, slot: DescriptorSlot, ) -> Result<Tensor, GroupError>
Extract one uniquely-owned descriptor while retaining all other group descriptors in place.
This is structural: aliased allocations return a typed error and the group remains unchanged.
§Errors
Returns GroupError::AliasedAllocation for an aliased allocation or
GroupError::InvalidDescriptor for an invalid slot; every extraction
failure leaves the group unchanged.
Sourcepub fn into_tensor(
self,
slot: DescriptorSlot,
) -> Result<Tensor, (Self, GroupError)>
pub fn into_tensor( self, slot: DescriptorSlot, ) -> Result<Tensor, (Self, GroupError)>
Consume the group and extract one descriptor as a standalone tensor.
Extraction is structural: it succeeds only when no other descriptor aliases the selected physical allocation. Failure returns the exact unchanged group and typed error without copying.
§Errors
Returns GroupError::AliasedAllocation when another descriptor
references the allocation, or GroupError::InvalidDescriptor for an
invalid slot. Each extraction failure returns the unchanged group.