summaryrefslogtreecommitdiff
path: root/lib/GSL
diff options
context:
space:
mode:
Diffstat (limited to 'lib/GSL')
-rw-r--r--lib/GSL/Matrix.hs33
-rw-r--r--lib/GSL/Special.hs6
-rw-r--r--lib/GSL/gsl-aux.c21
-rw-r--r--lib/GSL/gsl-aux.h4
4 files changed, 41 insertions, 23 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
diff --git a/lib/GSL/Special.hs b/lib/GSL/Special.hs
index bdee1b2..fa002b9 100644
--- a/lib/GSL/Special.hs
+++ b/lib/GSL/Special.hs
@@ -41,7 +41,6 @@ module GSL.Special (
41, module GSL.Special.Synchrotron 41, module GSL.Special.Synchrotron
42, module GSL.Special.Trig 42, module GSL.Special.Trig
43, module GSL.Special.Zeta 43, module GSL.Special.Zeta
44, setErrorHandlerOff
45) 44)
46where 45where
47 46
@@ -73,8 +72,3 @@ import GSL.Special.Psi
73import GSL.Special.Synchrotron 72import GSL.Special.Synchrotron
74import GSL.Special.Trig 73import GSL.Special.Trig
75import GSL.Special.Zeta 74import GSL.Special.Zeta
76
77
78-- | This action removes the GSL default error handler which aborts the program, so that
79-- GSL errors can be handled by Haskell (using Control.Exception) and ghci doesn't abort.
80foreign import ccall "gsl-aux.h no_abort_on_error" setErrorHandlerOff :: IO ()
diff --git a/lib/GSL/gsl-aux.c b/lib/GSL/gsl-aux.c
index 0e8406c..c602d5e 100644
--- a/lib/GSL/gsl-aux.c
+++ b/lib/GSL/gsl-aux.c
@@ -471,9 +471,9 @@ int QR(KRMAT(x),RMAT(q),RMAT(r)) {
471 OK 471 OK
472} 472}
473 473
474int chol(KRMAT(x),RMAT(l)) { 474int cholR(KRMAT(x),RMAT(l)) {
475 REQUIRES(xr==xc && lr==xr && lr==lc,BAD_SIZE); 475 REQUIRES(xr==xc && lr==xr && lr==lc,BAD_SIZE);
476 DEBUGMSG("chol"); 476 DEBUGMSG("cholR");
477 KDMVIEW(x); 477 KDMVIEW(x);
478 DMVIEW(l); 478 DMVIEW(l);
479 gsl_matrix_memcpy(M(l),M(x)); 479 gsl_matrix_memcpy(M(l),M(x));
@@ -488,6 +488,23 @@ int chol(KRMAT(x),RMAT(l)) {
488 OK 488 OK
489} 489}
490 490
491int cholC(KCMAT(x),CMAT(l)) {
492 REQUIRES(xr==xc && lr==xr && lr==lc,BAD_SIZE);
493 DEBUGMSG("cholC");
494 KCMVIEW(x);
495 CMVIEW(l);
496 gsl_matrix_complex_memcpy(M(l),M(x));
497 int res = 0; // gsl_linalg_complex_cholesky_decomp(M(l));
498 CHECK(res,res);
499 gsl_complex zero = {0.,0.};
500 int r,c;
501 for (r=0; r<xr-1; r++) {
502 for(c=r+1; c<xc; c++) {
503 lp[r*lc+c] = zero;
504 }
505 }
506 OK
507}
491 508
492int fft(int code, KCVEC(X), CVEC(R)) { 509int fft(int code, KCVEC(X), CVEC(R)) {
493 REQUIRES(Xn == Rn,BAD_SIZE); 510 REQUIRES(Xn == Rn,BAD_SIZE);
diff --git a/lib/GSL/gsl-aux.h b/lib/GSL/gsl-aux.h
index 8f8618a..dd1a247 100644
--- a/lib/GSL/gsl-aux.h
+++ b/lib/GSL/gsl-aux.h
@@ -38,7 +38,9 @@ int eigensystemC(KCMAT(x),RVEC(l),CMAT(v));
38 38
39int QR(KRMAT(x),RMAT(q),RMAT(r)); 39int QR(KRMAT(x),RMAT(q),RMAT(r));
40 40
41int chol(KRMAT(x),RMAT(l)); 41int cholR(KRMAT(x),RMAT(l));
42
43int cholC(KCMAT(x),CMAT(l));
42 44
43int fft(int code, KCVEC(a), CVEC(b)); 45int fft(int code, KCVEC(a), CVEC(b));
44 46