aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTom Smeding <tom@tomsmeding.com>2024-05-14 10:29:29 +0200
committerTom Smeding <tom@tomsmeding.com>2024-05-14 10:29:29 +0200
commit172925e245728efb50d692c2f7460fd3e5f6dca2 (patch)
treec8f6f84ad4ff7013807830462d79e07fc5c18857 /src
parentc2fb07100ef8954ef51a5fabfe1b77cd40dd9b61 (diff)
toVector
Diffstat (limited to 'src')
-rw-r--r--src/Data/Array/Nested.hs6
-rw-r--r--src/Data/Array/Nested/Internal.hs18
2 files changed, 21 insertions, 3 deletions
diff --git a/src/Data/Array/Nested.hs b/src/Data/Array/Nested.hs
index 758356c..6bc3b05 100644
--- a/src/Data/Array/Nested.hs
+++ b/src/Data/Array/Nested.hs
@@ -7,7 +7,7 @@ module Data.Array.Nested (
IxR(.., ZIR, (:.:)), IIxR, knownIxR,
ShR(.., ZSR, (:$:)), knownShR,
rshape, rindex, rindexPartial, rgenerate, rsumOuter1,
- rtranspose, rappend, rscalar, rfromVector, runScalar,
+ rtranspose, rappend, rscalar, rfromVector, rtoVector, runScalar,
rconstant, rfromList, rfromList1, rtoList, rtoList1,
rslice,
-- ** Lifting orthotope operations to 'Ranked' arrays
@@ -19,7 +19,7 @@ module Data.Array.Nested (
IxS(.., ZIS, (:.$)), IIxS,
ShS(..), KnownShape(..),
sshape, sindex, sindexPartial, sgenerate, ssumOuter1,
- stranspose, sappend, sscalar, sfromVector, sunScalar,
+ stranspose, sappend, sscalar, sfromVector, stoVector, sunScalar,
sconstant, sfromList, sfromList1, stoList, stoList1,
sslice,
-- ** Lifting orthotope operations to 'Shaped' arrays
@@ -29,7 +29,7 @@ module Data.Array.Nested (
Mixed,
IxX(..), IIxX,
KnownShapeX(..), StaticShX(..),
- mgenerate, mtranspose, mappend, mfromVector, munScalar,
+ mgenerate, mtranspose, mappend, mfromVector, mtoVector, munScalar,
mconstant, mfromList1, mtoList1, mslice,
-- * Array elements
diff --git a/src/Data/Array/Nested/Internal.hs b/src/Data/Array/Nested/Internal.hs
index 29592ac..3084e98 100644
--- a/src/Data/Array/Nested/Internal.hs
+++ b/src/Data/Array/Nested/Internal.hs
@@ -512,6 +512,12 @@ mfromVectorP sh v = M_Primitive (X.fromVector sh v)
mfromVector :: forall sh a. (KnownShapeX sh, Storable a, PrimElt a) => IShX sh -> VS.Vector a -> Mixed sh a
mfromVector sh v = fromPrimitive (mfromVectorP sh v)
+mtoVectorP :: Storable a => Mixed sh (Primitive a) -> VS.Vector a
+mtoVectorP (M_Primitive v) = X.toVector v
+
+mtoVector :: (Storable a, PrimElt a) => Mixed sh a -> VS.Vector a
+mtoVector arr = mtoVectorP (coerce toPrimitive arr)
+
mfromList1 :: (KnownShapeX '[n], Elt a) => NonEmpty a -> Mixed '[n] a
mfromList1 = mfromList . fmap mscalar
@@ -1036,6 +1042,12 @@ rfromVectorP sh v
rfromVector :: forall n a. (KnownINat n, Storable a, PrimElt a) => IShR n -> VS.Vector a -> Ranked n a
rfromVector sh v = coerce fromPrimitive (rfromVectorP sh v)
+rtoVectorP :: Storable a => Ranked n (Primitive a) -> VS.Vector a
+rtoVectorP = coerce mtoVectorP
+
+rtoVector :: (Storable a, PrimElt a) => Ranked n a -> VS.Vector a
+rtoVector = coerce mtoVector
+
rfromList :: forall n a. (KnownINat n, Elt a) => NonEmpty (Ranked n a) -> Ranked (S n) a
rfromList l
| Dict <- lemKnownReplicate (Proxy @n)
@@ -1236,6 +1248,12 @@ sfromVectorP v
sfromVector :: forall sh a. (KnownShape sh, Storable a, PrimElt a) => VS.Vector a -> Shaped sh a
sfromVector v = coerce fromPrimitive (sfromVectorP @sh @a v)
+stoVectorP :: Storable a => Shaped sh (Primitive a) -> VS.Vector a
+stoVectorP = coerce mtoVectorP
+
+stoVector :: (Storable a, PrimElt a) => Shaped sh a -> VS.Vector a
+stoVector = coerce mtoVector
+
sfromList :: forall n sh a. (KnownNat n, KnownShape sh, Elt a)
=> NonEmpty (Shaped sh a) -> Shaped (n : sh) a
sfromList l