diff options
Diffstat (limited to 'lib/GSL')
-rw-r--r-- | lib/GSL/Matrix.hs | 33 | ||||
-rw-r--r-- | lib/GSL/Special.hs | 6 | ||||
-rw-r--r-- | lib/GSL/gsl-aux.c | 21 | ||||
-rw-r--r-- | lib/GSL/gsl-aux.h | 4 |
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) |
159 | 2.236 0. | 159 | [ 1.0, 0.0 |
160 | 1.789 1.342 | 160 | , 2.0, 2.23606797749979 ]@ |
161 | \ | ||
162 | \> c \<\> 'trans' c | ||
163 | 5.000 4.000 | ||
164 | 4.000 5.000@ | ||
165 | 161 | ||
166 | -} | 162 | -} |
167 | chol :: Matrix Double -> Matrix Double | 163 | cholR :: Matrix Double -> Matrix Double |
168 | chol x = unsafePerformIO $ do | 164 | cholR 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 |
173 | foreign import ccall "gsl-aux.h chol" c_chol :: TMM | 169 | foreign import ccall "gsl-aux.h cholR" c_cholR :: TMM |
170 | |||
171 | cholC :: Matrix (Complex Double) -> Matrix (Complex Double) | ||
172 | cholC 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 | ||
177 | foreign 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 | ) |
46 | where | 45 | where |
47 | 46 | ||
@@ -73,8 +72,3 @@ import GSL.Special.Psi | |||
73 | import GSL.Special.Synchrotron | 72 | import GSL.Special.Synchrotron |
74 | import GSL.Special.Trig | 73 | import GSL.Special.Trig |
75 | import GSL.Special.Zeta | 74 | import 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. | ||
80 | foreign 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 | ||
474 | int chol(KRMAT(x),RMAT(l)) { | 474 | int 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 | ||
491 | int 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 | ||
492 | int fft(int code, KCVEC(X), CVEC(R)) { | 509 | int 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 | ||
39 | int QR(KRMAT(x),RMAT(q),RMAT(r)); | 39 | int QR(KRMAT(x),RMAT(q),RMAT(r)); |
40 | 40 | ||
41 | int chol(KRMAT(x),RMAT(l)); | 41 | int cholR(KRMAT(x),RMAT(l)); |
42 | |||
43 | int cholC(KCMAT(x),CMAT(l)); | ||
42 | 44 | ||
43 | int fft(int code, KCVEC(a), CVEC(b)); | 45 | int fft(int code, KCVEC(a), CVEC(b)); |
44 | 46 | ||