{-# LANGUAGE BangPatterns #-}
{-# 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
, toMutableByteArray
, fromMutableByteArray
, S(..)
, Storable
, toStorableVector
, toStorableMVector
, withPtr
, unsafeWithPtr
, U(..)
, Unbox
, toUnboxedVector
, toUnboxedMVector
, fromByteString
, toByteString
, toBuilder
) where
import Data.ByteString as S
import Data.ByteString.Builder
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.Word (Word8)
fromByteString ::
Comp
-> ByteString
-> Array M Ix1 Word8
fromByteString comp bs = MArray comp (S.length bs) (SU.unsafeIndex bs)
{-# INLINE fromByteString #-}
toByteString ::
Source r ix Word8
=> Array r ix Word8
-> ByteString
toByteString arr =
fst $ unfoldrN (totalElem (size arr)) (\ !i -> Just (unsafeLinearIndex arr i, i + 1)) 0
{-# INLINE toByteString #-}
toBuilder :: Source r ix e => (e -> Builder) -> Array r ix e -> Builder
toBuilder f = foldMono f
{-# INLINE toBuilder #-}