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.Fill
import Data.Array.Repa.Eval.Elt
import Data.Array.Repa.Eval.Cursored
import GHC.Exts
data C
data instance Array C sh e
= forall cursor. ACursored
{ cursoredExtent :: sh
, makeCursor :: sh -> cursor
, shiftCursor :: sh -> cursor -> cursor
, loadCursor :: cursor -> e }
instance Repr C a where
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 (Fillable r2 e, Elt e) => Fill C r2 DIM2 e where
fillP (ACursored (Z :. h :. w) makec shiftc loadc) marr
= fillCursoredBlock2P
(unsafeWriteMArr marr)
makec shiftc loadc
w 0 0 (w 1) (h 1)
fillS (ACursored (Z :. (I# h) :. (I# w)) makec shiftc loadc) marr
= fillCursoredBlock2S
(unsafeWriteMArr marr)
makec shiftc loadc
w 0# 0# (w -# 1#) (h -# 1#)
instance (Fillable r2 e, Elt e) => FillRange C r2 DIM2 e where
fillRangeP (ACursored (Z :. _h :. w) makec shiftc loadc) marr
(Z :. y0 :. x0) (Z :. y1 :. x1)
= fillCursoredBlock2P
(unsafeWriteMArr marr)
makec shiftc loadc
w x0 y0 x1 y1
fillRangeS (ACursored (Z :. _h :. (I# w)) makec shiftc loadc) marr
(Z :. (I# y0) :. (I# x0))
(Z :. (I# y1) :. (I# x1))
= fillCursoredBlock2S
(unsafeWriteMArr marr)
makec shiftc loadc
w x0 y0 x1 y1
makeCursored
:: sh
-> (sh -> cursor)
-> (sh -> cursor -> cursor)
-> (cursor -> e)
-> Array C sh e
makeCursored = ACursored