@@ -23,6 +23,74 @@ pub trait Eigh_: Scalar {
2323 ) -> Result < Vec < Self :: Real > > ;
2424}
2525
26+ pub struct EighWork < T : Scalar > {
27+ pub jobz : JobEv ,
28+ pub eigs : Vec < MaybeUninit < T :: Real > > ,
29+ pub work : Vec < MaybeUninit < T > > ,
30+ pub rwork : Option < Vec < MaybeUninit < T :: Real > > > ,
31+ }
32+
33+ pub trait EighWorkImpl : Sized {
34+ type Elem : Scalar ;
35+ fn new ( calc_eigenvectors : bool , layout : MatrixLayout ) -> Result < Self > ;
36+ fn calc ( & mut self , a : & mut [ Self :: Elem ] ) -> Result < & [ <Self :: Elem as Scalar >:: Real ] > ;
37+ fn eval ( self , a : & mut [ Self :: Elem ] ) -> Result < Vec < <Self :: Elem as Scalar >:: Real > > ;
38+ }
39+
40+ impl EighWorkImpl for EighWork < c64 > {
41+ type Elem = c64 ;
42+
43+ fn new ( calc_eigenvectors : bool , layout : MatrixLayout ) -> Result < Self > {
44+ assert_eq ! ( layout. len( ) , layout. lda( ) ) ;
45+ let n = layout. len ( ) ;
46+ let jobz = if calc_eigenvectors {
47+ JobEv :: All
48+ } else {
49+ JobEv :: None
50+ } ;
51+ let uplo = UPLO :: Upper ; // dummy, working memory is not affected by UPLO
52+ let mut eigs = vec_uninit ( n as usize ) ;
53+ let mut rwork = vec_uninit ( 3 * n as usize - 2 as usize ) ;
54+
55+ // calc work size
56+ let mut info = 0 ;
57+ let mut work_size = [ c64:: zero ( ) ] ;
58+ unsafe {
59+ lapack_sys:: zheev_ (
60+ jobz. as_ptr ( ) ,
61+ uplo. as_ptr ( ) ,
62+ & n,
63+ std:: ptr:: null_mut ( ) ,
64+ & n,
65+ AsPtr :: as_mut_ptr ( & mut eigs) ,
66+ AsPtr :: as_mut_ptr ( & mut work_size) ,
67+ & ( -1 ) ,
68+ AsPtr :: as_mut_ptr ( & mut rwork) ,
69+ & mut info,
70+ ) ;
71+ }
72+ info. as_lapack_result ( ) ?;
73+
74+ // actual ev
75+ let lwork = work_size[ 0 ] . to_usize ( ) . unwrap ( ) ;
76+ let work = vec_uninit ( lwork) ;
77+
78+ Ok ( EighWork {
79+ eigs,
80+ jobz,
81+ work,
82+ rwork : Some ( rwork) ,
83+ } )
84+ }
85+
86+ fn calc ( & mut self , _a : & mut [ Self :: Elem ] ) -> Result < & [ <Self :: Elem as Scalar >:: Real ] > {
87+ todo ! ( )
88+ }
89+ fn eval ( self , _a : & mut [ Self :: Elem ] ) -> Result < Vec < <Self :: Elem as Scalar >:: Real > > {
90+ todo ! ( )
91+ }
92+ }
93+
2694macro_rules! impl_eigh {
2795 ( @real, $scalar: ty, $ev: path) => {
2896 impl_eigh!( @body, $scalar, $ev, ) ;
0 commit comments