diff options
author | Mikolaj Konarski <mikolaj.konarski@gmail.com> | 2025-04-26 00:25:28 +0200 |
---|---|---|
committer | Mikolaj Konarski <mikolaj.konarski@gmail.com> | 2025-04-26 00:25:35 +0200 |
commit | 25d337c1b34192fedcd2496fe179acbd2051dd30 (patch) | |
tree | fd467d1d0d36153721dc865e31088abee028eda1 /src/Data/Array/Nested/Internal/Ranked.hs | |
parent | 4087d405b51cf32363cb7507df6ffe1a170c0f7f (diff) |
Show concisely arrays replicated from a single element (scalar or not)
Diffstat (limited to 'src/Data/Array/Nested/Internal/Ranked.hs')
-rw-r--r-- | src/Data/Array/Nested/Internal/Ranked.hs | 14 |
1 files changed, 11 insertions, 3 deletions
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 |