@@ -9,23 +9,17 @@ use num_traits::{ToPrimitive, Zero};
9
9
10
10
pub trait Solveh_ : Sized {
11
11
/// Bunch-Kaufman: wrapper of `*sytrf` and `*hetrf`
12
- unsafe fn bk ( l : MatrixLayout , uplo : UPLO , a : & mut [ Self ] ) -> Result < Pivot > ;
12
+ fn bk ( l : MatrixLayout , uplo : UPLO , a : & mut [ Self ] ) -> Result < Pivot > ;
13
13
/// Wrapper of `*sytri` and `*hetri`
14
- unsafe fn invh ( l : MatrixLayout , uplo : UPLO , a : & mut [ Self ] , ipiv : & Pivot ) -> Result < ( ) > ;
14
+ fn invh ( l : MatrixLayout , uplo : UPLO , a : & mut [ Self ] , ipiv : & Pivot ) -> Result < ( ) > ;
15
15
/// Wrapper of `*sytrs` and `*hetrs`
16
- unsafe fn solveh (
17
- l : MatrixLayout ,
18
- uplo : UPLO ,
19
- a : & [ Self ] ,
20
- ipiv : & Pivot ,
21
- b : & mut [ Self ] ,
22
- ) -> Result < ( ) > ;
16
+ fn solveh ( l : MatrixLayout , uplo : UPLO , a : & [ Self ] , ipiv : & Pivot , b : & mut [ Self ] ) -> Result < ( ) > ;
23
17
}
24
18
25
19
macro_rules! impl_solveh {
26
20
( $scalar: ty, $trf: path, $tri: path, $trs: path) => {
27
21
impl Solveh_ for $scalar {
28
- unsafe fn bk( l: MatrixLayout , uplo: UPLO , a: & mut [ Self ] ) -> Result <Pivot > {
22
+ fn bk( l: MatrixLayout , uplo: UPLO , a: & mut [ Self ] ) -> Result <Pivot > {
29
23
let ( n, _) = l. size( ) ;
30
24
let mut ipiv = vec![ 0 ; n as usize ] ;
31
25
if n == 0 {
@@ -35,50 +29,49 @@ macro_rules! impl_solveh {
35
29
// calc work size
36
30
let mut info = 0 ;
37
31
let mut work_size = [ Self :: zero( ) ] ;
38
- $trf(
39
- uplo as u8 ,
40
- n,
41
- a,
42
- l. lda( ) ,
43
- & mut ipiv,
44
- & mut work_size,
45
- -1 ,
46
- & mut info,
47
- ) ;
32
+ unsafe {
33
+ $trf(
34
+ uplo as u8 ,
35
+ n,
36
+ a,
37
+ l. lda( ) ,
38
+ & mut ipiv,
39
+ & mut work_size,
40
+ -1 ,
41
+ & mut info,
42
+ )
43
+ } ;
48
44
info. as_lapack_result( ) ?;
49
45
50
46
// actual
51
47
let lwork = work_size[ 0 ] . to_usize( ) . unwrap( ) ;
52
48
let mut work = vec![ Self :: zero( ) ; lwork] ;
53
- $trf(
54
- uplo as u8 ,
55
- n,
56
- a,
57
- l. lda( ) ,
58
- & mut ipiv,
59
- & mut work,
60
- lwork as i32 ,
61
- & mut info,
62
- ) ;
49
+ unsafe {
50
+ $trf(
51
+ uplo as u8 ,
52
+ n,
53
+ a,
54
+ l. lda( ) ,
55
+ & mut ipiv,
56
+ & mut work,
57
+ lwork as i32 ,
58
+ & mut info,
59
+ )
60
+ } ;
63
61
info. as_lapack_result( ) ?;
64
62
Ok ( ipiv)
65
63
}
66
64
67
- unsafe fn invh(
68
- l: MatrixLayout ,
69
- uplo: UPLO ,
70
- a: & mut [ Self ] ,
71
- ipiv: & Pivot ,
72
- ) -> Result <( ) > {
65
+ fn invh( l: MatrixLayout , uplo: UPLO , a: & mut [ Self ] , ipiv: & Pivot ) -> Result <( ) > {
73
66
let ( n, _) = l. size( ) ;
74
67
let mut info = 0 ;
75
68
let mut work = vec![ Self :: zero( ) ; n as usize ] ;
76
- $tri( uplo as u8 , n, a, l. lda( ) , ipiv, & mut work, & mut info) ;
69
+ unsafe { $tri( uplo as u8 , n, a, l. lda( ) , ipiv, & mut work, & mut info) } ;
77
70
info. as_lapack_result( ) ?;
78
71
Ok ( ( ) )
79
72
}
80
73
81
- unsafe fn solveh(
74
+ fn solveh(
82
75
l: MatrixLayout ,
83
76
uplo: UPLO ,
84
77
a: & [ Self ] ,
@@ -87,7 +80,7 @@ macro_rules! impl_solveh {
87
80
) -> Result <( ) > {
88
81
let ( n, _) = l. size( ) ;
89
82
let mut info = 0 ;
90
- $trs( uplo as u8 , n, 1 , a, l. lda( ) , ipiv, b, n, & mut info) ;
83
+ unsafe { $trs( uplo as u8 , n, 1 , a, l. lda( ) , ipiv, b, n, & mut info) } ;
91
84
info. as_lapack_result( ) ?;
92
85
Ok ( ( ) )
93
86
}
0 commit comments