summaryrefslogtreecommitdiff
path: root/lib/GSL/Matrix.hs
diff options
context:
space:
mode:
Diffstat (limited to 'lib/GSL/Matrix.hs')
-rw-r--r--lib/GSL/Matrix.hs33
1 files changed, 19 insertions, 14 deletions
diff --git a/lib/GSL/Matrix.hs b/lib/GSL/Matrix.hs
index ec8ceea..c1bce37 100644
--- a/lib/GSL/Matrix.hs
+++ b/lib/GSL/Matrix.hs
@@ -16,7 +16,7 @@ module GSL.Matrix(
16 eigSg, eigHg, 16 eigSg, eigHg,
17 svdg, 17 svdg,
18 qr, 18 qr,
19 chol, 19 cholR, -- cholC,
20 luSolveR, luSolveC, 20 luSolveR, luSolveC,
21 luR, luC, 21 luR, luC,
22 fromFile, extractRows 22 fromFile, extractRows
@@ -153,24 +153,29 @@ foreign import ccall "gsl-aux.h QR" c_qr :: TMMM
153 153
154{- | Cholesky decomposition of a symmetric positive definite real matrix using /gsl_linalg_cholesky_decomp/. 154{- | Cholesky decomposition of a symmetric positive definite real matrix using /gsl_linalg_cholesky_decomp/.
155 155
156@\> let c = chol $ 'fromLists' [[5,4],[4,5]] 156@\> chol $ (2><2) [1,2,
157\ 157 2,9::Double]
158\> c 158(2><2)
1592.236 0. 159 [ 1.0, 0.0
1601.789 1.342 160 , 2.0, 2.23606797749979 ]@
161\
162\> c \<\> 'trans' c
1635.000 4.000
1644.000 5.000@
165 161
166-} 162-}
167chol :: Matrix Double -> Matrix Double 163cholR :: Matrix Double -> Matrix Double
168chol x = unsafePerformIO $ do 164cholR x = unsafePerformIO $ do
169 res <- createMatrix RowMajor r r 165 res <- createMatrix RowMajor r r
170 c_chol // mat cdat x // mat dat res // check "chol" [cdat x] 166 c_cholR // mat cdat x // mat dat res // check "cholR" [cdat x]
171 return res 167 return res
172 where r = rows x 168 where r = rows x
173foreign import ccall "gsl-aux.h chol" c_chol :: TMM 169foreign import ccall "gsl-aux.h cholR" c_cholR :: TMM
170
171cholC :: Matrix (Complex Double) -> Matrix (Complex Double)
172cholC x = unsafePerformIO $ do
173 res <- createMatrix RowMajor r r
174 c_cholC // mat cdat x // mat dat res // check "cholC" [cdat x]
175 return res
176 where r = rows x
177foreign import ccall "gsl-aux.h cholC" c_cholC :: TCMCM
178
174 179
175-------------------------------------------------------- 180--------------------------------------------------------
176 181