packages feed

comfort-array 0.0 → 0.0.1

raw patch · 4 files changed

+28/−30 lines, 4 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

+ Data.Array.Comfort.Storable: map :: (C sh, Storable a, Storable b) => (a -> b) -> Array sh a -> Array sh b
+ Data.Array.Comfort.Storable.Internal: map :: (C sh, Storable a, Storable b) => (a -> b) -> Array sh a -> Array sh b
+ Data.Array.Comfort.Storable.Internal: unsafeCreateWithSize :: (C sh, Storable a) => sh -> (Int -> Ptr a -> IO ()) -> Array sh a

Files

comfort-array.cabal view
@@ -1,5 +1,5 @@ Name:             comfort-array-Version:          0.0+Version:          0.0.1 License:          BSD3 License-File:     LICENSE Author:           Henning Thielemann <haskell@henning-thielemann.de>@@ -45,7 +45,7 @@ Build-Type:       Simple  Source-Repository this-  Tag:         0.0+  Tag:         0.0.1   Type:        darcs   Location:    http://hub.darcs.net/thielema/comfort-array/ 
src/Data/Array/Comfort/Shape.hs view
@@ -1,11 +1,5 @@ {-# LANGUAGE TypeFamilies #-} {-# LANGUAGE TypeOperators #-}-{--Tests:-   map offset (indices sh) = [0..]-   length (indices sh) = size sh-   sizeOffset sh ix = (size sh, offset sh ix)--} module Data.Array.Comfort.Shape (    C(..), @@ -243,23 +237,6 @@  data sh0:+:sh1 = sh0:+:sh1    deriving (Eq, Show)--{---- cf. sample-frame:Stereo-instance (Storable sh0, Storable sh1) => Storable (sh0:+:sh1) where-   {-# INLINE sizeOf #-}-   {-# INLINE alignment #-}-   {-# INLINE peek #-}-   {-# INLINE poke #-}-   sizeOf ~(sh0:+:sh1) = sizeOf sh0 + mod (- sizeOf sh0) (alignment sh1) + sizeOf sh1-   alignment ~(sh0:+:sh1) = alignment sh0-   poke p (sh0:+:sh1) =-      let q = castToElemPtr p-      in  poke q sh0 >> pokeElemOff q 1 sh1-   peek p =-      let q = castToElemPtr p-      in  Monad.lift2 Shifted (peek q) (peekElemOff q 1)--}  instance (C sh0, C sh1) => C (sh0:+:sh1) where    type Index (sh0:+:sh1) = Either (Index sh0) (Index sh1)
src/Data/Array/Comfort/Storable.hs view
@@ -6,6 +6,8 @@    toList,    fromList,    vectorFromList,++   Array.map,    ) where -import Data.Array.Comfort.Storable.Internal+import Data.Array.Comfort.Storable.Internal as Array
src/Data/Array/Comfort/Storable/Internal.hs view
@@ -6,10 +6,13 @@     (!),    unsafeCreate,+   unsafeCreateWithSize,    toList,    fromList,    vectorFromList, +   map,+    createIO,    createWithSizeIO,    showIO,@@ -21,14 +24,14 @@  import qualified Data.Array.Comfort.Shape as Shape -import Foreign.Marshal.Array (pokeArray, peekArray, )-import Foreign.Storable (Storable, peekElemOff, )+import Foreign.Marshal.Array (pokeArray, peekArray, advancePtr, )+import Foreign.Storable (Storable, poke, peek, peekElemOff, ) import Foreign.ForeignPtr (ForeignPtr, withForeignPtr, mallocForeignPtrArray, ) import Foreign.Ptr (Ptr, )  import System.IO.Unsafe (unsafePerformIO, ) -import Prelude hiding (readIO, )+import Prelude hiding (map, readIO, )   data Array sh a =@@ -40,7 +43,6 @@ instance (Shape.C sh, Show sh, Storable a, Show a) => Show (Array sh a) where    show = unsafePerformIO . showIO --- add assertion, at least in an exposed version reshape :: sh1 -> Array sh0 a -> Array sh1 a reshape sh (Array _ fptr) = Array sh fptr @@ -54,6 +56,10 @@    (Shape.C sh, Storable a) => sh -> (Ptr a -> IO ()) -> Array sh a unsafeCreate sh = unsafePerformIO . createIO sh +unsafeCreateWithSize ::+   (Shape.C sh, Storable a) => sh -> (Int -> Ptr a -> IO ()) -> Array sh a+unsafeCreateWithSize sh = unsafePerformIO . createWithSizeIO sh+ (!) :: (Shape.C sh, Storable a) => Array sh a -> Shape.Index sh -> a (!) arr = unsafePerformIO . readIO arr @@ -65,6 +71,19 @@  vectorFromList :: (Storable a) => [a] -> Array (Shape.ZeroBased Int) a vectorFromList = unsafePerformIO . vectorFromListIO+++map ::+   (Shape.C sh, Storable a, Storable b) =>+   (a -> b) -> Array sh a -> Array sh b+map f (Array sh a) =+   unsafeCreate sh $ \dstPtr ->+   withForeignPtr a $ \srcPtr ->+   sequence_ $ take (Shape.size sh) $+      zipWith+         (\src dst -> poke dst . f =<< peek src)+         (iterate (flip advancePtr 1) srcPtr)+         (iterate (flip advancePtr 1) dstPtr)   createIO ::