From 172925e245728efb50d692c2f7460fd3e5f6dca2 Mon Sep 17 00:00:00 2001 From: Tom Smeding Date: Tue, 14 May 2024 10:29:29 +0200 Subject: toVector --- src/Data/Array/Nested/Internal.hs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'src/Data/Array/Nested') 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 -- cgit v1.2.3-70-g09d2