module Data.Array.Repa.Repr.ByteString
( B, Array (..)
, fromByteString, toByteString)
where
import Data.Array.Repa.Shape
import Data.Array.Repa.Base
import Data.Array.Repa.Repr.Delayed
import Data.Word
import qualified Data.ByteString as B
import qualified Data.ByteString.Unsafe as BU
import Data.ByteString (ByteString)
data B
instance Source B Word8 where
data Array B sh Word8
= AByteString !sh !ByteString
linearIndex (AByteString _ bs) ix
= bs `B.index` ix
{-# INLINE linearIndex #-}
unsafeLinearIndex (AByteString _ bs) ix
= bs `BU.unsafeIndex` ix
{-# INLINE unsafeLinearIndex #-}
extent (AByteString sh _)
= sh
{-# INLINE extent #-}
deepSeqArray (AByteString sh bs) x
= sh `deepSeq` bs `seq` x
{-# INLINE deepSeqArray #-}
deriving instance Show sh
=> Show (Array B sh Word8)
deriving instance Read sh
=> Read (Array B sh Word8)
fromByteString
:: sh -> ByteString -> Array B sh Word8
fromByteString sh bs
= AByteString sh bs
{-# INLINE fromByteString #-}
toByteString :: Array B sh Word8 -> ByteString
toByteString (AByteString _ bs) = bs
{-# INLINE toByteString #-}