packages feed

histogram-fill 0.7.2.0 → 0.7.3.0

raw patch · 4 files changed

+69/−17 lines, 4 filesPVP: major bump suggested

API removals or changes: PVP suggests a major version bump

API changes (from Hackage documentation)

- Data.Histogram.Bin.Bin2D: type :><: = Bin2D
- Data.Histogram.Fill: data HBuilder a b
+ Data.Histogram: atI :: (Bin bin, Unbox a) => Histogram bin a -> Int -> a
+ Data.Histogram: atV :: (Bin bin, Unbox a) => Histogram bin a -> BinValue bin -> a
+ Data.Histogram.Bin.Bin2D: type (:><:) = Bin2D
+ Data.Histogram.Fill: HBuilder :: (forall s. ST s (HBuilderM (ST s) a b)) -> HBuilder a b
+ Data.Histogram.Fill: mkStatefulBuilder :: PrimMonad m => (a -> m ()) -> m b -> HBuilderM m a b
+ Data.Histogram.Fill: newtype HBuilder a b
+ Data.Histogram.Generic: atI :: (Bin bin, Vector v a) => Histogram v bin a -> Int -> a
+ Data.Histogram.Generic: atV :: (Bin bin, Vector v a) => Histogram v bin a -> BinValue bin -> a
- Data.Histogram.Fill: toHBuilderST :: HBuilder a b -> forall s. ST s (HBuilderM (ST s) a b)
+ Data.Histogram.Fill: toHBuilderST :: HBuilder a b -> ST s (HBuilderM (ST s) a b)

Files

