aboutsummaryrefslogtreecommitdiff
path: root/src/Data/Array/Nested
diff options
context:
space:
mode:
authorTom Smeding <tom@tomsmeding.com>2024-05-20 23:25:36 +0200
committerTom Smeding <tom@tomsmeding.com>2024-05-20 23:25:36 +0200
commitd8d8fc39c6d52b0960c89f38bfa8ec3969a8ca02 (patch)
tree4cd0c9cf0ef6ac5ab60953bea824133e2fa8f4bf /src/Data/Array/Nested
parentdc9db431fea6bee2aa6533b9df7dee44c002f252 (diff)
iota
Diffstat (limited to 'src/Data/Array/Nested')
-rw-r--r--src/Data/Array/Nested/Internal.hs10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/Data/Array/Nested/Internal.hs b/src/Data/Array/Nested/Internal.hs
index e402f1e..308f8ce 100644
--- a/src/Data/Array/Nested/Internal.hs
+++ b/src/Data/Array/Nested/Internal.hs
@@ -55,6 +55,7 @@ import Foreign.Storable (Storable)
import GHC.IsList (IsList)
import qualified GHC.IsList as IsList
import GHC.TypeLits
+import qualified GHC.TypeNats as TypeNats
import Unsafe.Coerce
import Data.Array.Mixed
@@ -951,6 +952,9 @@ mreshape sh' arr =
(\sshIn -> X.reshapePartial (X.staticShapeFrom (mshape arr)) sshIn sh')
arr
+miota :: (Enum a, PrimElt a) => SNat n -> Mixed '[Just n] a
+miota sn = fromPrimitive $ M_Primitive (SKnown sn :$% ZSX) (X.iota sn)
+
masXArrayPrimP :: Mixed sh (Primitive a) -> (IShX sh, XArray sh a)
masXArrayPrimP (M_Primitive sh arr) = (sh, arr)
@@ -1489,6 +1493,9 @@ rreshape sh' rarr@(Ranked arr)
, Dict <- lemKnownReplicate (snatFromShR sh')
= Ranked (mreshape (shCvtRX sh') arr)
+riota :: (Enum a, PrimElt a, Elt a) => Int -> Ranked 1 a
+riota n = TypeNats.withSomeSNat (fromIntegral n) $ mtoRanked . miota
+
rasXArrayPrimP :: Ranked n (Primitive a) -> (IShR n, XArray (Replicate n Nothing) a)
rasXArrayPrimP (Ranked arr) = first shCvtXR' (masXArrayPrimP arr)
@@ -1749,6 +1756,9 @@ srev1 arr = slift (sshape arr) (\_ -> X.rev1) arr
sreshape :: Elt a => ShS sh' -> Shaped sh a -> Shaped sh' a
sreshape sh' (Shaped arr) = Shaped (mreshape (shCvtSX sh') arr)
+siota :: (Enum a, PrimElt a) => SNat n -> Shaped '[n] a
+siota sn = Shaped (miota sn)
+
sasXArrayPrimP :: Shaped sh (Primitive a) -> (ShS sh, XArray (MapJust sh) a)
sasXArrayPrimP (Shaped arr) = first shCvtXS' (masXArrayPrimP arr)