diff options
author | Alberto Ruiz <aruiz@um.es> | 2015-06-17 13:02:26 +0200 |
---|---|---|
committer | Alberto Ruiz <aruiz@um.es> | 2015-06-17 13:02:26 +0200 |
commit | e7d2916f78b5c140738fc4f4f95c9b13c1768293 (patch) | |
tree | feec2be3d7e7ad5ce80a5ada26b2a69fc3cbf947 /packages/base/src/Internal/Util.hs | |
parent | 34645d9ea1baccd21a94feebe9279a2089b91b5d (diff) |
luSolve'
Diffstat (limited to 'packages/base/src/Internal/Util.hs')
-rw-r--r-- | packages/base/src/Internal/Util.hs | 43 |
1 files changed, 39 insertions, 4 deletions
diff --git a/packages/base/src/Internal/Util.hs b/packages/base/src/Internal/Util.hs index f08f710..d9777ae 100644 --- a/packages/base/src/Internal/Util.hs +++ b/packages/base/src/Internal/Util.hs | |||
@@ -1,6 +1,5 @@ | |||
1 | {-# LANGUAGE FlexibleContexts #-} | 1 | {-# LANGUAGE FlexibleContexts #-} |
2 | {-# LANGUAGE FlexibleInstances #-} | 2 | {-# LANGUAGE FlexibleInstances #-} |
3 | {-# LANGUAGE TypeFamilies #-} | ||
4 | {-# LANGUAGE MultiParamTypeClasses #-} | 3 | {-# LANGUAGE MultiParamTypeClasses #-} |
5 | {-# LANGUAGE FunctionalDependencies #-} | 4 | {-# LANGUAGE FunctionalDependencies #-} |
6 | {-# LANGUAGE ViewPatterns #-} | 5 | {-# LANGUAGE ViewPatterns #-} |
@@ -55,7 +54,7 @@ module Internal.Util( | |||
55 | -- ** 2D | 54 | -- ** 2D |
56 | corr2, conv2, separable, | 55 | corr2, conv2, separable, |
57 | block2x2,block3x3,view1,unView1,foldMatrix, | 56 | block2x2,block3x3,view1,unView1,foldMatrix, |
58 | gaussElim_1, gaussElim_2, gaussElim, luST | 57 | gaussElim_1, gaussElim_2, gaussElim, luST, luSolve' |
59 | ) where | 58 | ) where |
60 | 59 | ||
61 | import Internal.Vector | 60 | import Internal.Vector |
@@ -65,7 +64,7 @@ import Internal.Element | |||
65 | import Internal.Container | 64 | import Internal.Container |
66 | import Internal.Vectorized | 65 | import Internal.Vectorized |
67 | import Internal.IO | 66 | import Internal.IO |
68 | import Internal.Algorithms hiding (i,Normed,swap,linearSolve') | 67 | import Internal.Algorithms hiding (Normed,linearSolve',luSolve') |
69 | import Numeric.Matrix() | 68 | import Numeric.Matrix() |
70 | import Numeric.Vector() | 69 | import Numeric.Vector() |
71 | import Internal.Random | 70 | import Internal.Random |
@@ -73,7 +72,7 @@ import Internal.Convolution | |||
73 | import Control.Monad(when,forM_) | 72 | import Control.Monad(when,forM_) |
74 | import Text.Printf | 73 | import Text.Printf |
75 | import Data.List.Split(splitOn) | 74 | import Data.List.Split(splitOn) |
76 | import Data.List(intercalate,sortBy) | 75 | import Data.List(intercalate,sortBy,foldl') |
77 | import Control.Arrow((&&&)) | 76 | import Control.Arrow((&&&)) |
78 | import Data.Complex | 77 | import Data.Complex |
79 | import Data.Function(on) | 78 | import Data.Function(on) |
@@ -690,6 +689,42 @@ luST ok (r,_) x = do | |||
690 | 689 | ||
691 | -------------------------------------------------------------------------------- | 690 | -------------------------------------------------------------------------------- |
692 | 691 | ||
692 | rowRange m = [0..rows m -1] | ||
693 | |||
694 | at k = Pos (idxs[k]) | ||
695 | |||
696 | backSust lup rhs = foldl' f (rhs?[]) (reverse ls) | ||
697 | where | ||
698 | ls = [ (d k , u k , b k) | k <- rowRange lup ] | ||
699 | where | ||
700 | d k = lup ?? (at k, at k) | ||
701 | u k = lup ?? (at k, Drop (k+1)) | ||
702 | b k = rhs ?? (at k, All) | ||
703 | |||
704 | f x (d,u,b) = (b - u<>x) / d | ||
705 | === | ||
706 | x | ||
707 | |||
708 | |||
709 | forwSust lup rhs = foldl' f (rhs?[]) ls | ||
710 | where | ||
711 | ls = [ (l k , b k) | k <- rowRange lup ] | ||
712 | where | ||
713 | l k = lup ?? (at k, Take k) | ||
714 | b k = rhs ?? (at k, All) | ||
715 | |||
716 | f x (l,b) = x | ||
717 | === | ||
718 | (b - l<>x) | ||
719 | |||
720 | |||
721 | luSolve' (lup,p) b = backSust lup (forwSust lup pb) | ||
722 | where | ||
723 | pb = b ?? (Pos (fixPerm' p), All) | ||
724 | |||
725 | |||
726 | -------------------------------------------------------------------------------- | ||
727 | |||
693 | instance Testable (Matrix I) where | 728 | instance Testable (Matrix I) where |
694 | checkT _ = test | 729 | checkT _ = test |
695 | 730 | ||