summaryrefslogtreecommitdiff
path: root/lib/LinearAlgebra/Algorithms.hs
diff options
context:
space:
mode:
Diffstat (limited to 'lib/LinearAlgebra/Algorithms.hs')
-rw-r--r--lib/LinearAlgebra/Algorithms.hs36
1 files changed, 19 insertions, 17 deletions
diff --git a/lib/LinearAlgebra/Algorithms.hs b/lib/LinearAlgebra/Algorithms.hs
index 481dbd6..682b17f 100644
--- a/lib/LinearAlgebra/Algorithms.hs
+++ b/lib/LinearAlgebra/Algorithms.hs
@@ -28,7 +28,7 @@ module LinearAlgebra.Algorithms (
28 svd, 28 svd,
29 full, economy, 29 full, economy,
30-- ** Eigensystems 30-- ** Eigensystems
31 eig, LinearAlgebra.Algorithms.eigS, LinearAlgebra.Algorithms.eigH, 31 eig, eigSH,
32-- ** Other 32-- ** Other
33 LinearAlgebra.Algorithms.qr, chol, 33 LinearAlgebra.Algorithms.qr, chol,
34-- * Nullspace 34-- * Nullspace
@@ -38,7 +38,7 @@ module LinearAlgebra.Algorithms (
38 eps, i, 38 eps, i,
39 ctrans, 39 ctrans,
40 Normed(..), NormType(..), 40 Normed(..), NormType(..),
41 GenMat(linearSolveSVD,lu,eigSH) 41 GenMat(linearSolveSVD,lu,eigSH')
42) where 42) where
43 43
44 44
@@ -50,15 +50,15 @@ import LinearAlgebra.LAPACK as LAPACK
50import Complex 50import Complex
51import LinearAlgebra.Linear 51import LinearAlgebra.Linear
52 52
53-- | matrix computations available for both real and complex matrices 53-- | Auxiliary typeclass used to define generic computations for both real and complex matrices.
54class (Linear Matrix t) => GenMat t where 54class (Linear Matrix t) => GenMat t where
55 svd :: Matrix t -> (Matrix t, Vector Double, Matrix t) 55 svd :: Matrix t -> (Matrix t, Vector Double, Matrix t)
56 lu :: Matrix t -> (Matrix t, Matrix t, [Int], t) 56 lu :: Matrix t -> (Matrix t, Matrix t, [Int], t)
57 linearSolve :: Matrix t -> Matrix t -> Matrix t 57 linearSolve :: Matrix t -> Matrix t -> Matrix t
58 linearSolveSVD :: Matrix t -> Matrix t -> Matrix t 58 linearSolveSVD :: Matrix t -> Matrix t -> Matrix t
59 eig :: Matrix t -> (Vector (Complex Double), Matrix (Complex Double)) 59 eig :: Matrix t -> (Vector (Complex Double), Matrix (Complex Double))
60 eigSH :: Matrix t -> (Vector Double, Matrix t) 60 eigSH' :: Matrix t -> (Vector Double, Matrix t)
61 chol :: Matrix t -> Matrix t 61 cholSH :: Matrix t -> Matrix t
62 -- | conjugate transpose 62 -- | conjugate transpose
63 ctrans :: Matrix t -> Matrix t 63 ctrans :: Matrix t -> Matrix t
64 64
@@ -69,8 +69,8 @@ instance GenMat Double where
69 linearSolveSVD = linearSolveSVDR Nothing 69 linearSolveSVD = linearSolveSVDR Nothing
70 ctrans = trans 70 ctrans = trans
71 eig = eigR 71 eig = eigR
72 eigSH = LAPACK.eigS 72 eigSH' = eigS
73 chol = cholS 73 cholSH = cholS
74 74
75instance GenMat (Complex Double) where 75instance GenMat (Complex Double) where
76 svd = svdC 76 svd = svdC
@@ -79,16 +79,18 @@ instance GenMat (Complex Double) where
79 linearSolveSVD = linearSolveSVDC Nothing 79 linearSolveSVD = linearSolveSVDC Nothing
80 ctrans = conjTrans 80 ctrans = conjTrans
81 eig = eigC 81 eig = eigC
82 eigSH = LAPACK.eigH 82 eigSH' = eigH
83 chol = cholH 83 cholSH = cholH
84 84
85-- | eigensystem of a symmetric matrix 85-- | eigensystem of complex hermitian or real symmetric matrix
86eigS :: Matrix Double -> (Vector Double, Matrix Double) 86eigSH :: GenMat t => Matrix t -> (Vector Double, Matrix t)
87eigS = LAPACK.eigS 87eigSH m | m `equal` ctrans m = eigSH' m
88 88 | otherwise = error "eigSH requires complex hermitian or real symmetric matrix"
89-- | eigensystem of a hermitian matrix 89
90eigH :: Matrix (Complex Double) -> (Vector Double, Matrix (Complex Double)) 90-- | Cholesky factorization of a positive definite hermitian or symmetric matrix
91eigH = LAPACK.eigH 91chol :: GenMat t => Matrix t -> Matrix t
92chol m | m `equal` ctrans m = cholSH m
93 | otherwise = error "chol requires positive definite complex hermitian or real symmetric matrix"
92 94
93qr :: Matrix Double -> (Matrix Double, Matrix Double) 95qr :: Matrix Double -> (Matrix Double, Matrix Double)
94qr = GSL.Matrix.qr 96qr = GSL.Matrix.qr