4

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

4

1 に答える 1

5

長さの配列を生成するように見え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すべてのインデックスが含まれます。x0 <= x < (n-1)

Prelude Data.Array.Repa> extent $ select (const True) id 10
Z :. 9
于 2011-06-05T08:24:53.727 に答える