aboutsummaryrefslogtreecommitdiff
path: root/src/Data/Array/Nested/Internal/Shaped.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/Shaped.hs
parenta6f2809ed7e245d5eee4704b152783b4672cc212 (diff)
Refactor the clever replicate-aware Show instances
Diffstat (limited to 'src/Data/Array/Nested/Internal/Shaped.hs')
-rw-r--r--src/Data/Array/Nested/Internal/Shaped.hs18
1 files changed, 5 insertions, 13 deletions
diff --git a/src/Data/Array/Nested/Internal/Shaped.hs b/src/Data/Array/Nested/Internal/Shaped.hs
index d5c9612..b7cb14d 100644
--- a/src/Data/Array/Nested/Internal/Shaped.hs
+++ b/src/Data/Array/Nested/Internal/Shaped.hs
@@ -65,18 +65,10 @@ newtype Shaped sh a = Shaped (Mixed (MapJust sh) a)
deriving instance Eq (Mixed (MapJust sh) a) => Eq (Shaped sh a)
deriving instance Ord (Mixed (MapJust sh) a) => Ord (Shaped sh a)
-instance (Show a, Elt a) => Show (Shaped sh a) where
- showsPrec d arr@(Shaped marr) = showParen (d > 10) $
- let defaultResult =
- showString "sfromListLinear " . shows (shsToList (sshape arr)) . showString " "
- . shows (stoListLinear arr)
- in if stridesAreZero (shxLength $ mshape marr) (mstrideTree marr)
- then case stoListLinear arr of
- [] -> defaultResult
- [_] -> defaultResult
- hd : _ -> showString "sreplicate " . shows (shsToList (sshape arr)) . showString " "
- . showsPrec 11 hd
- else defaultResult
+instance (Show a, Elt a) => Show (Shaped n a) where
+ showsPrec d arr@(Shaped marr) =
+ let sh = show (shsToList (sshape arr))
+ in showsMixedArray ("rfromListLinear " ++ sh) ("rreplicate " ++ sh) d marr
instance Elt a => NFData (Shaped sh a) where
rnf (Shaped arr) = rnf arr
@@ -150,7 +142,7 @@ instance Elt a => Elt (Shaped sh a) where
mshowShapeTree _ (sh, t) = "(" ++ show sh ++ ", " ++ mshowShapeTree (Proxy @a) t ++ ")"
- mstrideTree (M_Shaped arr) = mstrideTree arr
+ marrayStrides (M_Shaped arr) = marrayStrides arr
mvecsWrite :: forall sh' s. IShX sh' -> IIxX sh' -> Shaped sh a -> MixedVecs s sh' (Shaped sh a) -> ST s ()
mvecsWrite sh idx (Shaped arr) vecs =