From 25d337c1b34192fedcd2496fe179acbd2051dd30 Mon Sep 17 00:00:00 2001 From: Mikolaj Konarski Date: Sat, 26 Apr 2025 00:25:28 +0200 Subject: Show concisely arrays replicated from a single element (scalar or not) --- src/Data/Array/Nested/Internal/Ranked.hs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'src/Data/Array/Nested/Internal/Ranked.hs') diff --git a/src/Data/Array/Nested/Internal/Ranked.hs b/src/Data/Array/Nested/Internal/Ranked.hs index c501015..cb8aae0 100644 --- a/src/Data/Array/Nested/Internal/Ranked.hs +++ b/src/Data/Array/Nested/Internal/Ranked.hs @@ -65,9 +65,17 @@ deriving instance Eq (Mixed (Replicate n Nothing) a) => Eq (Ranked n a) deriving instance Ord (Mixed (Replicate n Nothing) a) => Ord (Ranked n a) instance (Show a, Elt a) => Show (Ranked n a) where - showsPrec d arr = showParen (d > 10) $ - showString "rfromListLinear " . shows (toList (rshape arr)) . showString " " - . shows (rtoListLinear arr) + showsPrec d arr@(Ranked marr) = showParen (d > 10) $ + let defaultResult = + showString "rfromListLinear " . shows (toList (rshape arr)) . showString " " + . shows (rtoListLinear arr) + in if stridesAreZero (shxLength $ mshape marr) (mstrideTree marr) + then case rtoListLinear arr of + [] -> defaultResult + [_] -> defaultResult + hd : _ -> showString "rreplicate " . shows (toList (rshape arr)) . showString " " + . showsPrec 11 hd + else defaultResult instance Elt a => NFData (Ranked n a) where rnf (Ranked arr) = rnf arr -- cgit v1.2.3-70-g09d2