diff options
Diffstat (limited to 'lib/Numeric/GSL')
-rw-r--r-- | lib/Numeric/GSL/Matrix.hs | 26 | ||||
-rw-r--r-- | lib/Numeric/GSL/Vector.hs | 1 | ||||
-rw-r--r-- | lib/Numeric/GSL/gsl-aux.c | 27 | ||||
-rw-r--r-- | lib/Numeric/GSL/gsl-aux.h | 3 |
4 files changed, 55 insertions, 2 deletions
diff --git a/lib/Numeric/GSL/Matrix.hs b/lib/Numeric/GSL/Matrix.hs index eb1931a..5a5c19e 100644 --- a/lib/Numeric/GSL/Matrix.hs +++ b/lib/Numeric/GSL/Matrix.hs | |||
@@ -16,7 +16,7 @@ | |||
16 | module Numeric.GSL.Matrix( | 16 | module Numeric.GSL.Matrix( |
17 | eigSg, eigHg, | 17 | eigSg, eigHg, |
18 | svdg, | 18 | svdg, |
19 | qr, | 19 | qr, qrPacked, unpackQR, |
20 | cholR, -- cholC, | 20 | cholR, -- cholC, |
21 | luSolveR, luSolveC, | 21 | luSolveR, luSolveC, |
22 | luR, luC | 22 | luR, luC |
@@ -149,6 +149,30 @@ qr x = unsafePerformIO $ do | |||
149 | c = cols x | 149 | c = cols x |
150 | foreign import ccall "gsl-aux.h QR" c_qr :: TMMM | 150 | foreign import ccall "gsl-aux.h QR" c_qr :: TMMM |
151 | 151 | ||
152 | qrPacked :: Matrix Double -> (Matrix Double, Vector Double) | ||
153 | qrPacked x = unsafePerformIO $ do | ||
154 | qr <- createMatrix RowMajor r c | ||
155 | tau <- createVector (min r c) | ||
156 | c_qrPacked // mat cdat x // mat dat qr // vec tau // check "qrUnpacked" [cdat x] | ||
157 | return (qr,tau) | ||
158 | where r = rows x | ||
159 | c = cols x | ||
160 | foreign import ccall "gsl-aux.h QRpacked" c_qrPacked :: TMMV | ||
161 | |||
162 | unpackQR :: (Matrix Double, Vector Double) -> (Matrix Double, Matrix Double) | ||
163 | unpackQR (qr,tau) = unsafePerformIO $ do | ||
164 | q <- createMatrix RowMajor r r | ||
165 | rot <- createMatrix RowMajor r c | ||
166 | c_qrUnpack // mat cdat qr // vec tau // mat dat q // mat dat rot // check "qrUnpack" [cdat qr,tau] | ||
167 | return (q,rot) | ||
168 | where r = rows qr | ||
169 | c = cols qr | ||
170 | foreign import ccall "gsl-aux.h QRunpack" c_qrUnpack :: TMVMM | ||
171 | |||
172 | |||
173 | type TMMV = Int -> Int -> PD -> TMV | ||
174 | type TMVMM = Int -> Int -> PD -> Int -> PD -> TMM | ||
175 | |||
152 | {- | Cholesky decomposition of a symmetric positive definite real matrix using /gsl_linalg_cholesky_decomp/. | 176 | {- | Cholesky decomposition of a symmetric positive definite real matrix using /gsl_linalg_cholesky_decomp/. |
153 | 177 | ||
154 | @\> chol $ (2><2) [1,2, | 178 | @\> chol $ (2><2) [1,2, |
diff --git a/lib/Numeric/GSL/Vector.hs b/lib/Numeric/GSL/Vector.hs index ef3d5e8..41efdc0 100644 --- a/lib/Numeric/GSL/Vector.hs +++ b/lib/Numeric/GSL/Vector.hs | |||
@@ -12,7 +12,6 @@ | |||
12 | -- Vector operations | 12 | -- Vector operations |
13 | -- | 13 | -- |
14 | ----------------------------------------------------------------------------- | 14 | ----------------------------------------------------------------------------- |
15 | -- #hide | ||
16 | 15 | ||
17 | module Numeric.GSL.Vector ( | 16 | module Numeric.GSL.Vector ( |
18 | FunCodeS(..), toScalarR, | 17 | FunCodeS(..), toScalarR, |
diff --git a/lib/Numeric/GSL/gsl-aux.c b/lib/Numeric/GSL/gsl-aux.c index c602d5e..83c3bf8 100644 --- a/lib/Numeric/GSL/gsl-aux.c +++ b/lib/Numeric/GSL/gsl-aux.c | |||
@@ -471,6 +471,33 @@ int QR(KRMAT(x),RMAT(q),RMAT(r)) { | |||
471 | OK | 471 | OK |
472 | } | 472 | } |
473 | 473 | ||
474 | int QRpacked(KRMAT(x),RMAT(qr),RVEC(tau)) { | ||
475 | //REQUIRES(xr==rr && xc==rc && qr==qc && xr==qr,BAD_SIZE); | ||
476 | DEBUGMSG("QRpacked"); | ||
477 | KDMVIEW(x); | ||
478 | DMVIEW(qr); | ||
479 | DVVIEW(tau); | ||
480 | //gsl_matrix * a = gsl_matrix_alloc(xr,xc); | ||
481 | //gsl_vector * tau = gsl_vector_alloc(MIN(xr,xc)); | ||
482 | gsl_matrix_memcpy(M(qr),M(x)); | ||
483 | int res = gsl_linalg_QR_decomp(M(qr),V(tau)); | ||
484 | CHECK(res,res); | ||
485 | OK | ||
486 | } | ||
487 | |||
488 | |||
489 | int QRunpack(KRMAT(xqr),KRVEC(tau),RMAT(q),RMAT(r)) { | ||
490 | //REQUIRES(xr==rr && xc==rc && qr==qc && xr==qr,BAD_SIZE); | ||
491 | DEBUGMSG("QRunpack"); | ||
492 | KDMVIEW(xqr); | ||
493 | KDVVIEW(tau); | ||
494 | DMVIEW(q); | ||
495 | DMVIEW(r); | ||
496 | gsl_linalg_QR_unpack(M(xqr),V(tau),M(q),M(r)); | ||
497 | OK | ||
498 | } | ||
499 | |||
500 | |||
474 | int cholR(KRMAT(x),RMAT(l)) { | 501 | int cholR(KRMAT(x),RMAT(l)) { |
475 | REQUIRES(xr==xc && lr==xr && lr==lc,BAD_SIZE); | 502 | REQUIRES(xr==xc && lr==xr && lr==lc,BAD_SIZE); |
476 | DEBUGMSG("cholR"); | 503 | DEBUGMSG("cholR"); |
diff --git a/lib/Numeric/GSL/gsl-aux.h b/lib/Numeric/GSL/gsl-aux.h index 3ccac25..cf22024 100644 --- a/lib/Numeric/GSL/gsl-aux.h +++ b/lib/Numeric/GSL/gsl-aux.h | |||
@@ -38,6 +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 QRpacked(KRMAT(x),RMAT(qr),RVEC(tau)); | ||
42 | int QRunpack(KRMAT(qr),KRVEC(tau),RMAT(q),RMAT(r)); | ||
43 | |||
41 | int cholR(KRMAT(x),RMAT(l)); | 44 | int cholR(KRMAT(x),RMAT(l)); |
42 | 45 | ||
43 | int cholC(KCMAT(x),CMAT(l)); | 46 | int cholC(KCMAT(x),CMAT(l)); |