Skip to content

Commit

Permalink
Fix show instance for empty 2D arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
tmcdonell committed Oct 27, 2016
1 parent 95ea146 commit ca23732
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions Data/Array/Accelerate/Array/Sugar.hs
Expand Up @@ -1194,14 +1194,15 @@ instance Show (Vector e) where

instance Show (Array DIM2 e) where
show arr@Array{}
= "Matrix (" ++ showShape (shape arr) ++ ") \n " ++ showMat (toMatrix (toList arr))
= "Matrix (" ++ showShape (shape arr) ++ ") " ++ showMat (toMatrix (toList arr))
where
Z :. _ :. cols = shape arr
toMatrix [] = []
toMatrix xs = let (r,rs) = splitAt cols xs
in r : toMatrix rs

showMat = ppMat . map (map show)
showMat [] = "[]"
showMat mat = "\n " ++ ppMat (map (map show) mat)

ppRow row = concatMap (++",") row
ppMat mat = "[" ++ init (intercalate "\n " (map ppRow (ppColumns mat))) ++ "]"
Expand Down

0 comments on commit ca23732

Please sign in to comment.