yarr-1.4.0.2: Yet another array library

Safe HaskellNone
LanguageHaskell98

Data.Yarr.Walk

Contents

Synopsis

Fold combinators

reduceL Source #

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)

ireduceL Source #

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)

reduceLeftM Source #

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)

reduceR Source #

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)

ireduceR Source #

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)

reduceRightM Source #

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 b Source #

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 b Source #

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.

mutate Source #

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)

imutate Source #

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

walk Source #

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 [])

iwalk Source #

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

rangeWalk Source #

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.

walkP Source #

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

iwalkP Source #

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.

rangeWalkP Source #

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.

walkSlicesSeparate Source #

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.

iwalkSlicesSeparate Source #

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.

rangeWalkSlicesSeparate Source #

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.

walkSlicesSeparateP Source #

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.

iwalkSlicesSeparateP Source #

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.

rangeWalkSlicesSeparateP Source #

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 s Source #

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 b Source #

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 b Source #

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.