aboutsummaryrefslogtreecommitdiff
path: root/src/Data
diff options
context:
space:
mode:
authorTom Smeding <tom@tomsmeding.com>2024-06-13 12:54:55 +0200
committerTom Smeding <tom@tomsmeding.com>2024-06-13 12:54:55 +0200
commit275847827d7550436eaf8cd10969f1430dae821d (patch)
tree3d33505da3c57242b2a8ba4d5e66009876cf49d3 /src/Data
parent2b447f89cbbfea6bd6c68af2f926bb52561cc822 (diff)
s{from,to}Orthotope
Diffstat (limited to 'src/Data')
-rw-r--r--src/Data/Array/Nested.hs1
-rw-r--r--src/Data/Array/Nested/Internal/Shaped.hs11
2 files changed, 12 insertions, 0 deletions
diff --git a/src/Data/Array/Nested.hs b/src/Data/Array/Nested.hs
index f75a71c..65d619a 100644
--- a/src/Data/Array/Nested.hs
+++ b/src/Data/Array/Nested.hs
@@ -38,6 +38,7 @@ module Data.Array.Nested (
-- ** Conversions
stoXArrayPrim, sfromXArrayPrim,
stoRanked,
+ sfromOrthotope, stoOrthotope,
-- * Mixed arrays
Mixed,
diff --git a/src/Data/Array/Nested/Internal/Shaped.hs b/src/Data/Array/Nested/Internal/Shaped.hs
index e453e51..5765595 100644
--- a/src/Data/Array/Nested/Internal/Shaped.hs
+++ b/src/Data/Array/Nested/Internal/Shaped.hs
@@ -21,6 +21,10 @@ import Prelude hiding (mappend, mconcat)
import Control.DeepSeq (NFData)
import Control.Monad.ST
+import Data.Array.Internal.ShapedS qualified as SS
+import Data.Array.Internal.ShapedG qualified as SG
+import Data.Array.Internal.RankedS qualified as RS
+import Data.Array.Internal.RankedG qualified as RG
import Data.Bifunctor (first)
import Data.Coerce (coerce)
import Data.Kind (Type)
@@ -316,6 +320,13 @@ sfromListPrimLinear sh l =
let M_Primitive _ xarr = toPrimitive (mfromListPrim l)
in Shaped $ fromPrimitive $ M_Primitive (shCvtSX sh) (X.reshape (SUnknown () :!% ZKX) (shCvtSX sh) xarr)
+sfromOrthotope :: PrimElt a => ShS sh -> SS.Array sh a -> Shaped sh a
+sfromOrthotope sh (SS.A (SG.A arr)) =
+ Shaped (fromPrimitive (M_Primitive (shCvtSX sh) (X.XArray (RS.A (RG.A (shsToList sh) arr)))))
+
+stoOrthotope :: PrimElt a => Shaped sh a -> SS.Array sh a
+stoOrthotope (stoPrimitive -> Shaped (M_Primitive _ (X.XArray (RS.A (RG.A _ arr))))) = SS.A (SG.A arr)
+
sunScalar :: Elt a => Shaped '[] a -> a
sunScalar arr = sindex arr ZIS