summaryrefslogtreecommitdiff
path: root/lib/Numeric/LinearAlgebra/LAPACK.hs
diff options
context:
space:
mode:
authorAlberto Ruiz <aruiz@um.es>2009-12-28 15:47:26 +0000
committerAlberto Ruiz <aruiz@um.es>2009-12-28 15:47:26 +0000
commitb2715e91d7aef5cee1b64b641b8f173167a7145a (patch)
treef97b82cfa435441f52153ccdfad5e1fa119f14dc /lib/Numeric/LinearAlgebra/LAPACK.hs
parent107478b2288b0904159599be94089230c7cd3edf (diff)
additional svd functions
Diffstat (limited to 'lib/Numeric/LinearAlgebra/LAPACK.hs')
-rw-r--r--lib/Numeric/LinearAlgebra/LAPACK.hs225
1 files changed, 157 insertions, 68 deletions
diff --git a/lib/Numeric/LinearAlgebra/LAPACK.hs b/lib/Numeric/LinearAlgebra/LAPACK.hs
index 30a3d3b..2eae9b7 100644
--- a/lib/Numeric/LinearAlgebra/LAPACK.hs
+++ b/lib/Numeric/LinearAlgebra/LAPACK.hs
@@ -1,4 +1,3 @@
1{-# OPTIONS_GHC #-}
2----------------------------------------------------------------------------- 1-----------------------------------------------------------------------------
3-- | 2-- |
4-- Module : Numeric.LinearAlgebra.LAPACK 3-- Module : Numeric.LinearAlgebra.LAPACK
@@ -9,21 +8,34 @@
9-- Stability : provisional 8-- Stability : provisional
10-- Portability : portable (uses FFI) 9-- Portability : portable (uses FFI)
11-- 10--
12-- Wrappers for a few LAPACK functions (<http://www.netlib.org/lapack>). 11-- Functional interface to selected LAPACK functions (<http://www.netlib.org/lapack>).
13-- 12--
14----------------------------------------------------------------------------- 13-----------------------------------------------------------------------------
15 14
16module Numeric.LinearAlgebra.LAPACK ( 15module Numeric.LinearAlgebra.LAPACK (
16 -- * Matrix product
17 multiplyR, multiplyC, 17 multiplyR, multiplyC,
18 svdR, svdRdd, svdC, 18 -- * Linear systems
19 eigC, eigR, eigS, eigH, eigS', eigH',
20 linearSolveR, linearSolveC, 19 linearSolveR, linearSolveC,
20 lusR, lusC,
21 linearSolveLSR, linearSolveLSC, 21 linearSolveLSR, linearSolveLSC,
22 linearSolveSVDR, linearSolveSVDC, 22 linearSolveSVDR, linearSolveSVDC,
23 luR, luC, lusR, lusC, 23 -- * SVD
24 svR, svRd, svC, svCd,
25 svdR, svdRd, svdC, svdCd,
26 thinSVDR, thinSVDRd, thinSVDC, thinSVDCd,
27 rightSVR, rightSVC, leftSVR, leftSVC,
28 -- * Eigensystems
29 eigR, eigC, eigS, eigS', eigH, eigH',
30 -- * LU
31 luR, luC,
32 -- * Cholesky
24 cholS, cholH, 33 cholS, cholH,
34 -- * QR
25 qrR, qrC, 35 qrR, qrC,
36 -- * Hessenberg
26 hessR, hessC, 37 hessR, hessC,
38 -- * Schur
27 schurR, schurC 39 schurR, schurC
28) where 40) where
29 41
@@ -61,28 +73,27 @@ multiplyC :: Matrix (Complex Double) -> Matrix (Complex Double) -> Matrix (Compl
61multiplyC a b = multiplyAux zgemmc "zgemmc" a b 73multiplyC a b = multiplyAux zgemmc "zgemmc" a b
62 74
63----------------------------------------------------------------------------- 75-----------------------------------------------------------------------------
64foreign import ccall "LAPACK/lapack-aux.h svd_l_R" dgesvd :: TMMVM 76foreign import ccall "svd_l_R" dgesvd :: TMMVM
65foreign import ccall "LAPACK/lapack-aux.h svd_l_C" zgesvd :: TCMCMVCM 77foreign import ccall "svd_l_C" zgesvd :: TCMCMVCM
66foreign import ccall "LAPACK/lapack-aux.h svd_l_Rdd" dgesdd :: TMMVM 78foreign import ccall "svd_l_Rdd" dgesdd :: TMMVM
79foreign import ccall "svd_l_Cdd" zgesdd :: TCMCMVCM
67 80
68-- | Wrapper for LAPACK's /dgesvd/, which computes the full svd decomposition of a real matrix. 81-- | Full SVD of a real matrix using LAPACK's /dgesvd/.
69--
70-- @(u,s,v)=full svdR m@ so that @m=u \<\> s \<\> 'trans' v@.
71svdR :: Matrix Double -> (Matrix Double, Vector Double, Matrix Double) 82svdR :: Matrix Double -> (Matrix Double, Vector Double, Matrix Double)
72svdR = svdAux dgesvd "svdR" . fmat 83svdR = svdAux dgesvd "svdR" . fmat
73 84
74-- | Wrapper for LAPACK's /dgesvd/, which computes the full svd decomposition of a real matrix. 85-- | Full SVD of a real matrix using LAPACK's /dgesdd/.
75-- 86svdRd :: Matrix Double -> (Matrix Double, Vector Double, Matrix Double)
76-- @(u,s,v)=full svdRdd m@ so that @m=u \<\> s \<\> 'trans' v@. 87svdRd = svdAux dgesdd "svdRdd" . fmat
77svdRdd :: Matrix Double -> (Matrix Double, Vector Double, Matrix Double)
78svdRdd = svdAux dgesdd "svdRdd" . fmat
79 88
80-- | Wrapper for LAPACK's /zgesvd/, which computes the full svd decomposition of a complex matrix. 89-- | Full SVD of a complex matrix using LAPACK's /zgesvd/.
81--
82-- @(u,s,v)=full svdC m@ so that @m=u \<\> comp s \<\> 'trans' v@.
83svdC :: Matrix (Complex Double) -> (Matrix (Complex Double), Vector Double, Matrix (Complex Double)) 90svdC :: Matrix (Complex Double) -> (Matrix (Complex Double), Vector Double, Matrix (Complex Double))
84svdC = svdAux zgesvd "svdC" . fmat 91svdC = svdAux zgesvd "svdC" . fmat
85 92
93-- | Full SVD of a complex matrix using LAPACK's /zgesdd/.
94svdCd :: Matrix (Complex Double) -> (Matrix (Complex Double), Vector Double, Matrix (Complex Double))
95svdCd = svdAux zgesdd "svdCdd" . fmat
96
86svdAux f st x = unsafePerformIO $ do 97svdAux f st x = unsafePerformIO $ do
87 u <- createMatrix ColumnMajor r r 98 u <- createMatrix ColumnMajor r r
88 s <- createVector (min r c) 99 s <- createVector (min r c)
@@ -92,7 +103,104 @@ svdAux f st x = unsafePerformIO $ do
92 where r = rows x 103 where r = rows x
93 c = cols x 104 c = cols x
94 105
106
107-- | Thin SVD of a real matrix, using LAPACK's /dgesvd/ with jobu == jobvt == \'S\'.
108thinSVDR :: Matrix Double -> (Matrix Double, Vector Double, Matrix Double)
109thinSVDR = thinSVDAux dgesvd "thinSVDR" . fmat
110
111-- | Thin SVD of a complex matrix, using LAPACK's /zgesvd/ with jobu == jobvt == \'S\'.
112thinSVDC :: Matrix (Complex Double) -> (Matrix (Complex Double), Vector Double, Matrix (Complex Double))
113thinSVDC = thinSVDAux zgesvd "thinSVDC" . fmat
114
115-- | Thin SVD of a real matrix, using LAPACK's /dgesdd/ with jobz == \'S\'.
116thinSVDRd :: Matrix Double -> (Matrix Double, Vector Double, Matrix Double)
117thinSVDRd = thinSVDAux dgesdd "thinSVDRdd" . fmat
118
119-- | Thin SVD of a complex matrix, using LAPACK's /zgesdd/ with jobz == \'S\'.
120thinSVDCd :: Matrix (Complex Double) -> (Matrix (Complex Double), Vector Double, Matrix (Complex Double))
121thinSVDCd = thinSVDAux zgesdd "thinSVDCdd" . fmat
122
123thinSVDAux f st x = unsafePerformIO $ do
124 u <- createMatrix ColumnMajor r q
125 s <- createVector q
126 v <- createMatrix ColumnMajor q c
127 app4 f mat x mat u vec s mat v st
128 return (u,s,trans v)
129 where r = rows x
130 c = cols x
131 q = min r c
132
133
134-- | Singular values of a real matrix, using LAPACK's /dgesvd/ with jobu == jobvt == \'N\'.
135svR :: Matrix Double -> Vector Double
136svR = svAux dgesvd "svR" . fmat
137
138-- | Singular values of a complex matrix, using LAPACK's /zgesvd/ with jobu == jobvt == \'N\'.
139svC :: Matrix (Complex Double) -> Vector Double
140svC = svAux zgesvd "svC" . fmat
141
142-- | Singular values of a real matrix, using LAPACK's /dgesdd/ with jobz == \'N\'.
143svRd :: Matrix Double -> Vector Double
144svRd = svAux dgesdd "svRd" . fmat
145
146-- | Singular values of a complex matrix, using LAPACK's /zgesdd/ with jobz == \'N\'.
147svCd :: Matrix (Complex Double) -> Vector Double
148svCd = svAux zgesdd "svCd" . fmat
149
150svAux f st x = unsafePerformIO $ do
151 s <- createVector q
152 app2 g mat x vec s st
153 return s
154 where r = rows x
155 c = cols x
156 q = min r c
157 g ra ca pa nb pb = f ra ca pa 0 0 nullPtr nb pb 0 0 nullPtr
158
159
160-- | Singular values and all right singular vectors of a real matrix, using LAPACK's /dgesvd/ with jobu == \'N\' and jobvt == \'A\'.
161rightSVR :: Matrix Double -> (Vector Double, Matrix Double)
162rightSVR = rightSVAux dgesvd "rightSVR" . fmat
163
164-- | Singular values and all right singular vectors of a complex matrix, using LAPACK's /zgesvd/ with jobu == \'N\' and jobvt == \'A\'.
165rightSVC :: Matrix (Complex Double) -> (Vector Double, Matrix (Complex Double))
166rightSVC = rightSVAux zgesvd "rightSVC" . fmat
167
168rightSVAux f st x = unsafePerformIO $ do
169 s <- createVector q
170 v <- createMatrix ColumnMajor c c
171 app3 g mat x vec s mat v st
172 return (s,trans v)
173 where r = rows x
174 c = cols x
175 q = min r c
176 g ra ca pa = f ra ca pa 0 0 nullPtr
177
178
179-- | Singular values and all left singular vectors of a real matrix, using LAPACK's /dgesvd/ with jobu == \'A\' and jobvt == \'N\'.
180leftSVR :: Matrix Double -> (Matrix Double, Vector Double)
181leftSVR = leftSVAux dgesvd "leftSVR" . fmat
182
183-- | Singular values and all left singular vectors of a complex matrix, using LAPACK's /zgesvd/ with jobu == \'A\' and jobvt == \'N\'.
184leftSVC :: Matrix (Complex Double) -> (Matrix (Complex Double), Vector Double)
185leftSVC = leftSVAux zgesvd "leftSVC" . fmat
186
187leftSVAux f st x = unsafePerformIO $ do
188 u <- createMatrix ColumnMajor r r
189 s <- createVector q
190 app3 g mat x mat u vec s st
191 return (u,s)
192 where r = rows x
193 c = cols x
194 q = min r c
195 g ra ca pa ru cu pu nb pb = f ra ca pa ru cu pu nb pb 0 0 nullPtr
196
95----------------------------------------------------------------------------- 197-----------------------------------------------------------------------------
198
199foreign import ccall "LAPACK/lapack-aux.h eig_l_R" dgeev :: TMMCVM
200foreign import ccall "LAPACK/lapack-aux.h eig_l_C" zgeev :: TCMCMCVCM
201foreign import ccall "LAPACK/lapack-aux.h eig_l_S" dsyev :: TMVM
202foreign import ccall "LAPACK/lapack-aux.h eig_l_H" zheev :: TCMVCM
203
96eigAux f st m 204eigAux f st m
97 | r == 1 = (fromList [flatten m `at` 0], singleton 1) 205 | r == 1 = (fromList [flatten m `at` 0], singleton 1)
98 | otherwise = unsafePerformIO $ do 206 | otherwise = unsafePerformIO $ do
@@ -104,28 +212,13 @@ eigAux f st m
104 where r = rows m 212 where r = rows m
105 213
106 214
107foreign import ccall "LAPACK/lapack-aux.h eig_l_C" zgeev :: TCMCMCVCM 215-- | Eigenvalues and right eigenvectors of a general complex matrix, using LAPACK's /zgeev/.
108foreign import ccall "LAPACK/lapack-aux.h eig_l_R" dgeev :: TMMCVM 216-- The eigenvectors are the columns of v. The eigenvalues are not sorted.
109foreign import ccall "LAPACK/lapack-aux.h eig_l_S" dsyev :: TMVM
110foreign import ccall "LAPACK/lapack-aux.h eig_l_H" zheev :: TCMVCM
111
112-- | Wrapper for LAPACK's /zgeev/, which computes the eigenvalues and right eigenvectors of a general complex matrix:
113--
114-- if @(l,v)=eigC m@ then @m \<\> v = v \<\> diag l@.
115--
116-- The eigenvectors are the columns of v.
117-- The eigenvalues are not sorted.
118eigC :: Matrix (Complex Double) -> (Vector (Complex Double), Matrix (Complex Double)) 217eigC :: Matrix (Complex Double) -> (Vector (Complex Double), Matrix (Complex Double))
119eigC = eigAux zgeev "eigC" . fmat 218eigC = eigAux zgeev "eigC" . fmat
120 219
121----------------------------------------------------------------------------- 220-- | Eigenvalues and right eigenvectors of a general real matrix, using LAPACK's /dgeev/.
122 221-- The eigenvectors are the columns of v. The eigenvalues are not sorted.
123-- | Wrapper for LAPACK's /dgeev/, which computes the eigenvalues and right eigenvectors of a general real matrix:
124--
125-- if @(l,v)=eigR m@ then @m \<\> v = v \<\> diag l@.
126--
127-- The eigenvectors are the columns of v.
128-- The eigenvalues are not sorted.
129eigR :: Matrix Double -> (Vector (Complex Double), Matrix (Complex Double)) 222eigR :: Matrix Double -> (Vector (Complex Double), Matrix (Complex Double))
130eigR m = (s', v'') 223eigR m = (s', v'')
131 where (s,v) = eigRaux (fmat m) 224 where (s,v) = eigRaux (fmat m)
@@ -155,17 +248,16 @@ fixeig _ _ = error "fixeig with impossible inputs"
155 248
156----------------------------------------------------------------------------- 249-----------------------------------------------------------------------------
157 250
158-- | Wrapper for LAPACK's /dsyev/, which computes the eigenvalues and right eigenvectors of a symmetric real matrix: 251-- | Eigenvalues and right eigenvectors of a symmetric real matrix, using LAPACK's /dsyev/.
159--
160-- if @(l,v)=eigSl m@ then @m \<\> v = v \<\> diag l@.
161--
162-- The eigenvectors are the columns of v. 252-- The eigenvectors are the columns of v.
163-- The eigenvalues are sorted in descending order (use eigS' for ascending order). 253-- The eigenvalues are sorted in descending order (use 'eigS'' for ascending order).
164eigS :: Matrix Double -> (Vector Double, Matrix Double) 254eigS :: Matrix Double -> (Vector Double, Matrix Double)
165eigS m = (s', fliprl v) 255eigS m = (s', fliprl v)
166 where (s,v) = eigS' (fmat m) 256 where (s,v) = eigS' (fmat m)
167 s' = fromList . reverse . toList $ s 257 s' = fromList . reverse . toList $ s
168 258
259-- | 'eigS' in ascending order
260eigS' :: Matrix Double -> (Vector Double, Matrix Double)
169eigS' m 261eigS' m
170 | r == 1 = (fromList [flatten m `at` 0], singleton 1) 262 | r == 1 = (fromList [flatten m `at` 0], singleton 1)
171 | otherwise = unsafePerformIO $ do 263 | otherwise = unsafePerformIO $ do
@@ -177,17 +269,16 @@ eigS' m
177 269
178----------------------------------------------------------------------------- 270-----------------------------------------------------------------------------
179 271
180-- | Wrapper for LAPACK's /zheev/, which computes the eigenvalues and right eigenvectors of a hermitian complex matrix: 272-- | Eigenvalues and right eigenvectors of a hermitian complex matrix, using LAPACK's /zheev/.
181--
182-- if @(l,v)=eigH m@ then @m \<\> s v = v \<\> diag l@.
183--
184-- The eigenvectors are the columns of v. 273-- The eigenvectors are the columns of v.
185-- The eigenvalues are sorted in descending order (use eigH' for ascending order). 274-- The eigenvalues are sorted in descending order (use 'eigH'' for ascending order).
186eigH :: Matrix (Complex Double) -> (Vector Double, Matrix (Complex Double)) 275eigH :: Matrix (Complex Double) -> (Vector Double, Matrix (Complex Double))
187eigH m = (s', fliprl v) 276eigH m = (s', fliprl v)
188 where (s,v) = eigH' (fmat m) 277 where (s,v) = eigH' (fmat m)
189 s' = fromList . reverse . toList $ s 278 s' = fromList . reverse . toList $ s
190 279
280-- | 'eigH' in ascending order
281eigH' :: Matrix (Complex Double) -> (Vector Double, Matrix (Complex Double))
191eigH' m 282eigH' m
192 | r == 1 = (fromList [realPart (flatten m `at` 0)], singleton 1) 283 | r == 1 = (fromList [realPart (flatten m `at` 0)], singleton 1)
193 | otherwise = unsafePerformIO $ do 284 | otherwise = unsafePerformIO $ do
@@ -212,11 +303,11 @@ linearSolveSQAux f st a b
212 r = rows b 303 r = rows b
213 c = cols b 304 c = cols b
214 305
215-- | Wrapper for LAPACK's /dgesv/, which solves a general real linear system (for several right-hand sides) internally using the lu decomposition. 306-- | Solve a real linear system (for square coefficient matrix and several right-hand sides) using the LU decomposition, based on LAPACK's /dgesv/. For underconstrained or overconstrained systems use 'linearSolveLSR' or 'linearSolveSVDR'. See also 'lusR'.
216linearSolveR :: Matrix Double -> Matrix Double -> Matrix Double 307linearSolveR :: Matrix Double -> Matrix Double -> Matrix Double
217linearSolveR a b = linearSolveSQAux dgesv "linearSolveR" (fmat a) (fmat b) 308linearSolveR a b = linearSolveSQAux dgesv "linearSolveR" (fmat a) (fmat b)
218 309
219-- | Wrapper for LAPACK's /zgesv/, which solves a general complex linear system (for several right-hand sides) internally using the lu decomposition. 310-- | Solve a complex linear system (for square coefficient matrix and several right-hand sides) using the LU decomposition, based on LAPACK's /zgesv/. For underconstrained or overconstrained systems use 'linearSolveLSC' or 'linearSolveSVDC'. See also 'lusC'.
220linearSolveC :: Matrix (Complex Double) -> Matrix (Complex Double) -> Matrix (Complex Double) 311linearSolveC :: Matrix (Complex Double) -> Matrix (Complex Double) -> Matrix (Complex Double)
221linearSolveC a b = linearSolveSQAux zgesv "linearSolveC" (fmat a) (fmat b) 312linearSolveC a b = linearSolveSQAux zgesv "linearSolveC" (fmat a) (fmat b)
222 313
@@ -234,17 +325,17 @@ linearSolveAux f st a b = unsafePerformIO $ do
234 n = cols a 325 n = cols a
235 nrhs = cols b 326 nrhs = cols b
236 327
237-- | Wrapper for LAPACK's /dgels/, which obtains the least squared error solution of an overconstrained real linear system or the minimum norm solution of an underdetermined system, for several right-hand sides. For rank deficient systems use 'linearSolveSVDR'. 328-- | Least squared error solution of an overconstrained real linear system, or the minimum norm solution of an underconstrained system, using LAPACK's /dgels/. For rank-deficient systems use 'linearSolveSVDR'.
238linearSolveLSR :: Matrix Double -> Matrix Double -> Matrix Double 329linearSolveLSR :: Matrix Double -> Matrix Double -> Matrix Double
239linearSolveLSR a b = subMatrix (0,0) (cols a, cols b) $ 330linearSolveLSR a b = subMatrix (0,0) (cols a, cols b) $
240 linearSolveAux dgels "linearSolverLSR" (fmat a) (fmat b) 331 linearSolveAux dgels "linearSolverLSR" (fmat a) (fmat b)
241 332
242-- | Wrapper for LAPACK's /zgels/, which obtains the least squared error solution of an overconstrained complex linear system or the minimum norm solution of an underdetermined system, for several right-hand sides. For rank deficient systems use 'linearSolveSVDC'. 333-- | Least squared error solution of an overconstrained complex linear system, or the minimum norm solution of an underconstrained system, using LAPACK's /zgels/. For rank-deficient systems use 'linearSolveSVDC'.
243linearSolveLSC :: Matrix (Complex Double) -> Matrix (Complex Double) -> Matrix (Complex Double) 334linearSolveLSC :: Matrix (Complex Double) -> Matrix (Complex Double) -> Matrix (Complex Double)
244linearSolveLSC a b = subMatrix (0,0) (cols a, cols b) $ 335linearSolveLSC a b = subMatrix (0,0) (cols a, cols b) $
245 linearSolveAux zgels "linearSolveLSC" (fmat a) (fmat b) 336 linearSolveAux zgels "linearSolveLSC" (fmat a) (fmat b)
246 337
247-- | Wrapper for LAPACK's /dgelss/, which obtains the minimum norm solution to a real linear least squares problem Ax=B using the svd, for several right-hand sides. Admits rank deficient systems but it is slower than 'linearSolveLSR'. The effective rank of A is determined by treating as zero those singular valures which are less than rcond times the largest singular value. If rcond == Nothing machine precision is used. 338-- | Minimum norm solution of a general real linear least squares problem Ax=B using the SVD, based on LAPACK's /dgelss/. Admits rank-deficient systems but it is slower than 'linearSolveLSR'. The effective rank of A is determined by treating as zero those singular valures which are less than rcond times the largest singular value. If rcond == Nothing machine precision is used.
248linearSolveSVDR :: Maybe Double -- ^ rcond 339linearSolveSVDR :: Maybe Double -- ^ rcond
249 -> Matrix Double -- ^ coefficient matrix 340 -> Matrix Double -- ^ coefficient matrix
250 -> Matrix Double -- ^ right hand sides (as columns) 341 -> Matrix Double -- ^ right hand sides (as columns)
@@ -253,7 +344,7 @@ linearSolveSVDR (Just rcond) a b = subMatrix (0,0) (cols a, cols b) $
253 linearSolveAux (dgelss rcond) "linearSolveSVDR" (fmat a) (fmat b) 344 linearSolveAux (dgelss rcond) "linearSolveSVDR" (fmat a) (fmat b)
254linearSolveSVDR Nothing a b = linearSolveSVDR (Just (-1)) (fmat a) (fmat b) 345linearSolveSVDR Nothing a b = linearSolveSVDR (Just (-1)) (fmat a) (fmat b)
255 346
256-- | Wrapper for LAPACK's /zgelss/, which obtains the minimum norm solution to a complex linear least squares problem Ax=B using the svd, for several right-hand sides. Admits rank deficient systems but it is slower than 'linearSolveLSC'. The effective rank of A is determined by treating as zero those singular valures which are less than rcond times the largest singular value. If rcond == Nothing machine precision is used. 347-- | Minimum norm solution of a general complex linear least squares problem Ax=B using the SVD, based on LAPACK's /zgelss/. Admits rank-deficient systems but it is slower than 'linearSolveLSC'. The effective rank of A is determined by treating as zero those singular valures which are less than rcond times the largest singular value. If rcond == Nothing machine precision is used.
257linearSolveSVDC :: Maybe Double -- ^ rcond 348linearSolveSVDC :: Maybe Double -- ^ rcond
258 -> Matrix (Complex Double) -- ^ coefficient matrix 349 -> Matrix (Complex Double) -- ^ coefficient matrix
259 -> Matrix (Complex Double) -- ^ right hand sides (as columns) 350 -> Matrix (Complex Double) -- ^ right hand sides (as columns)
@@ -266,13 +357,11 @@ linearSolveSVDC Nothing a b = linearSolveSVDC (Just (-1)) (fmat a) (fmat b)
266foreign import ccall "LAPACK/lapack-aux.h chol_l_H" zpotrf :: TCMCM 357foreign import ccall "LAPACK/lapack-aux.h chol_l_H" zpotrf :: TCMCM
267foreign import ccall "LAPACK/lapack-aux.h chol_l_S" dpotrf :: TMM 358foreign import ccall "LAPACK/lapack-aux.h chol_l_S" dpotrf :: TMM
268 359
269-- | Wrapper for LAPACK's /zpotrf/, which computes the Cholesky factorization of a 360-- | Cholesky factorization of a complex Hermitian positive definite matrix, using LAPACK's /zpotrf/.
270-- complex Hermitian positive definite matrix.
271cholH :: Matrix (Complex Double) -> Matrix (Complex Double) 361cholH :: Matrix (Complex Double) -> Matrix (Complex Double)
272cholH = cholAux zpotrf "cholH" . fmat 362cholH = cholAux zpotrf "cholH" . fmat
273 363
274-- | Wrapper for LAPACK's /dpotrf/, which computes the Cholesky factorization of a 364-- | Cholesky factorization of a real symmetric positive definite matrix, using LAPACK's /dpotrf/.
275-- real symmetric positive definite matrix.
276cholS :: Matrix Double -> Matrix Double 365cholS :: Matrix Double -> Matrix Double
277cholS = cholAux dpotrf "cholS" . fmat 366cholS = cholAux dpotrf "cholS" . fmat
278 367
@@ -286,11 +375,11 @@ cholAux f st a = unsafePerformIO $ do
286foreign import ccall "LAPACK/lapack-aux.h qr_l_R" dgeqr2 :: TMVM 375foreign import ccall "LAPACK/lapack-aux.h qr_l_R" dgeqr2 :: TMVM
287foreign import ccall "LAPACK/lapack-aux.h qr_l_C" zgeqr2 :: TCMCVCM 376foreign import ccall "LAPACK/lapack-aux.h qr_l_C" zgeqr2 :: TCMCVCM
288 377
289-- | Wrapper for LAPACK's /dgeqr2/, which computes a QR factorization of a real matrix. 378-- | QR factorization of a real matrix, using LAPACK's /dgeqr2/.
290qrR :: Matrix Double -> (Matrix Double, Vector Double) 379qrR :: Matrix Double -> (Matrix Double, Vector Double)
291qrR = qrAux dgeqr2 "qrR" . fmat 380qrR = qrAux dgeqr2 "qrR" . fmat
292 381
293-- | Wrapper for LAPACK's /zgeqr2/, which computes a QR factorization of a complex matrix. 382-- | QR factorization of a complex matrix, using LAPACK's /zgeqr2/.
294qrC :: Matrix (Complex Double) -> (Matrix (Complex Double), Vector (Complex Double)) 383qrC :: Matrix (Complex Double) -> (Matrix (Complex Double), Vector (Complex Double))
295qrC = qrAux zgeqr2 "qrC" . fmat 384qrC = qrAux zgeqr2 "qrC" . fmat
296 385
@@ -307,11 +396,11 @@ qrAux f st a = unsafePerformIO $ do
307foreign import ccall "LAPACK/lapack-aux.h hess_l_R" dgehrd :: TMVM 396foreign import ccall "LAPACK/lapack-aux.h hess_l_R" dgehrd :: TMVM
308foreign import ccall "LAPACK/lapack-aux.h hess_l_C" zgehrd :: TCMCVCM 397foreign import ccall "LAPACK/lapack-aux.h hess_l_C" zgehrd :: TCMCVCM
309 398
310-- | Wrapper for LAPACK's /dgehrd/, which computes a Hessenberg factorization of a square real matrix. 399-- | Hessenberg factorization of a square real matrix, using LAPACK's /dgehrd/.
311hessR :: Matrix Double -> (Matrix Double, Vector Double) 400hessR :: Matrix Double -> (Matrix Double, Vector Double)
312hessR = hessAux dgehrd "hessR" . fmat 401hessR = hessAux dgehrd "hessR" . fmat
313 402
314-- | Wrapper for LAPACK's /zgehrd/, which computes a Hessenberg factorization of a square complex matrix. 403-- | Hessenberg factorization of a square complex matrix, using LAPACK's /zgehrd/.
315hessC :: Matrix (Complex Double) -> (Matrix (Complex Double), Vector (Complex Double)) 404hessC :: Matrix (Complex Double) -> (Matrix (Complex Double), Vector (Complex Double))
316hessC = hessAux zgehrd "hessC" . fmat 405hessC = hessAux zgehrd "hessC" . fmat
317 406
@@ -328,11 +417,11 @@ hessAux f st a = unsafePerformIO $ do
328foreign import ccall "LAPACK/lapack-aux.h schur_l_R" dgees :: TMMM 417foreign import ccall "LAPACK/lapack-aux.h schur_l_R" dgees :: TMMM
329foreign import ccall "LAPACK/lapack-aux.h schur_l_C" zgees :: TCMCMCM 418foreign import ccall "LAPACK/lapack-aux.h schur_l_C" zgees :: TCMCMCM
330 419
331-- | Wrapper for LAPACK's /dgees/, which computes a Schur factorization of a square real matrix. 420-- | Schur factorization of a square real matrix, using LAPACK's /dgees/.
332schurR :: Matrix Double -> (Matrix Double, Matrix Double) 421schurR :: Matrix Double -> (Matrix Double, Matrix Double)
333schurR = schurAux dgees "schurR" . fmat 422schurR = schurAux dgees "schurR" . fmat
334 423
335-- | Wrapper for LAPACK's /zgees/, which computes a Schur factorization of a square complex matrix. 424-- | Schur factorization of a square complex matrix, using LAPACK's /zgees/.
336schurC :: Matrix (Complex Double) -> (Matrix (Complex Double), Matrix (Complex Double)) 425schurC :: Matrix (Complex Double) -> (Matrix (Complex Double), Matrix (Complex Double))
337schurC = schurAux zgees "schurC" . fmat 426schurC = schurAux zgees "schurC" . fmat
338 427
@@ -347,11 +436,11 @@ schurAux f st a = unsafePerformIO $ do
347foreign import ccall "LAPACK/lapack-aux.h lu_l_R" dgetrf :: TMVM 436foreign import ccall "LAPACK/lapack-aux.h lu_l_R" dgetrf :: TMVM
348foreign import ccall "LAPACK/lapack-aux.h lu_l_C" zgetrf :: TCMVCM 437foreign import ccall "LAPACK/lapack-aux.h lu_l_C" zgetrf :: TCMVCM
349 438
350-- | Wrapper for LAPACK's /dgetrf/, which computes a LU factorization of a general real matrix. 439-- | LU factorization of a general real matrix, using LAPACK's /dgetrf/.
351luR :: Matrix Double -> (Matrix Double, [Int]) 440luR :: Matrix Double -> (Matrix Double, [Int])
352luR = luAux dgetrf "luR" . fmat 441luR = luAux dgetrf "luR" . fmat
353 442
354-- | Wrapper for LAPACK's /zgees/, which computes a Schur factorization of a square complex matrix. 443-- | LU factorization of a general complex matrix, using LAPACK's /zgetrf/.
355luC :: Matrix (Complex Double) -> (Matrix (Complex Double), [Int]) 444luC :: Matrix (Complex Double) -> (Matrix (Complex Double), [Int])
356luC = luAux zgetrf "luC" . fmat 445luC = luAux zgetrf "luC" . fmat
357 446
@@ -370,11 +459,11 @@ type TQ a = CInt -> CInt -> PC -> a
370foreign import ccall "LAPACK/lapack-aux.h luS_l_R" dgetrs :: TMVMM 459foreign import ccall "LAPACK/lapack-aux.h luS_l_R" dgetrs :: TMVMM
371foreign import ccall "LAPACK/lapack-aux.h luS_l_C" zgetrs :: TQ (TW (TQ (TQ (IO CInt)))) 460foreign import ccall "LAPACK/lapack-aux.h luS_l_C" zgetrs :: TQ (TW (TQ (TQ (IO CInt))))
372 461
373-- | Wrapper for LAPACK's /dgetrs/, which solves a general real linear system (for several right-hand sides) from a precomputed LU decomposition. 462-- | Solve a real linear system from a precomputed LU decomposition ('luR'), using LAPACK's /dgetrs/.
374lusR :: Matrix Double -> [Int] -> Matrix Double -> Matrix Double 463lusR :: Matrix Double -> [Int] -> Matrix Double -> Matrix Double
375lusR a piv b = lusAux dgetrs "lusR" (fmat a) piv (fmat b) 464lusR a piv b = lusAux dgetrs "lusR" (fmat a) piv (fmat b)
376 465
377-- | Wrapper for LAPACK's /zgetrs/, which solves a general real linear system (for several right-hand sides) from a precomputed LU decomposition. 466-- | Solve a real linear system from a precomputed LU decomposition ('luC'), using LAPACK's /zgetrs/.
378lusC :: Matrix (Complex Double) -> [Int] -> Matrix (Complex Double) -> Matrix (Complex Double) 467lusC :: Matrix (Complex Double) -> [Int] -> Matrix (Complex Double) -> Matrix (Complex Double)
379lusC a piv b = lusAux zgetrs "lusC" (fmat a) piv (fmat b) 468lusC a piv b = lusAux zgetrs "lusC" (fmat a) piv (fmat b)
380 469