{-# 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(..)
, unwrapNormalForm
, evalNormalForm
, unwrapArray
, evalArray
, unwrapMutableArray
, evalMutableArray
, unwrapNormalFormArray
, evalNormalFormArray
, unwrapNormalFormMutableArray
, evalNormalFormMutableArray
, toBoxedVector
, toBoxedMVector
, evalBoxedVector
, evalBoxedMVector
, P(..)
, Prim
, toByteArray
, toByteArrayM
, unwrapByteArray
, fromByteArray
, fromByteArrayM
, toMutableByteArray
, unwrapMutableByteArray
, fromMutableByteArray
, fromMutableByteArrayM
, toPrimitiveVector
, toPrimitiveMVector
, fromPrimitiveVector
, fromPrimitiveMVector
, S(..)
, Storable
, toStorableVector
, toStorableMVector
, fromStorableVector
, fromStorableMVector
, withPtr
, U(..)
, Unbox
, toUnboxedVector
, toUnboxedMVector
, fromUnboxedVector
, fromUnboxedMVector
, fromByteString
, castFromByteString
, toByteString
, castToByteString
, toBuilder
, castToBuilder
) 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 #-}
castToBuilder :: Array S ix Word8 -> Builder
castToBuilder = byteString . castToByteString
{-# INLINE castToBuilder #-}
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 #-}