From 1f3d57e13441f86b97ee7ff213bb4a677e31f2db Mon Sep 17 00:00:00 2001 From: Tom Smeding Date: Sun, 9 Jun 2024 23:09:19 +0200 Subject: argmin and argmax --- src/Data/Array/Nested/Internal/Ranked.hs | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src/Data/Array/Nested/Internal/Ranked.hs') diff --git a/src/Data/Array/Nested/Internal/Ranked.hs b/src/Data/Array/Nested/Internal/Ranked.hs index 55ae59f..c16cfb7 100644 --- a/src/Data/Array/Nested/Internal/Ranked.hs +++ b/src/Data/Array/Nested/Internal/Ranked.hs @@ -449,6 +449,18 @@ rreshape sh' rarr@(Ranked arr) riota :: (Enum a, PrimElt a, Elt a) => Int -> Ranked 1 a riota n = TN.withSomeSNat (fromIntegral n) $ mtoRanked . miota +-- | Throws if the array is empty. +rargMinPrim :: (PrimElt a, NumElt a) => Ranked n a -> IIxR n +rargMinPrim rarr@(Ranked arr) + | Refl <- lemRankReplicate (rrank (rtoPrimitive rarr)) + = ixCvtXR (margMinPrim arr) + +-- | Throws if the array is empty. +rargMaxPrim :: (PrimElt a, NumElt a) => Ranked n a -> IIxR n +rargMaxPrim rarr@(Ranked arr) + | Refl <- lemRankReplicate (rrank (rtoPrimitive rarr)) + = ixCvtXR (margMaxPrim arr) + rtoXArrayPrimP :: Ranked n (Primitive a) -> (IShR n, XArray (Replicate n Nothing) a) rtoXArrayPrimP (Ranked arr) = first shCvtXR' (mtoXArrayPrimP arr) -- cgit v1.2.3-70-g09d2