repa-stream-4.2.2.1: Stream functions not present in the vector library.

Safe HaskellNone
LanguageHaskell98

Data.Repa.Stream

Contents

Description

Synopsis

Compacting

compactS Source

Arguments

:: Monad m 
=> (s -> a -> (s, Maybe b))

Worker function.

-> s

Starting state

-> Stream m a

Input elements.

-> Stream 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)

compactInS Source

Arguments

:: Monad m 
=> (a -> a -> (a, Maybe a))

Worker function.

-> Stream m a

Input elements.

-> Stream m a 

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.

Concatenating

catMaybesS :: Monad m => Stream m (Maybe a) -> Stream m a Source

Return the Just elements from a stream, dropping the Nothings.

Dicing

diceSepS Source

Arguments

:: Monad m 
=> (a -> Bool)

Detect the end of a column.

-> (a -> Bool)

Detect the end of a row.

-> Stream m a 
-> Stream m (Maybe (Int, Int), Maybe (Int, Int))

Segment starts and lengths

Given predicates that detect the begining and end of interesting segments of information, scan through a vector looking for when these begin and end.

Extracting

extractS Source

Arguments

:: Monad m 
=> (Int -> a)

Function to get elements from the source.

-> Stream m (Int, Int)

Segment start positions and lengths.

-> Stream m a

Result elements.

Extract segments from some source array and concatenate them.

Inserting

insertS Source

Arguments

:: Monad m 
=> (Int -> Maybe a)

Produce a new element for this index.

-> Stream m a

Source stream.

-> Stream m a 

Insert elements produced by the given function in to a stream.

Merging

mergeS Source

Arguments

:: (Monad m, Ord k) 
=> (k -> a -> b -> c)

Combine two values with the same key.

-> (k -> a -> c)

Handle a left value without a right value.

-> (k -> b -> c)

Handle a right value without a left value.

-> Stream m (k, a)

Stream of keys and left values.

-> Stream m (k, b)

Stream of keys and right values.

-> Stream m (k, c)

Stream of keys and results.

Merge two key-value streams.

The streams are assumed to be pre-sorted on the keys.

Padding

padForwardS Source

Arguments

:: (Monad m, Ord k) 
=> (k -> k)

Successor functinon for keys.

-> Stream m (k, v)

Input stream.

-> Stream m (k, v) 

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.

Ratcheting

unsafeRatchetS Source

Arguments

:: (MVector vm Int, Vector vv Int) 
=> vm (PrimState IO) Int

Starting values. Overwritten duing computation.

-> vv Int

Ending values

-> IORef (vm (PrimState IO) Int)

Vector holding segment lengths.

-> Stream IO Int 

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.

Replicating

replicatesS :: Monad m => Stream m (Int, a) -> Stream m a Source

Segmented replicate.

Given a stream of counts and values, produce a result stream where each value is replciated the associated number of times.

Segmenting

findSegmentsS Source

Arguments

:: Monad m 
=> (a -> Bool)

Predicate to check for start of segment.

-> (a -> Bool)

Predicate to check for end of segment.

-> i

Index of final element in stream.

-> Stream m (i, a)

Stream of indices and elements.

-> Stream m (i, i)

Stream of segment start and end indices.

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.

startLengthsOfSegsS Source

Arguments

:: Monad m 
=> Stream m (Int, Int)

Start and end indices.

-> Stream m (Int, Int)

Start indices and lengths of segments.

Given a stream of starting and ending indices for some segments, convert it to a stream of starting indices and segment lengths.

  • The ending indices must be after the starting indices, otherwise the result will contain negative lengths.