module Data.Array.Repa.Eval.Target
( Target (..)
, fromList)
where
import Data.Array.Repa.Base
import Data.Array.Repa.Shape
import Control.Monad
import System.IO.Unsafe
class Target r e where
data MVec r e
newMVec :: Int -> IO (MVec r e)
unsafeWriteMVec :: MVec r e -> Int -> e -> IO ()
unsafeFreezeMVec :: sh -> MVec r e -> IO (Array r sh e)
deepSeqMVec :: MVec r e -> a -> a
touchMVec :: MVec r e -> IO ()
fromList :: (Shape sh, Target r e)
=> sh -> [e] -> Array r sh e
fromList sh xx
= unsafePerformIO
$ do let len = length xx
if len /= size sh
then error "Data.Array.Repa.Eval.Fill.fromList: provide array shape does not match list length"
else do
mvec <- newMVec len
zipWithM_ (unsafeWriteMVec mvec) [0..] xx
unsafeFreezeMVec sh mvec