summaryrefslogtreecommitdiff
path: root/packages/base/src/Data/Packed/Internal/Numeric.hs
diff options
context:
space:
mode:
Diffstat (limited to 'packages/base/src/Data/Packed/Internal/Numeric.hs')
-rw-r--r--packages/base/src/Data/Packed/Internal/Numeric.hs19
1 files changed, 17 insertions, 2 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
215instance Container Vector Float 219instance 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
278instance Container Vector (Complex Double) 284instance 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
308instance Container Vector (Complex Float) 315instance 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
373emptyErrorV msg f v = 384emptyErrorV 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
378emptyErrorM msg f m = 389emptyErrorM 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'
402arctan2 :: (Fractional e, Container c e) => c e -> c e -> c e 413arctan2 :: (Fractional e, Container c e) => c e -> c e -> c e
403arctan2 = arctan2' 414arctan2 = arctan2'
404 415
416cmod :: (Integral e, Container c e) => e -> c e -> c e
417cmod = 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)
406cmap :: (Element b, Container c e) => (e -> b) -> c e -> c b 421cmap :: (Element b, Container c e) => (e -> b) -> c e -> c b
407cmap = cmap' 422cmap = cmap'