Skip to content

Commit

Permalink
WIP: reconstruct_eigs
Browse files Browse the repository at this point in the history
  • Loading branch information
termoshtt committed Sep 22, 2022
1 parent e603f61 commit 43b0480
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions lax/src/eig.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ pub struct EigWork<T: Scalar> {
pub jobvl: JobEv,

/// Eigenvalues used in complex routines
pub eigs: Option<Vec<MaybeUninit<T>>>,
pub eigs: Option<Vec<MaybeUninit<T::Complex>>>,
/// Real part of eigenvalues used in real routines
pub eigs_re: Option<Vec<MaybeUninit<T>>>,
pub eigs_re: Option<Vec<MaybeUninit<T::Real>>>,
/// Imaginary part of eigenvalues used in real routines
pub eigs_im: Option<Vec<MaybeUninit<T>>>,
pub eigs_im: Option<Vec<MaybeUninit<T::Real>>>,

/// Left eigenvectors
pub vl: Option<Vec<MaybeUninit<T>>>,
Expand All @@ -57,6 +57,26 @@ pub struct EigWork<T: Scalar> {
pub rwork: Option<Vec<MaybeUninit<T::Real>>>,
}

impl<T: Scalar> EigWork<T> {
/// Create complex eigenvalues from real and imaginary parts.
unsafe fn reconstruct_eigs(&mut self) {
let n = self.n as usize;
if self.eigs.is_none() {
self.eigs = Some(vec_uninit(n));
}
let eigs = self.eigs.as_mut().unwrap();
if let (Some(re), Some(im)) = (self.eigs_re.as_ref(), self.eigs_im.as_ref()) {
assert_eq!(re.len(), n);
assert_eq!(im.len(), n);
for i in 0..n {
eigs[i].write(T::complex(re[i].assume_init(), im[i].assume_init()));
}
} else {
panic!("Called without constructing eigs_re and eigs_im");
}
}
}

pub trait EigWorkImpl: Sized {
type Elem: Scalar;
/// Create new working memory for eigenvalues compution.
Expand Down

0 comments on commit 43b0480

Please sign in to comment.