aboutsummaryrefslogtreecommitdiff
path: root/src/Data/Array/Nested/Internal/Ranked.hs
diff options
context:
space:
mode:
authorTom Smeding <tom@tomsmeding.com>2024-06-09 23:09:19 +0200
committerTom Smeding <tom@tomsmeding.com>2024-06-09 23:09:19 +0200
commit1f3d57e13441f86b97ee7ff213bb4a677e31f2db (patch)
treee72bfd568b032a9af611118038c2eeb6f347ea22 /src/Data/Array/Nested/Internal/Ranked.hs
parentc8f99847359a92289cf0ded280069794f6abae6a (diff)
argmin and argmax
Diffstat (limited to 'src/Data/Array/Nested/Internal/Ranked.hs')
-rw-r--r--src/Data/Array/Nested/Internal/Ranked.hs12
1 files changed, 12 insertions, 0 deletions
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)