{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE CPP #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
module Data.Massiv.Array.Manifest
(
Manifest
, toManifest
, M
, B(..)
, N(..)
, Uninitialized(..)
, unwrapArray
, evalArray
, unwrapMutableArray
, evalMutableArray
, unwrapNormalFormArray
, evalNormalFormArray
, unwrapNormalFormMutableArray
, evalNormalFormMutableArray
, P(..)
, Prim
, toByteArray
, fromByteArray
, fromByteArrayM
, toMutableByteArray
, fromMutableByteArray
, fromMutableByteArrayM
, S(..)
, Storable
, toStorableVector
, toStorableMVector
, withPtr
, U(..)
, Unbox
, toUnboxedVector
, toUnboxedMVector
, fromByteString
, castFromByteString
, toByteString
, castToByteString
, toBuilder
) where
import Data.ByteString as S
import Data.ByteString.Builder
import Data.ByteString.Internal
import Data.ByteString.Unsafe as SU
import Data.Massiv.Array.Manifest.Boxed
import Data.Massiv.Array.Manifest.Internal
import Data.Massiv.Array.Manifest.Primitive
import Data.Massiv.Array.Manifest.Storable
import Data.Massiv.Array.Manifest.Unboxed
import Data.Massiv.Array.Ops.Fold
import Data.Massiv.Core.Common
import Data.Massiv.Core.Index.Internal (Sz(..))
import Data.Word (Word8)
fromByteString ::
Comp
-> ByteString
-> Array M Ix1 Word8
fromByteString comp bs = MArray comp (SafeSz (S.length bs)) (SU.unsafeIndex bs)
{-# INLINE fromByteString #-}
toByteString ::
Load r ix Word8
=> Array r ix Word8
-> ByteString
toByteString = castToByteString .
#if __GLASGOW_HASKELL__ >= 820
convert
#else
compute
#endif
{-# INLINE toByteString #-}
toBuilder :: Source r ix e => (e -> Builder) -> Array r ix e -> Builder
toBuilder = foldMono
{-# INLINE toBuilder #-}
castToByteString :: Array S ix Word8 -> ByteString
castToByteString = (\(fp, len) -> PS fp 0 len) . unsafeArrayToForeignPtr
{-# INLINE castToByteString #-}
castFromByteString :: Comp -> ByteString -> Array S Ix1 Word8
castFromByteString comp (PS fp offset len) = unsafeArrayFromForeignPtr comp fp offset (Sz len)
{-# INLINE castFromByteString #-}