packages feed

histogram-fill 0.6.1.0 → 0.6.2.0

raw patch · 15 files changed

+183/−64 lines, 15 filesdep +QuickCheckdep +histogram-filldep +test-frameworkdep ~vectorPVP: major bump suggested

API removals or changes: PVP suggests a major version bump

Dependencies added: QuickCheck, histogram-fill, test-framework, test-framework-quickcheck2

Dependency ranges changed: vector

API changes (from Hackage documentation)

- Data.Histogram.Bin.Bin2D: instance NFData (Bin2D bx by)
+ Data.Histogram: mapData :: (Unbox a, Unbox b, Bin bin) => (Vector a -> Vector b) -> Histogram bin a -> Histogram bin b
+ Data.Histogram.Bin.Bin2D: instance (NFData bx, NFData by) => NFData (Bin2D bx by)
+ Data.Histogram.Bin.BinF: instance Eq BinD
+ Data.Histogram.Bin.BinF: instance Eq f => Eq (BinF f)
+ Data.Histogram.Bin.MaybeBin: MaybeBin :: bin -> MaybeBin bin
+ Data.Histogram.Bin.MaybeBin: instance Bin bin => Bin (MaybeBin bin)
+ Data.Histogram.Bin.MaybeBin: instance BinEq bin => BinEq (MaybeBin bin)
+ Data.Histogram.Bin.MaybeBin: instance Eq bin => Eq (MaybeBin bin)
+ Data.Histogram.Bin.MaybeBin: instance Read bin => Read (MaybeBin bin)
+ Data.Histogram.Bin.MaybeBin: instance Show bin => Show (MaybeBin bin)
+ Data.Histogram.Bin.MaybeBin: instance Typeable1 MaybeBin
+ Data.Histogram.Bin.MaybeBin: instance VariableBin bin => VariableBin (MaybeBin bin)
+ Data.Histogram.Bin.MaybeBin: newtype MaybeBin bin
+ Data.Histogram.Bin.Read: eol :: ReadP Char
+ Data.Histogram.Bin.Read: keyword :: String -> ReadPrec ()
+ Data.Histogram.Bin.Read: maybeValue :: Read a => String -> ReadPrec (Maybe a)
+ Data.Histogram.Bin.Read: value :: Read a => String -> ReadPrec a
+ Data.Histogram.Bin.Read: ws :: ReadP String
+ Data.Histogram.Generic: mapData :: (Vector v a, Vector u b, Bin bin) => (v a -> u b) -> Histogram v bin a -> Histogram u bin b

Files

