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
長さの配列を生成するように見え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 :. 9