diff options
| author | Tom Smeding <tom@tomsmeding.com> | 2025-11-15 22:15:39 +0100 |
|---|---|---|
| committer | Tom Smeding <tom@tomsmeding.com> | 2025-11-15 22:15:39 +0100 |
| commit | 965ea2fd5aa21e1570f97957ae5613894fe8795d (patch) | |
| tree | 16da7673b5555f4d85aeeea3ac402b080e43689f | |
| parent | 91250bd41c600935207da3a35b7cc5eff6a7c5ee (diff) | |
XArray: Further optimise toListOuter
Again, thanks Mikolaj
| -rw-r--r-- | src/Data/Array/XArray.hs | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/src/Data/Array/XArray.hs b/src/Data/Array/XArray.hs index 8b4fd60..6ad48cc 100644 --- a/src/Data/Array/XArray.hs +++ b/src/Data/Array/XArray.hs @@ -302,12 +302,14 @@ fromListOuter ssh l _ -> XArray (S.ravel (ORB.fromList [length l] (coerce @[XArray sh a] @[S.Array (Rank sh) a] l))) toListOuter :: forall a n sh. Storable a => XArray (n : sh) a -> [XArray sh a] -toListOuter (XArray arr) = +toListOuter (XArray arr@(ORS.A (ORG.A _ t))) = case S.shapeL arr of + [] -> error "impossible" 0 : _ -> [] - -- orthotope doesn't seem to optimise this case, so we need to do it here + -- using orthotope's functions here would entail using rerank, which is slow, so we don't [_] | Refl <- (unsafeCoerceRefl :: sh :~: '[]) -> coerce (map S.scalar $ S.toList arr) - _ -> coerce (ORB.toList (S.unravel arr)) + -- TODO: this shares the backing array among all the results; is that what we want? + n : sh -> coerce $ map (ORG.A sh . OI.indexT t) [0 .. n - 1] fromList1 :: Storable a => StaticShX '[n] -> [a] -> XArray '[n] a fromList1 ssh l = |
