diff options
author | Alberto Ruiz <aruiz@um.es> | 2010-04-23 19:37:56 +0000 |
---|---|---|
committer | Alberto Ruiz <aruiz@um.es> | 2010-04-23 19:37:56 +0000 |
commit | 0ce6e74a5375b8d7ee1d95826252d8ff622f2cb4 (patch) | |
tree | cab666c674543adf0908ea5bc42ec9e9d35a9ea1 /lib/Numeric/LinearAlgebra | |
parent | f7cbac4bb8d8fc1c4210a548674c222b691f8e9c (diff) |
app5-10, some SCC, and other minor changes
Diffstat (limited to 'lib/Numeric/LinearAlgebra')
-rw-r--r-- | lib/Numeric/LinearAlgebra/Algorithms.hs | 44 | ||||
-rw-r--r-- | lib/Numeric/LinearAlgebra/LAPACK.hs | 1 | ||||
-rw-r--r-- | lib/Numeric/LinearAlgebra/Tests/Properties.hs | 2 |
3 files changed, 22 insertions, 25 deletions
diff --git a/lib/Numeric/LinearAlgebra/Algorithms.hs b/lib/Numeric/LinearAlgebra/Algorithms.hs index 60f5971..580f4bb 100644 --- a/lib/Numeric/LinearAlgebra/Algorithms.hs +++ b/lib/Numeric/LinearAlgebra/Algorithms.hs | |||
@@ -169,17 +169,17 @@ exactHermitian m = m `equal` ctrans m | |||
169 | 169 | ||
170 | -- | Full singular value decomposition. | 170 | -- | Full singular value decomposition. |
171 | svd :: Field t => Matrix t -> (Matrix t, Vector Double, Matrix t) | 171 | svd :: Field t => Matrix t -> (Matrix t, Vector Double, Matrix t) |
172 | svd = svd' | 172 | svd = {-# SCC "svd" #-} svd' |
173 | 173 | ||
174 | -- | A version of 'svd' which returns only the @min (rows m) (cols m)@ singular vectors of @m@. | 174 | -- | A version of 'svd' which returns only the @min (rows m) (cols m)@ singular vectors of @m@. |
175 | -- | 175 | -- |
176 | -- If @(u,s,v) = thinSVD m@ then @m == u \<> diag s \<> trans v@. | 176 | -- If @(u,s,v) = thinSVD m@ then @m == u \<> diag s \<> trans v@. |
177 | thinSVD :: Field t => Matrix t -> (Matrix t, Vector Double, Matrix t) | 177 | thinSVD :: Field t => Matrix t -> (Matrix t, Vector Double, Matrix t) |
178 | thinSVD = thinSVD' | 178 | thinSVD = {-# SCC "thinSVD" #-} thinSVD' |
179 | 179 | ||
180 | -- | Singular values only. | 180 | -- | Singular values only. |
181 | singularValues :: Field t => Matrix t -> Vector Double | 181 | singularValues :: Field t => Matrix t -> Vector Double |
182 | singularValues = sv' | 182 | singularValues = {-# SCC "singularValues" #-} sv' |
183 | 183 | ||
184 | -- | A version of 'svd' which returns an appropriate diagonal matrix with the singular values. | 184 | -- | A version of 'svd' which returns an appropriate diagonal matrix with the singular values. |
185 | -- | 185 | -- |
@@ -229,50 +229,50 @@ economy svdFun m = (u', subVector 0 d s, v') where | |||
229 | -------------------------------------------------------------- | 229 | -------------------------------------------------------------- |
230 | 230 | ||
231 | -- | Obtains the LU decomposition of a matrix in a compact data structure suitable for 'luSolve'. | 231 | -- | Obtains the LU decomposition of a matrix in a compact data structure suitable for 'luSolve'. |
232 | luPacked :: Field t => Matrix t -> (Matrix t, [Int]) | 232 | luPacked :: Field t => Matrix t -> (Matrix t, [Int]) |
233 | luPacked = luPacked' | 233 | luPacked = {-# SCC "luPacked" #-} luPacked' |
234 | 234 | ||
235 | -- | Solution of a linear system (for several right hand sides) from the precomputed LU factorization obtained by 'luPacked'. | 235 | -- | Solution of a linear system (for several right hand sides) from the precomputed LU factorization obtained by 'luPacked'. |
236 | luSolve :: Field t => (Matrix t, [Int]) -> Matrix t -> Matrix t | 236 | luSolve :: Field t => (Matrix t, [Int]) -> Matrix t -> Matrix t |
237 | luSolve = luSolve' | 237 | luSolve = {-# SCC "luSolve" #-} luSolve' |
238 | 238 | ||
239 | -- | Solve a linear system (for square coefficient matrix and several right-hand sides) using the LU decomposition. For underconstrained or overconstrained systems use 'linearSolveLS' or 'linearSolveSVD'. | 239 | -- | Solve a linear system (for square coefficient matrix and several right-hand sides) using the LU decomposition. For underconstrained or overconstrained systems use 'linearSolveLS' or 'linearSolveSVD'. |
240 | -- It is similar to 'luSolve' . 'luPacked', but @linearSolve@ raises an error if called on a singular system. | 240 | -- It is similar to 'luSolve' . 'luPacked', but @linearSolve@ raises an error if called on a singular system. |
241 | linearSolve :: Field t => Matrix t -> Matrix t -> Matrix t | 241 | linearSolve :: Field t => Matrix t -> Matrix t -> Matrix t |
242 | linearSolve = linearSolve' | 242 | linearSolve = {-# SCC "linearSolve" #-} linearSolve' |
243 | 243 | ||
244 | -- | Solve a symmetric or Hermitian positive definite linear system using a precomputed Cholesky decomposition obtained by 'chol'. | 244 | -- | Solve a symmetric or Hermitian positive definite linear system using a precomputed Cholesky decomposition obtained by 'chol'. |
245 | cholSolve :: Field t => Matrix t -> Matrix t -> Matrix t | 245 | cholSolve :: Field t => Matrix t -> Matrix t -> Matrix t |
246 | cholSolve = cholSolve' | 246 | cholSolve = {-# SCC "cholSolve" #-} cholSolve' |
247 | 247 | ||
248 | -- | Minimum norm solution of a general linear least squares problem Ax=B using the SVD. Admits rank-deficient systems but it is slower than 'linearSolveLS'. The effective rank of A is determined by treating as zero those singular valures which are less than 'eps' times the largest singular value. | 248 | -- | Minimum norm solution of a general linear least squares problem Ax=B using the SVD. Admits rank-deficient systems but it is slower than 'linearSolveLS'. The effective rank of A is determined by treating as zero those singular valures which are less than 'eps' times the largest singular value. |
249 | linearSolveSVD :: Field t => Matrix t -> Matrix t -> Matrix t | 249 | linearSolveSVD :: Field t => Matrix t -> Matrix t -> Matrix t |
250 | linearSolveSVD = linearSolveSVD' | 250 | linearSolveSVD = {-# SCC "linearSolveSVD" #-} linearSolveSVD' |
251 | 251 | ||
252 | 252 | ||
253 | -- | Least squared error solution of an overconstrained linear system, or the minimum norm solution of an underconstrained system. For rank-deficient systems use 'linearSolveSVD'. | 253 | -- | Least squared error solution of an overconstrained linear system, or the minimum norm solution of an underconstrained system. For rank-deficient systems use 'linearSolveSVD'. |
254 | linearSolveLS :: Field t => Matrix t -> Matrix t -> Matrix t | 254 | linearSolveLS :: Field t => Matrix t -> Matrix t -> Matrix t |
255 | linearSolveLS = linearSolveLS' | 255 | linearSolveLS = {-# SCC "linearSolveLS" #-} linearSolveLS' |
256 | 256 | ||
257 | -------------------------------------------------------------- | 257 | -------------------------------------------------------------- |
258 | 258 | ||
259 | -- | Eigenvalues and eigenvectors of a general square matrix. | 259 | -- | Eigenvalues and eigenvectors of a general square matrix. |
260 | -- | 260 | -- |
261 | -- If @(s,v) = eig m@ then @m \<> v == v \<> diag s@ | 261 | -- If @(s,v) = eig m@ then @m \<> v == v \<> diag s@ |
262 | eig :: Field t => Matrix t -> (Vector (Complex Double), Matrix (Complex Double)) | 262 | eig :: Field t => Matrix t -> (Vector (Complex Double), Matrix (Complex Double)) |
263 | eig = eig' | 263 | eig = {-# SCC "eig" #-} eig' |
264 | 264 | ||
265 | -- | Eigenvalues of a general square matrix. | 265 | -- | Eigenvalues of a general square matrix. |
266 | eigenvalues :: Field t => Matrix t -> Vector (Complex Double) | 266 | eigenvalues :: Field t => Matrix t -> Vector (Complex Double) |
267 | eigenvalues = eigOnly | 267 | eigenvalues = {-# SCC "eigenvalues" #-} eigOnly |
268 | 268 | ||
269 | -- | Similar to 'eigSH' without checking that the input matrix is hermitian or symmetric. It works with the upper triangular part. | 269 | -- | Similar to 'eigSH' without checking that the input matrix is hermitian or symmetric. It works with the upper triangular part. |
270 | eigSH' :: Field t => Matrix t -> (Vector Double, Matrix t) | 270 | eigSH' :: Field t => Matrix t -> (Vector Double, Matrix t) |
271 | eigSH' = eigSH'' | 271 | eigSH' = {-# SCC "eigSH'" #-} eigSH'' |
272 | 272 | ||
273 | -- | Similar to 'eigenvaluesSH' without checking that the input matrix is hermitian or symmetric. It works with the upper triangular part. | 273 | -- | Similar to 'eigenvaluesSH' without checking that the input matrix is hermitian or symmetric. It works with the upper triangular part. |
274 | eigenvaluesSH' :: Field t => Matrix t -> Vector Double | 274 | eigenvaluesSH' :: Field t => Matrix t -> Vector Double |
275 | eigenvaluesSH' = eigOnlySH | 275 | eigenvaluesSH' = {-# SCC "eigenvaluesSH'" #-} eigOnlySH |
276 | 276 | ||
277 | -- | Eigenvalues and Eigenvectors of a complex hermitian or real symmetric matrix. | 277 | -- | Eigenvalues and Eigenvectors of a complex hermitian or real symmetric matrix. |
278 | -- | 278 | -- |
@@ -291,14 +291,14 @@ eigenvaluesSH m | exactHermitian m = eigenvaluesSH' m | |||
291 | -- | QR factorization. | 291 | -- | QR factorization. |
292 | -- | 292 | -- |
293 | -- If @(q,r) = qr m@ then @m == q \<> r@, where q is unitary and r is upper triangular. | 293 | -- If @(q,r) = qr m@ then @m == q \<> r@, where q is unitary and r is upper triangular. |
294 | qr :: Field t => Matrix t -> (Matrix t, Matrix t) | 294 | qr :: Field t => Matrix t -> (Matrix t, Matrix t) |
295 | qr = qr' | 295 | qr = {-# SCC "qr" #-} qr' |
296 | 296 | ||
297 | -- | RQ factorization. | 297 | -- | RQ factorization. |
298 | -- | 298 | -- |
299 | -- If @(r,q) = rq m@ then @m == r \<> q@, where q is unitary and r is upper triangular. | 299 | -- If @(r,q) = rq m@ then @m == r \<> q@, where q is unitary and r is upper triangular. |
300 | rq :: Field t => Matrix t -> (Matrix t, Matrix t) | 300 | rq :: Field t => Matrix t -> (Matrix t, Matrix t) |
301 | rq m = (r,q) where | 301 | rq m = {-# SCC "rq" #-} (r,q) where |
302 | (q',r') = qr $ trans $ rev1 m | 302 | (q',r') = qr $ trans $ rev1 m |
303 | r = rev2 (trans r') | 303 | r = rev2 (trans r') |
304 | q = rev2 (trans q') | 304 | q = rev2 (trans q') |
@@ -474,8 +474,6 @@ nullspaceSVD :: Field t | |||
474 | -> (Vector Double, Matrix t) -- ^ 'rightSV' of m | 474 | -> (Vector Double, Matrix t) -- ^ 'rightSV' of m |
475 | -> [Vector t] -- ^ list of unitary vectors spanning the nullspace | 475 | -> [Vector t] -- ^ list of unitary vectors spanning the nullspace |
476 | nullspaceSVD hint a (s,v) = vs where | 476 | nullspaceSVD hint a (s,v) = vs where |
477 | r = rows a | ||
478 | c = cols a | ||
479 | tol = case hint of | 477 | tol = case hint of |
480 | Left t -> t | 478 | Left t -> t |
481 | _ -> eps | 479 | _ -> eps |
@@ -546,7 +544,7 @@ zt k v = join [subVector 0 (dim v - k) v, constant 0 k] | |||
546 | 544 | ||
547 | 545 | ||
548 | unpackQR :: (Field t) => (Matrix t, Vector t) -> (Matrix t, Matrix t) | 546 | unpackQR :: (Field t) => (Matrix t, Vector t) -> (Matrix t, Matrix t) |
549 | unpackQR (pq, tau) = (q,r) | 547 | unpackQR (pq, tau) = {-# SCC "unpackQR" #-} (q,r) |
550 | where cs = toColumns pq | 548 | where cs = toColumns pq |
551 | m = rows pq | 549 | m = rows pq |
552 | n = cols pq | 550 | n = cols pq |
diff --git a/lib/Numeric/LinearAlgebra/LAPACK.hs b/lib/Numeric/LinearAlgebra/LAPACK.hs index 539ffb9..f5af8be 100644 --- a/lib/Numeric/LinearAlgebra/LAPACK.hs +++ b/lib/Numeric/LinearAlgebra/LAPACK.hs | |||
@@ -237,7 +237,6 @@ eigR m = (s', v'') | |||
237 | s' = fixeig1 s | 237 | s' = fixeig1 s |
238 | v' = toRows $ trans v | 238 | v' = toRows $ trans v |
239 | v'' = fromColumns $ fixeig (toList s') v' | 239 | v'' = fromColumns $ fixeig (toList s') v' |
240 | r = rows m | ||
241 | 240 | ||
242 | eigRaux :: Matrix Double -> (Vector (Complex Double), Matrix Double) | 241 | eigRaux :: Matrix Double -> (Vector (Complex Double), Matrix Double) |
243 | eigRaux m = unsafePerformIO $ do | 242 | eigRaux m = unsafePerformIO $ do |
diff --git a/lib/Numeric/LinearAlgebra/Tests/Properties.hs b/lib/Numeric/LinearAlgebra/Tests/Properties.hs index 618094b..d29e19a 100644 --- a/lib/Numeric/LinearAlgebra/Tests/Properties.hs +++ b/lib/Numeric/LinearAlgebra/Tests/Properties.hs | |||
@@ -185,7 +185,7 @@ svdProp6b m = s |~| s' && v |~| v' && s |~| s'' && u |~| u' | |||
185 | svdProp7 m = s |~| s' && u |~| u' && v |~| v' && s |~| s''' | 185 | svdProp7 m = s |~| s' && u |~| u' && v |~| v' && s |~| s''' |
186 | where (u,s,v) = svd m | 186 | where (u,s,v) = svd m |
187 | (s',v') = rightSV m | 187 | (s',v') = rightSV m |
188 | (u',s'') = leftSV m | 188 | (u',_s'') = leftSV m |
189 | s''' = singularValues m | 189 | s''' = singularValues m |
190 | 190 | ||
191 | ------------------------------------------------------------------ | 191 | ------------------------------------------------------------------ |