Haskell Repa ---选择函数有点混乱

时间:2011-06-05 06:57:11

标签: arrays haskell 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

1 个答案:

答案 0 :(得分: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的“指数范围”包括x所有指数0 <= x < (n-1)

Prelude Data.Array.Repa> extent $ select (const True) id 10
Z :. 9