Data/Histogram.hs view
@@ -34,6 +34,7 @@      -- * Modification   , map   , bmap+  , mapData   , zip   , zipSafe     -- ** Type conversion@@ -128,6 +129,11 @@ bmap :: (Unbox a, Unbox b, Bin bin)      => (BinValue bin -> a -> b) -> Histogram bin a -> Histogram bin b bmap = H.bmap++mapData :: (Unbox a, Unbox b, Bin bin)+        => (Vector a -> Vector b) -> Histogram bin a -> Histogram bin b+mapData = H.mapData+  zip :: (Bin bin, BinEq bin, Unbox a, Unbox b, Unbox c)      => (a -> b -> c) -> Histogram bin a -> Histogram bin b -> Histogram bin c
Data/Histogram/Bin/Bin2D.hs view
@@ -17,7 +17,7 @@ import Text.Read       (Read(..))  import Data.Histogram.Bin.Classes-import Data.Histogram.Parse+import Data.Histogram.Bin.Read  -- | 2D bins. binX is binning along X axis and binY is one along Y --   axis. Data is stored in row-major order@@ -93,4 +93,7 @@     by <- readPrec     return $ Bin2D bx by -instance NFData (Bin2D bx by)+instance (NFData bx, NFData by) => NFData (Bin2D bx by) where+  rnf (Bin2D bx by) = rnf bx `seq`+                      rnf by `seq`+                      ()
Data/Histogram/Bin/BinEnum.hs view
@@ -14,7 +14,7 @@  import Data.Histogram.Bin.Classes import Data.Histogram.Bin.BinI-import Data.Histogram.Parse+import Data.Histogram.Bin.Read  -- | Bin for types which are instnaces of Enum type class. Value are --   converted to 'Int' using 'fromEnum' first and then binned.
Data/Histogram/Bin/BinF.hs view
@@ -23,7 +23,7 @@ import Text.Read       (Read(..))  import Data.Histogram.Bin.Classes-import Data.Histogram.Parse+import Data.Histogram.Bin.Read   -- | Floaintg point bins with equal sizes.@@ -35,7 +35,7 @@ data BinF f = BinF !f                  -- Lower bound                    !f                  -- Size of bin                    {-# UNPACK #-} !Int -- Number of bins-              deriving (Data,Typeable)+              deriving (Data,Typeable,Eq)  -- | Create bins. binF :: RealFrac f =>@@ -131,7 +131,7 @@ data BinD = BinD {-# UNPACK #-} !Double -- Lower bound                  {-# UNPACK #-} !Double -- Size of bin                  {-# UNPACK #-} !Int    -- Number of bins-            deriving (Data,Typeable)+            deriving (Data,Typeable,Eq)  -- | Create bins. binD :: Double -- ^ Lower bound of range
Data/Histogram/Bin/BinI.hs view
@@ -13,7 +13,7 @@ import Text.Read       (Read(..))  import Data.Histogram.Bin.Classes-import Data.Histogram.Parse+import Data.Histogram.Bin.Read   
Data/Histogram/Bin/BinInt.hs view
@@ -14,7 +14,7 @@ import Text.Read       (Read(..))  import Data.Histogram.Bin.Classes-import Data.Histogram.Parse+import Data.Histogram.Bin.Read   
Data/Histogram/Bin/Classes.hs view
@@ -116,8 +116,8 @@       n = nBins b         -- | How index should be dropped-data CutDirection = CutLower    -- ^ Drop bins with highest index-                  | CutHigher   -- ^ Drop bins with lowest index+data CutDirection = CutLower    -- ^ Drop bins with smallest index+                  | CutHigher   -- ^ Drop bins with bigger index   -- | Bin which support rebinning. 
Data/Histogram/Bin/Extra.hs view
@@ -32,7 +32,7 @@ import Text.Read          (Read(..))           import Data.Histogram.Bin-import Data.Histogram.Parse+import Data.Histogram.Bin.Read  ---------------------------------------------------------------- 
Data/Histogram/Bin/LogBinD.hs view
@@ -15,13 +15,13 @@ import Text.Read       (Read(..))  import Data.Histogram.Bin.Classes-import Data.Histogram.Parse+import Data.Histogram.Bin.Read    -- | Uniform binning in logarithmic scale. For roundtripping use: ----- > b = logBinDN (lowerBound b) (logBinDIncrement b) (nBins b)+-- > b = logBinDN (lowerLimit b) (logBinDIncrement b) (nBins b) data LogBinD = LogBinD                Double -- Low border                Double -- Increment ratio
+ Data/Histogram/Bin/MaybeBin.hs view
@@ -0,0 +1,40 @@+{-# LANGUAGE DeriveDataTypeable #-}+{-# LANGUAGE TypeFamilies #-}+{-# LANGUAGE GeneralizedNewtypeDeriving #-}+module Data.Histogram.Bin.MaybeBin (+    MaybeBin(..)+  ) where++import Control.Monad   (liftM)+import Data.Typeable   (Typeable)+import Text.Read       (Read(..))++import Data.Histogram.Bin.Classes+import Data.Histogram.Bin.Read+++-- | This binning algorithms adds special case of no value.+newtype MaybeBin bin = MaybeBin bin+                       deriving (BinEq,Eq,Typeable)++instance Bin bin => Bin (MaybeBin bin) where+  type BinValue (MaybeBin bin) = Maybe (BinValue bin)+  toIndex _            Nothing  = 0+  toIndex (MaybeBin b) (Just x) = 1 + toIndex b x++  fromIndex _            0 = Nothing+  fromIndex (MaybeBin b) i = Just (fromIndex b (i-1))++  nBins (MaybeBin b) = 1 + nBins b++instance VariableBin bin => VariableBin (MaybeBin bin) where+  binSizeN  _           0 = Nothing+  binSizeN (MaybeBin b) n = Just $ binSizeN b (n-1)++instance Show bin => Show (MaybeBin bin) where+  show (MaybeBin bin) = "# MaybeBin\n" ++ show bin++instance Read bin => Read (MaybeBin bin) where+  readPrec = do+    keyword "MaybeBin"+    liftM MaybeBin readPrec
+ Data/Histogram/Bin/Read.hs view
@@ -0,0 +1,45 @@+-- | Helper function for defining Read instances for bin data types.+module Data.Histogram.Bin.Read +  ( ws+  , eol+  , value+  , maybeValue+  , keyword+  ) where++import Text.Read+import Text.ParserCombinators.ReadP    (ReadP, many, satisfy, char, string)++-- | Whitespaces+ws :: ReadP String+ws = many $ satisfy (`elem` " \t")++-- | End of line+eol :: ReadP Char+eol = char '\n'++-- | Equal sign+eq :: ReadP ()+eq = ws >> char '=' >> return ()++-- | Key value pair+value :: Read a => String -> ReadPrec a+value str = do lift $ key str >> eq+               getVal++-- | Return optional value+maybeValue :: Read a => String -> ReadPrec (Maybe a)+maybeValue str = do lift (key str >> eq)+                    lift (ws >> eol >> return Nothing) <++ (Just `fmap` getVal)++-- | Keyword+keyword :: String -> ReadPrec ()+keyword str = lift $ key str >> ws >> eol >> return ()+++key :: String -> ReadP String+key s = char '#' >> ws >> string s ++getVal :: Read a => ReadPrec a+getVal = do x <- readPrec+            lift eol >> return x
Data/Histogram/Generic.hs view
@@ -31,6 +31,7 @@     -- * Modification   , map   , bmap+  , mapData   , zip   , zipSafe     -- ** Type conversion@@ -71,7 +72,7 @@ import qualified Prelude    (zip)  import Data.Histogram.Bin-import Data.Histogram.Parse+import Data.Histogram.Bin.Read  ---------------------------------------------------------------- -- Data type and smart constructors@@ -216,6 +217,13 @@ bmap f (Histogram bin _ vec) =   Histogram bin Nothing $ G.imap (f . fromIndex bin) vec +mapData :: (Vector v a, Vector u b, Bin bin)+        => (v a -> u b) -> Histogram v bin a -> Histogram u bin b+mapData f (Histogram bin _ v)+  | G.length v /= G.length v' = error "Data.Histogram.Generic.Histogram.mapData: vector length changed"+  | otherwise                 = Histogram bin Nothing v'+  where v' = f v+ -- | Zip two histograms elementwise. Bins of histograms must be equal --   otherwise error will be called. zip :: (Bin bin, BinEq bin, Vector v a, Vector v b, Vector v c) =>@@ -270,7 +278,8 @@ ----------------------------------------------------------------  -- | Slice histogram. Values/indices specify inclusive---   variant. Under/overflows are discarded.+--   variant. Under/overflows are discarded. If requested value falls+--   out of histogram range it will be truncated. slice :: (SliceableBin bin, Vector v a)       => HistIndex bin          -- ^ Lower inclusive bound       -> HistIndex bin          -- ^ Upper inclusive bound@@ -279,8 +288,9 @@ slice a b (Histogram bin _ v) =   Histogram (sliceBin i j bin) Nothing (G.slice i (j - i + 1) v)   where-    i = histIndex bin a-    j = histIndex bin b+    i = max 0 $ histIndex bin a+    j = min n $ histIndex bin b+    n = nBins bin - 1  -- | Rebin histogram by joining @n@ adjacent bins. rebin :: (MergeableBin bin, Vector v a)
− Data/Histogram/Parse.hs
@@ -1,44 +0,0 @@-module Data.Histogram.Parse ( ws-                            , eol-                            , value-                            , maybeValue-                            , keyword-                            ) where--import Text.Read-import Text.ParserCombinators.ReadP    (ReadP, many, satisfy, char, string)---- Whitespaces-ws :: ReadP String-ws = many $ satisfy (`elem` " \t")---- End of line-eol :: ReadP Char-eol = char '\n'---- Equal sign-eq :: ReadP ()-eq = ws >> char '=' >> return ()---- Key-key :: String -> ReadP String-key s = char '#' >> ws >> string s ---getVal :: Read a => ReadPrec a-getVal = do x <- readPrec-            lift eol >> return x---- Key value pair-value :: Read a => String -> ReadPrec a-value str = do lift $ key str >> eq-               getVal---- Return optional value-maybeValue :: Read a => String -> ReadPrec (Maybe a)-maybeValue str = do lift (key str >> eq)-                    lift (ws >> eol >> return Nothing) <++ (Just `fmap` getVal)---- Keyword-keyword :: String -> ReadPrec ()-keyword str = lift $ key str >> ws >> eol >> return ()
LICENSE view
@@ -0,0 +1,30 @@+Copyright (c)2009-2012, Aleksey Khudyakov++All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions are met:++    * Redistributions of source code must retain the above copyright+      notice, this list of conditions and the following disclaimer.++    * Redistributions in binary form must reproduce the above+      copyright notice, this list of conditions and the following+      disclaimer in the documentation and/or other materials provided+      with the distribution.++    * Neither the name of asd nor the names of other+      contributors may be used to endorse or promote products derived+      from this software without specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
histogram-fill.cabal view
@@ -1,10 +1,25 @@ Name:           histogram-fill-Version:        0.6.1.0+Version:        0.6.2.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.6.2.0+  .+  * MaybeBin added.+  .+  * Helper function for defining Read instances for bins are exposed. +  .+  * mapData function is added.+  .+  * Slicing histogram do not results in crash if indices are out of+    bounds.+  .+  * Eq instances for BinF and BinD are added.+  .+  * NFData instance for Bin2D is fixed.+  .   Changes in 0.6.1.0   .   * Helper function and type synonym for Bin2D@@ -13,7 +28,7 @@   .   * Fixed compilation with GHC 7.4 -Cabal-Version:  >= 1.6+Cabal-Version:  >= 1.8 License:        BSD3 License-File:   LICENSE Author:         Alexey Khudyakov@@ -47,9 +62,23 @@                         Data.Histogram.Bin.BinEnum                         Data.Histogram.Bin.BinF                         Data.Histogram.Bin.LogBinD+                        Data.Histogram.Bin.MaybeBin                         Data.Histogram.Bin.Bin2D                         Data.Histogram.Bin.Extra+                        Data.Histogram.Bin.Read                         Data.Histogram.ST-  Other-modules:        Data.Histogram.Parse   Ghc-options:          -O2 -Wall   Ghc-prof-options:     -auto-all++test-suite tests+  type:           exitcode-stdio-1.0+  hs-source-dirs: test+  main-is:        QC.hs+  other-modules:  QC.Instances+  ghc-options:    -Wall+  build-depends:  base >=3 && < 5,+                  histogram-fill,+                  vector,+                  QuickCheck >= 2,+                  test-framework,+                  test-framework-quickcheck2