aboutsummaryrefslogtreecommitdiff
path: root/src/Data/Array/Nested/Internal/Ranked.hs
diff options
context:
space:
mode:
authorTom Smeding <tom@tomsmeding.com>2024-06-03 19:56:57 +0200
committerTom Smeding <tom@tomsmeding.com>2024-06-03 19:56:57 +0200
commitac061cf450b1c8e153de06f7b12256914c496788 (patch)
tree6774c5752674d749518986d575f64ce95728568f /src/Data/Array/Nested/Internal/Ranked.hs
parenta25d4061e219cec153f066fddbf710abd63b5e48 (diff)
rrank, rtoOrthotope
Diffstat (limited to 'src/Data/Array/Nested/Internal/Ranked.hs')
-rw-r--r--src/Data/Array/Nested/Internal/Ranked.hs8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/Data/Array/Nested/Internal/Ranked.hs b/src/Data/Array/Nested/Internal/Ranked.hs
index d6eff31..894ed0d 100644
--- a/src/Data/Array/Nested/Internal/Ranked.hs
+++ b/src/Data/Array/Nested/Internal/Ranked.hs
@@ -215,6 +215,9 @@ instance (FloatElt a, NumElt a, PrimElt a) => Floating (Ranked n a) where
rshape :: forall n a. Elt a => Ranked n a -> IShR n
rshape (Ranked arr) = shCvtXR' (mshape arr)
+rrank :: Elt a => Ranked n a -> SNat n
+rrank = shrToSNat . rshape
+
rindex :: Elt a => Ranked n a -> IIxR n -> a
rindex (Ranked arr) idx = mindex arr (ixCvtRX idx)
@@ -331,6 +334,11 @@ rfromOrthotope sn arr
= let xarr = XArray arr
in Ranked (fromPrimitive (M_Primitive (X.shape (ssxFromSNat sn) xarr) xarr))
+rtoOrthotope :: PrimElt a => Ranked n a -> S.Array n a
+rtoOrthotope (rtoPrimitive -> Ranked (M_Primitive sh (XArray arr)))
+ | Refl <- lemRankReplicate (shrToSNat $ shCvtXR' sh)
+ = arr
+
runScalar :: Elt a => Ranked 0 a -> a
runScalar arr = rindex arr ZIR