diff options
Diffstat (limited to 'packages/base/src/Data')
-rw-r--r-- | packages/base/src/Data/Packed/Internal/Numeric.hs | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/packages/base/src/Data/Packed/Internal/Numeric.hs b/packages/base/src/Data/Packed/Internal/Numeric.hs index 67d047c..44d18b3 100644 --- a/packages/base/src/Data/Packed/Internal/Numeric.hs +++ b/packages/base/src/Data/Packed/Internal/Numeric.hs | |||
@@ -69,7 +69,7 @@ type instance ArgOf Matrix a = a -> a -> a | |||
69 | 69 | ||
70 | data Extractor | 70 | data Extractor |
71 | = All | 71 | = All |
72 | | Range Int Int | 72 | | Range Int Int Int |
73 | | Pos (Vector I) | 73 | | Pos (Vector I) |
74 | | PosCyc (Vector I) | 74 | | PosCyc (Vector I) |
75 | | Take Int | 75 | | Take Int |
@@ -89,16 +89,19 @@ infixl 9 ?? | |||
89 | 89 | ||
90 | extractError m e = error $ printf "can't extract %s from matrix %dx%d" (show e) (rows m) (cols m) | 90 | extractError m e = error $ printf "can't extract %s from matrix %dx%d" (show e) (rows m) (cols m) |
91 | 91 | ||
92 | m ?? e@(Range a b,_) | a < 0 || b >= rows m = extractError m e | 92 | m ?? (Range a s b,e) | s /= 1 = m ?? (Pos (idxs [a,a+s .. b]), e) |
93 | m ?? e@(_,Range a b) | a < 0 || b >= cols m = extractError m e | 93 | m ?? (e,Range a s b) | s /= 1 = m ?? (e, Pos (idxs [a,a+s .. b])) |
94 | |||
95 | m ?? e@(Range a _ b,_) | a < 0 || b >= rows m = extractError m e | ||
96 | m ?? e@(_,Range a _ b) | a < 0 || b >= cols m = extractError m e | ||
94 | 97 | ||
95 | m ?? e@(Pos vs,_) | minElement vs < 0 || maxElement vs >= fromIntegral (rows m) = extractError m e | 98 | m ?? e@(Pos vs,_) | minElement vs < 0 || maxElement vs >= fromIntegral (rows m) = extractError m e |
96 | m ?? e@(_,Pos vs) | minElement vs < 0 || maxElement vs >= fromIntegral (cols m) = extractError m e | 99 | m ?? e@(_,Pos vs) | minElement vs < 0 || maxElement vs >= fromIntegral (cols m) = extractError m e |
97 | 100 | ||
98 | m ?? (All,All) = m | 101 | m ?? (All,All) = m |
99 | 102 | ||
100 | m ?? (Range a b,e) | a > b = m ?? (Take 0,e) | 103 | m ?? (Range a _ b,e) | a > b = m ?? (Take 0,e) |
101 | m ?? (e,Range a b) | a > b = m ?? (e,Take 0) | 104 | m ?? (e,Range a _ b) | a > b = m ?? (e,Take 0) |
102 | 105 | ||
103 | m ?? (Take n,e) | 106 | m ?? (Take n,e) |
104 | | n <= 0 = (0><cols m) [] ?? (All,e) | 107 | | n <= 0 = (0><cols m) [] ?? (All,e) |
@@ -132,7 +135,7 @@ m ?? (er,ec) = extractR m moder rs modec cs | |||
132 | mkExt n (PosCyc ks) | 135 | mkExt n (PosCyc ks) |
133 | | n == 0 = mkExt n (Take 0) | 136 | | n == 0 = mkExt n (Take 0) |
134 | | otherwise = pos (cmod n ks) | 137 | | otherwise = pos (cmod n ks) |
135 | mkExt _ (Range mn mx) = ran mn mx | 138 | mkExt _ (Range mn _ mx) = ran mn mx |
136 | mkExt _ (Take k) = ran 0 (k-1) | 139 | mkExt _ (Take k) = ran 0 (k-1) |
137 | mkExt n (Drop k) = ran k (n-1) | 140 | mkExt n (Drop k) = ran k (n-1) |
138 | mkExt n _ = ran 0 (n-1) -- All | 141 | mkExt n _ = ran 0 (n-1) -- All |