-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Stream functions not present in the vector library. -- -- Stream functions not present in the vector library. @package repa-stream @version 4.2.3.1 -- | module Data.Repa.Stream -- | Combination of fold and filter. -- -- We walk over the stream front to back, maintaining an accumulator. At -- each point we can chose to emit an element (or not) compactS :: Monad m => (s -> a -> (s, Maybe b)) -> s -> Stream m a -> Stream m b -- | Like compact but use the first value of the stream as the -- initial state, and add the final state to the end of the output. compactInS :: Monad m => (a -> a -> (a, Maybe a)) -> Stream m a -> Stream m a -- | Return the Just elements from a stream, dropping the -- Nothings. catMaybesS :: Monad m => Stream m (Maybe a) -> Stream m a -- | Given predicates that detect the begining and end of interesting -- segments of information, scan through a vector looking for when these -- begin and end. diceSepS :: Monad m => (a -> Bool) -> (a -> Bool) -> Stream m a -> Stream m (Maybe (Int, Int), Maybe (Int, Int)) -- | Extract segments from some source array and concatenate them. extractS :: Monad m => (Int -> a) -> Stream m (Int, Int) -> Stream m a -- | Insert elements produced by the given function in to a stream. insertS :: Monad m => (Int -> Maybe a) -> Stream m a -> Stream m a -- | Merge two key-value streams. -- -- The streams are assumed to be pre-sorted on the keys. mergeS :: (Monad m, Ord k) => (k -> a -> b -> c) -> (k -> a -> c) -> (k -> b -> c) -> Stream m (k, a) -> Stream m (k, b) -> Stream m (k, c) -- | Given a stream of keys and values, and a successor function for keys, -- if the stream is has keys missing in the sequence then insert the -- missing key, copying forward the the previous value. padForwardS :: (Monad m, Ord k) => (k -> k) -> Stream m (k, v) -> Stream m (k, v) -- | Interleaved enumFromTo. -- -- Given a vector of starting values, and a vector of stopping values, -- produce an stream of elements where we increase each of the starting -- values to the stopping values in a round-robin order. Also produce a -- vector of result segment lengths. -- --
--   unsafeRatchetS [10,20,30,40] [15,26,33,47]
--   =  [10,20,30,40       -- 4
--      ,11,21,31,41       -- 4
--      ,12,22,32,42       -- 4
--      ,13,23   ,43       -- 3
--      ,14,24   ,44       -- 3
--         ,25   ,45       -- 2
--               ,46]      -- 1
--   
--          ^^^^             ^^^
--        Elements         Lengths
--   
-- -- The function takes the starting values in a mutable vector and updates -- it during computation. Computation proceeds by making passes through -- the mutable vector and updating the starting values until they match -- the stopping values. -- -- UNSAFE: Both input vectors must have the same length, but this is not -- checked. unsafeRatchetS :: (MVector vm Int, Vector vv Int) => vm (PrimState IO) Int -> vv Int -> IORef (vm (PrimState IO) Int) -> Stream IO Int -- | Segmented replicate. -- -- Given a stream of counts and values, produce a result stream where -- each value is replciated the associated number of times. replicatesS :: Monad m => Stream m (Int, a) -> Stream m a -- | Given predicates that detect the beginning and end of some interesting -- segment of information, scan through a vector looking for when these -- segments begin and end. findSegmentsS :: Monad m => (a -> Bool) -> (a -> Bool) -> i -> Stream m (i, a) -> Stream m (i, i) -- | Given a stream of starting and ending indices for some segments, -- convert it to a stream of starting indices and segment lengths. -- -- startLengthsOfSegsS :: Monad m => Stream m (Int, Int) -> Stream m (Int, Int) -- | module Data.Repa.Chain -- | A chain is an abstract, stateful producer of elements. It is similar a -- stream as used in stream fusion, except that internal state is visible -- in its type. This allows the computation to be paused and resumed at a -- later point. data Chain m s a Chain :: Size -> s -> (s -> m (Step s a)) -> Chain m s a -- | Expected size of the output. [mchainSize] :: Chain m s a -> Size -- | Starting state. [mchainState] :: Chain m s a -> s -- | Step the chain computation. [mchainStep] :: Chain m s a -> s -> m (Step s a) -- | Result of a chain computation step. data Step s a -- | Yield an output value and a new seed. Yield :: !a -> !s -> Step s a -- | Provide just a new seed. Skip :: !s -> Step s a -- | Signal that the computation has finished. Done :: !s -> Step s a -- | Lift a pure chain to a monadic chain. liftChain :: Monad m => Chain Identity s a -> Chain m s a -- | Resume a chain computation from a previous state. resumeChain :: s -> Chain m s a -> Chain m s a -- | A weave is a generalized merge of two input chains. -- -- The worker function takes the current state, values from the left and -- right input chains, and produces a Turn which describes any -- output at that point, as well as how the input chains should be -- advanced. weaveC :: Monad m => (k -> Option aL -> Option aR -> m (Turn k aX)) -> k -> Chain m sL aL -> Chain m sR aR -> Chain m (Weave sL aL sR aR k) aX -- | Internal state of a weave. data Weave sL aL sR aR k -- | What to do after considering two input elements. data Turn k a -- | Give an element and a new state. Give :: !a -> !k -> !Move -> Turn k a -- | Move to the next input. Next :: !k -> !Move -> Turn k a -- | Weave is finished for now. Finish :: !k -> !Move -> Turn k a -- | How to move the input chains after considering to input elements. data Move MoveLeft :: Move MoveRight :: Move MoveBoth :: Move MoveNone :: Move -- | Apply a Move instruction to a weave state. move :: k -> Move -> Weave s1 a1 s2 a2 k -> Weave s1 a1 s2 a2 k -- | Segmented fold over vectors of segment lengths and input values. -- -- The total lengths of all segments need not match the length of the -- input elements vector. The returned Folds state can be -- inspected to determine whether all segments were completely folded, or -- the vector of segment lengths or elements was too short relative to -- the other. foldsC :: Monad m => (a -> b -> m b) -> b -> Option3 n Int b -> Chain m sLen (n, Int) -> Chain m sVal a -> Chain m (Folds sLen sVal n a b) (n, b) -- | Return state of a folds operation. data Folds sLens sVals n a b Folds :: !sLens -> !sVals -> !(Option n) -> !Int -> !b -> Folds sLens sVals n a b -- | State of lengths chain. [_stateLens] :: Folds sLens sVals n a b -> !sLens -- | State of values chain. [_stateVals] :: Folds sLens sVals n a b -> !sVals -- | If we're currently in a segment, then hold its name, [_nameSeg] :: Folds sLens sVals n a b -> !(Option n) -- | Length of current segment. [_lenSeg] :: Folds sLens sVals n a b -> !Int -- | Accumulated value of current segment. [_valSeg] :: Folds sLens sVals n a b -> !b -- | Segmented unfold. -- -- The worker function takes the current element from the input stream -- and current state. -- -- If the worker returns Just x then that output element will be placed -- in the output stream, and it will be called again with the same input -- elemenent and next state. -- -- If the worker returns Nothing then we advance to the next element of -- the input stream. unfoldsC :: Monad m => (a -> k -> m (StepUnfold k b)) -> k -> Chain m s a -> Chain m (s, k, Option a) b data StepUnfold s a StepUnfoldGive :: a -> s -> StepUnfold s a StepUnfoldNext :: a -> s -> StepUnfold s a StepUnfoldBump :: s -> StepUnfold s a StepUnfoldFinish :: s -> StepUnfold s a -- | Perform a left-to-right scan through an input vector, maintaining a -- state value between each element. For each element of input we may or -- may not produce an element of output. scanMaybeC :: Monad m => (k -> a -> m (k, Maybe b)) -> k -> Chain m s a -> Chain m (s, k) b -- | From a stream of values which has consecutive runs of idential values, -- produce a stream of the lengths of these runs. groupsByC :: Monad m => (a -> a -> m Bool) -> Maybe (a, Int) -> Chain m s a -> Chain m (s, Maybe (a, Int)) (a, Int) -- | Converting Streams and Chains to and from generic -- Vectors. -- -- module Data.Repa.Vector.Generic -- | Unstream some elements to two separate vectors. -- -- Nothing values are ignored. unstreamToVector2 :: (PrimMonad m, Vector v a, Vector v b) => Stream m (Maybe a, Maybe b) -> m (v a, v b) -- | Unstream some elements to two separate mutable vectors. -- -- Nothing values are ignored. unstreamToMVector2 :: (PrimMonad m, MVector v a, MVector v b) => Stream m (Maybe a, Maybe b) -> m (v (PrimState m) a, v (PrimState m) b) -- | Combination of fold and filter. -- -- We walk over the stream front to back, maintaining an accumulator. At -- each point we can chose to emit an element (or not) compact :: (Vector v a, Vector v b) => (s -> a -> (s, Maybe b)) -> s -> v a -> v b -- | Like compact but use the first value of the stream as the -- initial state, and add the final state to the end of the output. compactIn :: Vector v a => (a -> a -> (a, Maybe a)) -> v a -> v a -- | Given predicates that detect the beginning and end of some interesting -- segment of information, scan through a vector looking for when these -- segments begin and end. Return vectors of the segment starting -- positions and lengths. -- -- findSegments :: (Vector v a, Vector v Int, Vector v (Int, Int)) => (a -> Bool) -> (a -> Bool) -> v a -> (v Int, v Int) -- | Given predicates that detect the beginning and end of some interesting -- segment of information, scan through a vector looking for when these -- segments begin and end. Return vectors of the segment starting -- positions and lengths. findSegmentsFrom :: (Vector v Int, Vector v (Int, Int)) => (a -> Bool) -> (a -> Bool) -> Int -> (Int -> a) -> (v Int, v Int) -- | Dice a vector stream into rows and columns. diceSep :: (Vector v a, Vector v (Int, Int)) => (a -> Bool) -> (a -> Bool) -> v a -> (v (Int, Int), v (Int, Int)) -- | Extract segments from some source array and concatenate them. -- --
--   let arr = [10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]
--   in  extractS (index arr) [(0, 1), (3, 3), (2, 6)]
--   
--    => [10, 13, 14, 15, 12, 13, 14, 15, 16, 17]
--   
extract :: (Vector v (Int, Int), Vector v a) => (Int -> a) -> v (Int, Int) -> v a -- | Insert elements produced by the given function into a vector. insert :: Vector v a => (Int -> Maybe a) -> v a -> v a -- | Merge two pre-sorted key-value streams. merge :: (Ord k, Vector v (k, a), Vector v (k, b), Vector v (k, c)) => (k -> a -> b -> c) -> (k -> a -> c) -> (k -> b -> c) -> v (k, a) -> v (k, b) -> v (k, c) -- | Like merge, but only produce the elements where the worker -- functions return Just. mergeMaybe :: (Ord k, Vector v (k, a), Vector v (k, b), Vector v (k, c)) => (k -> a -> b -> Maybe c) -> (k -> a -> Maybe c) -> (k -> b -> Maybe c) -> v (k, a) -> v (k, b) -> v (k, c) -- | Given a stream of keys and values, and a successor function for keys, -- if the stream is has keys missing in the sequence then insert the -- missing key, copying forward the the previous value. padForward :: (Ord k, Vector v (k, a)) => (k -> k) -> v (k, a) -> v (k, a) -- | Interleaved enumFromTo. -- -- Given a vector of starting values, and a vector of stopping values, -- produce an stream of elements where we increase each of the starting -- values to the stopping values in a round-robin order. Also produce a -- vector of result segment lengths. -- --
--   unsafeRatchetS [10,20,30,40] [15,26,33,47]
--   =  [10,20,30,40       -- 4
--      ,11,21,31,41       -- 4
--      ,12,22,32,42       -- 4
--      ,13,23   ,43       -- 3
--      ,14,24   ,44       -- 3
--         ,25   ,45       -- 2
--               ,46]      -- 1
--   
--          ^^^^             ^^^
--        Elements         Lengths
--   
ratchet :: (Vector v Int, Vector v (Int, Int)) => v (Int, Int) -> (v Int, v Int) -- | Segmented replicate. replicates :: (Vector v (Int, a), Vector v a) => v (Int, a) -> v a -- | Produce a chain from a generic vector. chainOfVector :: (Monad m, Vector v a) => v a -> Chain m Int a -- | Compute a chain into a generic vector. unchainToVector :: (PrimMonad m, Vector v a) => Chain m s a -> m (v a, s) -- | Compute a chain into a generic mutable vector. unchainToMVector :: (PrimMonad m, MVector v a) => Chain m s a -> m (v (PrimState m) a, s) -- | Segmented fold over vectors of segment lengths and input values. -- -- The total lengths of all segments need not match the length of the -- input elements vector. The returned Folds state can be -- inspected to determine whether all segments were completely folded, or -- the vector of segment lengths or elements was too short relative to -- the other. In the resulting state, foldLensState is the index -- into the lengths vector *after* the last one that was consumed. If -- this equals the length of the lengths vector then all segment lengths -- were consumed. Similarly for the elements vector. folds :: forall v n a b. (Vector v (n, Int), Vector v a, Vector v (n, b)) => (a -> b -> b) -> b -> Option3 n Int b -> v (n, Int) -> v a -> (v (n, b), Folds Int Int n a b) -- | Return state of a folds operation. data Folds sLens sVals n a b Folds :: !sLens -> !sVals -> !(Option n) -> !Int -> !b -> Folds sLens sVals n a b -- | State of lengths chain. [_stateLens] :: Folds sLens sVals n a b -> !sLens -- | State of values chain. [_stateVals] :: Folds sLens sVals n a b -> !sVals -- | If we're currently in a segment, then hold its name, [_nameSeg] :: Folds sLens sVals n a b -> !(Option n) -- | Length of current segment. [_lenSeg] :: Folds sLens sVals n a b -> !Int -- | Accumulated value of current segment. [_valSeg] :: Folds sLens sVals n a b -> !b -- | Perform a left-to-right scan through an input vector, maintaining a -- state value between each element. For each element of input we may or -- may not produce an element of output. scanMaybe :: forall v1 v2 a b s. (Vector v1 a, Vector v2 b) => (s -> a -> (s, Maybe b)) -> s -> v1 a -> (v2 b, s) -- | From a stream of values which has consecutive runs of idential values, -- produce a stream of the lengths of these runs. -- --
--   groupsBy (==) (Just (a, 4)) 
--                 ['a', 'a', 'a', 'b', 'b', 'c', 'd', 'd'] 
--    => ([(a, 7), (b, 2), (c, 1)], Just ('d', 2))
--   
groupsBy :: forall v1 v2 a. (Vector v1 a, Vector v2 (a, Int)) => (a -> a -> Bool) -> Maybe (a, Int) -> v1 a -> (v2 (a, Int), Maybe (a, Int)) module Data.Repa.Vector.Unboxed -- | Combination of fold and filter. -- -- We walk over the stream front to back, maintaining an accumulator. At -- each point we can chose to emit an element (or not) compact :: (Unbox a, Unbox b) => (s -> a -> (s, Maybe b)) -> s -> Vector a -> Vector b -- | Like compact but use the first value of the stream as the -- initial state, and add the final state to the end of the output. compactIn :: Unbox a => (a -> a -> (a, Maybe a)) -> Vector a -> Vector a -- | Given predicates that detect the beginning and end of some interesting -- segment of information, scan through a vector looking for when these -- segments begin and end. Return vectors of the segment starting -- positions and lengths. -- -- findSegments :: Unbox a => (a -> Bool) -> (a -> Bool) -> Vector a -> (Vector Int, Vector Int) -- | Given predicates that detect the beginning and end of some interesting -- segment of information, scan through a vector looking for when these -- segments begin and end. Return vectors of the segment starting -- positions and lengths. findSegmentsFrom :: (a -> Bool) -> (a -> Bool) -> Int -> (Int -> a) -> (Vector Int, Vector Int) -- | Dice a vector stream into rows and columns. diceSep :: Unbox a => (a -> Bool) -> (a -> Bool) -> Vector a -> (Vector (Int, Int), Vector (Int, Int)) -- | Extract segments from some source array and concatenate them. -- --
--   let arr = [10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]
--   in  extractS (index arr) [(0, 1), (3, 3), (2, 6)]
--   
--    => [10, 13, 14, 15, 12, 13, 14, 15, 16, 17]
--   
extract :: Unbox a => (Int -> a) -> Vector (Int, Int) -> Vector a -- | Insert elements produced by the given function into a vector. insert :: Unbox a => (Int -> Maybe a) -> Vector a -> Vector a -- | Merge two pre-sorted key-value streams. merge :: (Ord k, Unbox k, Unbox a, Unbox b, Unbox c) => (k -> a -> b -> c) -> (k -> a -> c) -> (k -> b -> c) -> Vector (k, a) -> Vector (k, b) -> Vector (k, c) -- | Like merge, but only produce the elements where the worker -- functions return Just. mergeMaybe :: (Ord k, Unbox k, Unbox a, Unbox b, Unbox c) => (k -> a -> b -> Maybe c) -> (k -> a -> Maybe c) -> (k -> b -> Maybe c) -> Vector (k, a) -> Vector (k, b) -> Vector (k, c) -- | Given a stream of keys and values, and a successor function for keys, -- if the stream is has keys missing in the sequence then insert the -- missing key, copying forward the the previous value. padForward :: (Unbox k, Unbox v, Ord k) => (k -> k) -> Vector (k, v) -> Vector (k, v) -- | Interleaved enumFromTo. -- -- Given a vector of starting values, and a vector of stopping values, -- produce an stream of elements where we increase each of the starting -- values to the stopping values in a round-robin order. Also produce a -- vector of result segment lengths. -- --
--   unsafeRatchetS [10,20,30,40] [15,26,33,47]
--   =  [10,20,30,40       -- 4
--      ,11,21,31,41       -- 4
--      ,12,22,32,42       -- 4
--      ,13,23   ,43       -- 3
--      ,14,24   ,44       -- 3
--         ,25   ,45       -- 2
--               ,46]      -- 1
--   
--          ^^^^             ^^^
--        Elements         Lengths
--   
ratchet :: Vector (Int, Int) -> (Vector Int, Vector Int) -- | Compute a chain into a vector. unchainToVector :: (PrimMonad m, Unbox a) => Chain m s a -> m (Vector a, s) -- | Compute a chain into a mutable vector. unchainToMVector :: (PrimMonad m, Unbox a) => Chain m s a -> m (MVector (PrimState m) a, s) -- | Segmented fold over vectors of segment lengths and input values. -- -- The total lengths of all segments need not match the length of the -- input elements vector. The returned Folds state can be -- inspected to determine whether all segments were completely folded, or -- the vector of segment lengths or elements was too short relative to -- the other. In the resulting state, foldLensState is the index -- into the lengths vector *after* the last one that was consumed. If -- this equals the length of the lengths vector then all segment lengths -- were consumed. Similarly for the elements vector. folds :: (Unbox n, Unbox a, Unbox b) => (a -> b -> b) -> b -> Option3 n Int b -> Vector (n, Int) -> Vector a -> (Vector (n, b), Folds Int Int n a b) -- | Return state of a folds operation. data Folds sLens sVals n a b Folds :: !sLens -> !sVals -> !(Option n) -> !Int -> !b -> Folds sLens sVals n a b -- | State of lengths chain. [_stateLens] :: Folds sLens sVals n a b -> !sLens -- | State of values chain. [_stateVals] :: Folds sLens sVals n a b -> !sVals -- | If we're currently in a segment, then hold its name, [_nameSeg] :: Folds sLens sVals n a b -> !(Option n) -- | Length of current segment. [_lenSeg] :: Folds sLens sVals n a b -> !Int -- | Accumulated value of current segment. [_valSeg] :: Folds sLens sVals n a b -> !b -- | Perform a left-to-right scan through an input vector, maintaining a -- state value between each element. For each element of input we may or -- may not produce an element of output. scanMaybe :: (Unbox a, Unbox b) => (s -> a -> (s, Maybe b)) -> s -> Vector a -> (Vector b, s) -- | From a stream of values which has consecutive runs of idential values, -- produce a stream of the lengths of these runs. -- --
--   groupsBy (==) (Just (a, 4)) 
--                 ['a', 'a', 'a', 'b', 'b', 'c', 'd', 'd'] 
--    => ([(a, 7), (b, 2), (c, 1)], Just ('d', 2))
--   
groupsBy :: Unbox a => (a -> a -> Bool) -> Maybe (a, Int) -> Vector a -> (Vector (a, Int), Maybe (a, Int)) -- | Produce a chain from a generic vector. chainOfVector :: (Monad m, Unbox a) => Vector a -> Chain m Int a