Skip to content

Commit 25dc071

Browse files
committed
Use lapack_sys in Eig_ impl for real
1 parent c0c3a37 commit 25dc071

File tree

1 file changed

+36
-35
lines changed

1 file changed

+36
-35
lines changed

lax/src/eig.rs

Lines changed: 36 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ macro_rules! impl_eig_real {
123123
fn eig(
124124
calc_v: bool,
125125
l: MatrixLayout,
126-
mut a: &mut [Self],
126+
a: &mut [Self],
127127
) -> Result<(Vec<Self::Complex>, Vec<Self::Complex>)> {
128128
let (n, _) = l.size();
129129
// LAPACK assumes a column-major input. A row-major input can
@@ -150,61 +150,62 @@ macro_rules! impl_eig_real {
150150
} else {
151151
(EigenVectorFlag::Not, EigenVectorFlag::Not)
152152
};
153-
let mut eig_re = unsafe { vec_uninit(n as usize) };
154-
let mut eig_im = unsafe { vec_uninit(n as usize) };
153+
let mut eig_re: Vec<Self> = unsafe { vec_uninit(n as usize) };
154+
let mut eig_im: Vec<Self> = unsafe { vec_uninit(n as usize) };
155155

156-
let mut vl = if jobvl == EigenVectorFlag::Calc {
156+
let mut vl: Option<Vec<Self>> = if jobvl == EigenVectorFlag::Calc {
157157
Some(unsafe { vec_uninit((n * n) as usize) })
158158
} else {
159159
None
160160
};
161-
let mut vr = if jobvr == EigenVectorFlag::Calc {
161+
let mut vr: Option<Vec<Self>> = if jobvr == EigenVectorFlag::Calc {
162162
Some(unsafe { vec_uninit((n * n) as usize) })
163163
} else {
164164
None
165165
};
166166

167167
// calc work size
168168
let mut info = 0;
169-
let mut work_size = [0.0];
169+
let mut work_size: [Self; 1] = [0.0];
170170
unsafe {
171171
$ev(
172-
jobvl as u8,
173-
jobvr as u8,
174-
n,
175-
&mut a,
176-
n,
177-
&mut eig_re,
178-
&mut eig_im,
179-
vl.as_mut().map(|v| v.as_mut_slice()).unwrap_or(&mut []),
180-
n,
181-
vr.as_mut().map(|v| v.as_mut_slice()).unwrap_or(&mut []),
182-
n,
183-
&mut work_size,
184-
-1,
172+
jobvl.as_ptr(),
173+
jobvr.as_ptr(),
174+
&n,
175+
AsPtr::as_mut_ptr(a),
176+
&n,
177+
AsPtr::as_mut_ptr(&mut eig_re),
178+
AsPtr::as_mut_ptr(&mut eig_im),
179+
AsPtr::as_mut_ptr(vl.as_mut().map(|v| v.as_mut_slice()).unwrap_or(&mut [])),
180+
&n,
181+
AsPtr::as_mut_ptr(vr.as_mut().map(|v| v.as_mut_slice()).unwrap_or(&mut [])),
182+
&n,
183+
AsPtr::as_mut_ptr(&mut work_size),
184+
&(-1),
185185
&mut info,
186186
)
187187
};
188188
info.as_lapack_result()?;
189189

190190
// actual ev
191191
let lwork = work_size[0].to_usize().unwrap();
192-
let mut work = unsafe { vec_uninit(lwork) };
192+
let mut work: Vec<Self> = unsafe { vec_uninit(lwork) };
193+
let lwork = lwork as i32;
193194
unsafe {
194195
$ev(
195-
jobvl as u8,
196-
jobvr as u8,
197-
n,
198-
&mut a,
199-
n,
200-
&mut eig_re,
201-
&mut eig_im,
202-
vl.as_mut().map(|v| v.as_mut_slice()).unwrap_or(&mut []),
203-
n,
204-
vr.as_mut().map(|v| v.as_mut_slice()).unwrap_or(&mut []),
205-
n,
206-
&mut work,
207-
lwork as i32,
196+
jobvl.as_ptr(),
197+
jobvr.as_ptr(),
198+
&n,
199+
AsPtr::as_mut_ptr(a),
200+
&n,
201+
AsPtr::as_mut_ptr(&mut eig_re),
202+
AsPtr::as_mut_ptr(&mut eig_im),
203+
AsPtr::as_mut_ptr(vl.as_mut().map(|v| v.as_mut_slice()).unwrap_or(&mut [])),
204+
&n,
205+
AsPtr::as_mut_ptr(vr.as_mut().map(|v| v.as_mut_slice()).unwrap_or(&mut [])),
206+
&n,
207+
AsPtr::as_mut_ptr(&mut work),
208+
&lwork,
208209
&mut info,
209210
)
210211
};
@@ -270,5 +271,5 @@ macro_rules! impl_eig_real {
270271
};
271272
}
272273

273-
impl_eig_real!(f64, lapack::dgeev);
274-
impl_eig_real!(f32, lapack::sgeev);
274+
impl_eig_real!(f64, lapack_sys::dgeev_);
275+
impl_eig_real!(f32, lapack_sys::sgeev_);

0 commit comments

Comments
 (0)