我对 repa 包中的 select 函数有点困惑:
select (\i -> True) (\i -> i) 10
给出结果
[0,1,2,3,4,5,6,7,8]
我以为我在 0 到 10 或 0 到 9 之间。为什么它在 0 到 8 之间?
修复 2.0.2.1
Looks like it produces an array of length len - 1
, which is 9 in your case. Which gives you indices in the [0-8] range. I agree that the documentation could be more clear.
If you look at the source, select
is implemented in terms of 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.
Apparently, 'extent of indices' for a given n
includes all indices x
such that 0 <= x < (n-1)
:
Prelude Data.Array.Repa> extent $ select (const True) id 10
Z :. 9