repa-bytestring 1.1.0.0 → 2.0.0.1
raw patch · 2 files changed
+55/−17 lines, 2 filesdep +vectordep −dph-prim-pardep ~repaPVP ok
version bump matches the API change (PVP)
Dependencies added: vector
Dependencies removed: dph-prim-par
Dependency ranges changed: repa
API changes (from Hackage documentation)
+ Data.Array.Repa.ByteString: copyFromPtrWord8 :: Shape sh => sh -> Ptr Word8 -> IO (Array sh Word8)
+ Data.Array.Repa.ByteString: copyToPtrWord8 :: Shape sh => Ptr Word8 -> Array sh Word8 -> IO ()
- Data.Array.Repa.ByteString: fromByteString :: (Shape sh) => sh -> ByteString -> Array sh Word8
+ Data.Array.Repa.ByteString: fromByteString :: Shape sh => sh -> ByteString -> Array sh Word8
- Data.Array.Repa.ByteString: toByteString :: (Shape sh) => Array sh Word8 -> ByteString
+ Data.Array.Repa.ByteString: toByteString :: Shape sh => Array sh Word8 -> ByteString
Files
- Data/Array/Repa/ByteString.hs +52/−11
- repa-bytestring.cabal +3/−6
Data/Array/Repa/ByteString.hs view
@@ -3,7 +3,9 @@ -- | Conversions between Repa Arrays and ByteStrings. module Data.Array.Repa.ByteString ( toByteString- , fromByteString)+ , fromByteString+ , copyFromPtrWord8+ , copyToPtrWord8) where import Data.Word import Data.Array.Repa@@ -11,29 +13,31 @@ import Foreign.Ptr import Foreign.Storable import System.IO.Unsafe+import qualified Data.Vector.Unboxed as V import qualified Data.ByteString as BS import Data.ByteString (ByteString)-import qualified "dph-prim-par" Data.Array.Parallel.Unlifted as U --- | Convert an `Array` to a (strict) `ByteString`.+-- | Copy an `Array` to a (strict) `ByteString`. toByteString :: Shape sh => Array sh Word8 -> ByteString- ++{-# NOINLINE toByteString #-} toByteString arr- = unsafePerformIO- $ allocaBytes (size $ extent arr) $ \(bufDest :: Ptr Word8) ->- let uarr = toUArray arr- len = size $ extent arr+ = withManifest' (force arr) $ \arr' + -> unsafePerformIO+ $ allocaBytes (size $ extent arr') $ \(bufDest :: Ptr Word8) ->+ let vec = toVector arr'+ len = size $ extent arr' copy offset | offset >= len = return () | otherwise- = do pokeByteOff bufDest offset (uarr U.!: offset)+ = do pokeByteOff bufDest offset (vec `V.unsafeIndex` offset) copy (offset + 1) in do@@ -41,8 +45,8 @@ BS.packCStringLen (castPtr bufDest, len) --- | Convert a (strict) `ByteString` to an `Array`.--- The given array size must match the length of the `ByteString`, else `error`.+-- | Copy a (strict) `ByteString` to a new `Array`.+-- The given array extent must match the length of the `ByteString`, else `error`. fromByteString :: Shape sh => sh@@ -58,3 +62,40 @@ | otherwise = fromFunction sh (\ix -> str `BS.index` toIndex sh ix) ++-- Ptr utils ------------------------------------------------------------------+-- | Copy some data from somewhere into a new `Array`.+copyFromPtrWord8 + :: Shape sh+ => sh+ -> Ptr Word8+ -> IO (Array sh Word8)++{-# INLINE copyFromPtrWord8 #-} +copyFromPtrWord8 sh ptr+ = do return $ fromFunction sh (\ix -> unsafePerformIO (peekElemOff ptr (toIndex sh ix)))+++-- | Copy array data somewhere.s+copyToPtrWord8 + :: Shape sh+ => Ptr Word8+ -> Array sh Word8+ -> IO ()+ +{-# INLINE copyToPtrWord8 #-}+copyToPtrWord8 ptr arr+ = let vec = toVector arr+ len = size $ extent arr+ + copy offset+ | offset >= len+ = return ()+ + | otherwise+ = do pokeByteOff ptr offset (vec `V.unsafeIndex` offset)+ copy (offset + 1)++ in do+ copy 0+ return ()
repa-bytestring.cabal view
@@ -1,5 +1,5 @@ Name: repa-bytestring-Version: 1.1.0.0+Version: 2.0.0.1 License: BSD3 License-file: LICENSE Author: The DPH Team@@ -11,19 +11,16 @@ Homepage: http://trac.haskell.org/repa Bug-reports: http://trac.haskell.org/repa/newticket Description:- NOTE: You must use the GHC head branch > 6.13.20100309 to get decent performance. Conversions between Repa Arrays and ByteStrings. Synopsis: Conversions between Repa Arrays and ByteStrings. -Tested-with: GHC == 6.13.20100309, GHC == 6.12.1- Library Build-Depends: base == 4.*,- dph-prim-par == 0.4.*,- repa == 1.1.*,+ repa == 2.0.*,+ vector == 0.7.*, bytestring == 0.9.1.* ghc-options: