on master help sign in
Change the signature of array getIndices
c8e46a7Ranjeet Kumar Ranjan
src/Streamly/Internal/Data/Array/Foreign.hs+6−3
@@ -150,6 +150,8 @@ import qualified Streamly.Internal.Data.Stream.StreamD as D
150import qualified Streamly.Internal.Data.Unfold as Unfold
150import qualified Streamly.Internal.Data.Unfold as Unfold
151import qualified Streamly.Internal.Data.Ring.Foreign as RB
151import qualified Streamly.Internal.Data.Ring.Foreign as RB
152
152
153+
154+
153-------------------------------------------------------------------------------
155-------------------------------------------------------------------------------
154-- Construction
156-- Construction
155-------------------------------------------------------------------------------
157-------------------------------------------------------------------------------
@@ -458,10 +460,11 @@ getIndex arr i =
458-- in Unfold.lmap f (getIndicesFromThenTo i (i - 1) 0)
460-- in Unfold.lmap f (getIndicesFromThenTo i (i - 1) 0)
459-- @
461-- @
460--
462--
461−-- /Unimplemented/
463+-- /Pre-release/
462{-# INLINE getIndices #-}
464{-# INLINE getIndices #-}
465+getIndices :: (MonadIO m, Storable a)
463−getIndices :: Unfold m (Array a) Int -> Unfold m (Array a) a
466+ => SerialT m Int -> Unfold m (Array a) a
464−getIndices = undefined
467+getIndices st = Unfold.lmap A.unsafeThaw (MA.getIndices st)
465
468
466-- | Unfolds @(from, then, to, array)@ generating a finite stream whose first
469-- | Unfolds @(from, then, to, array)@ generating a finite stream whose first
467-- element is the array value from the index @from@ and the successive elements
470-- element is the array value from the index @from@ and the successive elements
src/Streamly/Internal/Data/Array/Foreign/Mut/Type.hs+13−9
@@ -241,7 +241,8 @@ import GHC.Ptr (Ptr(..))
241import Streamly.Internal.BaseCompat
241import Streamly.Internal.BaseCompat
242import Streamly.Internal.Data.Fold.Type (Fold(..))
242import Streamly.Internal.Data.Fold.Type (Fold(..))
243import Streamly.Internal.Data.Producer.Type (Producer (..))
243import Streamly.Internal.Data.Producer.Type (Producer (..))
244−import Streamly.Internal.Data.SVar.Type (adaptState)
244+import Streamly.Internal.Data.Stream.Serial (SerialT(..))
245+import Streamly.Internal.Data.SVar.Type (adaptState, defState)
245import Streamly.Internal.Data.Unfold.Type (Unfold(..))
246import Streamly.Internal.Data.Unfold.Type (Unfold(..))
246import Streamly.Internal.System.IO (arrayPayloadSize, defaultChunkSize)
247import Streamly.Internal.System.IO (arrayPayloadSize, defaultChunkSize)
247import System.IO.Unsafe (unsafePerformIO)
248import System.IO.Unsafe (unsafePerformIO)
@@ -1090,20 +1091,19 @@ data GetIndicesState contents start end st =
1090-- bounds.
1091-- bounds.
1091--
1092--
1092-- /Pre-release/
1093-- /Pre-release/
1093−{-# INLINE getIndices #-}
1094+{-# INLINE getIndicesD #-}
1094−getIndices :: (MonadIO m, Storable a) =>
1095+getIndicesD :: (MonadIO m, Storable a) =>
1095− Unfold m (Array a) Int -> Unfold m (Array a) a
1096+ D.Stream m Int -> Unfold m (Array a) a
1096−getIndices (Unfold stepi injecti) = Unfold step inject
1097+getIndicesD (D.Stream stepi sti) = Unfold step inject
1097
1098
1098 where
1099 where
1099
1100
1100− inject arr@(Array contents start (Ptr end) _) = do
1101+ inject (Array contents start (Ptr end) _) =
1101− st <- injecti arr
1102− return $ GetIndicesState contents start (Ptr end) st
1102+ return $ GetIndicesState contents start (Ptr end) sti
1103
1103
1104 {-# INLINE_LATE step #-}
1104 {-# INLINE_LATE step #-}
1105 step (GetIndicesState contents start end st) = do
1105 step (GetIndicesState contents start end st) = do
1106− r <- stepi st
1106+ r <- stepi defState st
1107 case r of
1107 case r of
1108 D.Yield i s -> do
1108 D.Yield i s -> do
1109 x <- liftIO $ getIndexPtr start end i
1109 x <- liftIO $ getIndexPtr start end i
@@ -1113,6 +1113,10 @@ getIndices (Unfold stepi injecti) = Unfold step inject
1113 liftIO $ touch contents
1113 liftIO $ touch contents
1114 return D.Stop
1114 return D.Stop
1115
1115
1116+{-# INLINE getIndices #-}
1117+getIndices :: (MonadIO m, Storable a) => SerialT m Int -> Unfold m (Array a) a
1118+getIndices (SerialT stream) = getIndicesD $ D.fromStreamK stream
1119+
1116-------------------------------------------------------------------------------
1120-------------------------------------------------------------------------------
1117-- Subarrays
1121-- Subarrays
1118-------------------------------------------------------------------------------
1122-------------------------------------------------------------------------------