module Data.Repa.Array.Generic.Load
( Load (..)
, computeS
, computeIntoS)
where
import Data.Repa.Array.Internals.Target as A
import Data.Repa.Array.Internals.Load as A
import Data.Repa.Array.Internals.Bulk as A
import Data.Repa.Array.Generic.Index as A
import System.IO.Unsafe
#include "repa-array.h"
computeS :: (Load lSrc lDst a, Index lSrc ~ Index lDst)
=> Name lDst -> Array lSrc a -> Array lDst a
computeS !nDst !aSrc
= let !lDst = create nDst (extent $ layout aSrc)
Just aDst = computeIntoS lDst aSrc
in aDst `seq` aDst
computeIntoS :: Load lSrc lDst a
=> lDst -> Array lSrc a -> Maybe (Array lDst a)
computeIntoS !lDst !aSrc
| (A.size $ A.extent lDst) == A.length aSrc
= unsafePerformIO
$ do !buf <- unsafeNewBuffer lDst
loadS aSrc buf
!arr <- unsafeFreezeBuffer buf
return $ Just arr
| otherwise
= Nothing