1
我想在repa-io使用writeImageToBMP
將陣列寫入BMP文件之前將加速陣列轉換爲repa陣列。忽略加速中存在這樣一個函數的事實,我只是用它作爲問題的一個例子。採取:將加速度的A陣列表示轉換爲repa的U陣列表示
{-# LANGUAGE ScopedTypeVariables #-}
import qualified Data.Array.Accelerate.Interpreter as A (run)
import Data.Array.Accelerate
import qualified Data.Array.Accelerate as A
import qualified Data.Array.Accelerate.IO as A
import qualified Data.Array.Repa as Repa
import qualified Data.Array.Repa.IO.BMP as Repa
import GHC.Word
main :: IO()
main = do
let accelArr = A.fromList
(Z :. (2::Int) :. (1::Int))
([(1,2,3),(4,5,6)] :: [(Word8,Word8,Word8)])
computation :: A.Acc (A.Array A.DIM2 (Word8,Word8,Word8))
computation = A.map
(\triple ->
let (r',g',b') = unlift triple :: (Exp Word8,Exp Word8,Exp Word8)
in lift (constant 0,g',b')) (use accelArr)
repaArr :: Repa.Array A.A Repa.DIM2 (Word8,Word8,Word8)
repaArr = A.toRepa (A.run computation)
Repa.writeImageToBMP "out_repa.bmp" repaArr
這些軟件包加速,加速,io,repa和repa-io reuired編譯此代碼。
這並不編譯,因爲在repA的-IO writeImageToBmp
類型是:
writeImageToBMP
:: FilePath
-> Repa.Array Repa.U Repa.DIM2 (Word8, Word8, Word8)
-> IO()
凡U
表示repA的清單陣列。該GHC錯誤是:
Couldn't match type ‘A.A’ with ‘Repa.U’
Expected type: Repa.Array Repa.U Repa.DIM2 (Word8, Word8, Word8)
Actual type: Repa.Array A.A Repa.DIM2 (Word8, Word8, Word8)
In the second argument of ‘Repa.writeImageToBMP’, namely ‘repaArr’
In a stmt of a 'do' block:
Repa.writeImageToBMP "out_repa.bmp" repaArr
類型的repaArr
是:
Repa.Array A.A Repa.DIM2 (Word8,Word8,Word8)
這就是爲什麼GHC抱怨它作爲一個參數writeImageToBMP
。
問題:如何轉換的加速數組表示A
到repA的清單數組表示U
,這樣我就可以調用它writeImageToBMP
?
與將任何Repa數組轉換爲unboxed Repa數組的方式相同:['computeUnboxed {S/P}'](https://hackage.haskell.org/package/repa-3.2.3.3/docs/Data-陣列Repa.html#五:computeUnboxedP)。 – user2407038
@ user2407038 - 我能夠使'copyP'和'copyS'工作,但沒有任何計算方法,因爲缺少'Load'約束。 – ErikR