4242 }
4343}
4444
45+ impl < A , S , S2 > EighInto for ( ArrayBase < S , Ix2 > , ArrayBase < S2 , Ix2 > )
46+ where
47+ A : Scalar + Lapack ,
48+ S : DataMut < Elem = A > ,
49+ S2 : DataMut < Elem = A > ,
50+ {
51+ type EigVal = Array1 < A :: Real > ;
52+
53+ fn eigh_into ( mut self , uplo : UPLO ) -> Result < ( Self :: EigVal , Self ) > {
54+ let ( val, _) = self . eigh_inplace ( uplo) ?;
55+ Ok ( ( val, self ) )
56+ }
57+ }
58+
4559impl < A , S > Eigh for ArrayBase < S , Ix2 >
4660where
4761 A : Scalar + Lapack ,
5670 }
5771}
5872
73+ impl < A , S , S2 > Eigh for ( ArrayBase < S , Ix2 > , ArrayBase < S2 , Ix2 > )
74+ where
75+ A : Scalar + Lapack ,
76+ S : Data < Elem = A > ,
77+ S2 : Data < Elem = A > ,
78+ {
79+ type EigVal = Array1 < A :: Real > ;
80+ type EigVec = ( Array2 < A > , Array2 < A > ) ;
81+
82+ fn eigh ( & self , uplo : UPLO ) -> Result < ( Self :: EigVal , Self :: EigVec ) > {
83+ let ( a, b) = ( self . 0 . to_owned ( ) , self . 1 . to_owned ( ) ) ;
84+ ( a, b) . eigh_into ( uplo)
85+ }
86+ }
87+
5988impl < A , S > EighInplace for ArrayBase < S , Ix2 >
6089where
6190 A : Scalar + Lapack ,
@@ -75,6 +104,42 @@ where
75104 }
76105}
77106
107+ impl < A , S , S2 > EighInplace for ( ArrayBase < S , Ix2 > , ArrayBase < S2 , Ix2 > )
108+ where
109+ A : Scalar + Lapack ,
110+ S : DataMut < Elem = A > ,
111+ S2 : DataMut < Elem = A > ,
112+ {
113+ type EigVal = Array1 < A :: Real > ;
114+
115+ fn eigh_inplace ( & mut self , uplo : UPLO ) -> Result < ( Self :: EigVal , & mut Self ) > {
116+ let layout = self . 0 . square_layout ( ) ?;
117+ // XXX Force layout to be Fortran (see #146)
118+ match layout {
119+ MatrixLayout :: C ( _) => self . 0 . swap_axes ( 0 , 1 ) ,
120+ MatrixLayout :: F ( _) => { }
121+ }
122+
123+ let layout = self . 1 . square_layout ( ) ?;
124+ match layout {
125+ MatrixLayout :: C ( _) => self . 1 . swap_axes ( 0 , 1 ) ,
126+ MatrixLayout :: F ( _) => { }
127+ }
128+
129+ let s = unsafe {
130+ A :: eigh_generalized (
131+ true ,
132+ self . 0 . square_layout ( ) ?,
133+ uplo,
134+ self . 0 . as_allocated_mut ( ) ?,
135+ self . 1 . as_allocated_mut ( ) ?,
136+ ) ?
137+ } ;
138+
139+ Ok ( ( ArrayBase :: from ( s) , self ) )
140+ }
141+ }
142+
78143/// Calculate eigenvalues without eigenvectors
79144pub trait EigValsh {
80145 type EigVal ;
0 commit comments