summaryrefslogtreecommitdiff
path: root/packages/base/src/Internal/Algorithms.hs
diff options
context:
space:
mode:
Diffstat (limited to 'packages/base/src/Internal/Algorithms.hs')
-rw-r--r--packages/base/src/Internal/Algorithms.hs33
1 files changed, 20 insertions, 13 deletions
diff --git a/packages/base/src/Internal/Algorithms.hs b/packages/base/src/Internal/Algorithms.hs
index aaf6fbb..1235da3 100644
--- a/packages/base/src/Internal/Algorithms.hs
+++ b/packages/base/src/Internal/Algorithms.hs
@@ -29,7 +29,9 @@ import Internal.Conversion
29import Internal.LAPACK as LAPACK 29import Internal.LAPACK as LAPACK
30import Internal.Numeric 30import Internal.Numeric
31import Data.List(foldl1') 31import Data.List(foldl1')
32import Data.Array 32import qualified Data.Array as A
33import Internal.ST
34import Internal.Vectorized(range)
33 35
34{- | Generic linear algebra functions for double precision real and complex matrices. 36{- | Generic linear algebra functions for double precision real and complex matrices.
35 37
@@ -578,11 +580,6 @@ eps = 2.22044604925031e-16
578peps :: RealFloat x => x 580peps :: RealFloat x => x
579peps = x where x = 2.0 ** fromIntegral (1 - floatDigits x) 581peps = x where x = 2.0 ** fromIntegral (1 - floatDigits x)
580 582
581
582-- | The imaginary unit: @i = 0.0 :+ 1.0@
583i :: Complex Double
584i = 0:+1
585
586----------------------------------------------------------------------- 583-----------------------------------------------------------------------
587 584
588-- | The nullspace of a matrix from its precomputed SVD decomposition. 585-- | The nullspace of a matrix from its precomputed SVD decomposition.
@@ -796,13 +793,23 @@ signlp r vals = foldl f 1 (zip [0..r-1] vals)
796 where f s (a,b) | a /= b = -s 793 where f s (a,b) | a /= b = -s
797 | otherwise = s 794 | otherwise = s
798 795
799swap (arr,s) (a,b) | a /= b = (arr // [(a, arr!b),(b,arr!a)],-s) 796fixPerm r vals = (fromColumns $ A.elems res, sign)
800 | otherwise = (arr,s) 797 where
801 798 v = [0..r-1]
802fixPerm r vals = (fromColumns $ elems res, sign) 799 t = toColumns (ident r)
803 where v = [0..r-1] 800 (res,sign) = foldl swap (A.listArray (0,r-1) t, 1) (zip v vals)
804 s = toColumns (ident r) 801 swap (arr,s) (a,b)
805 (res,sign) = foldl swap (listArray (0,r-1) s, 1) (zip v vals) 802 | a /= b = (arr A.// [(a, arr A.! b),(b,arr A.! a)],-s)
803 | otherwise = (arr,s)
804
805fixPerm' :: [Int] -> Vector I
806fixPerm' s = res $ mutable f s0
807 where
808 s0 = reshape 1 (range (length s))
809 res = flatten . fst
810 swap m i j = rowOper (SWAP i j AllCols) m
811 f :: (Num t, Element t) => (Int, Int) -> STMatrix s t -> ST s () -- needed because of TypeFamilies
812 f _ p = sequence_ $ zipWith (swap p) [0..] s
806 813
807triang r c h v = (r><c) [el s t | s<-[0..r-1], t<-[0..c-1]] 814triang r c h v = (r><c) [el s t | s<-[0..r-1], t<-[0..c-1]]
808 where el p q = if q-p>=h then v else 1 - v 815 where el p q = if q-p>=h then v else 1 - v