pub struct WeightTensor {
pub data: Vec<f32>,
pub shape: Vec<usize>,
}Expand description
A named flat f32 weight tensor.
Weights are stored in row-major order. For a 2-D matrix W[m, n],
the element at row i column j is at data[i * n + j].
Fields§
§data: Vec<f32>Raw data in row-major order.
shape: Vec<usize>Shape of the tensor (product equals data.len()).
Implementations§
Source§impl WeightTensor
impl WeightTensor
Sourcepub fn from_data(data: Vec<f32>, shape: Vec<usize>) -> LmResult<Self>
pub fn from_data(data: Vec<f32>, shape: Vec<usize>) -> LmResult<Self>
Construct from existing data, validating that data.len() equals the
product of shape.
Sourcepub fn eye(rows: usize, cols: usize) -> Self
pub fn eye(rows: usize, cols: usize) -> Self
Identity-like weight: ones on the “diagonal” of a 2-D matrix.
For a non-square matrix the identity is placed in the top-left corner.
Sourcepub fn n_elements(&self) -> usize
pub fn n_elements(&self) -> usize
Total number of elements.
Sourcepub fn as_mut_slice(&mut self) -> &mut [f32]
pub fn as_mut_slice(&mut self) -> &mut [f32]
Mutable borrow of the underlying data.
Sourcepub fn row_slice(&self, row: usize) -> LmResult<&[f32]>
pub fn row_slice(&self, row: usize) -> LmResult<&[f32]>
For a 2-D weight matrix [rows × cols], return the row-th row slice.
Sourcepub fn validate_shape(&self, expected: &[usize]) -> LmResult<()>
pub fn validate_shape(&self, expected: &[usize]) -> LmResult<()>
Validate that this tensor has the given shape.
Trait Implementations§
Source§impl Clone for WeightTensor
impl Clone for WeightTensor
Source§fn clone(&self) -> WeightTensor
fn clone(&self) -> WeightTensor
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for WeightTensor
impl RefUnwindSafe for WeightTensor
impl Send for WeightTensor
impl Sync for WeightTensor
impl Unpin for WeightTensor
impl UnsafeUnpin for WeightTensor
impl UnwindSafe for WeightTensor
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