From 6a8520f957531bd0e41bd8adde9dedbf1cc916be Mon Sep 17 00:00:00 2001 From: Tom Smeding Date: Thu, 23 May 2024 23:10:23 +0200 Subject: fromList1Prim --- src/Data/Array/Nested/Internal.hs | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src/Data/Array/Nested') diff --git a/src/Data/Array/Nested/Internal.hs b/src/Data/Array/Nested/Internal.hs index 118612f..c70da54 100644 --- a/src/Data/Array/Nested/Internal.hs +++ b/src/Data/Array/Nested/Internal.hs @@ -926,6 +926,12 @@ mtoVector arr = mtoVectorP (toPrimitive arr) mfromList1 :: Elt a => NonEmpty a -> Mixed '[Nothing] a mfromList1 = mfromListOuter . fmap mscalar -- TODO: optimise? +mfromList1Prim :: PrimElt a => [a] -> Mixed '[Nothing] a +mfromList1Prim l = + let ssh = SUnknown () :!% ZKX + xarr = X.fromList1 ssh l + in fromPrimitive $ M_Primitive (X.shape ssh xarr) xarr + mtoList1 :: Elt a => Mixed '[n] a -> [a] mtoList1 = map munScalar . mtoListOuter @@ -1521,6 +1527,9 @@ rfromListOuter l rfromList1 :: Elt a => NonEmpty a -> Ranked 1 a rfromList1 l = Ranked (mfromList1 l) +rfromList1Prim :: PrimElt a => [a] -> Ranked 1 a +rfromList1Prim l = Ranked (mfromList1Prim l) + rtoListOuter :: forall n a. Elt a => Ranked (n + 1) a -> [Ranked n a] rtoListOuter (Ranked arr) | Refl <- X.lemReplicateSucc @(Nothing @Nat) @n @@ -1832,6 +1841,9 @@ sfromListOuter sn l = Shaped (mcast (SUnknown () :!% ZKX) (SKnown sn :$% ZSX) Pr sfromList1 :: Elt a => SNat n -> NonEmpty a -> Shaped '[n] a sfromList1 sn = Shaped . mcast (SUnknown () :!% ZKX) (SKnown sn :$% ZSX) Proxy . mfromList1 +sfromList1Prim :: (PrimElt a, Elt a) => SNat n -> [a] -> Shaped '[n] a +sfromList1Prim sn = Shaped . mcast (SUnknown () :!% ZKX) (SKnown sn :$% ZSX) Proxy . mfromList1Prim + stoListOuter :: Elt a => Shaped (n : sh) a -> [Shaped sh a] stoListOuter (Shaped arr) = coerce (mtoListOuter arr) -- cgit v1.2.3-70-g09d2