How to fold a Repa array to an arbitrary value?

All Repa reduction functions are discarded into the same types as the contents of the array. For example:

foldAllP :: (Shape sh, Source r a, Elt a, Unbox a, Monad m) => (a -> a -> a) -> a -> Array r sh a -> m a
foldAllS :: (Shape sh, Source r a, Elt a, Unbox a) => (a -> a -> a) -> a -> Array r sh a -> a

I would like to collapse the repa array into a data structure that I can pass to the GUI library for rendering, that is, an arbitrary value, but I cannot find a function in the library for this. Does this function exist or do I need to iterate over cells with [... | x <- [0..w-1], y <- [0..h-1]]?

+4
source share
1 answer

Turnip does not allow dumping in any particular direction, because when parallel computing:

foldAllP: Operator applications are connected arbitrarily.

, , , , , , foldAllS.

, , repa unboxed vector toUnboxed, vector. , , , , , . :

λ>  import qualified Data.Vector.Unboxed as V
λ> :t V.foldr
V.foldr :: Unbox a => (a -> b -> b) -> b -> Vector a -> b
λ> :t V.foldl
V.foldl :: Unbox b => (a -> b -> a) -> a -> Vector b -> a
λ> V.foldr ((&&) . (>0.5)) True $ toUnboxed repaArray
0

Source: https://habr.com/ru/post/1614092/


All Articles