pub enum TensorData {
Owned(Vec<u8>),
Borrowed(&'static [u8]),
Shared(Arc<Vec<u8>>),
Mapped {
mmap: Arc<Mmap>,
offset: usize,
length: usize,
},
Empty,
}Expand description
Container for tensor data with different storage backends
Variants§
Owned(Vec<u8>)
Owned byte vector (most common case)
Borrowed(&'static [u8])
Reference to borrowed data (zero-copy when possible)
Shared reference-counted data
Mapped
Memory-mapped data (when using mmap feature)
Fields
Empty
Empty/uninitialized data
Implementations§
Source§impl TensorData
impl TensorData
Sourcepub fn new_borrowed(data: &'static [u8]) -> Self
pub fn new_borrowed(data: &'static [u8]) -> Self
Create new borrowed tensor data
Create new shared tensor data
Sourcepub fn try_zeros(size: usize) -> Result<Self>
pub fn try_zeros(size: usize) -> Result<Self>
Fallibly create tensor data with the specified size filled with zeros.
Sourcepub fn filled(size: usize, value: u8) -> Self
pub fn filled(size: usize, value: u8) -> Self
Create tensor data with specified size filled with a value
Sourcepub fn try_filled(size: usize, value: u8) -> Result<Self>
pub fn try_filled(size: usize, value: u8) -> Result<Self>
Fallibly create tensor data with the specified size and fill value.
Sourcepub fn new_mapped(mmap: Arc<Mmap>, offset: usize, length: usize) -> Result<Self>
pub fn new_mapped(mmap: Arc<Mmap>, offset: usize, length: usize) -> Result<Self>
Create memory-mapped tensor data
Sourcepub fn as_slice(&self) -> &[u8] ⓘ
pub fn as_slice(&self) -> &[u8] ⓘ
Get a slice of the tensor data.
A Mapped value constructed directly with an invalid range yields an
empty slice. Use Self::try_as_slice when invalid mapped data must be
distinguished from valid empty data.
Sourcepub fn try_as_slice(&self) -> Result<&[u8]>
pub fn try_as_slice(&self) -> Result<&[u8]>
Get a checked slice of the tensor data.
Unlike Self::as_slice, this reports an invalid directly constructed
memory-mapped range as GGUFError::InvalidTensorData.
Sourcepub fn as_mut_slice(&mut self) -> Option<&mut [u8]>
pub fn as_mut_slice(&mut self) -> Option<&mut [u8]>
Get mutable access to the data (only for owned data)
Sourcepub fn try_to_owned(&self) -> Result<Vec<u8>>
pub fn try_to_owned(&self) -> Result<Vec<u8>>
Convert to owned data while reporting invalid mapped ranges and allocation failure.
Sourcepub fn into_owned(self) -> Vec<u8> ⓘ
pub fn into_owned(self) -> Vec<u8> ⓘ
Take ownership of the data if possible, otherwise clone
Sourcepub fn storage_type(&self) -> TensorStorageType
pub fn storage_type(&self) -> TensorStorageType
Get the storage type
Sourcepub fn storage_info(&self) -> TensorDataInfo
pub fn storage_info(&self) -> TensorDataInfo
Get storage information
Sourcepub fn is_aligned(&self) -> bool
pub fn is_aligned(&self) -> bool
Check if the data is properly aligned
Sourcepub fn is_aligned_to(&self, alignment: usize) -> bool
pub fn is_aligned_to(&self, alignment: usize) -> bool
Check if the data is aligned to a specific boundary
Sourcepub fn slice(&self, start: usize, length: usize) -> Result<TensorData>
pub fn slice(&self, start: usize, length: usize) -> Result<TensorData>
Create a slice of the tensor data
Sourcepub fn concat(&self, other: &TensorData) -> TensorData
pub fn concat(&self, other: &TensorData) -> TensorData
Concatenate with another tensor data
Sourcepub fn content_equals(&self, other: &TensorData) -> bool
pub fn content_equals(&self, other: &TensorData) -> bool
Check if two tensor data instances have the same content
Sourcepub fn hex_preview(&self, max_bytes: usize) -> String
pub fn hex_preview(&self, max_bytes: usize) -> String
Get a hexadecimal representation of the first few bytes (for debugging)
Sourcepub fn checksum(&self) -> u32
pub fn checksum(&self) -> u32
Calculate a small non-cryptographic checksum for caller-side comparison.
This value is not collision resistant and does not establish integrity or authenticity without a separately trusted reference value.
Sourcepub fn memory_usage(&self) -> TensorMemoryUsage
pub fn memory_usage(&self) -> TensorMemoryUsage
Get memory usage information
Trait Implementations§
Source§impl Clone for TensorData
impl Clone for TensorData
Source§impl Debug for TensorData
impl Debug for TensorData
Source§impl Default for TensorData
impl Default for TensorData
Source§impl Display for TensorData
Available on crate feature std only.
impl Display for TensorData
std only.