summaryrefslogtreecommitdiff
path: root/lib/Numeric
diff options
context:
space:
mode:
authorAlberto Ruiz <aruiz@um.es>2007-10-27 08:53:15 +0000
committerAlberto Ruiz <aruiz@um.es>2007-10-27 08:53:15 +0000
commitff177d3298f4458503e9485596559c7d74048769 (patch)
tree43f844f468ebd56c290ac59d17ed3438648ed09e /lib/Numeric
parent71320675021472b2f97191ba514c651ceb8a1617 (diff)
added doc
Diffstat (limited to 'lib/Numeric')
-rw-r--r--lib/Numeric/LinearAlgebra/Algorithms.hs31
-rw-r--r--lib/Numeric/LinearAlgebra/LAPACK/lapack-aux.c4
2 files changed, 30 insertions, 5 deletions
diff --git a/lib/Numeric/LinearAlgebra/Algorithms.hs b/lib/Numeric/LinearAlgebra/Algorithms.hs
index 7f8e84c..9395176 100644
--- a/lib/Numeric/LinearAlgebra/Algorithms.hs
+++ b/lib/Numeric/LinearAlgebra/Algorithms.hs
@@ -46,9 +46,9 @@ module Numeric.LinearAlgebra.Algorithms (
46 ctrans, 46 ctrans,
47 eps, i, 47 eps, i,
48-- * Util 48-- * Util
49 GenMat(linearSolveSVD,lu,eigSH',cholSH),
50 haussholder, 49 haussholder,
51 unpackQR, unpackHess 50 unpackQR, unpackHess,
51 GenMat(linearSolveSVD,lu,eigSH',cholSH)
52) where 52) where
53 53
54 54
@@ -71,6 +71,7 @@ class (Linear Matrix t) => GenMat t where
71 linearSolve :: Matrix t -> Matrix t -> Matrix t 71 linearSolve :: Matrix t -> Matrix t -> Matrix t
72 linearSolveSVD :: Matrix t -> Matrix t -> Matrix t 72 linearSolveSVD :: Matrix t -> Matrix t -> Matrix t
73 -- | Eigenvalues and eigenvectors of a general square matrix using lapack's dgeev or zgeev. 73 -- | Eigenvalues and eigenvectors of a general square matrix using lapack's dgeev or zgeev.
74 --
74 -- If @(s,v) = eig m@ then @m \<> v == v \<> diag s@ 75 -- If @(s,v) = eig m@ then @m \<> v == v \<> diag s@
75 eig :: Matrix t -> (Vector (Complex Double), Matrix (Complex Double)) 76 eig :: Matrix t -> (Vector (Complex Double), Matrix (Complex Double))
76 -- | Similar to eigSH without checking that the input matrix is hermitian or symmetric. 77 -- | Similar to eigSH without checking that the input matrix is hermitian or symmetric.
@@ -78,10 +79,22 @@ class (Linear Matrix t) => GenMat t where
78 -- | Similar to chol without checking that the input matrix is hermitian or symmetric. 79 -- | Similar to chol without checking that the input matrix is hermitian or symmetric.
79 cholSH :: Matrix t -> Matrix t 80 cholSH :: Matrix t -> Matrix t
80 -- | QR factorization using lapack's dgeqr2 or zgeqr2. 81 -- | QR factorization using lapack's dgeqr2 or zgeqr2.
82 --
83 -- If @(q,r) = qr m@ then @m == q \<> r@, where q is unitary and r is upper triangular.
81 qr :: Matrix t -> (Matrix t, Matrix t) 84 qr :: Matrix t -> (Matrix t, Matrix t)
82 -- | Hessenberg factorization using lapack's dgehrd or zgehrd. 85 -- | Hessenberg factorization using lapack's dgehrd or zgehrd.
86 --
87 -- If @(p,h) = hess m@ then @m == p \<> h \<> ctrans p@, where p is unitary
88 -- and h is in upper Hessenberg form.
83 hess :: Matrix t -> (Matrix t, Matrix t) 89 hess :: Matrix t -> (Matrix t, Matrix t)
84 -- | Schur factorization using lapack's dgees or zgees. 90 -- | Schur factorization using lapack's dgees or zgees.
91 --
92 -- If @(u,s) = schur m@ then @m == u \<> s \<> ctrans u@, where u is unitary
93 -- and s is a Shur matrix. A complex Schur matrix is upper triangular. A real Schur matrix is
94 -- upper triangular in 2x2 blocks.
95 --
96 -- \"Anything that the Jordan decomposition can do, the Schur decomposition
97 -- can do better!\" (Van Loan)
85 schur :: Matrix t -> (Matrix t, Matrix t) 98 schur :: Matrix t -> (Matrix t, Matrix t)
86 -- | Conjugate transpose. 99 -- | Conjugate transpose.
87 ctrans :: Matrix t -> Matrix t 100 ctrans :: Matrix t -> Matrix t
@@ -112,12 +125,16 @@ instance GenMat (Complex Double) where
112 hess = unpackHess hessC 125 hess = unpackHess hessC
113 schur = schurC 126 schur = schurC
114 127
115-- | Eigenvalues and Eigenvectors of a complex hermitian or real symmetric matrix using lapack's dsyev or zheev. If @(s,v) = eigSH m@ then @m == v \<> diag s \<> ctrans v@ 128-- | Eigenvalues and Eigenvectors of a complex hermitian or real symmetric matrix using lapack's dsyev or zheev.
129--
130-- If @(s,v) = eigSH m@ then @m == v \<> diag s \<> ctrans v@
116eigSH :: GenMat t => Matrix t -> (Vector Double, Matrix t) 131eigSH :: GenMat t => Matrix t -> (Vector Double, Matrix t)
117eigSH m | m `equal` ctrans m = eigSH' m 132eigSH m | m `equal` ctrans m = eigSH' m
118 | otherwise = error "eigSH requires complex hermitian or real symmetric matrix" 133 | otherwise = error "eigSH requires complex hermitian or real symmetric matrix"
119 134
120-- | Cholesky factorization of a positive definite hermitian or symmetric matrix using lapack's dpotrf or zportrf. 135-- | Cholesky factorization of a positive definite hermitian or symmetric matrix using lapack's dpotrf or zportrf.
136--
137-- If @c = chol m@ then @m == c \<> ctrans c@.
121chol :: GenMat t => Matrix t -> Matrix t 138chol :: GenMat t => Matrix t -> Matrix t
122chol m | m `equal` ctrans m = cholSH m 139chol m | m `equal` ctrans m = cholSH m
123 | otherwise = error "chol requires positive definite complex hermitian or real symmetric matrix" 140 | otherwise = error "chol requires positive definite complex hermitian or real symmetric matrix"
@@ -138,7 +155,9 @@ inv m | square m = m `linearSolve` ident (rows m)
138pinv :: GenMat t => Matrix t -> Matrix t 155pinv :: GenMat t => Matrix t -> Matrix t
139pinv m = linearSolveSVD m (ident (rows m)) 156pinv m = linearSolveSVD m (ident (rows m))
140 157
141-- | A version of 'svd' which returns an appropriate diagonal matrix with the singular values: if @(u,d,v) = full svd m@ then @m == u \<> d \<> trans v@. 158-- | A version of 'svd' which returns an appropriate diagonal matrix with the singular values.
159--
160-- If @(u,d,v) = full svd m@ then @m == u \<> d \<> trans v@.
142full :: Field t 161full :: Field t
143 => (Matrix t -> (Matrix t, Vector Double, Matrix t)) -> Matrix t -> (Matrix t, Matrix Double, Matrix t) 162 => (Matrix t -> (Matrix t, Vector Double, Matrix t)) -> Matrix t -> (Matrix t, Matrix Double, Matrix t)
144full svd m = (u, d ,v) where 163full svd m = (u, d ,v) where
@@ -147,7 +166,9 @@ full svd m = (u, d ,v) where
147 r = rows m 166 r = rows m
148 c = cols m 167 c = cols m
149 168
150-- | A version of 'svd' which returns only the nonzero singular values and the corresponding rows and columns of the rotations: if @(u,s,v) = economy svd m@ then @m == u \<> diag s \<> trans v@. 169-- | A version of 'svd' which returns only the nonzero singular values and the corresponding rows and columns of the rotations.
170--
171-- If @(u,s,v) = economy svd m@ then @m == u \<> diag s \<> trans v@.
151economy :: Field t 172economy :: Field t
152 => (Matrix t -> (Matrix t, Vector Double, Matrix t)) -> Matrix t -> (Matrix t, Vector Double, Matrix t) 173 => (Matrix t -> (Matrix t, Vector Double, Matrix t)) -> Matrix t -> (Matrix t, Vector Double, Matrix t)
153economy svd m = (u', subVector 0 d s, v') where 174economy svd m = (u', subVector 0 d s, v') where
diff --git a/lib/Numeric/LinearAlgebra/LAPACK/lapack-aux.c b/lib/Numeric/LinearAlgebra/LAPACK/lapack-aux.c
index cab3f5b..058232c 100644
--- a/lib/Numeric/LinearAlgebra/LAPACK/lapack-aux.c
+++ b/lib/Numeric/LinearAlgebra/LAPACK/lapack-aux.c
@@ -728,6 +728,9 @@ int schur_l_R(KDMAT(a), DMAT(u), DMAT(s)) {
728} 728}
729 729
730int schur_l_C(KCMAT(a), CMAT(u), CMAT(s)) { 730int schur_l_C(KCMAT(a), CMAT(u), CMAT(s)) {
731 #ifdef _WIN32
732 return NOSPRTD;
733 #else
731 integer m = ar; 734 integer m = ar;
732 integer n = ac; 735 integer n = ac;
733 REQUIRES(m>=1 && n==m && ur==n && uc==n && sr==n && sc==n, BAD_SIZE); 736 REQUIRES(m>=1 && n==m && ur==n && uc==n && sr==n && sc==n, BAD_SIZE);
@@ -749,4 +752,5 @@ int schur_l_C(KCMAT(a), CMAT(u), CMAT(s)) {
749 free(BWORK); 752 free(BWORK);
750 free(WORK); 753 free(WORK);
751 OK 754 OK
755 #endif
752} 756}