summaryrefslogtreecommitdiff
path: root/packages/base/src/Data/Packed
diff options
context:
space:
mode:
authorAlberto Ruiz <aruiz@um.es>2015-05-25 09:23:39 +0200
committerAlberto Ruiz <aruiz@um.es>2015-05-25 09:23:39 +0200
commite803d45acc0fd3202af9ea3844c554a9b807bade (patch)
treeee8982d68735e54c7ce6c8db7f843df18065dc5f /packages/base/src/Data/Packed
parent11095a22c59bed6a011723641dfb782415e2c02b (diff)
At range, idxs
Diffstat (limited to 'packages/base/src/Data/Packed')
-rw-r--r--packages/base/src/Data/Packed/Internal/Numeric.hs24
1 files changed, 14 insertions, 10 deletions
diff --git a/packages/base/src/Data/Packed/Internal/Numeric.hs b/packages/base/src/Data/Packed/Internal/Numeric.hs
index 60dd167..cda9429 100644
--- a/packages/base/src/Data/Packed/Internal/Numeric.hs
+++ b/packages/base/src/Data/Packed/Internal/Numeric.hs
@@ -39,7 +39,7 @@ module Data.Packed.Internal.Numeric (
39 roundVector, fromInt, 39 roundVector, fromInt,
40 RealOf, ComplexOf, SingleOf, DoubleOf, 40 RealOf, ComplexOf, SingleOf, DoubleOf,
41 IndexOf, 41 IndexOf,
42 CInt, Extractor(..), (??), range, 42 CInt, Extractor(..), (??), range, idxs,
43 module Data.Complex 43 module Data.Complex
44) where 44) where
45 45
@@ -70,12 +70,13 @@ type instance ArgOf Matrix a = a -> a -> a
70data Extractor 70data Extractor
71 = All 71 = All
72 | Range Int Int 72 | Range Int Int
73 | At [Int] 73 | At Idxs
74 | AtCyc [Int] 74 | AtCyc Idxs
75 | Take Int 75 | Take Int
76 | Drop Int 76 | Drop Int
77 deriving Show 77 deriving Show
78 78
79idxs :: [Int] -> Idxs
79idxs js = fromList (map fromIntegral js) :: Idxs 80idxs js = fromList (map fromIntegral js) :: Idxs
80 81
81infixl 9 ?? 82infixl 9 ??
@@ -86,8 +87,9 @@ extractError m e = error $ printf "can't extract %s from matrix %dx%d" (show e)
86 87
87m ?? e@(Range a b,_) | a < 0 || b >= rows m = extractError m e 88m ?? e@(Range a b,_) | a < 0 || b >= rows m = extractError m e
88m ?? e@(_,Range a b) | a < 0 || b >= cols m = extractError m e 89m ?? e@(_,Range a b) | a < 0 || b >= cols m = extractError m e
89m ?? e@(At ps,_) | minimum ps < 0 || maximum ps >= rows m = extractError m e 90
90m ?? e@(_,At ps) | minimum ps < 0 || maximum ps >= cols m = extractError m e 91m ?? e@(At vs,_) | minElement vs < 0 || maxElement vs >= fromIntegral (rows m) = extractError m e
92m ?? e@(_,At vs) | minElement vs < 0 || maxElement vs >= fromIntegral (cols m) = extractError m e
91 93
92m ?? (All,All) = m 94m ?? (All,All) = m
93 95
@@ -112,9 +114,11 @@ m ?? (er,ec) = extractR m moder rs modec cs
112 (moder,rs) = mkExt (rows m) er 114 (moder,rs) = mkExt (rows m) er
113 (modec,cs) = mkExt (cols m) ec 115 (modec,cs) = mkExt (cols m) ec
114 ran a b = (0, idxs [a,b]) 116 ran a b = (0, idxs [a,b])
115 pos ks = (1, idxs ks) 117 pos ks = (1, ks)
116 mkExt _ (At ks) = pos ks 118 mkExt _ (At ks) = pos ks
117 mkExt n (AtCyc ks) = pos (map (`mod` n) ks) 119 mkExt n (AtCyc ks)
120 | n == 0 = mkExt n (Take 0)
121 | otherwise = pos (cmod n ks)
118 mkExt n All = ran 0 (n-1) 122 mkExt n All = ran 0 (n-1)
119 mkExt _ (Range mn mx) = ran mn mx 123 mkExt _ (Range mn mx) = ran mn mx
120 mkExt n (Take k) 124 mkExt n (Take k)
@@ -420,8 +424,8 @@ scale = scale'
420arctan2 :: (Fractional e, Container c e) => c e -> c e -> c e 424arctan2 :: (Fractional e, Container c e) => c e -> c e -> c e
421arctan2 = arctan2' 425arctan2 = arctan2'
422 426
423cmod :: (Integral e, Container c e) => e -> c e -> c e 427cmod :: (Integral e, Container c e) => Int -> c e -> c e
424cmod = cmod' 428cmod m = cmod' (fromIntegral m)
425 429
426fromInt :: (Container c e) => c CInt -> c e 430fromInt :: (Container c e) => c CInt -> c e
427fromInt = fromInt' 431fromInt = fromInt'