packages feed

repa 2.1.0.1 → 2.1.1.1

raw patch · 5 files changed

+46/−28 lines, 5 files

Files

Data/Array/Repa.hs view
@@ -124,7 +124,11 @@ -- Instances -------------------------------------------------------------------------------------- -- Show instance (Shape sh, Elt a, Show a) => Show (Array sh a) where- 	show arr = show $ toList arr+        show arr =+          let shape = showShape (extent arr)+              elems = show      (toList arr)+          in+          "Array (" P.++ shape P.++ ") " P.++ elems   -- Eq
Data/Array/Repa/Internals/EvalReduction.hs view
@@ -7,7 +7,7 @@ import Data.Array.Repa.Internals.Gang import qualified Data.Vector.Unboxed            as V import qualified Data.Vector.Unboxed.Mutable    as M-import GHC.Base                                 ( quotInt )+import GHC.Base                                 ( quotInt, divInt )   -- | Sequential reduction of a multidimensional array along the innermost dimension.@@ -54,7 +54,7 @@     split !ix = len `min` (ix * step)      {-# INLINE fill #-}-    fill !start !end = iter start start+    fill !start !end = iter start (start * n)       where         {-# INLINE iter #-}         iter !sh !sz | sh >= end = return ()@@ -89,17 +89,20 @@          -> Int                 -- ^ number of elements          -> IO a {-# INLINE foldAllP #-}-foldAllP !f !c !r !len = do-  mvec <- M.unsafeNew threads-  gangIO theGang $ \tid -> fill mvec tid (split tid) (split (tid+1))-  vec  <- V.unsafeFreeze mvec-  return $! V.foldl' c r vec+foldAllP !f !c !r !len+  | len == 0    = return r+  | otherwise   = do+      mvec <- M.unsafeNew chunks+      gangIO theGang $ \tid -> fill mvec tid (split tid) (split (tid+1))+      vec  <- V.unsafeFreeze mvec+      return $! V.foldl' c r vec   where-    !threads  = gangSize theGang-    !step     = (len + threads - 1) `quotInt` threads+    !threads    = gangSize theGang+    !step       = (len + threads - 1) `quotInt` threads+    chunks      = ((len + step - 1) `divInt` step) `min` threads      {-# INLINE split #-}-    split !ix = len `min` (ix * step)+    split !ix   = len `min` (ix * step)      {-# INLINE fill #-}     fill !mvec !tid !start !end
Data/Array/Repa/Properties.hs view
@@ -10,11 +10,18 @@ import qualified Data.Vector.Unboxed    as V import Control.Monad import Test.QuickCheck-import Prelude				as P+import Prelude				as P hiding (compare) +stage   :: String stage	= "Data.Array.Repa.Properties" +compare :: (Eq a, Show a) => a -> a -> Property+compare ans ref = printTestCase message (ref == ans)+  where+    message = unlines ["*** Expected:", show ref+                      ,"*** Received:", show ans ] + -- Data.Array.Repa.Index -------------------------------------------------------------------------- -- | QuickCheck properties for "Data.Array.Repa.Index". props_DataArrayRepaIndex :: [(String, Property)]@@ -26,14 +33,12 @@ prop_toIndexFromIndex_DIM1 sh ix 	=   (sizeIsValid sh) 	==> (inShape sh ix)-	==> fromIndex sh (toIndex sh ix) == ix-	where	_types	= ( sh :: DIM1-			  , ix :: DIM1)+	==> fromIndex sh (toIndex sh ix) `compare` (ix :: DIM1)  prop_toIndexFromIndex_DIM2  =	forAll arbitraryShape   $ \(sh :: DIM2) ->    	forAll (genInShape2 sh) $ \(ix :: DIM2) ->-	fromIndex sh (toIndex sh ix) == ix+	fromIndex sh (toIndex sh ix) `compare` ix   @@ -57,48 +62,48 @@ -- The Eq instance uses fold and zipWith. prop_id_force_DIM5  = 	forAll (arbitrarySmallArray 10)			$ \(arr :: Array DIM5 Int) ->-	arr == force arr+	force arr `compare` arr  prop_id_toScalarUnit (x :: Int)- =	toScalar (singleton x) == x+ =	toScalar (singleton x) `compare` x  -- Conversions ------------------------ prop_id_toListFromList_DIM3  =	forAll (arbitrarySmallShape 10)			$ \(sh :: DIM3) -> 	forAll (arbitraryListOfLength (S.size sh))	$ \(xx :: [Int]) ->-	toList (fromList sh xx) == xx+	toList (fromList sh xx) `compare` xx  -- Index Space Transforms ------------- prop_id_transpose_DIM4  = 	forAll (arbitrarySmallArray 20)			$ \(arr :: Array DIM3 Int) ->-	transpose (transpose arr) == arr+	transpose (transpose arr) `compare` arr  -- A reshaped array has the same size and sum as the original prop_reshapeTranspose_DIM3  = 	forAll (arbitrarySmallArray 20)			$ \(arr :: Array DIM3 Int) ->    let	arr'	= transpose arr    	sh'	= extent arr'-   in	(S.size $ extent arr) == S.size (extent (reshape sh' arr))-     && (sumAll arr          == sumAll arr')+   in	(S.size (extent (reshape sh' arr)) `compare` S.size (extent arr))+   .&&. (sumAll arr'                       `compare` sumAll arr)  prop_appendIsAppend_DIM3  = 	forAll (arbitrarySmallArray 20)			$ \(arr1 :: Array DIM3 Int) ->-	sumAll (append arr1 arr1) == (2 * sumAll arr1)+	sumAll (append arr1 arr1) `compare` (2 * sumAll arr1)  -- Reductions -------------------------- prop_sumIsSum_DIM3-  = forAll (arbitrarySmallArray 20)                     $ \(arr :: Array DIM3 Float) ->+  = forAll (arbitrarySmallArray 20)                     $ \(arr :: Array DIM3 Int) ->     let sh :. sz  = extent arr         elemFn ix = V.foldl' (+) 0                   $ V.map (\i -> arr ! (ix :. i))                           (V.enumFromTo 0 (sz-1))     in-    R.fold (+) 0 arr == fromFunction sh elemFn+    R.fold (+) 0 arr `compare` fromFunction sh elemFn  prop_sumAllIsSum_DIM3  = 	forAll (arbitrarySmallShape 20)		        $ \(sh :: DIM3) -> 	forAll (arbitraryListOfLength (S.size sh))	$ \(xx :: [Int]) ->-	sumAll (fromList sh xx) == P.sum xx+        sumAll (fromList sh xx) `compare` P.sum xx   -- Utils ------------------------------------------------------------------------------------------
Data/Array/Repa/Shape.hs view
@@ -3,7 +3,8 @@ -- | Class of types that can be used as array shapes and indices. module Data.Array.Repa.Shape 	( Shape(..)-	, inShape )+        , inShape+        , showShape ) where  -- Shape ------------------------------------------------------------------------------------------@@ -73,4 +74,9 @@ {-# INLINE inShape #-} inShape sh ix 	= inShapeRange zeroDim sh ix+++-- | Nicely format a shape as a string+showShape :: Shape sh => sh -> String+showShape = foldr (\sh str -> str ++ " :. " ++ show sh) "Z" . listOfShape 
repa.cabal view
@@ -1,5 +1,5 @@ Name:                repa-Version:             2.1.0.1+Version:             2.1.1.1 License:             BSD3 License-file:        LICENSE Author:              The DPH Team