Skip to content

Commit 3c4dc5e

Browse files
committed
Use lapack_sys in Eig_ impl for complex
1 parent e21e932 commit 3c4dc5e

File tree

1 file changed

+36
-33
lines changed

1 file changed

+36
-33
lines changed

lax/src/eig.rs

Lines changed: 36 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ macro_rules! impl_eig_complex {
2020
fn eig(
2121
calc_v: bool,
2222
l: MatrixLayout,
23-
mut a: &mut [Self],
23+
a: &mut [Self],
2424
) -> Result<(Vec<Self::Complex>, Vec<Self::Complex>)> {
2525
let (n, _) = l.size();
2626
// LAPACK assumes a column-major input. A row-major input can
@@ -42,52 +42,55 @@ macro_rules! impl_eig_complex {
4242
(EigenVectorFlag::Not, EigenVectorFlag::Not)
4343
};
4444
let mut eigs = unsafe { vec_uninit(n as usize) };
45-
let mut rwork = unsafe { vec_uninit(2 * n as usize) };
45+
let mut rwork: Vec<Self::Real> = unsafe { vec_uninit(2 * n as usize) };
4646

47-
let mut vl = jobvl.then(|| unsafe { vec_uninit((n * n) as usize) });
48-
let mut vr = jobvr.then(|| unsafe { vec_uninit((n * n) as usize) });
47+
let mut vl: Option<Vec<Self>> =
48+
jobvl.then(|| unsafe { vec_uninit((n * n) as usize) });
49+
let mut vr: Option<Vec<Self>> =
50+
jobvr.then(|| unsafe { vec_uninit((n * n) as usize) });
4951

5052
// calc work size
5153
let mut info = 0;
5254
let mut work_size = [Self::zero()];
5355
unsafe {
5456
$ev(
55-
jobvl as u8,
56-
jobvr as u8,
57-
n,
58-
&mut a,
59-
n,
60-
&mut eigs,
61-
&mut vl.as_mut().map(|v| v.as_mut_slice()).unwrap_or(&mut []),
62-
n,
63-
&mut vr.as_mut().map(|v| v.as_mut_slice()).unwrap_or(&mut []),
64-
n,
65-
&mut work_size,
66-
-1,
67-
&mut rwork,
57+
jobvl.as_ptr(),
58+
jobvr.as_ptr(),
59+
&n,
60+
AsPtr::as_mut_ptr(a),
61+
&n,
62+
AsPtr::as_mut_ptr(&mut eigs),
63+
AsPtr::as_mut_ptr(vl.as_mut().map(|v| v.as_mut_slice()).unwrap_or(&mut [])),
64+
&n,
65+
AsPtr::as_mut_ptr(vr.as_mut().map(|v| v.as_mut_slice()).unwrap_or(&mut [])),
66+
&n,
67+
AsPtr::as_mut_ptr(&mut work_size),
68+
&(-1),
69+
AsPtr::as_mut_ptr(&mut rwork),
6870
&mut info,
6971
)
7072
};
7173
info.as_lapack_result()?;
7274

7375
// actal ev
7476
let lwork = work_size[0].to_usize().unwrap();
75-
let mut work = unsafe { vec_uninit(lwork) };
77+
let mut work: Vec<Self> = unsafe { vec_uninit(lwork) };
78+
let lwork = lwork as i32;
7679
unsafe {
7780
$ev(
78-
jobvl as u8,
79-
jobvr as u8,
80-
n,
81-
&mut a,
82-
n,
83-
&mut eigs,
84-
&mut vl.as_mut().map(|v| v.as_mut_slice()).unwrap_or(&mut []),
85-
n,
86-
&mut vr.as_mut().map(|v| v.as_mut_slice()).unwrap_or(&mut []),
87-
n,
88-
&mut work,
89-
lwork as i32,
90-
&mut rwork,
81+
jobvl.as_ptr(),
82+
jobvr.as_ptr(),
83+
&n,
84+
AsPtr::as_mut_ptr(a),
85+
&n,
86+
AsPtr::as_mut_ptr(&mut eigs),
87+
AsPtr::as_mut_ptr(vl.as_mut().map(|v| v.as_mut_slice()).unwrap_or(&mut [])),
88+
&n,
89+
AsPtr::as_mut_ptr(vr.as_mut().map(|v| v.as_mut_slice()).unwrap_or(&mut [])),
90+
&n,
91+
AsPtr::as_mut_ptr(&mut work),
92+
&lwork,
93+
AsPtr::as_mut_ptr(&mut rwork),
9194
&mut info,
9295
)
9396
};
@@ -106,8 +109,8 @@ macro_rules! impl_eig_complex {
106109
};
107110
}
108111

109-
impl_eig_complex!(c64, lapack::zgeev);
110-
impl_eig_complex!(c32, lapack::cgeev);
112+
impl_eig_complex!(c64, lapack_sys::zgeev_);
113+
impl_eig_complex!(c32, lapack_sys::cgeev_);
111114

112115
macro_rules! impl_eig_real {
113116
($scalar:ty, $ev:path) => {

0 commit comments

Comments
 (0)