Skip to content

Commit 75f9726

Browse files
committed
Add workaround for zero-size arrays with bk()
There is a bug in the LAPACKE `*sytrf` routines that makes them fail for zero-size arrays. Basically, what happens is that when `LAPACKE_*sytrf` queries for the optimal `lwork` parameter value, `dsytrf.f` suggests `0`. When `LAPACKE_*sytrf` actually tries to use `0` for `lwork`, `dsytrf.f` returns an error indicating that `lwork` needs to be at least `1`.
1 parent 2944c81 commit 75f9726

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/lapack_traits/solveh.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,13 @@ impl Solveh_ for $scalar {
2626
unsafe fn bk(l: MatrixLayout, uplo: UPLO, a: &mut [Self]) -> Result<Pivot> {
2727
let (n, _) = l.size();
2828
let mut ipiv = vec![0; n as usize];
29-
let info = $trf(l.lapacke_layout(), uplo as u8, n, a, l.lda(), &mut ipiv);
30-
into_result(info, ipiv)
29+
if n == 0 {
30+
// Work around bug in LAPACKE functions.
31+
Ok(ipiv)
32+
} else {
33+
let info = $trf(l.lapacke_layout(), uplo as u8, n, a, l.lda(), &mut ipiv);
34+
into_result(info, ipiv)
35+
}
3136
}
3237

3338
unsafe fn invh(l: MatrixLayout, uplo: UPLO, a: &mut [Self], ipiv: &Pivot) -> Result<()> {

0 commit comments

Comments
 (0)