@@ -1,184 +0,0 @@
2−-- Module : Streamly.Benchmark.Data.ArrayOps
3−-- Copyright : (c) 2020 Composewell Technologies
5−-- License : BSD-3-Clause
6−-- Maintainer : streamly@composewell.com
9−{-# LANGUAGE FlexibleContexts #-}
10−{-# LANGUAGE ScopedTypeVariables #-}
15−module Streamly.Benchmark.Data.ArrayOps where
17−import Control.Monad.IO.Class (MonadIO)
18−import Prelude (Bool, Int, Maybe(..), ($), (+), (.), (==), (>), undefined)
20−import qualified Prelude as P
21−import qualified Streamly.Prelude as S
25−import qualified Data.Foldable as F
29−#if defined(DATA_ARRAY)
30−import qualified Streamly.Internal.Data.Array as A
34−-------------------------------------------------------------------------------
36−-------------------------------------------------------------------------------
38−-------------------------------------------------------------------------------
39−-- Stream generation and elimination
40−-------------------------------------------------------------------------------
42−-------------------------------------------------------------------------------
45−-------------------------------------------------------------------------------
47−{-# INLINE sourceUnfoldr #-}
48−sourceUnfoldr :: MonadIO m => Int -> Int -> m (Stream Int)
49−sourceUnfoldr value n = S.fold (A.writeN value) $ S.unfoldr step n
54− else (Just (cnt, cnt + 1))
56−{-# INLINE sourceIntFromTo #-}
57−sourceIntFromTo :: MonadIO m => Int -> Int -> m (Stream Int)
58−sourceIntFromTo value n = S.fold (A.writeN value) $ S.enumerateFromTo n (n + value)
60−{-# INLINE sourceFromList #-}
61−sourceFromList :: MonadIO m => Int -> Int -> m (Stream Int)
62−sourceFromList value n = S.fold (A.writeN value) $ S.fromList [n..n+value]
65−{-# INLINE sourceIntFromToFromList #-}
66−sourceIntFromToFromList :: MonadIO m => Int -> Int -> m (Stream Int)
67−sourceIntFromToFromList value n = P.return $ A.fromList $ [n..n + value]
69−-------------------------------------------------------------------------------
72−-------------------------------------------------------------------------------
75−{-# INLINE sourceIntFromToFromStream #-}
76−sourceIntFromToFromStream :: MonadIO m => Int -> Int -> m (Stream Int)
77−sourceIntFromToFromStream value n = S.fold A.write $ S.enumerateFromTo n (n + value)
79−-------------------------------------------------------------------------------
81−-------------------------------------------------------------------------------
83−-------------------------------------------------------------------------------
86−-------------------------------------------------------------------------------
88−{-# INLINE composeN #-}
90− => Int -> (Stream Int -> m (Stream Int)) -> Stream Int -> m (Stream Int)
95− 3 -> f x P.>>= f P.>>= f
96− 4 -> f x P.>>= f P.>>= f P.>>= f
100−{-# INLINE scanl1' #-}
103−scanl' , scanl1', map
104− :: MonadIO m => Int -> Int -> Stream Int -> m (Stream Int)
107−{-# INLINE onArray #-}
109− :: MonadIO m => Int -> (S.SerialT m Int -> S.SerialT m Int)
112−onArray value f arr = S.fold (A.writeN value) $ f $ (S.unfold A.read arr)
114−scanl' value n = composeN n $ onArray value $ S.scanl' (+) 0
115−scanl1' value n = composeN n $ onArray value $ S.scanl1' (+)
116−map value n = composeN n $ onArray value $ S.map (+1)
117−-- map n = composeN n $ A.map (+1)
119−{-# INLINE eqInstance #-}
120−eqInstance :: Stream Int -> Bool
121−eqInstance src = src == src
123−{-# INLINE eqInstanceNotEq #-}
124−eqInstanceNotEq :: Stream Int -> Bool
125−eqInstanceNotEq src = src P./= src
127−{-# INLINE ordInstance #-}
128−ordInstance :: Stream Int -> Bool
129−ordInstance src = src P.< src
131−{-# INLINE ordInstanceMin #-}
132−ordInstanceMin :: Stream Int -> Stream Int
133−ordInstanceMin src = P.min src src
135−{-# INLINE showInstance #-}
136−showInstance :: Stream Int -> P.String
137−showInstance src = P.show src
139−{-# INLINE pureFoldl' #-}
140−pureFoldl' :: MonadIO m => Stream Int -> m Int
141−pureFoldl' = S.foldl' (+) 0 . S.unfold A.read
143−-------------------------------------------------------------------------------
146−-------------------------------------------------------------------------------
149−{-# INLINE readInstance #-}
150−readInstance :: P.String -> Stream Int
155− _ -> P.error "readInstance: no parse"
159−{-# INLINE foldableFoldl' #-}
160−foldableFoldl' :: Stream Int -> Int
161−foldableFoldl' = F.foldl' (+) 0
163−{-# INLINE foldableSum #-}
164−foldableSum :: Stream Int -> Int
169−-------------------------------------------------------------------------------
171−-------------------------------------------------------------------------------
173−-------------------------------------------------------------------------------
176−-------------------------------------------------------------------------------
178−{-# INLINE unfoldReadDrain #-}
179−unfoldReadDrain :: MonadIO m => Stream Int -> m ()
180−unfoldReadDrain = S.drain . S.unfold A.read
182−{-# INLINE toStreamRevDrain #-}
183−toStreamRevDrain :: MonadIO m => Stream Int -> m ()
184−toStreamRevDrain = S.drain . A.toStreamRev