pub struct LuMod<'a, T> { /* private fields */ }Expand description
An updatable square-matrix representation backed by caller-owned factor storage.
The logical dimension never exceeds the capacity. The borrowed buffers contain the factors for the current square matrix and all update and solve operations allocate no heap memory. A represented matrix may be singular or contain non-finite values; solve operations report invalid U diagonals.
Implementations§
Source§impl<'a, T: Real> LuMod<'a, T>
impl<'a, T: Real> LuMod<'a, T>
Sourcepub fn from_storage(
dimension: usize,
capacity: usize,
l: &'a mut [T],
u: &'a mut [T],
) -> Result<Self, StorageError>
pub fn from_storage( dimension: usize, capacity: usize, l: &'a mut [T], u: &'a mut [T], ) -> Result<Self, StorageError>
Adopts existing factor storage without changing its contents.
l needs capacity * capacity factor elements followed by
capacity solve-work elements. u uses packed upper-triangular
storage and needs capacity * (capacity + 1) / 2 elements. Extra
elements are ignored.
§Preconditions
Unless dimension is zero, the required prefixes of l and u must
already encode factors produced for the same capacity, such as buffers
retained from an earlier LuMod. This mathematical condition is not
validated.
§Postconditions
The buffer contents are unchanged and the returned value has the given dimension and capacity.
§Errors
Returns StorageError::InvalidDimension when dimension > capacity,
StorageError::SizeOverflow when buffer-length arithmetic overflows,
or StorageError::InsufficientStorage when either buffer is too short.
Sourcepub fn capacity(&self) -> usize
pub fn capacity(&self) -> usize
Returns the maximum matrix dimension supported by the borrowed storage.
Sourcepub fn push(
&mut self,
row: &[T],
column: &[T],
diagonal: T,
workspace: &mut Workspace<'_, T>,
) -> Result<(), UpdateError>
pub fn push( &mut self, row: &[T], column: &[T], diagonal: T, workspace: &mut Workspace<'_, T>, ) -> Result<(), UpdateError>
Appends a last row and column to the represented matrix.
If the current matrix is A, success represents
[[A, column], [row, diagonal]] and increases the dimension by one.
row and column must each contain the current dimension, and the
workspace must contain at least the new dimension. Singular and
non-finite values are accepted.
§Errors
Returns UpdateError::CapacityExceeded, UpdateError::LengthMismatch,
or UpdateError::InsufficientWorkspace when the corresponding
structural requirement is not met. On error, the factors and dimension
are unchanged.
Sourcepub fn replace_row(
&mut self,
row: RowIndex,
values: &[T],
workspace: &mut Workspace<'_, T>,
) -> Result<(), UpdateError>
pub fn replace_row( &mut self, row: RowIndex, values: &[T], workspace: &mut Workspace<'_, T>, ) -> Result<(), UpdateError>
Replaces one row of the represented matrix.
On success, values becomes the complete row at the zero-based row
index. The dimension is unchanged. Singular and non-finite values are
accepted.
§Errors
Returns UpdateError::RowOutOfBounds, UpdateError::LengthMismatch,
or UpdateError::InsufficientWorkspace. On error, the factors and
dimension are unchanged.
Sourcepub fn replace_column(
&mut self,
column: ColumnIndex,
values: &[T],
workspace: &mut Workspace<'_, T>,
) -> Result<(), UpdateError>
pub fn replace_column( &mut self, column: ColumnIndex, values: &[T], workspace: &mut Workspace<'_, T>, ) -> Result<(), UpdateError>
Replaces one column of the represented matrix.
On success, values becomes the complete column at the zero-based
column index. The dimension is unchanged. Singular and non-finite
values are accepted.
§Errors
Returns UpdateError::ColumnOutOfBounds,
UpdateError::LengthMismatch, or
UpdateError::InsufficientWorkspace. On error, the factors and
dimension are unchanged.
Sourcepub fn remove(
&mut self,
row: RowIndex,
column: ColumnIndex,
workspace: &mut Workspace<'_, T>,
) -> Result<Removal, UpdateError>
pub fn remove( &mut self, row: RowIndex, column: ColumnIndex, workspace: &mut Workspace<'_, T>, ) -> Result<Removal, UpdateError>
Removes a row and column, reducing the dimension by one.
Before removal, the last row is moved into row and the last column is
moved into column when either requested index is not already last.
The returned Removal identifies the original last indices that were
moved, allowing callers to keep external row and column identities in
sync. The workspace must contain at least the current dimension.
§Errors
Returns UpdateError::RowOutOfBounds,
UpdateError::ColumnOutOfBounds, or
UpdateError::InsufficientWorkspace. On error, the factors and
dimension are unchanged.
Sourcepub fn solve_in_place(&self, rhs: &mut [T]) -> Result<(), SolveError>
pub fn solve_in_place(&self, rhs: &mut [T]) -> Result<(), SolveError>
Solves A * x = rhs and overwrites rhs with x.
§Errors
Returns SolveError::LengthMismatch unless rhs.len() == dimension,
SolveError::Singular for a zero U-factor diagonal, or
SolveError::NonFiniteDiagonal for an infinite or NaN diagonal. On
error, rhs is unchanged.
Sourcepub fn solve_transpose_in_place(&self, rhs: &mut [T]) -> Result<(), SolveError>
pub fn solve_transpose_in_place(&self, rhs: &mut [T]) -> Result<(), SolveError>
Solves Aᵀ * x = rhs and overwrites rhs with x.
§Errors
Returns SolveError::LengthMismatch unless rhs.len() == dimension,
SolveError::Singular for a zero U-factor diagonal, or
SolveError::NonFiniteDiagonal for an infinite or NaN diagonal. On
error, rhs is unchanged.