summaryrefslogtreecommitdiff
path: root/lib/Numeric/GSL
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Numeric/GSL')
-rw-r--r--lib/Numeric/GSL/Matrix.hs26
-rw-r--r--lib/Numeric/GSL/Vector.hs1
-rw-r--r--lib/Numeric/GSL/gsl-aux.c27
-rw-r--r--lib/Numeric/GSL/gsl-aux.h3
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 @@
16module Numeric.GSL.Matrix( 16module 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
150foreign import ccall "gsl-aux.h QR" c_qr :: TMMM 150foreign import ccall "gsl-aux.h QR" c_qr :: TMMM
151 151
152qrPacked :: Matrix Double -> (Matrix Double, Vector Double)
153qrPacked 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
160foreign import ccall "gsl-aux.h QRpacked" c_qrPacked :: TMMV
161
162unpackQR :: (Matrix Double, Vector Double) -> (Matrix Double, Matrix Double)
163unpackQR (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
170foreign import ccall "gsl-aux.h QRunpack" c_qrUnpack :: TMVMM
171
172
173type TMMV = Int -> Int -> PD -> TMV
174type 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
17module Numeric.GSL.Vector ( 16module 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
474int 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
489int 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
474int cholR(KRMAT(x),RMAT(l)) { 501int 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
39int QR(KRMAT(x),RMAT(q),RMAT(r)); 39int QR(KRMAT(x),RMAT(q),RMAT(r));
40 40
41int QRpacked(KRMAT(x),RMAT(qr),RVEC(tau));
42int QRunpack(KRMAT(qr),KRVEC(tau),RMAT(q),RMAT(r));
43
41int cholR(KRMAT(x),RMAT(l)); 44int cholR(KRMAT(x),RMAT(l));
42 45
43int cholC(KCMAT(x),CMAT(l)); 46int cholC(KCMAT(x),CMAT(l));