yarr-1.2.3: Yet another array library

Safe HaskellNone

Data.Yarr.Work

Contents

Synopsis

Fold combinators

See source of these 4 functions to construct more similar ones, if you need.

reduceLSource

Arguments

:: Foldl i a b

foldl or curried unrolledFoldl

-> (b -> a -> b)

Pure left reduce

-> StatefulWork i a b

Result stateful work to be passed to work runners

O(0)

reduceLeftMSource

Arguments

:: Foldl i a b

foldl or curried unrolledFoldl

-> (b -> a -> IO b)

Monadic left reduce

-> StatefulWork i a b

Result stateful work to be passed to work runners

O(0)

reduceRSource

Arguments

:: Foldr i a b

foldr or curried unrolledFoldr

-> (a -> b -> b)

Pure right reduce

-> StatefulWork i a b

Result stateful work to be passed to work runners

O(0)

reduceRightMSource

Arguments

:: Foldr i a b

foldr or curried unrolledFoldr

-> (a -> b -> IO b)

Monadic right reduce

-> StatefulWork i a b

Result stateful work to be passed to work runners

O(0)

Combinators to work with mutable state

Added specially to improve performance of tasks like histogram filling.

Unfortunately, GHC doesn't figure that folding state isn't changed as ADT in such cases and doesn't lift it's evaluation higher from folding routine.

mutateSource

Arguments

:: Fill i a

fill or curried unrolledFill. If mutating is associative, dim2BlockFill is also acceptable.

-> (s -> a -> IO ())

(state -> array element -> (state has changed)) -- State mutating function

-> StatefulWork i a s

Result stateful work to be passed to work runners

O(0)

imutateSource

Arguments

:: Fill i a

fill or curried unrolledFill. If mutating is associative, dim2BlockFill is also acceptable.

-> (s -> i -> a -> IO ())

Indexed state mutating function

-> StatefulWork i a s

Result stateful work to be passed to work runners

O(0) Version of mutate, accepts mutating function which additionaly accepts array index.

Work runners

workSource

Arguments

:: (USource r l sh a, PreferredWorkIndex l sh i) 
=> StatefulWork i a s

Stateful working function

-> IO s

Monadic initial state (fold zero). Wrap pure state in return.

-> UArray r l sh a

Source array

-> IO s

Final state (fold result)

O(n) Run non-indexed stateful work.

Example:

toList = work (reduceR foldr (:)) (return [])

iworkSource

Arguments

:: USource r l sh a 
=> StatefulWork sh a s

Stateful working function

-> IO s

Monadic initial state (fold zero). Wrap pure state in return.

-> UArray r l sh a

Source array

-> IO s

Final state (fold result)

O(n) Run indexed stateful work.

Example:

res <- iwork (foldl (\s i a -> ...)) foldZero sourceArray

rangeWorkSource

Arguments

:: USource r l sh a 
=> StatefulWork sh a s

Stateful working function

-> IO s

Monadic initial state (fold zero). Wrap pure state in return.

-> UArray r l sh a

Source array

-> sh

Top-left

-> sh

and bottom-right corners of range to work in

-> IO s

Final state (fold result)

O(n) Run stateful work in specified range of indices.

workPSource

Arguments

:: (USource r l sh a, PreferredWorkIndex l sh i) 
=> Threads

Number of threads to parallelize work on

-> StatefulWork i a s

Associative stateful working function

-> IO s

Monadic zero state. Wrap pure state in return.

-> (s -> s -> IO s)

Associative monadic state joining function

-> UArray r l sh a

Source array

-> IO s

Gathered state (fold result)

O(n) Run associative non-indexed stateful work in parallel.

Example -- associative image histogram filling in the test: https://github.com/leventov/yarr/blob/master/tests/lum-equalization.hs

iworkPSource

Arguments

:: USource r l sh a 
=> Threads

Number of threads to parallelize work on

-> StatefulWork sh a s

Associative stateful working function

-> IO s

Monadic zero state. Wrap pure state in return.

-> (s -> s -> IO s)

Associative monadic state joining function

-> UArray r l sh a

Source array

-> IO s

Gathered state (fold result)

O(n) Run associative indexed stateful work in parallel.

rangeWorkPSource

Arguments

:: USource r l sh a 
=> Threads

Number of threads to parallelize work on

-> StatefulWork sh a s

