我对repa包中的select函数有点困惑:
select (\i -> True) (\i -> i) 10给出结果
[0,1,2,3,4,5,6,7,8]我以为我在0和10之间,或者0和9之间,为什么是在0和8之间?
repa 2.0.2.1
发布于 2011-06-05 16:24:54
看起来它生成了一个长度为len - 1的数组,在本例中长度为9。它给出了0-8范围内的索引。我同意文档可以更清晰。
如果你看一下源代码,就会发现select是用selectChunkedP实现的
-- | Select indices matching a predicate, in parallel.
-- The array is chunked up, with one chunk being given to each thread.
-- The number of elements in the result array depends on how many threads
-- you're running the program with.
selectChunkedP
:: forall a
. Unbox a
=> (Int -> Bool) -- ^ See if this predicate matches.
-> (Int -> a) -- .. and apply fn to the matching index
-> Int -- Extent of indices to apply to predicate.显然,给定n的“索引范围”包括所有的索引x,使得0 <= x < (n-1)
Prelude Data.Array.Repa> extent $ select (const True) id 10
Z :. 9https://stackoverflow.com/questions/6241452
复制相似问题