diff options
Diffstat (limited to 'packages/base/src/Data/Packed/Internal/Numeric.hs')
-rw-r--r-- | packages/base/src/Data/Packed/Internal/Numeric.hs | 39 |
1 files changed, 28 insertions, 11 deletions
diff --git a/packages/base/src/Data/Packed/Internal/Numeric.hs b/packages/base/src/Data/Packed/Internal/Numeric.hs index 9cd18df..3c1c1d0 100644 --- a/packages/base/src/Data/Packed/Internal/Numeric.hs +++ b/packages/base/src/Data/Packed/Internal/Numeric.hs | |||
@@ -49,6 +49,7 @@ import Data.Complex | |||
49 | import Control.Applicative((<*>)) | 49 | import Control.Applicative((<*>)) |
50 | 50 | ||
51 | import Numeric.LinearAlgebra.LAPACK(multiplyR,multiplyC,multiplyF,multiplyQ) | 51 | import Numeric.LinearAlgebra.LAPACK(multiplyR,multiplyC,multiplyF,multiplyQ) |
52 | import Data.Packed.Internal | ||
52 | 53 | ||
53 | ------------------------------------------------------------------- | 54 | ------------------------------------------------------------------- |
54 | 55 | ||
@@ -65,7 +66,9 @@ type instance ArgOf Matrix a = a -> a -> a | |||
65 | ------------------------------------------------------------------- | 66 | ------------------------------------------------------------------- |
66 | 67 | ||
67 | -- | Basic element-by-element functions for numeric containers | 68 | -- | Basic element-by-element functions for numeric containers |
68 | class (Complexable c, Fractional e, Element e) => Container c e where | 69 | class (Complexable c, Fractional e, Element e) => Container c e |
70 | where | ||
71 | size' :: c e -> IndexOf c | ||
69 | scalar' :: e -> c e | 72 | scalar' :: e -> c e |
70 | conj' :: c e -> c e | 73 | conj' :: c e -> c e |
71 | scale' :: e -> c e -> c e | 74 | scale' :: e -> c e -> c e |
@@ -114,7 +117,9 @@ class (Complexable c, Fractional e, Element e) => Container c e where | |||
114 | 117 | ||
115 | -------------------------------------------------------------------------- | 118 | -------------------------------------------------------------------------- |
116 | 119 | ||
117 | instance Container Vector Float where | 120 | instance Container Vector Float |
121 | where | ||
122 | size' = dim | ||
118 | scale' = vectorMapValF Scale | 123 | scale' = vectorMapValF Scale |
119 | scaleRecip = vectorMapValF Recip | 124 | scaleRecip = vectorMapValF Recip |
120 | addConstant = vectorMapValF AddConstant | 125 | addConstant = vectorMapValF AddConstant |
@@ -125,7 +130,7 @@ instance Container Vector Float where | |||
125 | equal u v = dim u == dim v && maxElement (vectorMapF Abs (sub u v)) == 0.0 | 130 | equal u v = dim u == dim v && maxElement (vectorMapF Abs (sub u v)) == 0.0 |
126 | arctan2' = vectorZipF ATan2 | 131 | arctan2' = vectorZipF ATan2 |
127 | scalar' x = fromList [x] | 132 | scalar' x = fromList [x] |
128 | konst' = constant | 133 | konst' = constantD |
129 | build' = buildV | 134 | build' = buildV |
130 | conj' = id | 135 | conj' = id |
131 | cmap' = mapVector | 136 | cmap' = mapVector |
@@ -142,7 +147,9 @@ instance Container Vector Float where | |||
142 | accum' = accumV | 147 | accum' = accumV |
143 | cond' = condV condF | 148 | cond' = condV condF |
144 | 149 | ||
145 | instance Container Vector Double where | 150 | instance Container Vector Double |
151 | where | ||
152 | size' = dim | ||
146 | scale' = vectorMapValR Scale | 153 | scale' = vectorMapValR Scale |
147 | scaleRecip = vectorMapValR Recip | 154 | scaleRecip = vectorMapValR Recip |
148 | addConstant = vectorMapValR AddConstant | 155 | addConstant = vectorMapValR AddConstant |
@@ -153,7 +160,7 @@ instance Container Vector Double where | |||
153 | equal u v = dim u == dim v && maxElement (vectorMapR Abs (sub u v)) == 0.0 | 160 | equal u v = dim u == dim v && maxElement (vectorMapR Abs (sub u v)) == 0.0 |
154 | arctan2' = vectorZipR ATan2 | 161 | arctan2' = vectorZipR ATan2 |
155 | scalar' x = fromList [x] | 162 | scalar' x = fromList [x] |
156 | konst' = constant | 163 | konst' = constantD |
157 | build' = buildV | 164 | build' = buildV |
158 | conj' = id | 165 | conj' = id |
159 | cmap' = mapVector | 166 | cmap' = mapVector |
@@ -170,7 +177,9 @@ instance Container Vector Double where | |||
170 | accum' = accumV | 177 | accum' = accumV |
171 | cond' = condV condD | 178 | cond' = condV condD |
172 | 179 | ||
173 | instance Container Vector (Complex Double) where | 180 | instance Container Vector (Complex Double) |
181 | where | ||
182 | size' = dim | ||
174 | scale' = vectorMapValC Scale | 183 | scale' = vectorMapValC Scale |
175 | scaleRecip = vectorMapValC Recip | 184 | scaleRecip = vectorMapValC Recip |
176 | addConstant = vectorMapValC AddConstant | 185 | addConstant = vectorMapValC AddConstant |
@@ -181,7 +190,7 @@ instance Container Vector (Complex Double) where | |||
181 | equal u v = dim u == dim v && maxElement (mapVector magnitude (sub u v)) == 0.0 | 190 | equal u v = dim u == dim v && maxElement (mapVector magnitude (sub u v)) == 0.0 |
182 | arctan2' = vectorZipC ATan2 | 191 | arctan2' = vectorZipC ATan2 |
183 | scalar' x = fromList [x] | 192 | scalar' x = fromList [x] |
184 | konst' = constant | 193 | konst' = constantD |
185 | build' = buildV | 194 | build' = buildV |
186 | conj' = conjugateC | 195 | conj' = conjugateC |
187 | cmap' = mapVector | 196 | cmap' = mapVector |
@@ -198,7 +207,9 @@ instance Container Vector (Complex Double) where | |||
198 | accum' = accumV | 207 | accum' = accumV |
199 | cond' = undefined -- cannot match | 208 | cond' = undefined -- cannot match |
200 | 209 | ||
201 | instance Container Vector (Complex Float) where | 210 | instance Container Vector (Complex Float) |
211 | where | ||
212 | size' = dim | ||
202 | scale' = vectorMapValQ Scale | 213 | scale' = vectorMapValQ Scale |
203 | scaleRecip = vectorMapValQ Recip | 214 | scaleRecip = vectorMapValQ Recip |
204 | addConstant = vectorMapValQ AddConstant | 215 | addConstant = vectorMapValQ AddConstant |
@@ -209,7 +220,7 @@ instance Container Vector (Complex Float) where | |||
209 | equal u v = dim u == dim v && maxElement (mapVector magnitude (sub u v)) == 0.0 | 220 | equal u v = dim u == dim v && maxElement (mapVector magnitude (sub u v)) == 0.0 |
210 | arctan2' = vectorZipQ ATan2 | 221 | arctan2' = vectorZipQ ATan2 |
211 | scalar' x = fromList [x] | 222 | scalar' x = fromList [x] |
212 | konst' = constant | 223 | konst' = constantD |
213 | build' = buildV | 224 | build' = buildV |
214 | conj' = conjugateQ | 225 | conj' = conjugateQ |
215 | cmap' = mapVector | 226 | cmap' = mapVector |
@@ -228,7 +239,9 @@ instance Container Vector (Complex Float) where | |||
228 | 239 | ||
229 | --------------------------------------------------------------- | 240 | --------------------------------------------------------------- |
230 | 241 | ||
231 | instance (Container Vector a) => Container Matrix a where | 242 | instance (Container Vector a) => Container Matrix a |
243 | where | ||
244 | size' = size | ||
232 | scale' x = liftMatrix (scale' x) | 245 | scale' x = liftMatrix (scale' x) |
233 | scaleRecip x = liftMatrix (scaleRecip x) | 246 | scaleRecip x = liftMatrix (scaleRecip x) |
234 | addConstant x = liftMatrix (addConstant x) | 247 | addConstant x = liftMatrix (addConstant x) |
@@ -637,7 +650,7 @@ diag v = diagRect 0 v n n where n = dim v | |||
637 | 650 | ||
638 | -- | creates the identity matrix of given dimension | 651 | -- | creates the identity matrix of given dimension |
639 | ident :: (Num a, Element a) => Int -> Matrix a | 652 | ident :: (Num a, Element a) => Int -> Matrix a |
640 | ident n = diag (constant 1 n) | 653 | ident n = diag (constantD 1 n) |
641 | 654 | ||
642 | -------------------------------------------------------- | 655 | -------------------------------------------------------- |
643 | 656 | ||
@@ -681,8 +694,12 @@ condV f a b l e t = f a' b' l' e' t' | |||
681 | 694 | ||
682 | class Transposable t | 695 | class Transposable t |
683 | where | 696 | where |
697 | -- | (conjugate) transpose | ||
684 | tr :: t -> t | 698 | tr :: t -> t |
685 | 699 | ||
700 | instance (Container Vector t) => Transposable (Matrix t) | ||
701 | where | ||
702 | tr = ctrans | ||
686 | 703 | ||
687 | class Linear t v | 704 | class Linear t v |
688 | where | 705 | where |