Associative stateful working function

-> IO s

Monadic zero state. Wrap pure state in return.

-> (s -> s -> IO s)

Associative monadic state joining function

-> UArray r l sh a

Source array

-> sh

Top-left

-> sh

and bottom-right corners of range to work in

-> IO s

Gathered state (fold result)

O(n) Run associative stateful work in specified range in parallel.

workOnSlicesSeparateSource

Arguments

:: (UVecSource r slr l sh v e, PreferredWorkIndex l sh i) 
=> StatefulWork i e s

Stateful slice-wise working function

-> IO s

Monadic initial state (fold zero). Wrap pure state in return.

-> UArray r l sh (v e)

Source array of vectors

-> IO (VecList (Dim v) s)

Vector of final states (fold results)

O(n) Run non-indexed stateful work over each slice of array of vectors.

iworkOnSlicesSeparateSource

Arguments

:: UVecSource r slr l sh v e 
=> StatefulWork sh e s

Stateful slice-wise working function

-> IO s

Monadic initial state (fold zero). Wrap pure state in return.

-> UArray r l sh (v e)

Source array of vectors

-> IO (VecList (Dim v) s)

Vector of final states (fold results)

O(n) Run indexed stateful work over each slice of array of vectors.

rangeWorkOnSlicesSeparateSource

Arguments

:: UVecSource r slr l sh v e 
=> StatefulWork sh e s

Stateful slice-wise working function

-> IO s

Monadic initial state (fold zero). Wrap pure state in return.

-> UArray r l sh (v e)

Source array of vectors

-> sh

Top-left

-> sh

and bottom-right corners of range to work in

-> IO (VecList (Dim v) s)

Vector of final states (fold results)

O(n) Run stateful work in specified range over each slice of array of vectors.

workOnSlicesSeparatePSource

Arguments

:: (UVecSource r slr l sh v e, PreferredWorkIndex l sh i) 
=> Threads

Number of threads to parallelize work on

-> StatefulWork i e s

Stateful slice-wise working function

-> IO s

Monadic zero state. Wrap pure state in return.

-> (s -> s -> IO s)

Associative monadic state joining function

-> UArray r l sh (v e)

Source array of vectors

-> IO (VecList (Dim v) s)

Vector of gathered per slice results

O(n) Run associative non-indexed stateful work over slices of array of vectors in parallel.

iworkOnSlicesSeparatePSource

Arguments

:: UVecSource r slr l sh v e 
=> Threads

Number of threads to parallelize work on

-> StatefulWork sh e s

Stateful slice-wise working function

-> IO s

Monadic zero state. Wrap pure state in return.

-> (s -> s -> IO s)

Associative monadic state joining function

-> UArray r l sh (v e)

Source array of vectors

-> IO (VecList (Dim v) s)

Vector of gathered per slice results

O(n) Run associative indexed stateful work over slices of array of vectors in parallel.

rangeWorkOnSlicesSeparatePSource

Arguments

:: UVecSource r slr l sh v e 
=> Threads

Number of threads to parallelize work on

-> StatefulWork sh e s

Stateful slice-wise working function

-> IO s

Monadic zero state. Wrap pure state in return.

-> (s -> s -> IO s)

Associative monadic state joining function

-> UArray r l sh (v e)

Source array of vectors

-> sh

Top-left

-> sh

and bottom-right corners of range to work in

-> IO (VecList (Dim v) s)

Vector of gathered per slice results

O(n) Run associative stateful work in specified range over slices of array of vectors in parallel.

Aliases for work types

type StatefulWork sh a sSource

Arguments

 = IO s

Initial state

-> (sh -> IO a)

Indexing function

-> Work sh s

Curried result function -- worker, emits final state

Generalizes both partially applied left and right folds, as well as works on mutable state.

To be passed to fold runners from Data.Yarr.Work module.

type Foldl sh a bSource

Arguments

 = (b -> sh -> a -> IO b)

Generalized left reduce

-> StatefulWork sh a b

Curried result stateful work

Generalizes left to right folds.

To be passed to fold combinators from Data.Yarr.Work module.

type Foldr sh a bSource

Arguments

 = (sh -> a -> b -> IO b)

Generalized right reduce

-> StatefulWork sh a b

Curried result stateful work

Generalizes right to left folds.

To be passed to fold combinators from Data.Yarr.Work module.