We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
minIndexBy
minIndex
maxIndexBy
maxIndex
Hello, it would be handy to have minIndexBy, minIndex, maxIndexBy, maxIndex. I adapted them from Data.Vector as follows:
Data.Vector
{-# INLINE minIndexBy #-} minIndexBy :: Massiv.Stream v Massiv.Ix1 a => (a -> a -> Ordering) -> Massiv.Vector v a -> Massiv.Ix1 minIndexBy cmpr = fst . Massiv.sfoldl1' imin . Massiv.szip (Massiv.sfromList [0..]) where imin (i,x) (j,y) = i `seq` j `seq` case cmpr x y of GT -> (j,y) _ -> (i,x) {-# INLINE minIndex #-} minIndex :: Ord a => Massiv.Stream v Massiv.Ix1 a => Massiv.Vector v a -> Massiv.Ix1 minIndex = minIndexBy compare {-# INLINE maxIndexBy #-} maxIndexBy :: Massiv.Stream v Massiv.Ix1 a => (a -> a -> Ordering) -> Massiv.Vector v a -> Massiv.Ix1 maxIndexBy cmpr = fst . Massiv.sfoldl1' imax . Massiv.szip (Massiv.sfromList [0..]) where imax (i,x) (j,y) = i `seq` j `seq` case cmpr x y of LT -> (j,y) _ -> (i,x) {-# INLINE maxIndex #-} maxIndex :: Ord a => Massiv.Stream v Massiv.Ix1 a => Massiv.Vector v a -> Massiv.Ix1 maxIndex = maxIndexBy compare {- minIndex $ ((Massiv.fromList Massiv.Seq ([4,3,2,1,0,1,2])) :: Massiv.Vector Massiv.P Massiv.Ix1) -- == 4 [index]...................................0 1 2 3 4 5 6 maxIndex $ ((Massiv.fromList Massiv.Seq ([4,3,2,1,9,1,2])) :: Massiv.Vector Massiv.P Massiv.Ix1) -- == 4 -}
The text was updated successfully, but these errors were encountered:
No branches or pull requests
Hello, it would be handy to have
minIndexBy
,minIndex
,maxIndexBy
,maxIndex
. I adapted them fromData.Vector
as follows:The text was updated successfully, but these errors were encountered: