From 03ef563a681fce281c07d03efc693ecd343cf23d Mon Sep 17 00:00:00 2001 From: Tom Smeding Date: Mon, 20 May 2024 17:38:25 +0200 Subject: rfromOrthotope --- src/Data/Array/Nested.hs | 1 + src/Data/Array/Nested/Internal.hs | 8 +++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/Data/Array/Nested.hs b/src/Data/Array/Nested.hs index 2208349..7298918 100644 --- a/src/Data/Array/Nested.hs +++ b/src/Data/Array/Nested.hs @@ -16,6 +16,7 @@ module Data.Array.Nested ( -- ** Conversions rasXArrayPrim, rfromXArrayPrim, rcastToShaped, + rfromOrthotope, -- * Shaped arrays Shaped(Shaped), diff --git a/src/Data/Array/Nested/Internal.hs b/src/Data/Array/Nested/Internal.hs index a05ff84..8f18724 100644 --- a/src/Data/Array/Nested/Internal.hs +++ b/src/Data/Array/Nested/Internal.hs @@ -28,7 +28,7 @@ {-| TODO: -* Write `rconst :: OR.Array n a -> Ranked n a` +(empty list) -} @@ -1403,6 +1403,12 @@ rtoList (Ranked arr) rtoList1 :: Elt a => Ranked 1 a -> [a] rtoList1 = map runScalar . rtoList +rfromOrthotope :: PrimElt a => SNat n -> S.Array n a -> Ranked n a +rfromOrthotope sn arr + | Refl <- lemRankReplicate sn + = let xarr = XArray arr + in Ranked (fromPrimitive (M_Primitive (X.shape (ssxFromSNat sn) xarr) xarr)) + runScalar :: Elt a => Ranked 0 a -> a runScalar arr = rindex arr ZIR -- cgit v1.2.3-70-g09d2