Skip to content

Commit f155620

Browse files
committed
Use lapack_sys in solveh.rs
1 parent 68b8ae5 commit f155620

File tree

1 file changed

+64
-22
lines changed

1 file changed

+64
-22
lines changed

lax/src/solveh.rs

Lines changed: 64 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -30,30 +30,30 @@ macro_rules! impl_solveh {
3030
let mut work_size = [Self::zero()];
3131
unsafe {
3232
$trf(
33-
uplo as u8,
34-
n,
35-
a,
36-
l.lda(),
37-
&mut ipiv,
38-
&mut work_size,
39-
-1,
33+
uplo.as_ptr(),
34+
&n,
35+
AsPtr::as_mut_ptr(a),
36+
&l.lda(),
37+
ipiv.as_mut_ptr(),
38+
AsPtr::as_mut_ptr(&mut work_size),
39+
&(-1),
4040
&mut info,
4141
)
4242
};
4343
info.as_lapack_result()?;
4444

4545
// actual
4646
let lwork = work_size[0].to_usize().unwrap();
47-
let mut work = unsafe { vec_uninit(lwork) };
47+
let mut work: Vec<Self> = unsafe { vec_uninit(lwork) };
4848
unsafe {
4949
$trf(
50-
uplo as u8,
51-
n,
52-
a,
53-
l.lda(),
54-
&mut ipiv,
55-
&mut work,
56-
lwork as i32,
50+
uplo.as_ptr(),
51+
&n,
52+
AsPtr::as_mut_ptr(a),
53+
&l.lda(),
54+
ipiv.as_mut_ptr(),
55+
AsPtr::as_mut_ptr(&mut work),
56+
&(lwork as i32),
5757
&mut info,
5858
)
5959
};
@@ -64,8 +64,18 @@ macro_rules! impl_solveh {
6464
fn invh(l: MatrixLayout, uplo: UPLO, a: &mut [Self], ipiv: &Pivot) -> Result<()> {
6565
let (n, _) = l.size();
6666
let mut info = 0;
67-
let mut work = unsafe { vec_uninit(n as usize) };
68-
unsafe { $tri(uplo as u8, n, a, l.lda(), ipiv, &mut work, &mut info) };
67+
let mut work: Vec<Self> = unsafe { vec_uninit(n as usize) };
68+
unsafe {
69+
$tri(
70+
uplo.as_ptr(),
71+
&n,
72+
AsPtr::as_mut_ptr(a),
73+
&l.lda(),
74+
ipiv.as_ptr(),
75+
AsPtr::as_mut_ptr(&mut work),
76+
&mut info,
77+
)
78+
};
6979
info.as_lapack_result()?;
7080
Ok(())
7181
}
@@ -79,15 +89,47 @@ macro_rules! impl_solveh {
7989
) -> Result<()> {
8090
let (n, _) = l.size();
8191
let mut info = 0;
82-
unsafe { $trs(uplo as u8, n, 1, a, l.lda(), ipiv, b, n, &mut info) };
92+
unsafe {
93+
$trs(
94+
uplo.as_ptr(),
95+
&n,
96+
&1,
97+
AsPtr::as_ptr(a),
98+
&l.lda(),
99+
ipiv.as_ptr(),
100+
AsPtr::as_mut_ptr(b),
101+
&n,
102+
&mut info,
103+
)
104+
};
83105
info.as_lapack_result()?;
84106
Ok(())
85107
}
86108
}
87109
};
88110
} // impl_solveh!
89111

90-
impl_solveh!(f64, lapack::dsytrf, lapack::dsytri, lapack::dsytrs);
91-
impl_solveh!(f32, lapack::ssytrf, lapack::ssytri, lapack::ssytrs);
92-
impl_solveh!(c64, lapack::zhetrf, lapack::zhetri, lapack::zhetrs);
93-
impl_solveh!(c32, lapack::chetrf, lapack::chetri, lapack::chetrs);
112+
impl_solveh!(
113+
f64,
114+
lapack_sys::dsytrf_,
115+
lapack_sys::dsytri_,
116+
lapack_sys::dsytrs_
117+
);
118+
impl_solveh!(
119+
f32,
120+
lapack_sys::ssytrf_,
121+
lapack_sys::ssytri_,
122+
lapack_sys::ssytrs_
123+
);
124+
impl_solveh!(
125+
c64,
126+
lapack_sys::zhetrf_,
127+
lapack_sys::zhetri_,
128+
lapack_sys::zhetrs_
129+
);
130+
impl_solveh!(
131+
c32,
132+
lapack_sys::chetrf_,
133+
lapack_sys::chetri_,
134+
lapack_sys::chetrs_
135+
);

0 commit comments

Comments
 (0)