module Data.Array.Repa.Repr.Partitioned
( P, Array (..)
, Range(..)
, inRange)
where
import Data.Array.Repa.Base
import Data.Array.Repa.Shape
import Data.Array.Repa.Eval
import Data.Array.Repa.Repr.Delayed
data P r1 r2
data Range sh
= Range !sh !sh
(sh -> Bool)
inRange :: Range sh -> sh -> Bool
inRange (Range _ _ p) ix
= p ix
instance (Source r1 e, Source r2 e) => Source (P r1 r2) e where
data Array (P r1 r2) sh e
= APart !sh
!(Range sh) !(Array r1 sh e)
!(Array r2 sh e)
index (APart _ range arr1 arr2) ix
| inRange range ix = index arr1 ix
| otherwise = index arr2 ix
linearIndex arr@(APart sh _ _ _) ix
= index arr $ fromIndex sh ix
extent (APart sh _ _ _)
= sh
deepSeqArray (APart sh range arr1 arr2) y
= sh `deepSeq` range `deepSeqRange` arr1 `deepSeqArray` arr2 `deepSeqArray` y
deepSeqRange :: Shape sh => Range sh -> b -> b
deepSeqRange (Range ix sz f) y
= ix `deepSeq` sz `deepSeq` f `seq` y
instance (LoadRange r1 sh e, Load r2 sh e)
=> Load (P r1 r2) sh e where
loadP (APart _ (Range ix sz _) arr1 arr2) marr
= do loadRangeP arr1 marr ix sz
loadP arr2 marr
loadS (APart _ (Range ix sz _) arr1 arr2) marr
= do loadRangeS arr1 marr ix sz
loadS arr2 marr