diff options
author | Alberto Ruiz <aruiz@um.es> | 2010-01-18 08:54:22 +0000 |
---|---|---|
committer | Alberto Ruiz <aruiz@um.es> | 2010-01-18 08:54:22 +0000 |
commit | 830164c7c34d874aa66754206be956f85456842f (patch) | |
tree | 8ddc23931a05b5d479187e3c61c2d84711f0be63 /lib/Numeric/LinearAlgebra/Algorithms.hs | |
parent | 3fb3a81e63540497a81b717c615f711ce031c76f (diff) |
scalar moved to Linear and equal used for ==
Diffstat (limited to 'lib/Numeric/LinearAlgebra/Algorithms.hs')
-rw-r--r-- | lib/Numeric/LinearAlgebra/Algorithms.hs | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/lib/Numeric/LinearAlgebra/Algorithms.hs b/lib/Numeric/LinearAlgebra/Algorithms.hs index de88dd9..51e0922 100644 --- a/lib/Numeric/LinearAlgebra/Algorithms.hs +++ b/lib/Numeric/LinearAlgebra/Algorithms.hs | |||
@@ -147,6 +147,14 @@ instance Field (Complex Double) where | |||
147 | 147 | ||
148 | -------------------------------------------------------------- | 148 | -------------------------------------------------------------- |
149 | 149 | ||
150 | square m = rows m == cols m | ||
151 | |||
152 | vertical m = rows m >= cols m | ||
153 | |||
154 | exactHermitian m = m `equal` ctrans m | ||
155 | |||
156 | -------------------------------------------------------------- | ||
157 | |||
150 | -- | Full singular value decomposition. | 158 | -- | Full singular value decomposition. |
151 | svd :: Field t => Matrix t -> (Matrix t, Vector Double, Matrix t) | 159 | svd :: Field t => Matrix t -> (Matrix t, Vector Double, Matrix t) |
152 | svd = svd' | 160 | svd = svd' |
@@ -179,7 +187,6 @@ compactSVD m = (u', subVector 0 d s, v') where | |||
179 | u' = takeColumns d u | 187 | u' = takeColumns d u |
180 | v' = takeColumns d v | 188 | v' = takeColumns d v |
181 | 189 | ||
182 | vertical m = rows m >= cols m | ||
183 | 190 | ||
184 | -- | Singular values and all right singular vectors. | 191 | -- | Singular values and all right singular vectors. |
185 | rightSV :: Field t => Matrix t -> (Vector Double, Matrix t) | 192 | rightSV :: Field t => Matrix t -> (Vector Double, Matrix t) |
@@ -255,12 +262,12 @@ eigenvaluesSH' = eigOnlySH | |||
255 | -- | 262 | -- |
256 | -- If @(s,v) = eigSH m@ then @m == v \<> diag s \<> ctrans v@ | 263 | -- If @(s,v) = eigSH m@ then @m == v \<> diag s \<> ctrans v@ |
257 | eigSH :: Field t => Matrix t -> (Vector Double, Matrix t) | 264 | eigSH :: Field t => Matrix t -> (Vector Double, Matrix t) |
258 | eigSH m | m `equal` ctrans m = eigSH' m | 265 | eigSH m | exactHermitian m = eigSH' m |
259 | | otherwise = error "eigSH requires complex hermitian or real symmetric matrix" | 266 | | otherwise = error "eigSH requires complex hermitian or real symmetric matrix" |
260 | 267 | ||
261 | -- | Eigenvalues of a complex hermitian or real symmetric matrix. | 268 | -- | Eigenvalues of a complex hermitian or real symmetric matrix. |
262 | eigenvaluesSH :: Field t => Matrix t -> Vector Double | 269 | eigenvaluesSH :: Field t => Matrix t -> Vector Double |
263 | eigenvaluesSH m | m `equal` ctrans m = eigenvaluesSH' m | 270 | eigenvaluesSH m | exactHermitian m = eigenvaluesSH' m |
264 | | otherwise = error "eigenvaluesSH requires complex hermitian or real symmetric matrix" | 271 | | otherwise = error "eigenvaluesSH requires complex hermitian or real symmetric matrix" |
265 | 272 | ||
266 | -------------------------------------------------------------- | 273 | -------------------------------------------------------------- |
@@ -317,14 +324,12 @@ cholSH = cholSH' | |||
317 | -- | 324 | -- |
318 | -- If @c = chol m@ then @m == ctrans c \<> c@. | 325 | -- If @c = chol m@ then @m == ctrans c \<> c@. |
319 | chol :: Field t => Matrix t -> Matrix t | 326 | chol :: Field t => Matrix t -> Matrix t |
320 | chol m | m `equal` ctrans m = cholSH m | 327 | chol m | exactHermitian m = cholSH m |
321 | | otherwise = error "chol requires positive definite complex hermitian or real symmetric matrix" | 328 | | otherwise = error "chol requires positive definite complex hermitian or real symmetric matrix" |
322 | 329 | ||
323 | 330 | ||
324 | 331 | ||
325 | 332 | ||
326 | square m = rows m == cols m | ||
327 | |||
328 | -- | Determinant of a square matrix. | 333 | -- | Determinant of a square matrix. |
329 | det :: Field t => Matrix t -> t | 334 | det :: Field t => Matrix t -> t |
330 | det m | square m = s * (product $ toList $ takeDiag $ lup) | 335 | det m | square m = s * (product $ toList $ takeDiag $ lup) |
@@ -569,7 +574,7 @@ diagonalize m = if rank v == n | |||
569 | then Just (l,v) | 574 | then Just (l,v) |
570 | else Nothing | 575 | else Nothing |
571 | where n = rows m | 576 | where n = rows m |
572 | (l,v) = if m `equal` ctrans m | 577 | (l,v) = if exactHermitian m |
573 | then let (l',v') = eigSH m in (real l', v') | 578 | then let (l',v') = eigSH m in (real l', v') |
574 | else eig m | 579 | else eig m |
575 | 580 | ||