-- 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 -- |
-- 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. -- --
-- 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.
--
-- -- 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