3
我有一個向量Float
由getVectorFloat
功能創建的元素。 爲了進行一些測量,我需要使用deepSeqArray
。 但是,我無法做到這一點。deepSeqArray的單精度陣列
這是我的例子:
import Data.Array.Repa as R
import Data.Array.Repa.Algorithms.Randomish
len :: Int
len = 3000000
main = do
ws <- getVectorFloat len
ws `deepSeqArray` return()
getVectorFloat :: Int -> Array DIM1 Float
getVectorFloat len = R.map (toFloat) (getVectorDouble len)
toFloat :: Double -> Float
toFloat a = realToFrac a
getVectorDouble :: Int -> Array DIM1 Double
getVectorDouble len = randomishDoubleArray (Z :. len) (-100) 100 1
而我得到的錯誤:
haskell.hs:9:9:
Couldn't match expected type `Array sh0 a0'
with actual type `Float'
In the first argument of `deepSeqArray', namely `ws'
In the expression: ws `deepSeqArray` return()
In the expression:
do { ws <- getVectorFloat len;
ws `deepSeqArray` return() }
我不明白爲什麼Array sh0 a0
不能匹配Array Dim1 Float
。
謝謝你的幫助
好的。 所以我在main之前設置了'ws = getVectorFloat len'。現在主要包含'do ws \'deepSeqArray \'return()'。 編譯正確。 謝謝! – 2011-04-11 12:47:39