module Data.Array.Repa.Operators.Selection
(selectP)
where
import Data.Array.Repa.Index
import Data.Array.Repa.Base
import Data.Array.Repa.Eval.Selection
import Data.Array.Repa.Repr.Unboxed as U
import qualified Data.Vector.Unboxed as V
import System.IO.Unsafe
selectP :: (Unbox a, Monad m)
=> (Int -> Bool)
-> (Int -> a)
-> Int
-> m (Array U DIM1 a)
selectP match produce len
= return
$ unsafePerformIO
$ do (sh, vec) <- selectIO
return $ sh `seq` vec `seq`
fromUnboxed sh vec
where
selectIO
= do vecs <- selectChunkedP match produce len
vecs' <- mapM V.unsafeFreeze vecs
let result = V.concat vecs'
return (Z :. V.length result, result)