diff options
Diffstat (limited to 'packages/base/src/Data')
-rw-r--r-- | packages/base/src/Data/Packed/Internal/Numeric.hs | 19 | ||||
-rw-r--r-- | packages/base/src/Data/Packed/Numeric.hs | 2 |
2 files changed, 18 insertions, 3 deletions
diff --git a/packages/base/src/Data/Packed/Internal/Numeric.hs b/packages/base/src/Data/Packed/Internal/Numeric.hs index 6c30a72..3e6c90c 100644 --- a/packages/base/src/Data/Packed/Internal/Numeric.hs +++ b/packages/base/src/Data/Packed/Internal/Numeric.hs | |||
@@ -21,7 +21,7 @@ module Data.Packed.Internal.Numeric ( | |||
21 | ident, diag, ctrans, | 21 | ident, diag, ctrans, |
22 | -- * Generic operations | 22 | -- * Generic operations |
23 | Container(..), | 23 | Container(..), |
24 | scalar, conj, scale, arctan2, cmap, | 24 | scalar, conj, scale, arctan2, cmap, cmod, |
25 | atIndex, minIndex, maxIndex, minElement, maxElement, | 25 | atIndex, minIndex, maxIndex, minElement, maxElement, |
26 | sumElements, prodElements, | 26 | sumElements, prodElements, |
27 | step, cond, find, assoc, accum, | 27 | step, cond, find, assoc, accum, |
@@ -178,6 +178,7 @@ class Element e => Container c e | |||
178 | -- | 178 | -- |
179 | -- element by element inverse tangent | 179 | -- element by element inverse tangent |
180 | arctan2' :: Fractional e => c e -> c e -> c e | 180 | arctan2' :: Fractional e => c e -> c e -> c e |
181 | cmod' :: Integral e => e -> c e -> c e | ||
181 | 182 | ||
182 | 183 | ||
183 | -------------------------------------------------------------------------- | 184 | -------------------------------------------------------------------------- |
@@ -211,6 +212,9 @@ instance Container Vector CInt | |||
211 | scaleRecip = undefined -- cannot match | 212 | scaleRecip = undefined -- cannot match |
212 | divide = undefined | 213 | divide = undefined |
213 | arctan2' = undefined | 214 | arctan2' = undefined |
215 | cmod' m x | ||
216 | | m /= 0 = vectorMapValI ModVS m x | ||
217 | | otherwise = error $ "cmod 0 on vector of size "++(show $ dim x) | ||
214 | 218 | ||
215 | instance Container Vector Float | 219 | instance Container Vector Float |
216 | where | 220 | where |
@@ -241,6 +245,7 @@ instance Container Vector Float | |||
241 | scaleRecip = vectorMapValF Recip | 245 | scaleRecip = vectorMapValF Recip |
242 | divide = vectorZipF Div | 246 | divide = vectorZipF Div |
243 | arctan2' = vectorZipF ATan2 | 247 | arctan2' = vectorZipF ATan2 |
248 | cmod' = undefined | ||
244 | 249 | ||
245 | 250 | ||
246 | 251 | ||
@@ -273,6 +278,7 @@ instance Container Vector Double | |||
273 | scaleRecip = vectorMapValR Recip | 278 | scaleRecip = vectorMapValR Recip |
274 | divide = vectorZipR Div | 279 | divide = vectorZipR Div |
275 | arctan2' = vectorZipR ATan2 | 280 | arctan2' = vectorZipR ATan2 |
281 | cmod' = undefined | ||
276 | 282 | ||
277 | 283 | ||
278 | instance Container Vector (Complex Double) | 284 | instance Container Vector (Complex Double) |
@@ -304,6 +310,7 @@ instance Container Vector (Complex Double) | |||
304 | scaleRecip = vectorMapValC Recip | 310 | scaleRecip = vectorMapValC Recip |
305 | divide = vectorZipC Div | 311 | divide = vectorZipC Div |
306 | arctan2' = vectorZipC ATan2 | 312 | arctan2' = vectorZipC ATan2 |
313 | cmod' = undefined | ||
307 | 314 | ||
308 | instance Container Vector (Complex Float) | 315 | instance Container Vector (Complex Float) |
309 | where | 316 | where |
@@ -334,6 +341,7 @@ instance Container Vector (Complex Float) | |||
334 | scaleRecip = vectorMapValQ Recip | 341 | scaleRecip = vectorMapValQ Recip |
335 | divide = vectorZipQ Div | 342 | divide = vectorZipQ Div |
336 | arctan2' = vectorZipQ ATan2 | 343 | arctan2' = vectorZipQ ATan2 |
344 | cmod' = undefined | ||
337 | 345 | ||
338 | --------------------------------------------------------------- | 346 | --------------------------------------------------------------- |
339 | 347 | ||
@@ -368,12 +376,15 @@ instance (Num a, Element a, Container Vector a) => Container Matrix a | |||
368 | scaleRecip x = liftMatrix (scaleRecip x) | 376 | scaleRecip x = liftMatrix (scaleRecip x) |
369 | divide = liftMatrix2 divide | 377 | divide = liftMatrix2 divide |
370 | arctan2' = liftMatrix2 arctan2' | 378 | arctan2' = liftMatrix2 arctan2' |
379 | cmod' m x | ||
380 | | m /= 0 = liftMatrix (cmod' m) x | ||
381 | | otherwise = error $ "cmod 0 on matrix "++shSize x | ||
371 | 382 | ||
372 | 383 | ||
373 | emptyErrorV msg f v = | 384 | emptyErrorV msg f v = |
374 | if dim v > 0 | 385 | if dim v > 0 |
375 | then f v | 386 | then f v |
376 | else error $ msg ++ " of Vector with dim = 0" | 387 | else error $ msg ++ " of empty Vector" |
377 | 388 | ||
378 | emptyErrorM msg f m = | 389 | emptyErrorM msg f m = |
379 | if rows m > 0 && cols m > 0 | 390 | if rows m > 0 && cols m > 0 |
@@ -402,6 +413,10 @@ scale = scale' | |||
402 | arctan2 :: (Fractional e, Container c e) => c e -> c e -> c e | 413 | arctan2 :: (Fractional e, Container c e) => c e -> c e -> c e |
403 | arctan2 = arctan2' | 414 | arctan2 = arctan2' |
404 | 415 | ||
416 | cmod :: (Integral e, Container c e) => e -> c e -> c e | ||
417 | cmod = cmod' | ||
418 | |||
419 | |||
405 | -- | like 'fmap' (cannot implement instance Functor because of Element class constraint) | 420 | -- | like 'fmap' (cannot implement instance Functor because of Element class constraint) |
406 | cmap :: (Element b, Container c e) => (e -> b) -> c e -> c b | 421 | cmap :: (Element b, Container c e) => (e -> b) -> c e -> c b |
407 | cmap = cmap' | 422 | cmap = cmap' |
diff --git a/packages/base/src/Data/Packed/Numeric.hs b/packages/base/src/Data/Packed/Numeric.hs index d11ecf9..2821eae 100644 --- a/packages/base/src/Data/Packed/Numeric.hs +++ b/packages/base/src/Data/Packed/Numeric.hs | |||
@@ -33,7 +33,7 @@ module Data.Packed.Numeric ( | |||
33 | -- * Generic operations | 33 | -- * Generic operations |
34 | Container(..), Numeric, | 34 | Container(..), Numeric, |
35 | -- add, mul, sub, divide, equal, scaleRecip, addConstant, | 35 | -- add, mul, sub, divide, equal, scaleRecip, addConstant, |
36 | scalar, conj, scale, arctan2, cmap, | 36 | scalar, conj, scale, arctan2, cmap, cmod, |
37 | atIndex, minIndex, maxIndex, minElement, maxElement, | 37 | atIndex, minIndex, maxIndex, minElement, maxElement, |
38 | sumElements, prodElements, | 38 | sumElements, prodElements, |
39 | step, cond, find, assoc, accum, | 39 | step, cond, find, assoc, accum, |