arrays - Haskell Repa --- select 函数有点困惑

标签 arrays haskell repa

我对 repa 包中的 select 函数有点困惑:

select (\i -> True) (\i -> i) 10

给出结果
[0,1,2,3,4,5,6,7,8]

我以为 i 在 0 到 10 或 0 到 9 之间。为什么它在 0 到 8 之间?

修复 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

关于arrays - Haskell Repa --- select 函数有点困惑,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6241452/

相关文章:

java - 从查询中填充 Jtable

apache - 如何使用 Haskell 编写 CGI 脚本?

haskell 将管道字符串输入 IO

arrays - 编写一次并行数组 Haskell 表达式,在 CPU 和 GPU 上运行 repa 并加速

haskell - Repa 性能与列表

ios - Swift 4 - SwiftyJson 比较数组并合并找到的值

python - 使用带有稀疏 scipy 矩阵的广播

haskell - 模式匹配是多余的,haskell

haskell - 没有并行化的 Repa

java - 如何访问 JSONObject、JSONObject 和 JSONArray 中的内容? Java/安卓