From ac061cf450b1c8e153de06f7b12256914c496788 Mon Sep 17 00:00:00 2001 From: Tom Smeding Date: Mon, 3 Jun 2024 19:56:57 +0200 Subject: rrank, rtoOrthotope --- src/Data/Array/Nested/Internal/Ranked.hs | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'src/Data/Array/Nested') 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 -- cgit v1.2.3-70-g09d2