diff options
Diffstat (limited to 'lib/Numeric')
-rw-r--r-- | lib/Numeric/Container.hs | 19 | ||||
-rw-r--r-- | lib/Numeric/LinearAlgebra/Algorithms.hs | 8 |
2 files changed, 11 insertions, 16 deletions
diff --git a/lib/Numeric/Container.hs b/lib/Numeric/Container.hs index 44e2711..2c9c500 100644 --- a/lib/Numeric/Container.hs +++ b/lib/Numeric/Container.hs | |||
@@ -71,9 +71,11 @@ class (Element e) => Container c e where | |||
71 | -- | element by element division | 71 | -- | element by element division |
72 | divide :: c e -> c e -> c e | 72 | divide :: c e -> c e -> c e |
73 | equal :: c e -> c e -> Bool | 73 | equal :: c e -> c e -> Bool |
74 | 74 | -- | |
75 | -- | cannot implement instance Functor because of Element class constraint | 75 | -- | cannot implement instance Functor because of Element class constraint |
76 | cmap :: (Element a, Element b) => (a -> b) -> c a -> c b | 76 | cmap :: (Element a, Element b) => (a -> b) -> c a -> c b |
77 | -- | constant structure of given size | ||
78 | konst :: e -> IndexOf c -> c e | ||
77 | -- | 79 | -- |
78 | -- | indexing function | 80 | -- | indexing function |
79 | atIndex :: c e -> IndexOf c -> e | 81 | atIndex :: c e -> IndexOf c -> e |
@@ -107,8 +109,7 @@ instance Container Vector Float where | |||
107 | divide = vectorZipF Div | 109 | divide = vectorZipF Div |
108 | equal u v = dim u == dim v && maxElement (vectorMapF Abs (sub u v)) == 0.0 | 110 | equal u v = dim u == dim v && maxElement (vectorMapF Abs (sub u v)) == 0.0 |
109 | scalar x = fromList [x] | 111 | scalar x = fromList [x] |
110 | -- | 112 | konst = constantD |
111 | --instance Container Vector Float where | ||
112 | cmap = mapVector | 113 | cmap = mapVector |
113 | atIndex = (@>) | 114 | atIndex = (@>) |
114 | minIndex = round . toScalarF MinIdx | 115 | minIndex = round . toScalarF MinIdx |
@@ -128,8 +129,7 @@ instance Container Vector Double where | |||
128 | divide = vectorZipR Div | 129 | divide = vectorZipR Div |
129 | equal u v = dim u == dim v && maxElement (vectorMapR Abs (sub u v)) == 0.0 | 130 | equal u v = dim u == dim v && maxElement (vectorMapR Abs (sub u v)) == 0.0 |
130 | scalar x = fromList [x] | 131 | scalar x = fromList [x] |
131 | -- | 132 | konst = constantD |
132 | --instance Container Vector Double where | ||
133 | cmap = mapVector | 133 | cmap = mapVector |
134 | atIndex = (@>) | 134 | atIndex = (@>) |
135 | minIndex = round . toScalarR MinIdx | 135 | minIndex = round . toScalarR MinIdx |
@@ -149,8 +149,7 @@ instance Container Vector (Complex Double) where | |||
149 | divide = vectorZipC Div | 149 | divide = vectorZipC Div |
150 | equal u v = dim u == dim v && maxElement (mapVector magnitude (sub u v)) == 0.0 | 150 | equal u v = dim u == dim v && maxElement (mapVector magnitude (sub u v)) == 0.0 |
151 | scalar x = fromList [x] | 151 | scalar x = fromList [x] |
152 | -- | 152 | konst = constantD |
153 | --instance Container Vector (Complex Double) where | ||
154 | cmap = mapVector | 153 | cmap = mapVector |
155 | atIndex = (@>) | 154 | atIndex = (@>) |
156 | minIndex = minIndex . fst . fromComplex . (zipVectorWith (*) `ap` mapVector conjugate) | 155 | minIndex = minIndex . fst . fromComplex . (zipVectorWith (*) `ap` mapVector conjugate) |
@@ -170,8 +169,7 @@ instance Container Vector (Complex Float) where | |||
170 | divide = vectorZipQ Div | 169 | divide = vectorZipQ Div |
171 | equal u v = dim u == dim v && maxElement (mapVector magnitude (sub u v)) == 0.0 | 170 | equal u v = dim u == dim v && maxElement (mapVector magnitude (sub u v)) == 0.0 |
172 | scalar x = fromList [x] | 171 | scalar x = fromList [x] |
173 | -- | 172 | konst = constantD |
174 | --instance Container Vector (Complex Float) where | ||
175 | cmap = mapVector | 173 | cmap = mapVector |
176 | atIndex = (@>) | 174 | atIndex = (@>) |
177 | minIndex = minIndex . fst . fromComplex . (zipVectorWith (*) `ap` mapVector conjugate) | 175 | minIndex = minIndex . fst . fromComplex . (zipVectorWith (*) `ap` mapVector conjugate) |
@@ -193,8 +191,7 @@ instance (Container Vector a) => Container Matrix a where | |||
193 | divide = liftMatrix2 divide | 191 | divide = liftMatrix2 divide |
194 | equal a b = cols a == cols b && flatten a `equal` flatten b | 192 | equal a b = cols a == cols b && flatten a `equal` flatten b |
195 | scalar x = (1><1) [x] | 193 | scalar x = (1><1) [x] |
196 | -- | 194 | konst v (r,c) = reshape c (konst v (r*c)) |
197 | --instance (Container Vector a) => Container Matrix a where | ||
198 | cmap f = liftMatrix (mapVector f) | 195 | cmap f = liftMatrix (mapVector f) |
199 | atIndex = (@@>) | 196 | atIndex = (@@>) |
200 | minIndex m = let (r,c) = (rows m,cols m) | 197 | minIndex m = let (r,c) = (rows m,cols m) |
diff --git a/lib/Numeric/LinearAlgebra/Algorithms.hs b/lib/Numeric/LinearAlgebra/Algorithms.hs index 6e703fa..5bc9ca5 100644 --- a/lib/Numeric/LinearAlgebra/Algorithms.hs +++ b/lib/Numeric/LinearAlgebra/Algorithms.hs | |||
@@ -83,8 +83,6 @@ import Data.List(foldl1') | |||
83 | import Data.Array | 83 | import Data.Array |
84 | import Numeric.Container | 84 | import Numeric.Container |
85 | 85 | ||
86 | constant x = constantD x | ||
87 | |||
88 | -- | Auxiliary typeclass used to define generic computations for both real and complex matrices. | 86 | -- | Auxiliary typeclass used to define generic computations for both real and complex matrices. |
89 | class (Product t, Container Vector t, Container Matrix t) => Field t where | 87 | class (Product t, Container Vector t, Container Matrix t) => Field t where |
90 | svd' :: Matrix t -> (Matrix t, Vector Double, Matrix t) | 88 | svd' :: Matrix t -> (Matrix t, Vector Double, Matrix t) |
@@ -469,7 +467,7 @@ zh k v = fromList $ replicate (k-1) 0 ++ (1:drop k xs) | |||
469 | where xs = toList v | 467 | where xs = toList v |
470 | 468 | ||
471 | zt 0 v = v | 469 | zt 0 v = v |
472 | zt k v = join [subVector 0 (dim v - k) v, constant 0 k] | 470 | zt k v = join [subVector 0 (dim v - k) v, konst 0 k] |
473 | 471 | ||
474 | 472 | ||
475 | unpackQR :: (Field t) => (Matrix t, Vector t) -> (Matrix t, Matrix t) | 473 | unpackQR :: (Field t) => (Matrix t, Vector t) -> (Matrix t, Matrix t) |
@@ -623,10 +621,10 @@ luFact (l_u,perm) | r <= c = (l ,u ,p, s) | |||
623 | c = cols l_u | 621 | c = cols l_u |
624 | tu = triang r c 0 1 | 622 | tu = triang r c 0 1 |
625 | tl = triang r c 0 0 | 623 | tl = triang r c 0 0 |
626 | l = takeColumns r (l_u |*| tl) |+| diagRect (constant 1 r) r r | 624 | l = takeColumns r (l_u |*| tl) |+| diagRect (konst 1 r) r r |
627 | u = l_u |*| tu | 625 | u = l_u |*| tu |
628 | (p,s) = fixPerm r perm | 626 | (p,s) = fixPerm r perm |
629 | l' = (l_u |*| tl) |+| diagRect (constant 1 c) r c | 627 | l' = (l_u |*| tl) |+| diagRect (konst 1 c) r c |
630 | u' = takeRows c (l_u |*| tu) | 628 | u' = takeRows c (l_u |*| tu) |
631 | (|+|) = add | 629 | (|+|) = add |
632 | (|*|) = mul | 630 | (|*|) = mul |