Skip to content

Commit a30426a

Browse files
authored
Merge pull request #18 from Mikolaj/master
Make error display consistent
2 parents e64c77a + 98ec66b commit a30426a

File tree

6 files changed

+23
-23
lines changed

6 files changed

+23
-23
lines changed

Data/Array/Dynamic/MatMul.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ matMul x y | [m, n] <- shX, [n', o] <- shY, n == n' =
2525
yv = reshape [n] $ slice [(0, n), (j, 1)] y
2626
in sum $ zipWithA (*) xv yv
2727
| otherwise =
28-
error $ "matMul: bad shapes " ++
28+
error $ "matMul: bad shapes: " ++
2929
show shX ++ " * " ++ show shY
3030
where shX = shapeL x
3131
shY = shapeL y

Data/Array/Internal.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,7 @@ padT v aps ash at = (ss, fromVectorT ss $ vConcat $ pad' aps ash st at)
488488
pad' [] sh _ t = [toVectorT sh t]
489489
pad' ((l,h):ps) (s:sh) (n:ns) t =
490490
[vReplicate (n*l) v] ++ concatMap (pad' ps sh ns . indexT t) [0..s-1] ++ [vReplicate (n*h) v]
491-
pad' _ _ _ _ = error $ "pad: rank mismatch: " ++ show (length aps, length ash)
491+
pad' _ _ _ _ = error $ "pad: rank mismatch " ++ show (length aps, length ash)
492492
_ : st = getStridesT ss
493493
ss = zipWithLong2 (\ (l,h) s -> l+s+h) aps ash
494494

@@ -507,7 +507,7 @@ simpleReshape osts os ns
507507
loop [] [] = []
508508
loop (1:ss) sts = 0 : loop ss sts
509509
loop (_:ss) (st:sts) = st : loop ss sts
510-
loop _ _ = error $ "simpleReshape: shouldn't happen: " ++ show (osts, os, ns)
510+
loop _ _ = error $ "simpleReshape: shouldn't happen " ++ show (osts, os, ns)
511511
simpleReshape _ _ _ = Nothing
512512

513513
-- Note: assumes + is commutative&associative.

Data/Array/Internal/DynamicG.hs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ toVector (A sh t) = toVectorT sh t
125125
-- O(n) time.
126126
{-# INLINE fromList #-}
127127
fromList :: (HasCallStack, Vector v, VecElem v a) => ShapeL -> [a] -> Array v a
128-
fromList ss vs | n /= l = error $ "fromList: size mismatch" ++ show (n, l)
128+
fromList ss vs | n /= l = error $ "fromList: size mismatch " ++ show (n, l)
129129
| otherwise = A ss $ T st 0 $ vFromList vs
130130
where n : st = getStridesT ss
131131
l = length vs
@@ -135,7 +135,7 @@ fromList ss vs | n /= l = error $ "fromList: size mismatch" ++ show (n, l)
135135
-- O(1) time.
136136
{-# INLINE fromVector #-}
137137
fromVector :: (HasCallStack, Vector v, VecElem v a) => ShapeL -> v a -> Array v a
138-
fromVector ss v | n /= l = error $ "fromList: size mismatch" ++ show (n, l)
138+
fromVector ss v | n /= l = error $ "fromList: size mismatch " ++ show (n, l)
139139
| otherwise = A ss $ T st 0 v
140140
where n : st = getStridesT ss
141141
l = vLength v
@@ -211,31 +211,31 @@ mapA f (A s t) = A s (mapT s f t)
211211
zipWithA :: (HasCallStack, Vector v, VecElem v a, VecElem v b, VecElem v c) =>
212212
(a -> b -> c) -> Array v a -> Array v b -> Array v c
213213
zipWithA f (A s t) (A s' t') | s == s' = A s (zipWithT s f t t')
214-
| otherwise = error $ "zipWithA: shape mismatch: " ++ show (s, s')
214+
| otherwise = error $ "zipWithA: shape mismatch " ++ show (s, s')
215215

216216
-- | Map over the array elements.
217217
-- O(n) time.
218218
{-# INLINE zipWith3A #-}
219219
zipWith3A :: (HasCallStack, Vector v, VecElem v a, VecElem v b, VecElem v c, VecElem v d) =>
220220
(a -> b -> c -> d) -> Array v a -> Array v b -> Array v c -> Array v d
221221
zipWith3A f (A s t) (A s' t') (A s'' t'') | s == s' && s == s'' = A s (zipWith3T s f t t' t'')
222-
| otherwise = error $ "zipWith3A: shape mismatch: " ++ show (s, s', s'')
222+
| otherwise = error $ "zipWith3A: shape mismatch " ++ show (s, s', s'')
223223

224224
-- | Map over the array elements.
225225
-- O(n) time.
226226
{-# INLINE zipWith4A #-}
227227
zipWith4A :: (HasCallStack, Vector v, VecElem v a, VecElem v b, VecElem v c, VecElem v d, VecElem v e) =>
228228
(a -> b -> c -> d -> e) -> Array v a -> Array v b -> Array v c -> Array v d -> Array v e
229229
zipWith4A f (A s t) (A s' t') (A s'' t'') (A s''' t''') | s == s' && s == s'' && s == s''' = A s (zipWith4T s f t t' t'' t''')
230-
| otherwise = error $ "zipWith4A: shape mismatch: " ++ show (s, s', s'', s''')
230+
| otherwise = error $ "zipWith4A: shape mismatch " ++ show (s, s', s'', s''')
231231

232232
-- | Map over the array elements.
233233
-- O(n) time.
234234
{-# INLINE zipWith5A #-}
235235
zipWith5A :: (HasCallStack, Vector v, VecElem v a, VecElem v b, VecElem v c, VecElem v d, VecElem v e, VecElem v f) =>
236236
(a -> b -> c -> d -> e -> f) -> Array v a -> Array v b -> Array v c -> Array v d -> Array v e -> Array v f
237237
zipWith5A f (A s t) (A s' t') (A s'' t'') (A s''' t''') (A s'''' t'''') | s == s' && s == s'' && s == s''' && s == s'''' = A s (zipWith5T s f t t' t'' t''' t'''')
238-
| otherwise = error $ "zipWith5A: shape mismatch: " ++ show (s, s', s'', s''', s'''')
238+
| otherwise = error $ "zipWith5A: shape mismatch " ++ show (s, s', s'', s''', s'''')
239239

240240
-- | Pad each dimension on the low and high side with the given value.
241241
-- O(n) time.
@@ -317,9 +317,9 @@ window :: (HasCallStack, Vector v) => [Int] -> Array v a -> Array v a
317317
window aws (A ash (T ss o v)) = A (win aws ash) (T (ss' ++ ss) o v)
318318
where ss' = zipWith const ss aws
319319
win (w:ws) (s:sh) | w <= s = s - w + 1 : win ws sh
320-
| otherwise = error $ "window: bad window size : " ++ show (w, s)
320+
| otherwise = error $ "window: bad window size " ++ show (w, s)
321321
win [] sh = aws ++ sh
322-
win _ _ = error $ "window: rank mismatch: " ++ show (aws, ash)
322+
win _ _ = error $ "window: rank mismatch " ++ show (aws, ash)
323323

324324
-- | Stride the outermost dimensions.
325325
-- E.g., if the array shape is @[10,12,8]@ and the strides are
@@ -331,7 +331,7 @@ stride :: (HasCallStack, Vector v) => [Int] -> Array v a -> Array v a
331331
stride ats (A ash (T ss o v)) = A (str ats ash) (T (zipWith (*) (ats ++ repeat 1) ss) o v)
332332
where str (t:ts) (s:sh) = (s+t-1) `quot` t : str ts sh
333333
str [] sh = sh
334-
str _ _ = error $ "stride: rank mismatch: " ++ show (ats, ash)
334+
str _ _ = error $ "stride: rank mismatch " ++ show (ats, ash)
335335

336336
-- | Rotate the array k times along the d'th dimension.
337337
-- E.g., if the array shape is @[2, 3, 2]@, d is 1, and k is 4,
@@ -496,7 +496,7 @@ broadcast ds sh a | length ds /= rank a = error "broadcast: wrong number of broa
496496
update :: (HasCallStack, Vector v, VecElem v a) =>
497497
Array v a -> [([Int], a)] -> Array v a
498498
update (A sh t) us | all (ok . fst) us = A sh $ updateT sh t us
499-
| otherwise = error $ "update: index out of bounds " ++ show (filter (not . ok) $ map fst us)
499+
| otherwise = error $ "update: index out of bounds: " ++ show (filter (not . ok) $ map fst us)
500500
where ok is = length is == r && and (zipWith (\ i s -> 0 <= i && i < s) is sh)
501501
r = length sh
502502

Data/Array/Internal/RankedG.hs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ fromList ss vs | n /= l = error $ "fromList: size mismatch " ++ show (n, l)
151151
{-# INLINE fromVector #-}
152152
fromVector :: forall n v a . (HasCallStack, Vector v, VecElem v a, KnownNat n) =>
153153
ShapeL -> v a -> Array n v a
154-
fromVector ss v | n /= l = error $ "fromVector: size mismatch" ++ show (n, l)
154+
fromVector ss v | n /= l = error $ "fromVector: size mismatch " ++ show (n, l)
155155
| length ss /= valueOf @n = error $ "fromVector: rank mismatch " ++ show (length ss, valueOf @n :: Int)
156156
| otherwise = A ss $ T st 0 v
157157
where n : st = getStridesT ss
@@ -233,15 +233,15 @@ mapA f (A s t) = A s (mapT s f t)
233233
zipWithA :: (Vector v, VecElem v a, VecElem v b, VecElem v c) =>
234234
(a -> b -> c) -> Array n v a -> Array n v b -> Array n v c
235235
zipWithA f (A s t) (A s' t') | s == s' = A s (zipWithT s f t t')
236-
| otherwise = error $ "zipWithA: shape mismatch: " ++ show (s, s')
236+
| otherwise = error $ "zipWithA: shape mismatch " ++ show (s, s')
237237

238238
-- | Map over the array elements.
239239
-- O(n) time.
240240
{-# INLINE zipWith3A #-}
241241
zipWith3A :: (Vector v, VecElem v a, VecElem v b, VecElem v c, VecElem v d) =>
242242
(a -> b -> c -> d) -> Array n v a -> Array n v b -> Array n v c -> Array n v d
243243
zipWith3A f (A s t) (A s' t') (A s'' t'') | s == s' && s == s'' = A s (zipWith3T s f t t' t'')
244-
| otherwise = error $ "zipWith3A: shape mismatch: " ++ show (s, s', s'')
244+
| otherwise = error $ "zipWith3A: shape mismatch " ++ show (s, s', s'')
245245

246246
-- | Pad each dimension on the low and high side with the given value.
247247
-- O(n) time.
@@ -322,13 +322,13 @@ unravel = rerank @1 scalar
322322
{-# INLINE window #-}
323323
window :: forall n n' v a . (Vector v, KnownNat n, KnownNat n') =>
324324
[Int] -> Array n v a -> Array n' v a
325-
window aws _ | valueOf @n' /= length aws + valueOf @n = error $ "window: rank mismatch: " ++ show (valueOf @n' :: Int, length aws, valueOf @n :: Int)
325+
window aws _ | valueOf @n' /= length aws + valueOf @n = error $ "window: rank mismatch " ++ show (valueOf @n' :: Int, length aws, valueOf @n :: Int)
326326
window aws (A ash (T ss o v)) = A (win aws ash) (T (ss' ++ ss) o v)
327327
where ss' = zipWith const ss aws
328328
win (w:ws) (s:sh) | w <= s = s - w + 1 : win ws sh
329-
| otherwise = error $ "window: bad window size : " ++ show (w, s)
329+
| otherwise = error $ "window: bad window size " ++ show (w, s)
330330
win [] sh = aws ++ sh
331-
win _ _ = error $ "window: rank mismatch: " ++ show (aws, ash)
331+
win _ _ = error $ "window: rank mismatch " ++ show (aws, ash)
332332

333333
-- | Stride the outermost dimensions.
334334
-- E.g., if the array shape is @[10,12,8]@ and the strides are
@@ -339,7 +339,7 @@ stride :: (Vector v) => [Int] -> Array n v a -> Array n v a
339339
stride ats (A ash (T ss o v)) = A (str ats ash) (T (zipWith (*) (ats ++ repeat 1) ss) o v)
340340
where str (t:ts) (s:sh) = (s+t-1) `quot` t : str ts sh
341341
str [] sh = sh
342-
str _ _ = error $ "stride: rank mismatch: " ++ show (ats, ash)
342+
str _ _ = error $ "stride: rank mismatch " ++ show (ats, ash)
343343

344344
-- | Rotate the array k times along the d'th dimension.
345345
-- E.g., if the array shape is @[2, 3, 2]@, d is 1, and k is 4,

Data/Array/Internal/Shape.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ withShapeP [] f = f (Proxy :: Proxy ('[] :: [Nat]))
203203
withShapeP (n:ns) f =
204204
case someNatVal (toInteger n) of
205205
Just (SomeNat (_ :: Proxy n)) -> withShapeP ns (\ (_ :: Proxy ns) -> f (Proxy :: Proxy (n ': ns)))
206-
_ -> error $ "withShape: bad size " ++ show n
206+
_ -> error $ "withShape: bad size: " ++ show n
207207

208208
withShape :: [Int] -> (forall sh . (Shape sh) => r) -> r
209209
withShape sh f = withShapeP sh (\ (_ :: Proxy sh) -> f @sh)

Data/Array/Internal/ShapedG.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ rank _ = valueOf @(Rank sh)
121121
{-# INLINE index #-}
122122
index :: forall s sh v a . (HasCallStack, Vector v, KnownNat s) =>
123123
Array (s:sh) v a -> Int -> Array sh v a
124-
index (A t) i | i < 0 || i >= s = error $ "index: out of bounds " ++ show i ++ " >= " ++ show s
124+
index (A t) i | i < 0 || i >= s = error $ "index: out of bounds: " ++ show i ++ " >= " ++ show s
125125
| otherwise = A $ indexT t i
126126
where s = valueOf @s
127127

@@ -155,7 +155,7 @@ fromList vs | n /= l = error $ "fromList: size mismatch " ++ show (n, l)
155155
{-# INLINE fromVector #-}
156156
fromVector :: forall sh v a . (HasCallStack, Vector v, VecElem v a, Shape sh) =>
157157
v a -> Array sh v a
158-
fromVector v | n /= l = error $ "fromVector: size mismatch" ++ show (n, l)
158+
fromVector v | n /= l = error $ "fromVector: size mismatch " ++ show (n, l)
159159
| otherwise = A $ T st 0 v
160160
where n : st = getStridesT ss
161161
l = vLength v

0 commit comments

Comments
 (0)