packages feed

PrimitiveArray 0.2.0.0 → 0.2.1.0

raw patch · 3 files changed

+74/−4 lines, 3 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

+ Data.PrimitiveArray.Zero: Arr0 :: !sh -> {-# UNPACK #-} !Array elm -> Arr0 sh elm
+ Data.PrimitiveArray.Zero: MArr0 :: !sh -> {-# UNPACK #-} !MutableArray s elm -> MArr0 s sh elm
+ Data.PrimitiveArray.Zero: data Arr0 sh elm
+ Data.PrimitiveArray.Zero: data MArr0 s sh elm
+ Data.PrimitiveArray.Zero: instance (Shape sh, ExtShape sh, Prim elm) => MPrimArrayOps MArr0 sh elm
+ Data.PrimitiveArray.Zero: instance (Shape sh, ExtShape sh, Prim elm) => PrimArrayOps Arr0 sh elm

Files

Data/PrimitiveArray.hs view
@@ -43,7 +43,7 @@   fromListM :: PrimMonad m => sh -> sh -> [elm] -> m (marr (PrimState m) sh elm)    -- | Creates a new array with the given bounds with each element within the-  -- array being in a random state.+  -- array being in an undefined state.    newM :: PrimMonad m => sh -> sh -> m (marr (PrimState m) sh elm) @@ -96,8 +96,6 @@ {-# INLINE (!) #-}  -- | Returns true if the index is valid for the array.------ TODO can't give a typedef  inBoundsM :: MPrimArrayOps marr sh elm => marr s sh elm -> sh -> Bool inBoundsM marr idx = let (lb,ub) = boundsM marr in inShapeRange lb ub idx
+ Data/PrimitiveArray/Zero.hs view
@@ -0,0 +1,71 @@+{-# LANGUAGE MultiParamTypeClasses #-}+{-# LANGUAGE FlexibleInstances #-}+{-# LANGUAGE TypeFamilies #-}++-- | Boxed, primitive arrays. A good use-case is to store boxed or unboxed+-- vectors.++module Data.PrimitiveArray.Zero where++import Control.Monad+import Data.Array.Repa.Index+import Data.Array.Repa.Shape+import Data.Primitive+import Data.Primitive.Array+import Data.Primitive.Types+import Control.Exception (assert)++import Data.ExtShape+import Data.PrimitiveArray++++-- | Monadic arrays of primitive type.++data MArr0 s sh elm = MArr0 !sh {-# UNPACK #-} !(MutableArray s elm)++-- | Immutable arrays of primitive type.++data Arr0 sh elm = Arr0 !sh {-# UNPACK #-} !(Array elm)++++type instance MutArray Arr0 = MArr0++-- NOTE inLb, inUb is including bound, while exUb is excluding upper bound.+-- Differentiates between largest included index, first excluded index.++instance (Shape sh, ExtShape sh, Prim elm) => MPrimArrayOps MArr0 sh elm where+  boundsM (MArr0 exUb _) = (zeroDim,exUb `subDim` unitDim)+  fromListM inLb inUb xs = do+    ma <- newM inLb inUb+    let exUb = inUb `addDim` unitDim+    let (MArr0 _ mba) = ma+    zipWithM_ (\k x -> assert (length xs == size exUb) $ writeArray mba k x) [0.. toIndex exUb inUb] xs+    return ma+  newM inLb inUb = let exUb = inUb `addDim` unitDim in+    unless (inLb == zeroDim) (error "MArr0 lb/=zeroDim") >>+    MArr0 exUb `liftM` newArray (size exUb) undefined+  newWithM inLb inUb def = do+    let exUb = inUb `addDim` unitDim+    ma <- newM inLb inUb+    let (MArr0 _ mba) = ma+    forM_ [0 .. toIndex exUb inUb] $ \k -> writeArray mba k def+    return ma+  readM (MArr0 exUb mba) idx = assert (inShape exUb idx) $ readArray mba (toIndex exUb idx)+  writeM (MArr0 exUb mba) idx elm = assert (inShape exUb idx) $ writeArray mba (toIndex exUb idx) elm+  {-# INLINE boundsM #-}+  {-# INLINE fromListM #-}+  {-# INLINE newM #-}+  {-# INLINE newWithM #-}+  {-# INLINE readM #-}+  {-# INLINE writeM #-}++instance (Shape sh, ExtShape sh, Prim elm) => PrimArrayOps Arr0 sh elm where+  bounds (Arr0 exUb _) = (zeroDim,exUb `subDim` unitDim)+  freeze (MArr0 exUb mba) = Arr0 exUb `liftM` unsafeFreezeArray mba+  index (Arr0 exUb ba) idx = assert (inShape exUb idx) $ indexArray ba (toIndex exUb idx)+  {-# INLINE bounds #-}+  {-# INLINE freeze #-}+  {-# INLINE index #-}+
PrimitiveArray.cabal view
@@ -1,5 +1,5 @@ Name:           PrimitiveArray-Version:        0.2.0.0+Version:        0.2.1.0 License:        BSD3 License-file:   LICENSE Author:         Christian Hoener zu Siederdissen@@ -33,6 +33,7 @@     Data.ExtShape     Data.PrimitiveArray     Data.PrimitiveArray.Unboxed.Zero+    Data.PrimitiveArray.Zero   Build-depends:     base >= 4 && <5,     primitive >= 0.4,