aboutsummaryrefslogtreecommitdiff
path: root/src/Data/Array/Nested/Internal/Shaped.hs
diff options
context:
space:
mode:
authorTom Smeding <tom@tomsmeding.com>2024-06-09 21:06:13 +0200
committerTom Smeding <tom@tomsmeding.com>2024-06-09 21:06:13 +0200
commitf70a381a05ec86767365b7d16b674ceff318d07d (patch)
tree09cbcf7877ca24df087978cdfb50175a80be5080 /src/Data/Array/Nested/Internal/Shaped.hs
parent5763bf70dc67c5437207ff8e9dd08585d2ea5384 (diff)
nest, unNest
Diffstat (limited to 'src/Data/Array/Nested/Internal/Shaped.hs')
-rw-r--r--src/Data/Array/Nested/Internal/Shaped.hs10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/Data/Array/Nested/Internal/Shaped.hs b/src/Data/Array/Nested/Internal/Shaped.hs
index 7d523b0..d1881c1 100644
--- a/src/Data/Array/Nested/Internal/Shaped.hs
+++ b/src/Data/Array/Nested/Internal/Shaped.hs
@@ -310,6 +310,16 @@ sfromListPrimLinear sh l =
sunScalar :: Elt a => Shaped '[] a -> a
sunScalar arr = sindex arr ZIS
+snest :: forall sh sh' a. Elt a => ShS sh -> Shaped (sh ++ sh') a -> Shaped sh (Shaped sh' a)
+snest sh arr
+ | Refl <- lemMapJustApp sh (Proxy @sh')
+ = coerce (mnest (ssxFromShape (shCvtSX sh)) (coerce arr))
+
+sunNest :: forall sh sh' a. Elt a => Shaped sh (Shaped sh' a) -> Shaped (sh ++ sh') a
+sunNest sarr@(Shaped (M_Shaped (M_Nest _ arr)))
+ | Refl <- lemMapJustApp (sshape sarr) (Proxy @sh')
+ = Shaped arr
+
srerankP :: forall sh1 sh2 sh a b. (Storable a, Storable b)
=> ShS sh -> ShS sh2
-> (Shaped sh1 (Primitive a) -> Shaped sh2 (Primitive b))