Data/Histogram.hs view
@@ -35,6 +35,8 @@   , HistIndex(..)    , histIndex   , at+  , atV+  , atI     -- * Transformations   , map   , bmap@@ -130,6 +132,14 @@  at :: (Bin bin, Unbox a) => Histogram bin a -> HistIndex bin -> a at = H.at++atV :: (Bin bin, Unbox a) => Histogram bin a -> BinValue bin -> a+atV = H.atV++atI :: (Bin bin, Unbox a) => Histogram bin a -> Int -> a+atI = H.atI++  ---------------------------------------------------------------- -- Modify histograms
Data/Histogram/Fill.hs view
@@ -26,7 +26,7 @@   , joinHBuilderM   , treeHBuilderM     -- ** Stateless-  , HBuilder+  , HBuilder(HBuilder)   , toHBuilderST   , toHBuilderIO   , joinHBuilder@@ -45,6 +45,8 @@   , mkFoldBuilderG     -- ** Pure fold   , mkFolder+    -- ** Generic constructors+  , mkStatefulBuilder     -- * Fill histograms   , fillBuilder   , fillBuilderVec@@ -74,6 +76,8 @@ import Data.Histogram.Bin import Data.Histogram.ST ++ ---------------------------------------------------------------- -- Type class ----------------------------------------------------------------@@ -194,16 +198,18 @@ -- Monadic builder ---------------------------------------------------------------- --- | Stateful histogram builder. There is no direct way to construct---   such builder. Only way to do it is to create 'HBuilder' and use---   'toHBuilderST' or 'toHBuilderIO'.+-- | Stateful histogram builder. Adding value to builder could be done+--   with 'feedOne' and result could be extracted with+--   'freezeHBuilderM'. -----   It's useful when result should be extracted many times from the---   same accumulator.+--   There are two ways to obtain stateful builder. First and+--   recommended is to thaw 'HBuilder' using 'toHBuilderIO' or+--   'toHBuilderST'. Second is to use 'mkStatefulBuilder'. data HBuilderM m a b = HBuilderM { hbInput  :: a -> m ()                                  , hbOutput :: m b                                  } +-- | Builders modified using 'HistBuilder' API will share same buffer. instance PrimMonad m => HistBuilder (HBuilderM m) where     modifyIn    f h = h { hbInput  = hbInput h . f }     addCut      f h = h { hbInput  = \x -> when (f x) (hbInput h x) }@@ -236,8 +242,8 @@ feedOne = hbInput {-# INLINE feedOne #-} --- | Create stateful histogram from instructions. Histograms could---   be filled either in the ST monad or with createHistograms+-- | Extract result from histogram builder. It's safe to call this+--   function multiple times and mutate builder afterwards. freezeHBuilderM :: PrimMonad m => HBuilderM m a b -> m b freezeHBuilderM = hbOutput {-# INLINE freezeHBuilderM #-}@@ -254,23 +260,29 @@ treeHBuilderM fs h = joinHBuilderM $ fmap ($ h) fs {-# INLINE treeHBuilderM #-} ++ ---------------------------------------------------------------- -- Stateless ---------------------------------------------------------------- --- | Stateless histogram builder-newtype HBuilder a b = HBuilder { toHBuilderST :: forall s . ST s (HBuilderM (ST s) a b)-                                  -- ^ Convert builder to stateful builder in ST monad-                                }+-- | Wrapper around stateful histogram builder. It is much more+--   convenient to work with than 'HBuilderM'.+newtype HBuilder a b = HBuilder (forall s . ST s (HBuilderM (ST s) a b)) +-- | Convert builder to stateful builder in ST monad+toHBuilderST :: HBuilder a b -> ST s (HBuilderM (ST s) a b)+{-# INLINE toHBuilderST #-}+toHBuilderST (HBuilder hb) = hb+ -- | Convert builder to builder in IO monad toHBuilderIO :: HBuilder a b -> IO (HBuilderM IO a b)+{-# INLINE toHBuilderIO #-} 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)@@ -288,6 +300,7 @@     mappend h g = mappend <$> h <*> g     mconcat     = fmap mconcat . joinHBuilder     {-# INLINE mempty  #-}+    {-# INLINE mappend #-}     {-# INLINE mconcat #-}  -- | Join hitogram builders in container.@@ -378,9 +391,10 @@   -- | Create histogram builder which just does ordinary pure fold. It--- is intended for use when some fold should be performed together--- with histogram filling+--   is intended for use when some fold should be performed together+--   with histogram filling mkFolder :: b -> (a -> b -> b) -> HBuilder a b+{-# INLINE mkFolder #-} mkFolder a f = HBuilder $ do   ref <- newSTRef a   return HBuilderM { hbInput  = \x -> do acc <- readSTRef ref@@ -388,7 +402,17 @@                                          writeSTRef ref acc'                    , hbOutput = readSTRef ref                    }-{-# INLINE mkFolder #-}+++-- | Create stateful histogram builder. Output function should be safe+--   to call multiple times and builder could be modified afterwards.+--   So functions like @unsafeFreeze@ from @vector@ couldn't be used.+mkStatefulBuilder :: PrimMonad m+                  => (a -> m ()) -- ^ Add value to accumulator+                  -> m b         -- ^ Extract result from accumulator+                  -> HBuilderM m a b+{-# INLINE mkStatefulBuilder #-}+mkStatefulBuilder = HBuilderM   
Data/Histogram/Generic.hs view
@@ -33,6 +33,8 @@   , HistIndex(..)    , histIndex   , at+  , atV+  , atI     -- * Transformations   , map   , bmap@@ -269,6 +271,16 @@ -- | Index histogtam. at :: (Bin bin, Vector v a) => Histogram v bin a -> HistIndex bin -> a at (Histogram bin _ v) i = v ! histIndex bin i++-- | Index histogram using bin value+atV :: (Bin bin, Vector v a) => Histogram v bin a -> BinValue bin -> a+atV h = at h . Value++-- | Index histogram using vector index+atI :: (Bin bin, Vector v a) => Histogram v bin a -> Int -> a+atI h = at h . Index++  ---------------------------------------------------------------- -- Transformation
histogram-fill.cabal view
@@ -1,9 +1,15 @@ Name:           histogram-fill-Version:        0.7.2.0+Version:        0.7.3.0 Synopsis:       Library for histograms creation. Description:       This is library for histograms filling. Its aim to provide   convenient way to create and fill histograms. +  .+  Changes in 0.7.3.0+  .+  * @mkStatefulBuilder@ is added and HBuilder constructor is exposed.+  .+  * Indexing operators for immutable histograms are added.   .   Changes in 0.7.2.0   .