summaryrefslogtreecommitdiff
path: root/lib/Numeric/LinearAlgebra
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Numeric/LinearAlgebra')
-rw-r--r--lib/Numeric/LinearAlgebra/Algorithms.hs44
-rw-r--r--lib/Numeric/LinearAlgebra/LAPACK.hs1
-rw-r--r--lib/Numeric/LinearAlgebra/Tests/Properties.hs2
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.
171svd :: Field t => Matrix t -> (Matrix t, Vector Double, Matrix t) 171svd :: Field t => Matrix t -> (Matrix t, Vector Double, Matrix t)
172svd = svd' 172svd = {-# 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@.
177thinSVD :: Field t => Matrix t -> (Matrix t, Vector Double, Matrix t) 177thinSVD :: Field t => Matrix t -> (Matrix t, Vector Double, Matrix t)
178thinSVD = thinSVD' 178thinSVD = {-# SCC "thinSVD" #-} thinSVD'
179 179
180-- | Singular values only. 180-- | Singular values only.
181singularValues :: Field t => Matrix t -> Vector Double 181singularValues :: Field t => Matrix t -> Vector Double
182singularValues = sv' 182singularValues = {-# 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'.
232luPacked :: Field t => Matrix t -> (Matrix t, [Int]) 232luPacked :: Field t => Matrix t -> (Matrix t, [Int])
233luPacked = luPacked' 233luPacked = {-# 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'.
236luSolve :: Field t => (Matrix t, [Int]) -> Matrix t -> Matrix t 236luSolve :: Field t => (Matrix t, [Int]) -> Matrix t -> Matrix t
237luSolve = luSolve' 237luSolve = {-# 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.
241linearSolve :: Field t => Matrix t -> Matrix t -> Matrix t 241linearSolve :: Field t => Matrix t -> Matrix t -> Matrix t
242linearSolve = linearSolve' 242linearSolve = {-# 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'.
245cholSolve :: Field t => Matrix t -> Matrix t -> Matrix t 245cholSolve :: Field t => Matrix t -> Matrix t -> Matrix t
246cholSolve = cholSolve' 246cholSolve = {-# 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.
249linearSolveSVD :: Field t => Matrix t -> Matrix t -> Matrix t 249linearSolveSVD :: Field t => Matrix t -> Matrix t -> Matrix t
250linearSolveSVD = linearSolveSVD' 250linearSolveSVD = {-# 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'.
254linearSolveLS :: Field t => Matrix t -> Matrix t -> Matrix t 254linearSolveLS :: Field t => Matrix t -> Matrix t -> Matrix t
255linearSolveLS = linearSolveLS' 255linearSolveLS = {-# 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@
262eig :: Field t => Matrix t -> (Vector (Complex Double), Matrix (Complex Double)) 262eig :: Field t => Matrix t -> (Vector (Complex Double), Matrix (Complex Double))
263eig = eig' 263eig = {-# SCC "eig" #-} eig'
264 264
265-- | Eigenvalues of a general square matrix. 265-- | Eigenvalues of a general square matrix.
266eigenvalues :: Field t => Matrix t -> Vector (Complex Double) 266eigenvalues :: Field t => Matrix t -> Vector (Complex Double)
267eigenvalues = eigOnly 267eigenvalues = {-# 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.
270eigSH' :: Field t => Matrix t -> (Vector Double, Matrix t) 270eigSH' :: Field t => Matrix t -> (Vector Double, Matrix t)
271eigSH' = eigSH'' 271eigSH' = {-# 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.
274eigenvaluesSH' :: Field t => Matrix t -> Vector Double 274eigenvaluesSH' :: Field t => Matrix t -> Vector Double
275eigenvaluesSH' = eigOnlySH 275eigenvaluesSH' = {-# 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.
294qr :: Field t => Matrix t -> (Matrix t, Matrix t) 294qr :: Field t => Matrix t -> (Matrix t, Matrix t)
295qr = qr' 295qr = {-# 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.
300rq :: Field t => Matrix t -> (Matrix t, Matrix t) 300rq :: Field t => Matrix t -> (Matrix t, Matrix t)
301rq m = (r,q) where 301rq 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
476nullspaceSVD hint a (s,v) = vs where 476nullspaceSVD 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
548unpackQR :: (Field t) => (Matrix t, Vector t) -> (Matrix t, Matrix t) 546unpackQR :: (Field t) => (Matrix t, Vector t) -> (Matrix t, Matrix t)
549unpackQR (pq, tau) = (q,r) 547unpackQR (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
242eigRaux :: Matrix Double -> (Vector (Complex Double), Matrix Double) 241eigRaux :: Matrix Double -> (Vector (Complex Double), Matrix Double)
243eigRaux m = unsafePerformIO $ do 242eigRaux 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'
185svdProp7 m = s |~| s' && u |~| u' && v |~| v' && s |~| s''' 185svdProp7 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------------------------------------------------------------------