首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Haskell Repa - select函数有点混乱

Haskell Repa - select函数有点混乱
EN

Stack Overflow用户
提问于 2011-06-05 14:57:11
回答 1查看 356关注 0票数 4

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

代码语言:javascript
复制
select (\i -> True) (\i -> i) 10

给出结果

代码语言:javascript
复制
[0,1,2,3,4,5,6,7,8]

我以为我在0和10之间,或者0和9之间,为什么是在0和8之间?

repa 2.0.2.1

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-06-05 16:24:54

看起来它生成了一个长度为len - 1的数组,在本例中长度为9。它给出了0-8范围内的索引。我同意文档可以更清晰。

如果你看一下源代码,就会发现select是用selectChunkedP实现的

代码语言:javascript
复制
-- | 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)

代码语言:javascript
复制
Prelude Data.Array.Repa> extent $ select (const True) id 10
Z :. 9
票数 5
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/6241452

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档