aboutsummaryrefslogtreecommitdiff
path: root/src/Data/Array/XArray.hs
diff options
context:
space:
mode:
authorTom Smeding <tom@tomsmeding.com>2025-11-15 17:15:37 +0100
committerTom Smeding <tom@tomsmeding.com>2025-11-15 17:15:37 +0100
commit91250bd41c600935207da3a35b7cc5eff6a7c5ee (patch)
tree91de6969b0fc3736b74a6b436ea74322eeb2515e /src/Data/Array/XArray.hs
parentf7025bc3727e5ee058df3dfebb1fb73b933ee6b0 (diff)
XArray: Optimise toListOuter
Thanks Mikolaj!
Diffstat (limited to 'src/Data/Array/XArray.hs')
-rw-r--r--src/Data/Array/XArray.hs4
1 files changed, 3 insertions, 1 deletions
diff --git a/src/Data/Array/XArray.hs b/src/Data/Array/XArray.hs
index 92d9e13..8b4fd60 100644
--- a/src/Data/Array/XArray.hs
+++ b/src/Data/Array/XArray.hs
@@ -301,10 +301,12 @@ fromListOuter ssh l
"does not match the type (" ++ show (fromSNat' m) ++ ")"
_ -> XArray (S.ravel (ORB.fromList [length l] (coerce @[XArray sh a] @[S.Array (Rank sh) a] l)))
-toListOuter :: Storable a => XArray (n : sh) a -> [XArray sh a]
+toListOuter :: forall a n sh. Storable a => XArray (n : sh) a -> [XArray sh a]
toListOuter (XArray arr) =
case S.shapeL arr of
0 : _ -> []
+ -- orthotope doesn't seem to optimise this case, so we need to do it here
+ [_] | Refl <- (unsafeCoerceRefl :: sh :~: '[]) -> coerce (map S.scalar $ S.toList arr)
_ -> coerce (ORB.toList (S.unravel arr))
fromList1 :: Storable a => StaticShX '[n] -> [a] -> XArray '[n] a