From 2b0391b9a5885af1b551c83f2dc4b8ef2b48d7bf Mon Sep 17 00:00:00 2001 From: Tom Smeding Date: Sat, 20 Apr 2024 21:56:12 +0200 Subject: fromList1 (the analogue to orthotope's fromList) --- src/Data/Array/Nested.hs | 6 +++--- src/Data/Array/Nested/Internal.hs | 9 +++++++++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/Data/Array/Nested.hs b/src/Data/Array/Nested.hs index 9219a74..8fadef6 100644 --- a/src/Data/Array/Nested.hs +++ b/src/Data/Array/Nested.hs @@ -5,7 +5,7 @@ module Data.Array.Nested ( IxR(..), rshape, rindex, rindexPartial, rgenerate, rsumOuter1, rtranspose, rappend, rscalar, rfromVector, runScalar, - rconstant, rfromList, + rconstant, rfromList, rfromList1, -- ** Lifting orthotope operations to 'Ranked' arrays rlift, @@ -15,7 +15,7 @@ module Data.Array.Nested ( KnownShape(..), SShape(..), sshape, sindex, sindexPartial, sgenerate, ssumOuter1, stranspose, sappend, sscalar, sfromVector, sunScalar, - sconstant, sfromList, + sconstant, sfromList, sfromList1, -- ** Lifting orthotope operations to 'Shaped' arrays slift, @@ -24,7 +24,7 @@ module Data.Array.Nested ( IxX(..), KnownShapeX(..), StaticShapeX(..), mgenerate, mtranspose, mappend, mfromVector, munScalar, - mconstant, + mconstant, mfromList1, -- * Array elements Elt(mshape, mindex, mindexPartial, mscalar, mfromList, mlift, mlift2), diff --git a/src/Data/Array/Nested/Internal.hs b/src/Data/Array/Nested/Internal.hs index f76b2ab..6f0cfc8 100644 --- a/src/Data/Array/Nested/Internal.hs +++ b/src/Data/Array/Nested/Internal.hs @@ -489,6 +489,9 @@ mfromVector sh v | otherwise = M_Primitive (X.fromVector sh v) +mfromList1 :: (KnownShapeX '[n], Elt a) => NonEmpty a -> Mixed '[n] a +mfromList1 = mfromList . fmap mscalar + munScalar :: Elt a => Mixed '[] a -> a munScalar arr = mindex arr IZX @@ -918,6 +921,9 @@ rfromVector sh v | Dict <- lemKnownReplicate (Proxy @n) = Ranked (mfromVector (ixCvtRX sh) v) +rfromList1 :: Elt a => NonEmpty a -> Ranked I1 a +rfromList1 = Ranked . mfromList . fmap mscalar + runScalar :: Elt a => Ranked I0 a -> a runScalar arr = rindex arr IZR @@ -1051,6 +1057,9 @@ sfromVector v | Dict <- lemKnownMapJust (Proxy @sh) = Shaped (mfromVector (ixCvtSX (cvtSShapeIxS (knownShape @sh))) v) +sfromList1 :: (KnownNat n, Elt a) => NonEmpty a -> Shaped '[n] a +sfromList1 = Shaped . mfromList . fmap mscalar + sunScalar :: Elt a => Shaped '[] a -> a sunScalar arr = sindex arr IZS -- cgit v1.2.3-70-g09d2