Yro*_*irg 4 arrays haskell repa
我对修复包中的select函数有点困惑:
select (\i -> True) (\i -> i) 10
Run Code Online (Sandbox Code Playgroud)
给出结果
[0,1,2,3,4,5,6,7,8]
Run Code Online (Sandbox Code Playgroud)
我以为我介于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.
Run Code Online (Sandbox Code Playgroud)
显然,给定的"指数范围" n包括所有指数,x例如0 <= x < (n-1):
Prelude Data.Array.Repa> extent $ select (const True) id 10
Z :. 9
Run Code Online (Sandbox Code Playgroud)