summaryrefslogtreecommitdiff
path: root/packages/base/src/Data
diff options
context:
space:
mode:
Diffstat (limited to 'packages/base/src/Data')
-rw-r--r--packages/base/src/Data/Packed/Internal/Numeric.hs15
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
70data Extractor 70data 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
90extractError m e = error $ printf "can't extract %s from matrix %dx%d" (show e) (rows m) (cols m) 90extractError m e = error $ printf "can't extract %s from matrix %dx%d" (show e) (rows m) (cols m)
91 91
92m ?? e@(Range a b,_) | a < 0 || b >= rows m = extractError m e 92m ?? (Range a s b,e) | s /= 1 = m ?? (Pos (idxs [a,a+s .. b]), e)
93m ?? e@(_,Range a b) | a < 0 || b >= cols m = extractError m e 93m ?? (e,Range a s b) | s /= 1 = m ?? (e, Pos (idxs [a,a+s .. b]))
94
95m ?? e@(Range a _ b,_) | a < 0 || b >= rows m = extractError m e
96m ?? e@(_,Range a _ b) | a < 0 || b >= cols m = extractError m e
94 97
95m ?? e@(Pos vs,_) | minElement vs < 0 || maxElement vs >= fromIntegral (rows m) = extractError m e 98m ?? e@(Pos vs,_) | minElement vs < 0 || maxElement vs >= fromIntegral (rows m) = extractError m e
96m ?? e@(_,Pos vs) | minElement vs < 0 || maxElement vs >= fromIntegral (cols m) = extractError m e 99m ?? e@(_,Pos vs) | minElement vs < 0 || maxElement vs >= fromIntegral (cols m) = extractError m e
97 100
98m ?? (All,All) = m 101m ?? (All,All) = m
99 102
100m ?? (Range a b,e) | a > b = m ?? (Take 0,e) 103m ?? (Range a _ b,e) | a > b = m ?? (Take 0,e)
101m ?? (e,Range a b) | a > b = m ?? (e,Take 0) 104m ?? (e,Range a _ b) | a > b = m ?? (e,Take 0)
102 105
103m ?? (Take n,e) 106m ?? (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