aboutsummaryrefslogtreecommitdiff
path: root/src/Data/Array/Nested/Internal/Ranked.hs
diff options
context:
space:
mode:
authorTom Smeding <tom@tomsmeding.com>2025-04-26 10:27:39 +0200
committerTom Smeding <tom@tomsmeding.com>2025-04-26 10:27:39 +0200
commit8db33035826609bf48e15a82742981a58a0b5982 (patch)
tree848bf1bcfbd31a67c01b740c0065870f837543eb /src/Data/Array/Nested/Internal/Ranked.hs
parenta6f2809ed7e245d5eee4704b152783b4672cc212 (diff)
Refactor the clever replicate-aware Show instances
Diffstat (limited to 'src/Data/Array/Nested/Internal/Ranked.hs')
-rw-r--r--src/Data/Array/Nested/Internal/Ranked.hs16
1 files changed, 4 insertions, 12 deletions
diff --git a/src/Data/Array/Nested/Internal/Ranked.hs b/src/Data/Array/Nested/Internal/Ranked.hs
index cb8aae0..2aba1bc 100644
--- a/src/Data/Array/Nested/Internal/Ranked.hs
+++ b/src/Data/Array/Nested/Internal/Ranked.hs
@@ -65,17 +65,9 @@ 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@(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
+ showsPrec d arr@(Ranked marr) =
+ let sh = show (toList (rshape arr))
+ in showsMixedArray ("rfromListLinear " ++ sh) ("rreplicate " ++ sh) d marr
instance Elt a => NFData (Ranked n a) where
rnf (Ranked arr) = rnf arr
@@ -152,7 +144,7 @@ instance Elt a => Elt (Ranked n a) where
mshowShapeTree _ (sh, t) = "(" ++ show sh ++ ", " ++ mshowShapeTree (Proxy @a) t ++ ")"
- mstrideTree (M_Ranked arr) = mstrideTree arr
+ marrayStrides (M_Ranked arr) = marrayStrides arr
mvecsWrite :: forall sh s. IShX sh -> IIxX sh -> Ranked n a -> MixedVecs s sh (Ranked n a) -> ST s ()
mvecsWrite sh idx (Ranked arr) vecs =