module Data.Array.Repa.Base
( Array
, Repr (..), (!), toList
, deepSeqArrays)
where
import Data.Array.Repa.Shape
data family Array r sh e
class Repr r e where
extent :: Shape sh => Array r sh e -> sh
index, unsafeIndex
:: Shape sh => Array r sh e -> sh -> e
index arr ix = arr `linearIndex` toIndex (extent arr) ix
unsafeIndex arr ix = arr `unsafeLinearIndex` toIndex (extent arr) ix
linearIndex, unsafeLinearIndex
:: Shape sh => Array r sh e -> Int -> e
unsafeLinearIndex = linearIndex
deepSeqArray :: Shape sh => Array r sh e -> b -> b
(!) :: (Repr r e, Shape sh) => Array r sh e -> sh -> e
(!) = index
toList :: (Shape sh, Repr r e)
=> Array r sh e -> [e]
toList arr
= go 0
where len = size (extent arr)
go ix
| ix == len = []
| otherwise = unsafeLinearIndex arr ix : go (ix + 1)
deepSeqArrays
:: (Shape sh, Repr r e)
=> [Array r sh e] -> b -> b
deepSeqArrays arrs x
= case arrs of
[] -> x
[a1]
-> a1 `deepSeqArray` x
[a1, a2]
-> a1 `deepSeqArray` a2 `deepSeqArray` x
[a1, a2, a3]
-> a1 `deepSeqArray` a2 `deepSeqArray` a3 `deepSeqArray` x
[a1, a2, a3, a4]
-> a1 `deepSeqArray` a2 `deepSeqArray` a3 `deepSeqArray` a4 `deepSeqArray` x
_ -> error "deepSeqArrays: only works for up to four arrays"