-
Notifications
You must be signed in to change notification settings - Fork 83
Add calculation for tridiagonal matrices (solve, factorize, det, rcond) #196
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
I removed a 1-norm field |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Excellent work :)
} | ||
|
||
/// An interface for making a Tridiagonal struct. | ||
pub trait ToTridiagonal<A: Scalar> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pub trait ToTridiagonal<A: Scalar> { | |
pub trait ExtractTridiagonal<A: Scalar> { |
pub trait TridiagIndex { | ||
fn to_tuple(&self) -> (i32, i32); | ||
} | ||
impl TridiagIndex for [Ix; 2] { | ||
fn to_tuple(&self) -> (i32, i32) { | ||
(self[0] as i32, self[1] as i32) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think ndarray::NdIndex<Ix2>
could be better for it, but it does not enough iterface for implementing this PR, e.g. Into<Ix2>
. I keep this code as it is.
Thank a lot :) |
I added the calculation for tridiagonal matrices, which might be important for solving differential equations.
First, I made a struct of
TriDiagonal
for LU factorization and solving equation using LAPACK. It represents a tridiagonal matrix as 3 one-dimensionalArray
(diagonal, sub-diagonal and super-diagonal elements).And this struct also holds the layout and 1-norm of the raw matrix. They are used in some methods (
solve_tridiagonal
,rcond_tridiagonal
, etc.)Second,
LUFactorizedTriDiagonal
struct contains additional 1DArray
of the second super-diagonal of matrix U andipiv
, just likeLUFactorized
.These structs and
ArrayBase<S, Ix2>
havelu (*gttrf)
,rcond (*gtcon)
,solve (*gttrs)
like methods using LAPACK and adet
like method using a recurrent relation implemented in Rust.I also added an example and some test functions. Please confirm that you can use them just like any other methods implemented for general or triangular matrices.