vector-strategies 0.1 → 0.2
raw patch · 2 files changed
+9/−20 lines, 2 files
Files
- Data/Vector/Strategies.hs +8/−19
- vector-strategies.cabal +1/−1
Data/Vector/Strategies.hs view
@@ -4,8 +4,9 @@ , NFData, using ) where -import Control.DeepSeq (NFData)+import Control.DeepSeq (NFData(..)) import Control.Parallel.Strategies+import Control.Monad import qualified Data.Vector as V -- |Evaluate the elements of a boxed vector in parallel.@@ -17,24 +18,12 @@ -- Use this along with the "parallel" package's 'using' function: -- -- @--- vec `using` (parVector chunkSize)+-- vec \``using`\` (`parVector` chunkSize) -- @ ----- This is not useful on unboxed vectors (will not provide any performance increase)+-- 'parVector' can not provide any benefits (read: no parallelism) for unboxed vectors! parVector :: NFData a => Int -> Strategy (V.Vector a)-parVector minChunk vector- | minChunk <= 0 = parVector 1 vector- | otherwise = go vector- where- go vec =- let vLen = V.length vec- half = vLen `div` 2- in if vLen > minChunk- then do- go (V.unsafeSlice 0 half vec)- go (V.unsafeSlice half (vLen - half) vec)- return vec- else evalChunk (vLen-1) >> return vec- where- evalChunk (-1) = return vec- evalChunk i = rpar (rdeepseq (vec V.! i)) >> evalChunk (i-1)+parVector n = liftM V.fromList . parListChunk n rdeepseq . V.toList++instance NFData a => NFData (V.Vector a) where+ rnf = rnf . V.toList
vector-strategies.cabal view
@@ -7,7 +7,7 @@ -- The package version. See the Haskell package versioning policy -- (http://www.haskell.org/haskellwiki/Package_versioning_policy) for -- standards guiding when and how versions should be incremented.-Version: 0.1+Version: 0.2 -- A short (one-line) description of the package. Synopsis: A parallel evaluation strategy for boxed vectors