yarr-0.9.2: Yet another array library

Safe HaskellNone

Data.Yarr.Fold

Contents

Synopsis

Fold support

type Fold sh a bSource

Arguments

 = IO b

Zero

-> (sh -> IO a)

Get

-> sh

Start

-> sh

End

-> IO b

Result

Curried Foldl or Foldr. Generalizes both partially applied left and right folds.

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

reduceLSource

Arguments

:: Foldl sh a b

foldl or curried unrolledFoldl

-> (b -> a -> b)

Pure left reduce

-> Fold sh a b

Curried fold to be passed to runFold functions.

O(0)

reduceLeftMSource

Arguments

:: Foldl sh a b

foldl or curried unrolledFoldl

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

Monaric left reduce

-> Fold sh a b

Curried fold to be passed to runFold functions.

O(0)

reduceRSource

Arguments

:: Foldr sh a b

foldr or curried unrolledFoldr

-> (a -> b -> b)

Pure right reduce

-> Fold sh a b

Curried fold to be passed to runFold functions.

O(0)

reduceRightMSource

Arguments

:: Foldr sh a b

foldr or curried unrolledFoldr

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

Monaric right reduce

-> Fold sh a b

Curried fold to be passed to runFold functions.

O(0)

Fold runners

runFoldSource

Arguments

:: (USource r l sh a, Reduce l sh fsh) 
=> Fold fsh a b

Curried folding worker function

-> IO b

Monadic fold zero. Wrap pure zero in return.

-> UArray r l sh a

Source array

-> IO b

Fold result

O(n)

Example:

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

runFoldPSource

Arguments

:: (USource r l sh a, Reduce l sh fsh) 
=> Threads

Number of threads to parallelize folding on

-> Fold fsh a b

Curried folding worker function

-> IO b

Monadic fold zero. Wrap pure zero in return.

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

Associative monadic result joining function

-> UArray r l sh a

Source array

-> IO b

Fold result

O(n) Run associative fold in parallel.

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

runFoldSlicesSeparateSource

Arguments

:: (UVecSource r slr l sh v e, Reduce l sh fsh) 
=> Fold fsh e b

Curried folding function to work on slices

-> IO b

Monadic fold zero. Wrap pure zero in return.

-> UArray r l sh (v e)

Source array of vectors

-> IO (VecList (Dim v) b)

Vector of fold results

O(n)

runFoldSlicesSeparatePSource

Arguments

:: (UVecSource r slr l sh v e, Reduce l sh fsh) 
=> Threads

Number of threads to parallelize folding on

-> Fold fsh e b

Curried folding function to work on slices

-> IO b

Monadic fold zero. Wrap pure zero in return.

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

Associative monadic result joining function

-> UArray r l sh (v e)

Source array of vectors

-> IO (VecList (Dim v) b)

Vector of fold results

O(n) Run associative fold over slices of array of vectors in parallel.

Shortcuts

toList :: (USource r l sh a, Reduce l sh fsh) => UArray r l sh a -> IO [a]Source

O(n) Covert array to list.