@@ -36,12 +36,8 @@ pub struct SVDOutput<A: Scalar> {
3636/// Wraps `*gesvd`
3737pub trait SVD_ : Scalar {
3838 /// Calculate singular value decomposition $ A = U \Sigma V^T $
39- unsafe fn svd (
40- l : MatrixLayout ,
41- calc_u : bool ,
42- calc_vt : bool ,
43- a : & mut [ Self ] ,
44- ) -> Result < SVDOutput < Self > > ;
39+ fn svd ( l : MatrixLayout , calc_u : bool , calc_vt : bool , a : & mut [ Self ] )
40+ -> Result < SVDOutput < Self > > ;
4541}
4642
4743macro_rules! impl_svd {
@@ -53,12 +49,7 @@ macro_rules! impl_svd {
5349 } ;
5450 ( @body, $scalar: ty, $gesvd: path, $( $rwork_ident: ident) ,* ) => {
5551 impl SVD_ for $scalar {
56- unsafe fn svd(
57- l: MatrixLayout ,
58- calc_u: bool ,
59- calc_vt: bool ,
60- mut a: & mut [ Self ] ,
61- ) -> Result <SVDOutput <Self >> {
52+ fn svd( l: MatrixLayout , calc_u: bool , calc_vt: bool , mut a: & mut [ Self ] , ) -> Result <SVDOutput <Self >> {
6253 let ju = match l {
6354 MatrixLayout :: F { .. } => FlagSVD :: from_bool( calc_u) ,
6455 MatrixLayout :: C { .. } => FlagSVD :: from_bool( calc_vt) ,
@@ -90,45 +81,49 @@ macro_rules! impl_svd {
9081 // eval work size
9182 let mut info = 0 ;
9283 let mut work_size = [ Self :: zero( ) ] ;
93- $gesvd(
94- ju as u8 ,
95- jvt as u8 ,
96- m,
97- n,
98- & mut a,
99- m,
100- & mut s,
101- u. as_mut( ) . map( |x| x. as_mut_slice( ) ) . unwrap_or( & mut [ ] ) ,
102- m,
103- vt. as_mut( ) . map( |x| x. as_mut_slice( ) ) . unwrap_or( & mut [ ] ) ,
104- n,
105- & mut work_size,
106- -1 ,
107- $( & mut $rwork_ident, ) *
108- & mut info,
109- ) ;
84+ unsafe {
85+ $gesvd(
86+ ju as u8 ,
87+ jvt as u8 ,
88+ m,
89+ n,
90+ & mut a,
91+ m,
92+ & mut s,
93+ u. as_mut( ) . map( |x| x. as_mut_slice( ) ) . unwrap_or( & mut [ ] ) ,
94+ m,
95+ vt. as_mut( ) . map( |x| x. as_mut_slice( ) ) . unwrap_or( & mut [ ] ) ,
96+ n,
97+ & mut work_size,
98+ -1 ,
99+ $( & mut $rwork_ident, ) *
100+ & mut info,
101+ ) ;
102+ }
110103 info. as_lapack_result( ) ?;
111104
112105 // calc
113106 let lwork = work_size[ 0 ] . to_usize( ) . unwrap( ) ;
114107 let mut work = vec![ Self :: zero( ) ; lwork] ;
115- $gesvd(
116- ju as u8 ,
117- jvt as u8 ,
118- m,
119- n,
120- & mut a,
121- m,
122- & mut s,
123- u. as_mut( ) . map( |x| x. as_mut_slice( ) ) . unwrap_or( & mut [ ] ) ,
124- m,
125- vt. as_mut( ) . map( |x| x. as_mut_slice( ) ) . unwrap_or( & mut [ ] ) ,
126- n,
127- & mut work,
128- lwork as i32 ,
129- $( & mut $rwork_ident, ) *
130- & mut info,
131- ) ;
108+ unsafe {
109+ $gesvd(
110+ ju as u8 ,
111+ jvt as u8 ,
112+ m,
113+ n,
114+ & mut a,
115+ m,
116+ & mut s,
117+ u. as_mut( ) . map( |x| x. as_mut_slice( ) ) . unwrap_or( & mut [ ] ) ,
118+ m,
119+ vt. as_mut( ) . map( |x| x. as_mut_slice( ) ) . unwrap_or( & mut [ ] ) ,
120+ n,
121+ & mut work,
122+ lwork as i32 ,
123+ $( & mut $rwork_ident, ) *
124+ & mut info,
125+ ) ;
126+ }
132127 info. as_lapack_result( ) ?;
133128 match l {
134129 MatrixLayout :: F { .. } => Ok ( SVDOutput { s, u, vt } ) ,
0 commit comments