aboutsummaryrefslogtreecommitdiff
path: root/src/Data/Array
diff options
context:
space:
mode:
authorTom Smeding <tom@tomsmeding.com>2024-04-20 21:56:12 +0200
committerTom Smeding <tom@tomsmeding.com>2024-04-20 22:08:07 +0200
commit2b0391b9a5885af1b551c83f2dc4b8ef2b48d7bf (patch)
tree92d555a5a4f1318967bf8ff1447fadc69a26bcda /src/Data/Array
parent6fc6f4327391f14f026a9848f68a28e70cef6185 (diff)
fromList1 (the analogue to orthotope's fromList)
Diffstat (limited to 'src/Data/Array')
-rw-r--r--src/Data/Array/Nested.hs6
-rw-r--r--src/Data/Array/Nested/Internal.hs9
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