yarr-1.3.2: Yet another array library

Safe HaskellNone

Data.Yarr.Walk

Contents

Synopsis

Fold combinators

reduceLSource

Arguments

:: Foldl i a b

foldl or curried unrolledFoldl

-> (b -> a -> b)

Pure left reduce

-> StatefulWalk i a b

Result stateful walk to be passed to walk runners

O(1)

ireduceLSource

Arguments

:: Foldl i a b

foldl or curried unrolledFoldl

-> (b -> i -> a -> b)

Pure indexed left reduce

-> StatefulWalk i a b

Result stateful walk to be passed to walk runners

O(1)

reduceLeftMSource

Arguments

:: Foldl i a b

foldl or curried unrolledFoldl

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

Monadic left reduce

-> StatefulWalk i a b

Result stateful walk to be passed to walk runners

O(1)

reduceRSource

Arguments

:: Foldr i a b

foldr or curried unrolledFoldr

-> (a -> b -> b)

Pure right reduce

-> StatefulWalk i a b

Result stateful walk to be passed to walk runners

O(1)

ireduceRSource

Arguments

:: Foldr i a b

foldr or curried unrolledFoldr

-> (i -> a -> b -> b)

Pure indexed right reduce

-> StatefulWalk i a b

Result stateful walk to be passed to walk runners

O(1)

reduceRightMSource

Arguments

:: Foldr i a b

foldr or curried unrolledFoldr

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

Monadic right reduce

-> StatefulWalk i a b

Result stateful walk to be passed to walk runners

O(1)

Inner dim reducers

reduceInner :: (USource r l sh a, MultiShape sh lsh, PreferredWorkIndex l sh i) => StatefulWalk i a b -> (lsh -> IO b) -> UArray r l sh a -> UArray D SH lsh bSource

O(1)

ireduceInner :: (USource r l sh a, MultiShape sh lsh) => StatefulWalk sh a b -> (lsh -> IO b) -> UArray r l sh a -> UArray D SH lsh bSource

O(1)

Combinators to walk 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

-> StatefulWalk i a s

Result stateful walk to be passed to walk runners

O(1)

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

-> StatefulWalk i a s

Result stateful walk to be passed to walk runners

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

Walk runners

walkSource

Arguments

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

Stateful walking 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) Walk with state, with non-indexed function (reduceL group of fold combinators, mutate).

Example:

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

iwalkSource

Arguments

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

Stateful walking 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) Walk with state, with indexed function (foldl, foldr, imutate, etc).

Example:

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

rangeWalkSource

Arguments

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

Stateful walking 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 walk in

-> IO s

Final state (fold result)

O(n) Walk with state, in specified range of indices.

walkPSource

Arguments

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

Number of threads to parallelize walk on

-> StatefulWalk i a s

Associative stateful walking 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 walk, in parallel.

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

iwalkPSource

Arguments

:: USource r l sh a 
=> Threads

Number of threads to parallelize walk on

-> StatefulWalk sh a s

Associative stateful walking 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 walk, in parallel.

rangeWalkPSource

Arguments

:: USource r l sh a 
=> Threads

Number of threads to parallelize walk on

-> StatefulWalk sh a s

Associative stateful walking 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 walk in

-> IO s

Gathered state (fold result)

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

walkSlicesSeparateSource

Arguments

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

Stateful slice-wise walking 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) Walk with state, with non-indexed function, over each slice of array of vectors.

iwalkSlicesSeparateSource

Arguments

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

Stateful slice-wise walking 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) Walk with state, with indexed function, over each slice of array of vectors.

rangeWalkSlicesSeparateSource

Arguments

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

Stateful slice-wise walking 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 walk in

-> IO (VecList (Dim v) s)

Vector of final states (fold results)

O(n) Walk with state, in specified range of indices, over each slice of array of vectors.

walkSlicesSeparatePSource

Arguments

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

Number of threads to parallelize walk on

-> StatefulWalk i e s

Stateful slice-wise walking 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 walk over slices of array of vectors, in parallel.

iwalkSlicesSeparatePSource

Arguments

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

Number of threads to parallelize walk on

-> StatefulWalk sh e s

Stateful slice-wise walking 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 walk over slices of array of vectors, in parallel.

rangeWalkSlicesSeparatePSource

Arguments

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

Number of threads to parallelize walk on

-> StatefulWalk sh e s

Stateful slice-wise walking 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 walk in

-> IO (VecList (Dim v) s)

Vector of gathered per slice results

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

Aliases for walk types

type StatefulWalk sh a sSource

Arguments

 = IO s

Initial state

-> (sh -> IO a)

Indexing function

-> Walk sh s

Curried result function -- walker, emits final state

Generalizes both partially applied left and right folds, as well as walks with mutable state.

To be passed to walk runners from Data.Yarr.Walk module.

type Foldl sh a bSource

Arguments

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

Generalized left reduce

-> StatefulWalk sh a b

Curried result stateful walk

Generalizes left folds.

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

type Foldr sh a bSource

Arguments

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

Generalized right reduce

-> StatefulWalk sh a b

Curried result stateful walk

Generalizes right folds.

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