on master help sign in
Implement Array modifyIndices may accept index as argument
commite01bc90866c1da52aeacea47c846659b2fea54ba authorRanjeet Kumar Ranjan <ranjeetr@composewell.com> dateThu 24 Mar 2022, 15:04 (5 years ago) parente0cf3aa
2 files changed+4−4
benchmark/Streamly/Benchmark/Data/Array/Foreign/Mut.hs+1−1 core/src/Streamly/Internal/Data/Array/Foreign/Mut/Type.hs+3−3
benchmark/Streamly/Benchmark/Data/Array/Foreign/Mut.hs+1−1
@@ -66,7 +66,7 @@ o_1_space_serial_marray value ~(array, indices) =
6666 , benchIO "strip (> 0)" (const array)
6767 $ MArray.strip (> 0)
6868 , benchIO "modifyIndices (+ 1)" (const indices)
69− $ Stream.fold (MArray.modifyIndices (+ 1) array)
69+ $ Stream.fold (MArray.modifyIndices (\_idx val -> val + 1) array)
7070 . Stream.unfold Array.read
7171 ]
7272
core/src/Streamly/Internal/Data/Array/Foreign/Mut/Type.hs+3−3
@@ -624,8 +624,8 @@ modifyIndex i f arr@(Array{..}) = do
624624--
625625-- /Pre-release/
626626{-# INLINE modifyIndices #-}
627−modifyIndices :: forall m a. (MonadIO m, Storable a)
628− => (a -> a) -> Array a -> Fold m Int ()
627+modifyIndices :: forall m a . (MonadIO m, Storable a)
628+ => (Int -> a -> a) -> Array a -> Fold m Int ()
629629modifyIndices f Array{..} = Fold step initial extract
630630
631631 where
@@ -633,7 +633,7 @@ modifyIndices f Array{..} = Fold step initial extract
633633 initial = return $ FL.Partial ()
634634
635635 step () i =
636− let f1 x = (f x, ())
636+ let f1 x = (f i x, ())
637637 in FL.Partial <$> liftIO (modifyIndexPtr i f1 arrStart aEnd)
638638
639639 extract () = liftIO $ touch arrContents