module Data.Array.Repa.Repr.Cursored
( C, Array (..)
, makeCursored)
where
import Data.Array.Repa.Base
import Data.Array.Repa.Shape
import Data.Array.Repa.Index
import Data.Array.Repa.Repr.Delayed
import Data.Array.Repa.Repr.Undefined
import Data.Array.Repa.Eval.Load
import Data.Array.Repa.Eval.Elt
import Data.Array.Repa.Eval.Cursored
import Data.Array.Repa.Eval.Target
import GHC.Exts
import Debug.Trace
data C
instance Source C a where
data Array C sh a
= forall cursor. ACursored
{ cursoredExtent :: !sh
, makeCursor :: sh -> cursor
, shiftCursor :: sh -> cursor -> cursor
, loadCursor :: cursor -> a }
index (ACursored _ makec _ loadc)
= loadc . makec
unsafeIndex = index
linearIndex (ACursored sh makec _ loadc)
= loadc . makec . fromIndex sh
extent (ACursored sh _ _ _)
= sh
deepSeqArray (ACursored sh makec shiftc loadc) y
= sh `deepSeq` makec `seq` shiftc `seq` loadc `seq` y
instance Elt e => Load C DIM2 e where
loadP (ACursored (Z :. (I# h) :. (I# w)) makec shiftc loadc) marr
= do traceEventIO "Repa.loadP[Cursored]: start"
fillCursoredBlock2P
(unsafeWriteMVec marr)
makec shiftc loadc
w 0# 0# w h
touchMVec marr
traceEventIO "Repa.loadP[Cursored]: end"
loadS (ACursored (Z :. (I# h) :. (I# w)) makec shiftc loadc) marr
= do traceEventIO "Repa.loadS[Cursored]: start"
fillCursoredBlock2S
(unsafeWriteMVec marr)
makec shiftc loadc
w 0# 0# w h
touchMVec marr
traceEventIO "Repa.loadS[Cursored]: end"
instance Elt e => LoadRange C DIM2 e where
loadRangeP (ACursored (Z :. _h :. (I# w)) makec shiftc loadc) marr
(Z :. (I# y0) :. (I# x0)) (Z :. (I# h0) :. (I# w0))
= do traceEventIO "Repa.loadRangeP[Cursored]: start"
fillCursoredBlock2P
(unsafeWriteMVec marr)
makec shiftc loadc
w x0 y0 w0 h0
touchMVec marr
traceEventIO "Repa.loadRangeP[Cursored]: end"
loadRangeS (ACursored (Z :. _h :. (I# w)) makec shiftc loadc) marr
(Z :. (I# y0) :. (I# x0))
(Z :. (I# h0) :. (I# w0))
= do traceEventIO "Repa.loadRangeS[Cursored]: start"
fillCursoredBlock2S
(unsafeWriteMVec marr)
makec shiftc loadc
w x0 y0 w0 h0
touchMVec marr
traceEventIO "Repa.loadRangeS[Cursored]: end"
makeCursored
:: sh
-> (sh -> cursor)
-> (sh -> cursor -> cursor)
-> (cursor -> e)
-> Array C sh e
makeCursored = ACursored