4

RepafromListUnboxed允许从值列表创建一维数组。但是,如何在给定一维未装箱列表(长度相等)的情况下创建一个二维呢?

4

2 回答 2

1

使用reshape功能:reshape :: (Shape sh1, Shape sh2, Source r1 e) => sh2 -> Array r1 sh1 e -> Array D sh2 e。它只是编译时的(没有运行时开销)。

于 2016-01-03T20:31:39.980 回答
0

我也偶然发现了这个问题。我通过将数组列表转换为未装箱的向量,将它们连接起来并将它们转换回 repa 数组来解决它。非常笨拙,但这是我能想到的。

import           Data.Array.Repa     as R
import           Data.Vector.Unboxed as V
import           Prelude             as P

arrs = P.replicate 5 $ fromListUnboxed (ix1 10) [0..9 :: Int]

main = print concatenatedArrs
  where vectors = P.map toUnboxed arrs
        concatenatedVectors = V.concat vectors
        concatenatedArrs = fromUnboxed (R.ix2 5 10) concatenatedVectors
于 2019-02-25T11:16:08.753 回答