diff options
Diffstat (limited to 'packages/base/src/Internal/Algorithms.hs')
-rw-r--r-- | packages/base/src/Internal/Algorithms.hs | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/packages/base/src/Internal/Algorithms.hs b/packages/base/src/Internal/Algorithms.hs index 6027c46..f5bddc6 100644 --- a/packages/base/src/Internal/Algorithms.hs +++ b/packages/base/src/Internal/Algorithms.hs | |||
@@ -70,8 +70,10 @@ class (Numeric t, | |||
70 | linearSolveSVD' :: Matrix t -> Matrix t -> Matrix t | 70 | linearSolveSVD' :: Matrix t -> Matrix t -> Matrix t |
71 | linearSolveLS' :: Matrix t -> Matrix t -> Matrix t | 71 | linearSolveLS' :: Matrix t -> Matrix t -> Matrix t |
72 | eig' :: Matrix t -> (Vector (Complex Double), Matrix (Complex Double)) | 72 | eig' :: Matrix t -> (Vector (Complex Double), Matrix (Complex Double)) |
73 | geig' :: Matrix t -> Matrix t -> (Vector (Complex Double), Vector t, Matrix (Complex Double)) | ||
73 | eigSH'' :: Matrix t -> (Vector Double, Matrix t) | 74 | eigSH'' :: Matrix t -> (Vector Double, Matrix t) |
74 | eigOnly :: Matrix t -> Vector (Complex Double) | 75 | eigOnly :: Matrix t -> Vector (Complex Double) |
76 | geigOnly :: Matrix t -> Matrix t -> (Vector (Complex Double), Vector t) | ||
75 | eigOnlySH :: Matrix t -> Vector Double | 77 | eigOnlySH :: Matrix t -> Vector Double |
76 | cholSH' :: Matrix t -> Matrix t | 78 | cholSH' :: Matrix t -> Matrix t |
77 | mbCholSH' :: Matrix t -> Maybe (Matrix t) | 79 | mbCholSH' :: Matrix t -> Maybe (Matrix t) |
@@ -96,7 +98,9 @@ instance Field Double where | |||
96 | linearSolveSVD' = linearSolveSVDR Nothing | 98 | linearSolveSVD' = linearSolveSVDR Nothing |
97 | eig' = eigR | 99 | eig' = eigR |
98 | eigSH'' = eigS | 100 | eigSH'' = eigS |
101 | geig' = eigG | ||
99 | eigOnly = eigOnlyR | 102 | eigOnly = eigOnlyR |
103 | geigOnly = eigOnlyG | ||
100 | eigOnlySH = eigOnlyS | 104 | eigOnlySH = eigOnlyS |
101 | cholSH' = cholS | 105 | cholSH' = cholS |
102 | mbCholSH' = mbCholS | 106 | mbCholSH' = mbCholS |
@@ -126,7 +130,9 @@ instance Field (Complex Double) where | |||
126 | linearSolveLS' = linearSolveLSC | 130 | linearSolveLS' = linearSolveLSC |
127 | linearSolveSVD' = linearSolveSVDC Nothing | 131 | linearSolveSVD' = linearSolveSVDC Nothing |
128 | eig' = eigC | 132 | eig' = eigC |
133 | geig' = eigGC | ||
129 | eigOnly = eigOnlyC | 134 | eigOnly = eigOnlyC |
135 | geigOnly = eigOnlyGC | ||
130 | eigSH'' = eigH | 136 | eigSH'' = eigH |
131 | eigOnlySH = eigOnlyH | 137 | eigOnlySH = eigOnlyH |
132 | cholSH' = cholH | 138 | cholSH' = cholH |
@@ -512,10 +518,25 @@ a = (3><3) | |||
512 | eig :: Field t => Matrix t -> (Vector (Complex Double), Matrix (Complex Double)) | 518 | eig :: Field t => Matrix t -> (Vector (Complex Double), Matrix (Complex Double)) |
513 | eig = {-# SCC "eig" #-} eig' | 519 | eig = {-# SCC "eig" #-} eig' |
514 | 520 | ||
521 | -- | Generalized eigenvalues (not ordered) and eigenvectors (as columns) of a pair of nonsymmetric matrices. | ||
522 | -- Eigenvalues are represented as pairs of alpha, beta, where eigenvalue = alpha / beta. Alpha is always | ||
523 | -- complex, but betas has the same type as the input matrix. | ||
524 | -- | ||
525 | -- If @(alphas, betas, v) = geig a b@, then @a \<> v == b \<> v \<> diag (alphas / betas)@ | ||
526 | -- | ||
527 | -- Note that beta can be 0 and that has reasonable interpretation. | ||
528 | geig :: Field t => Matrix t -> Matrix t -> (Vector (Complex Double), Vector t, Matrix (Complex Double)) | ||
529 | geig = {-# SCC "geig" #-} geig' | ||
530 | |||
515 | -- | Eigenvalues (not ordered) of a general square matrix. | 531 | -- | Eigenvalues (not ordered) of a general square matrix. |
516 | eigenvalues :: Field t => Matrix t -> Vector (Complex Double) | 532 | eigenvalues :: Field t => Matrix t -> Vector (Complex Double) |
517 | eigenvalues = {-# SCC "eigenvalues" #-} eigOnly | 533 | eigenvalues = {-# SCC "eigenvalues" #-} eigOnly |
518 | 534 | ||
535 | -- | Generalized eigenvalues of a pair of matrices. Represented as pairs of alpha, beta, | ||
536 | -- where eigenvalue is alpha / beta as in 'geig'. | ||
537 | geigenvalues :: Field t => Matrix t -> Matrix t -> (Vector (Complex Double), Vector t) | ||
538 | geigenvalues = {-# SCC "geigenvalues" #-} geigOnly | ||
539 | |||
519 | -- | Similar to 'eigSH' without checking that the input matrix is hermitian or symmetric. It works with the upper triangular part. | 540 | -- | Similar to 'eigSH' without checking that the input matrix is hermitian or symmetric. It works with the upper triangular part. |
520 | eigSH' :: Field t => Matrix t -> (Vector Double, Matrix t) | 541 | eigSH' :: Field t => Matrix t -> (Vector Double, Matrix t) |
521 | eigSH' = {-# SCC "eigSH'" #-} eigSH'' | 542 | eigSH' = {-# SCC "eigSH'" #-} eigSH'' |