diff options
author | Alberto Ruiz <aruiz@um.es> | 2015-05-25 09:23:39 +0200 |
---|---|---|
committer | Alberto Ruiz <aruiz@um.es> | 2015-05-25 09:23:39 +0200 |
commit | e803d45acc0fd3202af9ea3844c554a9b807bade (patch) | |
tree | ee8982d68735e54c7ce6c8db7f843df18065dc5f /packages/base/src/Data/Packed/Internal | |
parent | 11095a22c59bed6a011723641dfb782415e2c02b (diff) |
At range, idxs
Diffstat (limited to 'packages/base/src/Data/Packed/Internal')
-rw-r--r-- | packages/base/src/Data/Packed/Internal/Numeric.hs | 24 |
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 | |||
70 | data Extractor | 70 | data 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 | ||
79 | idxs :: [Int] -> Idxs | ||
79 | idxs js = fromList (map fromIntegral js) :: Idxs | 80 | idxs js = fromList (map fromIntegral js) :: Idxs |
80 | 81 | ||
81 | infixl 9 ?? | 82 | infixl 9 ?? |
@@ -86,8 +87,9 @@ extractError m e = error $ printf "can't extract %s from matrix %dx%d" (show e) | |||
86 | 87 | ||
87 | m ?? e@(Range a b,_) | a < 0 || b >= rows m = extractError m e | 88 | m ?? e@(Range a b,_) | a < 0 || b >= rows m = extractError m e |
88 | m ?? e@(_,Range a b) | a < 0 || b >= cols m = extractError m e | 89 | m ?? e@(_,Range a b) | a < 0 || b >= cols m = extractError m e |
89 | m ?? e@(At ps,_) | minimum ps < 0 || maximum ps >= rows m = extractError m e | 90 | |
90 | m ?? e@(_,At ps) | minimum ps < 0 || maximum ps >= cols m = extractError m e | 91 | m ?? e@(At vs,_) | minElement vs < 0 || maxElement vs >= fromIntegral (rows m) = extractError m e |
92 | m ?? e@(_,At vs) | minElement vs < 0 || maxElement vs >= fromIntegral (cols m) = extractError m e | ||
91 | 93 | ||
92 | m ?? (All,All) = m | 94 | m ?? (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' | |||
420 | arctan2 :: (Fractional e, Container c e) => c e -> c e -> c e | 424 | arctan2 :: (Fractional e, Container c e) => c e -> c e -> c e |
421 | arctan2 = arctan2' | 425 | arctan2 = arctan2' |
422 | 426 | ||
423 | cmod :: (Integral e, Container c e) => e -> c e -> c e | 427 | cmod :: (Integral e, Container c e) => Int -> c e -> c e |
424 | cmod = cmod' | 428 | cmod m = cmod' (fromIntegral m) |
425 | 429 | ||
426 | fromInt :: (Container c e) => c CInt -> c e | 430 | fromInt :: (Container c e) => c CInt -> c e |
427 | fromInt = fromInt' | 431 | fromInt = fromInt' |