packages feed

histogram-fill 0.3.0.1 → 0.3.1

raw patch · 5 files changed

+61/−24 lines, 5 filesdep ~vector

Dependency ranges changed: vector

Files

Data/Histogram/Bin.hs view
@@ -144,8 +144,8 @@ -- | Simple binning algorithm which map continous range of bins onto -- indices. Each number correcsponds to different bin data BinI = BinI-            {-# UNPACK #-} !Int -- ^ Lower bound (inclusive)-            {-# UNPACK #-} !Int -- ^ Upper bound (inclusive)+            {-# UNPACK #-} !Int -- Lower bound (inclusive)+            {-# UNPACK #-} !Int -- Upper bound (inclusive)             deriving (Eq,Typeable)  -- | Construct BinI with n bins. Indexing starts from 0@@ -191,9 +191,9 @@  -- | Integer bins with size which differ from 1. data BinInt = BinInt-              {-# UNPACK #-} !Int -- ^ Low bound-              {-# UNPACK #-} !Int -- ^ Bin size-              {-# UNPACK #-} !Int -- ^ Number of bins+              {-# UNPACK #-} !Int -- Low bound+              {-# UNPACK #-} !Int -- Bin size+              {-# UNPACK #-} !Int -- Number of bins               deriving (Eq,Typeable)  -- | Construct BinInt.@@ -281,9 +281,9 @@ -- -- Note that due to GHC bug #2271 this toIndex is really slow (20x -- slowdown with respect to BinD) and use of BinD is recommended-data BinF f = BinF {-# UNPACK #-} !f   -- ^ Lower bound-                   {-# UNPACK #-} !f   -- ^ Size of bin-                   {-# UNPACK #-} !Int -- ^ Number of bins+data BinF f = BinF {-# UNPACK #-} !f   -- Lower bound+                   {-# UNPACK #-} !f   -- Size of bin+                   {-# UNPACK #-} !Int -- Number of bins               deriving (Eq,Typeable)  -- | Create bins.@@ -355,9 +355,9 @@ ---------------------------------------------------------------- -- | Floaintg point bins with equal sizes. If you work with Doubles -- this data type should be used instead of BinF.-data BinD = BinD {-# UNPACK #-} !Double -- ^ Lower bound-                 {-# UNPACK #-} !Double -- ^ Size of bin-                 {-# UNPACK #-} !Int    -- ^ Number of bins+data BinD = BinD {-# UNPACK #-} !Double -- Lower bound+                 {-# UNPACK #-} !Double -- Size of bin+                 {-# UNPACK #-} !Int    -- Number of bins             deriving (Eq,Typeable)  -- | Create bins.@@ -433,10 +433,10 @@ ---------------------------------------------------------------- -- | Logarithmic scale bins. data LogBinD = LogBinD-               Double -- ^ Low border-               Double -- ^ Hi border-               Double -- ^ Increment ratio-               Int    -- ^ Number of bins+               Double -- Low border+               Double -- Hi border+               Double -- Increment ratio+               Int    -- Number of bins                deriving (Eq,Typeable)  -- | Create log-scale bins.
Data/Histogram/Fill.hs view
@@ -27,6 +27,8 @@                            , treeHBuilderMonoidM                              -- ** Stateless                            , HBuilder+                           , toHBuilderST+                           , toHBuilderIO                            , joinHBuilder                            , joinHBuilderMonoid                            , treeHBuilder@@ -49,8 +51,9 @@ import Control.Monad.ST  import Control.Monad.Primitive -import Data.Monoid         (Monoid(..))-import Data.Vector.Unboxed (Unbox)+import Data.Monoid            (Monoid(..))+-- import Data.Monoid.Statistics (StatMonoid)+import Data.Vector.Unboxed    (Unbox)  import Data.Histogram import Data.Histogram.Bin@@ -176,8 +179,19 @@ ----------------------------------------------------------------  -- | Stateless histogram builder-newtype HBuilder a b = HBuilder { toBuilderM :: (forall s . ST s (HBuilderM (ST s) a b)) }+newtype HBuilder a b = HBuilder { toHBuilderST :: (forall s . ST s (HBuilderM (ST s) a b)) +                                  -- ^ Convert builder to stateful builder in 'ST' monad+                                } +-- | Convert builder to builder in IO monad+toHBuilderIO :: HBuilder a b -> IO (HBuilderM IO a b)+toHBuilderIO (HBuilder h) = do +  builder <- stToIO h+  return (HBuilderM +          (stToIO . hbInput builder) +          (stToIO $ hbOutput builder))+{-# INLINE toHBuilderIO #-}+   instance HistBuilder (HBuilder) where     modifyIn  f (HBuilder h) = HBuilder (modifyIn  f <$> h)     addCut    f (HBuilder h) = HBuilder (addCut    f <$> h)@@ -192,7 +206,7 @@  -- | Join list of builders joinHBuilder :: [HBuilder a b] -> HBuilder a [b]-joinHBuilder hs = HBuilder (joinHBuilderM <$> mapM toBuilderM hs)+joinHBuilder hs = HBuilder (joinHBuilderM <$> mapM toHBuilderST hs) {-# INLINE joinHBuilder #-}  -- | Join list of builders@@ -238,13 +252,21 @@                                                   } {-# INLINE mkMonoidal #-} +-- mkMonoidalAcc :: (Bin bin, Unbox val, StatMonoid val a+--                  ) => bin -> HBuilder (BinValue bin,a) (Histogram bin val)+-- mkMonoidalAcc bin = HBuilder $ do acc <- newMHistogram mempty bin+--                                   return $ HBuilderM { hbInput  = fillMonoidAccum acc+--                                                      , hbOutput = freezeHist acc+--                                                      }+-- {-# INLINE mkMonoidalAcc #-}+ ---------------------------------------------------------------- -- Actual filling of histograms ----------------------------------------------------------------  fillBuilder :: HBuilder a b -> [a] -> b fillBuilder hb xs = -    runST $ do h <- toBuilderM hb+    runST $ do h <- toHBuilderST hb                mapM_ (feedOne h) xs                freezeHBuilderM h 
Data/Histogram/Generic.hs view
@@ -192,7 +192,7 @@     where       (nx, ny) = nBins2D b       mkSlice i = ( fromIndex (binY b) i-                  , Histogram (binX b) Nothing (G.slice nx (nx*i) a) )+                  , Histogram (binX b) Nothing (G.slice (nx*i) nx a) )  -- | Slice 2D histogram along X axis. sliceX :: (Vector v a, Bin bX, Bin bY) => Histogram v (Bin2D bX bY) a -> [(BinValue bX, Histogram v bY a)]
Data/Histogram/ST.hs view
@@ -14,6 +14,7 @@                          , fillOne                          , fillOneW                          , fillMonoid+                         -- , fillMonoidAccum                          , unsafeFreezeHist                          , freezeHist                          ) where@@ -21,6 +22,7 @@ import Control.Monad.Primitive  import Data.Monoid+-- import Data.Monoid.Statistics import qualified Data.Vector.Unboxed as U import qualified Data.Vector.Unboxed.Mutable as MU import qualified Data.Vector.Generic as G@@ -73,7 +75,17 @@       i = toIndex bin x {-# INLINE fillMonoid #-} -+-- -- | Add one element to monoidal accumulator+-- fillMonoidAccum :: (PrimMonad m, StatMonoid val a, U.Unbox val, Bin bin) +--                 => MHistogram (PrimState m) bin val -> (BinValue bin, a) -> m ()+-- fillMonoidAccum (MHistogram bin uo arr) !(x,a)+--     | i < 0              = MU.unsafeWrite uo  0 . pappend a =<< MU.unsafeRead uo  0+--     | i >= MU.length arr = MU.unsafeWrite uo  1 . pappend a =<< MU.unsafeRead uo  1+--     | otherwise          = MU.unsafeWrite arr i . pappend a =<< MU.unsafeRead arr i+--     where +--       i = toIndex bin x+-- {-# INLINE fillMonoidAccum #-}+     -- | Create immutable histogram from mutable one. This operation is -- unsafe! Accumulator mustn't be used after that unsafeFreezeHist :: (PrimMonad m, U.Unbox a, Bin bin) => MHistogram (PrimState m) bin a -> m (Histogram bin a)
histogram-fill.cabal view
@@ -1,5 +1,5 @@ Name:           histogram-fill-Version:        0.3.0.1+Version:        0.3.1 Cabal-Version:  >= 1.6 License:        BSD3 License-File:   LICENSE@@ -18,7 +18,10 @@   location: http://bitbucket.org/Shimuuar/histogram-fill  Library-  Build-Depends:        base >=3 && <5, primitive, vector+  Build-Depends:        base >=3 && <5,+                        primitive,+                        vector >= 0.6.0.2+--                        monoid-statistics == 0.1.*   Exposed-modules:      Data.Histogram                         Data.Histogram.Generic                         Data.Histogram.Fill