diff options
Diffstat (limited to 'packages/base/src/Internal/Algorithms.hs')
-rw-r--r-- | packages/base/src/Internal/Algorithms.hs | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/packages/base/src/Internal/Algorithms.hs b/packages/base/src/Internal/Algorithms.hs index d2f17f4..ee3ddff 100644 --- a/packages/base/src/Internal/Algorithms.hs +++ b/packages/base/src/Internal/Algorithms.hs | |||
@@ -470,17 +470,25 @@ eigenvaluesSH (Her m) = eigenvaluesSH' m | |||
470 | 470 | ||
471 | -------------------------------------------------------------- | 471 | -------------------------------------------------------------- |
472 | 472 | ||
473 | -- | QR decomposition of a matrix in compact form. (The orthogonal matrix is not explicitly formed.) | ||
474 | data QR t = QR (Matrix t) (Vector t) | ||
475 | |||
473 | -- | QR factorization. | 476 | -- | QR factorization. |
474 | -- | 477 | -- |
475 | -- If @(q,r) = qr m@ then @m == q \<> r@, where q is unitary and r is upper triangular. | 478 | -- If @(q,r) = qr m@ then @m == q \<> r@, where q is unitary and r is upper triangular. |
476 | qr :: Field t => Matrix t -> (Matrix t, Matrix t) | 479 | qr :: Field t => Matrix t -> (Matrix t, Matrix t) |
477 | qr = {-# SCC "qr" #-} unpackQR . qr' | 480 | qr = {-# SCC "qr" #-} unpackQR . qr' |
478 | 481 | ||
479 | qrRaw m = qr' m | 482 | -- | Compute the QR decomposition of a matrix in compact form. |
483 | qrRaw :: Field t => Matrix t -> QR t | ||
484 | qrRaw m = QR x v | ||
485 | where | ||
486 | (x,v) = qr' m | ||
480 | 487 | ||
481 | {- | generate a matrix with k orthogonal columns from the output of qrRaw | 488 | -- | generate a matrix with k orthogonal columns from the compact QR decomposition obtained by 'qrRaw'. |
482 | -} | 489 | -- |
483 | qrgr n (a,t) | 490 | qrgr :: Field t => Int -> QR t -> Matrix t |
491 | qrgr n (QR a t) | ||
484 | | dim t > min (cols a) (rows a) || n < 0 || n > dim t = error "qrgr expects k <= min(rows,cols)" | 492 | | dim t > min (cols a) (rows a) || n < 0 || n > dim t = error "qrgr expects k <= min(rows,cols)" |
485 | | otherwise = qrgr' n (a,t) | 493 | | otherwise = qrgr' n (a,t) |
486 | 494 | ||
@@ -870,6 +878,8 @@ fixPerm' s = res $ mutable f s0 | |||
870 | triang r c h v = (r><c) [el s t | s<-[0..r-1], t<-[0..c-1]] | 878 | triang r c h v = (r><c) [el s t | s<-[0..r-1], t<-[0..c-1]] |
871 | where el p q = if q-p>=h then v else 1 - v | 879 | where el p q = if q-p>=h then v else 1 - v |
872 | 880 | ||
881 | -- | Compute the explicit LU decomposition from the compact one obtained by 'luPacked'. | ||
882 | luFact :: Numeric t => LU t -> (Matrix t, Matrix t, Matrix t, t) | ||
873 | luFact (LU l_u perm) | 883 | luFact (LU l_u perm) |
874 | | r <= c = (l ,u ,p, s) | 884 | | r <= c = (l ,u ,p, s) |
875 | | otherwise = (l',u',p, s) | 885 | | otherwise = (l',u',p, s) |