aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Smeding <tom@tomsmeding.com>2024-05-20 17:38:25 +0200
committerTom Smeding <tom@tomsmeding.com>2024-05-20 17:38:25 +0200
commit03ef563a681fce281c07d03efc693ecd343cf23d (patch)
tree511eec4ca1168b314affe9d5f8acc44e263ef646
parent697d4360aefee9e5142091e880e7384112a3419d (diff)
rfromOrthotope
-rw-r--r--src/Data/Array/Nested.hs1
-rw-r--r--src/Data/Array/Nested/Internal.hs8
2 files changed, 8 insertions, 1 deletions
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