aboutsummaryrefslogtreecommitdiff
path: root/src/Data/Array/Nested/Internal/Ranked.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/Ranked.hs
parent5763bf70dc67c5437207ff8e9dd08585d2ea5384 (diff)
nest, unNest
Diffstat (limited to 'src/Data/Array/Nested/Internal/Ranked.hs')
-rw-r--r--src/Data/Array/Nested/Internal/Ranked.hs10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/Data/Array/Nested/Internal/Ranked.hs b/src/Data/Array/Nested/Internal/Ranked.hs
index 3e911ac..d6e05e6 100644
--- a/src/Data/Array/Nested/Internal/Ranked.hs
+++ b/src/Data/Array/Nested/Internal/Ranked.hs
@@ -349,6 +349,16 @@ rtoOrthotope (rtoPrimitive -> Ranked (M_Primitive sh (XArray arr)))
runScalar :: Elt a => Ranked 0 a -> a
runScalar arr = rindex arr ZIR
+rnest :: forall n m a. Elt a => SNat n -> Ranked (n + m) a -> Ranked n (Ranked m a)
+rnest n arr
+ | Refl <- lemReplicatePlusApp n (Proxy @m) (Proxy @(Nothing @Nat))
+ = coerce (mnest (ssxFromSNat n) (coerce arr))
+
+runNest :: forall n m a. Elt a => Ranked n (Ranked m a) -> Ranked (n + m) a
+runNest rarr@(Ranked (M_Ranked (M_Nest _ arr)))
+ | Refl <- lemReplicatePlusApp (rrank rarr) (Proxy @m) (Proxy @(Nothing @Nat))
+ = Ranked arr
+
rrerankP :: forall n1 n2 n a b. (Storable a, Storable b)
=> SNat n -> IShR n2
-> (Ranked n1 (Primitive a) -> Ranked n2 (Primitive b))