pub struct TridiagonalMatrix<A>{ /* private fields */ }
Expand description
Tridiagonal matrix representation
A tridiagonal matrix stores only the three diagonals, giving O(n) storage instead of O(n²) for dense matrices.
§Examples
use scirs2_core::ndarray::{array, Array1};
use scirs2_linalg::specialized::TridiagonalMatrix;
use scirs2_linalg::SpecializedMatrix;
// Create a 4x4 tridiagonal matrix
let a = array![1.0, 2.0, 3.0, 4.0]; // Main diagonal
let b = array![5.0, 6.0, 7.0]; // Superdiagonal
let c = array![8.0, 9.0, 10.0]; // Subdiagonal
let tri = TridiagonalMatrix::new(a.view(), b.view(), c.view()).unwrap();
// The matrix is equivalent to:
// [[ 1.0, 5.0, 0.0, 0.0 ],
// [ 8.0, 2.0, 6.0, 0.0 ],
// [ 0.0, 9.0, 3.0, 7.0 ],
// [ 0.0, 0.0, 10.0, 4.0 ]]
// Get elements
assert_eq!(tri.get(0, 0).unwrap(), 1.0);
assert_eq!(tri.get(0, 1).unwrap(), 5.0);
assert_eq!(tri.get(1, 0).unwrap(), 8.0);
assert_eq!(tri.get(2, 3).unwrap(), 7.0);
assert_eq!(tri.get(0, 2).unwrap(), 0.0); // Off-tridiagonal element
// Matrix-vector multiplication
let x = array![1.0, 2.0, 3.0, 4.0];
let y = tri.matvec(&x.view()).unwrap();
Implementations§
Source§impl<A> TridiagonalMatrix<A>
impl<A> TridiagonalMatrix<A>
Sourcepub fn new(
diag: ArrayView1<'_, A>,
superdiag: ArrayView1<'_, A>,
subdiag: ArrayView1<'_, A>,
) -> LinalgResult<Self>
pub fn new( diag: ArrayView1<'_, A>, superdiag: ArrayView1<'_, A>, subdiag: ArrayView1<'_, A>, ) -> LinalgResult<Self>
Sourcepub fn frommatrix(a: &ArrayView2<'_, A>) -> LinalgResult<Self>
pub fn frommatrix(a: &ArrayView2<'_, A>) -> LinalgResult<Self>
Sourcepub fn solve(&self, b: &ArrayView1<'_, A>) -> LinalgResult<Array1<A>>
pub fn solve(&self, b: &ArrayView1<'_, A>) -> LinalgResult<Array1<A>>
Trait Implementations§
Source§impl<A> Clone for TridiagonalMatrix<A>
impl<A> Clone for TridiagonalMatrix<A>
Source§fn clone(&self) -> TridiagonalMatrix<A>
fn clone(&self) -> TridiagonalMatrix<A>
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreSource§impl<A> Debug for TridiagonalMatrix<A>
impl<A> Debug for TridiagonalMatrix<A>
Source§impl<A> SpecializedMatrix<A> for TridiagonalMatrix<A>
impl<A> SpecializedMatrix<A> for TridiagonalMatrix<A>
Source§fn matvec(&self, x: &ArrayView1<'_, A>) -> LinalgResult<Array1<A>>
fn matvec(&self, x: &ArrayView1<'_, A>) -> LinalgResult<Array1<A>>
Perform matrix-vector multiplication: A * x
Source§fn matvec_transpose(&self, x: &ArrayView1<'_, A>) -> LinalgResult<Array1<A>>
fn matvec_transpose(&self, x: &ArrayView1<'_, A>) -> LinalgResult<Array1<A>>
Perform transposed matrix-vector multiplication: A^T * x
Source§fn to_dense(&self) -> LinalgResult<Array2<A>>
fn to_dense(&self) -> LinalgResult<Array2<A>>
Convert to a dense matrix representation
Source§fn to_operator(&self) -> LinalgResult<LinearOperator<A>>
fn to_operator(&self) -> LinalgResult<LinearOperator<A>>
Convert to a matrix-free operator
Auto Trait Implementations§
impl<A> Freeze for TridiagonalMatrix<A>
impl<A> RefUnwindSafe for TridiagonalMatrix<A>where
A: RefUnwindSafe,
impl<A> Send for TridiagonalMatrix<A>
impl<A> Sync for TridiagonalMatrix<A>
impl<A> Unpin for TridiagonalMatrix<A>
impl<A> UnwindSafe for TridiagonalMatrix<A>where
A: RefUnwindSafe,
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more