Hello community,
here is the log from the commit of package ghc-histogram-fill for
openSUSE:Factory checked in at 2017-03-12 20:04:12
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Comparing /work/SRC/openSUSE:Factory/ghc-histogram-fill (Old)
and /work/SRC/openSUSE:Factory/.ghc-histogram-fill.new (New)
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "ghc-histogram-fill"
Sun Mar 12 20:04:12 2017 rev:2 rq:477836 version:0.8.5.0
Changes:
--------
--- /work/SRC/openSUSE:Factory/ghc-histogram-fill/ghc-histogram-fill.changes
2017-03-01 23:42:59.706708262 +0100
+++
/work/SRC/openSUSE:Factory/.ghc-histogram-fill.new/ghc-histogram-fill.changes
2017-03-12 20:04:15.175609606 +0100
@@ -1,0 +2,5 @@
+Mon Feb 20 08:42:04 UTC 2017 - [email protected]
+
+- Update to version 0.8.5.0 with cabal2obs.
+
+-------------------------------------------------------------------
Old:
----
histogram-fill-0.8.4.1.tar.gz
New:
----
histogram-fill-0.8.5.0.tar.gz
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Other differences:
------------------
++++++ ghc-histogram-fill.spec ++++++
--- /var/tmp/diff_new_pack.SZ622h/_old 2017-03-12 20:04:15.743529244 +0100
+++ /var/tmp/diff_new_pack.SZ622h/_new 2017-03-12 20:04:15.743529244 +0100
@@ -1,7 +1,7 @@
#
# spec file for package ghc-histogram-fill
#
-# Copyright (c) 2016 SUSE LINUX GmbH, Nuernberg, Germany.
+# Copyright (c) 2017 SUSE LINUX GmbH, Nuernberg, Germany.
#
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
@@ -18,22 +18,19 @@
%global pkg_name histogram-fill
Name: ghc-%{pkg_name}
-Version: 0.8.4.1
+Version: 0.8.5.0
Release: 0
Summary: Library for histograms creation
License: BSD-3-Clause
-Group: System/Libraries
+Group: Development/Languages/Other
Url: https://hackage.haskell.org/package/%{pkg_name}
Source0:
https://hackage.haskell.org/package/%{pkg_name}-%{version}/%{pkg_name}-%{version}.tar.gz
BuildRequires: ghc-Cabal-devel
-# Begin cabal-rpm deps:
BuildRequires: ghc-deepseq-devel
-BuildRequires: ghc-monad-primitive-devel
BuildRequires: ghc-primitive-devel
BuildRequires: ghc-rpm-macros
BuildRequires: ghc-vector-devel
BuildRoot: %{_tmppath}/%{name}-%{version}-build
-# End cabal-rpm deps
%description
This is library for histograms filling. Its aim to provide convenient way to
@@ -53,15 +50,12 @@
%prep
%setup -q -n %{pkg_name}-%{version}
-
%build
%ghc_lib_build
-
%install
%ghc_lib_install
-
%post devel
%ghc_pkg_recache
@@ -74,6 +68,6 @@
%files devel -f %{name}-devel.files
%defattr(-,root,root,-)
-%doc ChangeLog
+%doc ChangeLog.md
%changelog
++++++ histogram-fill-0.8.4.1.tar.gz -> histogram-fill-0.8.5.0.tar.gz ++++++
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/histogram-fill-0.8.4.1/ChangeLog
new/histogram-fill-0.8.5.0/ChangeLog
--- old/histogram-fill-0.8.4.1/ChangeLog 2015-01-07 10:59:33.000000000
+0100
+++ new/histogram-fill-0.8.5.0/ChangeLog 1970-01-01 01:00:00.000000000
+0100
@@ -1,94 +0,0 @@
-Changes in 0.8.4.1
-
- * All fields of LogDinD are strict and unpacked. This fixes NFData
- instance and improves performance
-
-
-Changes in 0.8.4.0
-
- * Missing instances for CutDirection added
-
- * Missing NFData instances for MaybeBin, BinEnum2D, BinPermute
-
- * Compatibility with deepseq 1.4
-
-
-Changes in 0.8.3.0
-
- * Constraints are relaxed from `PrimMonad' to `Monad' wherever possible in
- Data.Histogram.Fill module.
-
-
-Changes in 0.8.2.0
-
- * Smart constructors for BinF and BinD check that bin number is not
- negative.
- * Fixed bug in `binInt'
- * Fields of `Histogram' data type are strict now.
- * Compatibility with GHC 7.8
-
-
-Changes in 0.8.1.0
-
- * Constructor of @HBuilderM@ exported.
-
-
-Changes in 0.8.0.0
-
- * `toHBuilderM' added and internal definition of `HBuilder' is
- changed. It required adding dependency on @monad-primitive@.
- * `joinHBuilder' and @treeHBuilder@ are deprecated.
-
-
-Changes in 0.7.4.0
-
- * Function for searching for minimum/maximum added.
- * @NFData@ instance is fixed.
-
-
-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
-
- * fromMaybeBin added.
-
-
-Changes in 0.7.1.0
-
- * breduceX and breduceY are added.
-
-
-Changes in 0.7.0.0
-
- * mkFoldBuilder is added to `Data.Histogram.Fill'
- * fill functions in `Data.Histogram.ST' are replaced with generic
- variant.
- * Indexing for immutable histograms is added and special constructor
- for first and last bin are added to `HistIndex' data type.
- * Functions to calculate sum, minimum and maximum of immutable
- histogram are added.
-
-
-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
-
-
-Changes in 0.6.0.1
-
- * Fixed compilation with GHC 7.4
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/histogram-fill-0.8.4.1/ChangeLog.md
new/histogram-fill-0.8.5.0/ChangeLog.md
--- old/histogram-fill-0.8.4.1/ChangeLog.md 1970-01-01 01:00:00.000000000
+0100
+++ new/histogram-fill-0.8.5.0/ChangeLog.md 2017-02-19 10:23:04.000000000
+0100
@@ -0,0 +1,101 @@
+Changes in 0.8.5.0
+
+ * BinVar added
+ * Redundant constraints on functions removed
+ * Histogram data type now stores overflows/underflows as strict data type
+ * Support for GHC<7.6 is dropped
+
+Changes in 0.8.4.1
+
+ * All fields of LogDinD are strict and unpacked. This fixes NFData
+ instance and improves performance
+
+
+Changes in 0.8.4.0
+
+ * Missing instances for CutDirection added
+
+ * Missing NFData instances for MaybeBin, BinEnum2D, BinPermute
+
+ * Compatibility with deepseq 1.4
+
+
+Changes in 0.8.3.0
+
+ * Constraints are relaxed from `PrimMonad' to `Monad' wherever possible in
+ Data.Histogram.Fill module.
+
+
+Changes in 0.8.2.0
+
+ * Smart constructors for BinF and BinD check that bin number is not
+ negative.
+ * Fixed bug in `binInt'
+ * Fields of `Histogram' data type are strict now.
+ * Compatibility with GHC 7.8
+
+
+Changes in 0.8.1.0
+
+ * Constructor of @HBuilderM@ exported.
+
+
+Changes in 0.8.0.0
+
+ * `toHBuilderM' added and internal definition of `HBuilder' is
+ changed. It required adding dependency on @monad-primitive@.
+ * `joinHBuilder' and @treeHBuilder@ are deprecated.
+
+
+Changes in 0.7.4.0
+
+ * Function for searching for minimum/maximum added.
+ * @NFData@ instance is fixed.
+
+
+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
+
+ * fromMaybeBin added.
+
+
+Changes in 0.7.1.0
+
+ * breduceX and breduceY are added.
+
+
+Changes in 0.7.0.0
+
+ * mkFoldBuilder is added to `Data.Histogram.Fill'
+ * fill functions in `Data.Histogram.ST' are replaced with generic
+ variant.
+ * Indexing for immutable histograms is added and special constructor
+ for first and last bin are added to `HistIndex' data type.
+ * Functions to calculate sum, minimum and maximum of immutable
+ histogram are added.
+
+
+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
+
+
+Changes in 0.6.0.1
+
+ * Fixed compilation with GHC 7.4
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/histogram-fill-0.8.4.1/Data/Histogram/Bin/Bin2D.hs
new/histogram-fill-0.8.5.0/Data/Histogram/Bin/Bin2D.hs
--- old/histogram-fill-0.8.4.1/Data/Histogram/Bin/Bin2D.hs 2015-01-07
10:59:33.000000000 +0100
+++ new/histogram-fill-0.8.5.0/Data/Histogram/Bin/Bin2D.hs 2017-02-19
10:23:04.000000000 +0100
@@ -47,7 +47,7 @@
{-# INLINE nBins #-}
-- | Convert index into pair of indices for X and Y axes
-toIndex2D :: (Bin binX, Bin binY) => Bin2D binX binY -> Int -> (Int,Int)
+toIndex2D :: (Bin binX) => Bin2D binX binY -> Int -> (Int,Int)
toIndex2D !b !i = let (iy,ix) = divMod i (nBins $ binX b) in (ix,iy)
{-# INLINE toIndex2D #-}
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/histogram-fill-0.8.4.1/Data/Histogram/Bin/BinF.hs
new/histogram-fill-0.8.5.0/Data/Histogram/Bin/BinF.hs
--- old/histogram-fill-0.8.4.1/Data/Histogram/Bin/BinF.hs 2015-01-07
10:59:33.000000000 +0100
+++ new/histogram-fill-0.8.5.0/Data/Histogram/Bin/BinF.hs 2017-02-19
10:23:04.000000000 +0100
@@ -125,7 +125,7 @@
, "# Step = " ++ show step
, "# N = " ++ show n
]
-instance (Read f, RealFrac f) => Read (BinF f) where
+instance (Read f) => Read (BinF f) where
readPrec = keyword "BinF" >> liftM3 BinF (value "Base") (value "Step")
(value "N")
instance NFData f => NFData (BinF f) where
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/histogram-fill-0.8.4.1/Data/Histogram/Bin/BinVar.hs
new/histogram-fill-0.8.5.0/Data/Histogram/Bin/BinVar.hs
--- old/histogram-fill-0.8.4.1/Data/Histogram/Bin/BinVar.hs 1970-01-01
01:00:00.000000000 +0100
+++ new/histogram-fill-0.8.5.0/Data/Histogram/Bin/BinVar.hs 2017-02-19
10:23:04.000000000 +0100
@@ -0,0 +1,155 @@
+{-# LANGUAGE BangPatterns #-}
+{-# LANGUAGE CPP #-}
+{-# LANGUAGE DeriveDataTypeable #-}
+{-# LANGUAGE FlexibleContexts #-}
+{-# LANGUAGE FlexibleInstances #-}
+{-# LANGUAGE MultiParamTypeClasses #-}
+{-# LANGUAGE TypeFamilies #-}
+{-# LANGUAGE UndecidableInstances #-}
+module Data.Histogram.Bin.BinVar (
+ BinVarG(..)
+ , BinVar
+ , unsafeBinVar
+ , binVar
+ , cuts
+ , deleteCut
+ , addCut
+ ) where
+
+import Control.DeepSeq (NFData(..))
+import Data.Typeable
+import Data.Maybe
+import qualified Data.Vector.Generic as G
+import Data.Vector.Generic (Vector,(!))
+import qualified Data.Vector.Unboxed as U
+import Text.Read (Read(..))
+
+import Data.Histogram.Bin.Classes
+import Data.Histogram.Bin.Read
+
+
+
+-- | Bins of variable size. Bins are defined by a vector of `cuts`
+-- marking the boundary between bins. This assumes that the entire
+-- range is continuous. There are n+1 cuts for n bins. This also
+-- implies that cuts are in ascending order.
+newtype BinVarG v a = BinVarG { _cuts :: v a } -- vector of cuts
+ deriving (Eq
+#if MIN_VERSION_base(4,7,0)
+ , Typeable
+#endif
+ )
+
+-- | Type synonym for @BinVarG@ specialized for unboxed vectors
+type BinVar = BinVarG U.Vector
+
+#if !MIN_VERSION_base(4,7,0)
+histTyCon :: String -> String -> TyCon
+histTyCon = mkTyCon3 "histogram-fill"
+
+instance Typeable1 v => Typeable1 (BinVarG v) where
+ typeOf1 b = mkTyConApp (histTyCon "Data.Histogram.Bin.BinVar" "BinVarG")
+ [typeOf1 $ cuts b]
+#endif
+
+-- | Create variable bins unsafely
+unsafeBinVar :: v a -- ^ cuts
+ -> BinVarG v a
+unsafeBinVar = BinVarG
+
+-- | Create variable bins unsafely
+binVar :: (Vector v a, Vector v Bool, Ord a)
+ => v a -- ^ cuts
+ -> BinVarG v a
+binVar c
+ | G.length c < 2
+ = error "Data.Histogram.Bin.BinVar.binVar': nonpositive number of bins"
+ | G.or $ G.zipWith (>=) c (G.tail c)
+ = error "Data.Histogram.Bin.BinVar.binVar': cuts not in ascending order"
+ | otherwise = BinVarG c
+
+-- | access cuts
+cuts :: BinVarG v a -> v a
+cuts (BinVarG c) = c
+
+instance (Vector v a, Ord a, Fractional a) => Bin (BinVarG v a) where
+ type BinValue (BinVarG v a) = a
+ toIndex (BinVarG c) !x = case G.findIndex (>x) c of
+ Nothing -> G.length c - 1
+ Just i -> case i of
+ 0 -> -1
+ _ -> i-1
+
+ -- FIXME: We use fractional here but it means that we cannot use it for Int!
+ fromIndex (BinVarG c) !i
+ | i >= G.length c - 1 =
+ error "Data.Histogram.Bin.BinVar.fromIndex: above range"
+ | otherwise = ((c ! i) + (c ! (i+1)))/2
+ nBins (BinVarG c) = if G.length c < 2 then 0 else G.length c - 1
+ {-# INLINE toIndex #-}
+
+instance (Vector v a, Ord a, Fractional a) => IntervalBin (BinVarG v a) where
+ binInterval (BinVarG c) i = (c ! i, c ! (i+1))
+
+instance (Vector v a, Ord a, Fractional a) => Bin1D (BinVarG v a) where
+ lowerLimit (BinVarG c) = G.head c
+ upperLimit (BinVarG c) = G.last c
+
+instance (Vector v a, Ord a, Fractional a) => SliceableBin (BinVarG v a) where
+ unsafeSliceBin i j (BinVarG c) = BinVarG (G.drop i $ G.take (j + 2) c)
+
+instance (Vector v a, Ord a, Fractional a) => VariableBin (BinVarG v a) where
+ binSizeN (BinVarG c) !i = c ! (i+1) - c ! i
+
+-- | Equality is up to 3e-11 (2/3th of digits)
+instance (Vector v a, Vector v Bool, Ord a, Fractional a) => BinEq (BinVarG v
a) where
+ binEq (BinVarG c) (BinVarG c')
+ = (G.length c == G.length c')
+ && (G.and (G.zipWith eq c c'))
+ where
+ eq x y = abs (x - y) < eps * (abs x `max` abs y)
+ eps = 3e-11
+
+instance (Vector v a, Show a) => Show (BinVarG v a) where
+ show (BinVarG c) = "# BinVar\n# cuts = " ++ show (G.toList c) ++ "\n"
+
+instance (Vector v a, Vector v Bool, Read a, Ord a) => Read (BinVarG v a) where
+ readPrec = do keyword "BinVar"
+ xs <- value "cuts"
+ return $ binVar $ G.fromList xs
+
+
+instance (NFData (v a)) => NFData (BinVarG v a) where
+ rnf (BinVarG c) =
+ rnf c `seq` ()
+
+-- | Delete a cut, which effectively reduces the entire range of the
+-- bins (if the cut was the first or last one) or merges two bins
+-- (if the cut was in the middle)
+deleteCut :: (Vector v a, Ord a, Fractional a)
+ => BinVarG v a -- bin
+ -> Int -- cut index
+ -> BinVarG v a
+deleteCut (BinVarG c) !i
+ | G.length c <= 2 =
+ error "Data.Histogram.Bin.BinVar.deleteCut: deleting cut but 2 or less
cuts"
+ | otherwise = BinVarG (G.take i c G.++ G.drop (i+1) c)
+
+-- | insert a new cut which effectively extends the range of the bins or
splits a bin
+addCut :: (Vector v a, Ord a)
+ => BinVarG v a -- bin
+ -> a -- new cut value
+ -> BinVarG v a
+addCut (BinVarG c) !x = BinVarG (G.concat [G.take i c, G.singleton x, G.drop i
c])
+ where
+ i = fromMaybe (G.length c) (G.findIndex (> x) c)
+
+instance ( Bin1D b
+ , Vector v (BinValue b)
+ , Vector v Bool
+ , a ~ (BinValue b)
+ , Fractional a)
+ => ConvertBin b (BinVarG v a) where
+ convertBin b
+ = binVar
+ $ lowerLimit b `G.cons` G.generate (nBins b) (snd . binInterval b)
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/histogram-fill-0.8.4.1/Data/Histogram/Bin/LogBinD.hs
new/histogram-fill-0.8.5.0/Data/Histogram/Bin/LogBinD.hs
--- old/histogram-fill-0.8.4.1/Data/Histogram/Bin/LogBinD.hs 2015-01-07
10:59:33.000000000 +0100
+++ new/histogram-fill-0.8.5.0/Data/Histogram/Bin/LogBinD.hs 2017-02-19
10:23:04.000000000 +0100
@@ -62,10 +62,10 @@
instance Bin LogBinD where
type BinValue LogBinD = Double
- toIndex !(LogBinD base step _) !x = floorD $ logBase step (x / base)
- fromIndex !(LogBinD base step _) !i | i >= 0 = base * step **
(fromIntegral i + 0.5)
- | otherwise = -1 / 0
- nBins !(LogBinD _ _ n) = n
+ toIndex (LogBinD base step _) !x = floorD $ logBase step (x / base)
+ fromIndex (LogBinD base step _) !i | i >= 0 = base * step **
(fromIntegral i + 0.5)
+ | otherwise = -1 / 0
+ nBins (LogBinD _ _ n) = n
{-# INLINE toIndex #-}
instance IntervalBin LogBinD where
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/histogram-fill-0.8.4.1/Data/Histogram/Bin.hs
new/histogram-fill-0.8.5.0/Data/Histogram/Bin.hs
--- old/histogram-fill-0.8.4.1/Data/Histogram/Bin.hs 2015-01-07
10:59:33.000000000 +0100
+++ new/histogram-fill-0.8.5.0/Data/Histogram/Bin.hs 2017-02-19
10:23:04.000000000 +0100
@@ -1,7 +1,7 @@
--- Requred for Bin2D conversions
+-- Required for Bin2D conversions
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE OverlappingInstances #-}
--- Yes I DO want orphans here
+-- Yes, I DO want orphans here
{-# OPTIONS_GHC -fno-warn-orphans #-}
-- |
-- Module : Data.Histogram.Bin
@@ -10,8 +10,8 @@
-- Maintainer : Alexey Khudyakov <[email protected]>
-- Stability : experimental
--
--- Binning algorithms. This is mapping from set of interest to integer
--- indices and approximate reverse.
+-- Binning algorithms. This is a mapping from set of interest to integer
+-- indices and an approximate reverse.
module Data.Histogram.Bin (
-- * Type classes
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/histogram-fill-0.8.4.1/Data/Histogram/Fill.hs
new/histogram-fill-0.8.5.0/Data/Histogram/Fill.hs
--- old/histogram-fill-0.8.4.1/Data/Histogram/Fill.hs 2015-01-07
10:59:33.000000000 +0100
+++ new/histogram-fill-0.8.5.0/Data/Histogram/Fill.hs 2017-02-19
10:23:04.000000000 +0100
@@ -66,9 +66,9 @@
import Control.Monad.ST
import Control.Monad.Primitive
-import Data.PrimRef
import Data.Monoid (Monoid(..))
import Data.Vector.Unboxed (Unbox)
+import Data.Primitive.MutVar
import qualified Data.Vector.Generic as G
import qualified Data.Foldable as F
import qualified Data.Traversable as F
@@ -122,7 +122,7 @@
{-# INLINE (<<?) #-}
-- | Apply function which modify builder
-(<<-$) :: HistBuilder h => h a b -> (h a b -> h a' b) -> h a' b
+(<<-$) :: h a b -> (h a b -> h a' b) -> h a' b
h <<-$ f = f h
{-# INLINE (<<-$) #-}
@@ -131,7 +131,7 @@
(-<<) = modifyOut
{-# INLINE (-<<) #-}
--- Fixity of operator
+-- Fixity of operators
infixl 5 <<-
infixl 5 <<-|
infixl 5 <<?
@@ -142,12 +142,12 @@
-- $examples
--
-- All examples will make use of operators to create builders. It's
--- possible to avoid their use but operators offer clear notation and
--- compose nicely in pipeline. Also note that data flows from right to
--- left as with '.' operator.
+-- possible to avoid their use, but operators offer clear notation and
+-- compose nicely in a pipeline. Also note that data flows from right to
+-- left as with the '.' operator.
--
--- First example just counts ints in in [0..4] inclusive range.
--- 'fillBuilder' is used to put all values into accumulator.
+-- First example just counts ints in the [0..4] inclusive range.
+-- 'fillBuilder' is used to put all values into an accumulator.
--
-- > ghci> let h = forceInt -<< mkSimple (BinI 0 4)
-- > ghci> fillBuilder h [0,0,0,1,1,2,3,4,4,4]
@@ -163,33 +163,33 @@
-- > 3 1
-- > 4 3
--
--- More involved example only accept even numbers. Filtering could be
--- achieved with either 'addCut' or '<<?' operator.
+-- More involved example that only accepts even numbers. Filtering could be
+-- achieved with either 'addCut' or the '<<?' operator.
--
-- > forceInt -<< mkSimple (BinI 0 4) <<? even
--
--- Although for example above same result could be acheved by
--- filtering of input it doesn't work when multiple histograms with
+-- Although for example above same result could be achieved by
+-- filtering of input, it doesn't work when multiple histograms with
-- different cuts are filled simultaneously.
--
--- Next example illustrate use of applicative interface. Here two
--- histograms are filled at the same time. First accept only even
--- numbers and second only odd ones. Results are put into the tuple.
+-- Next example illustrates the use of an applicative interface. Here
+-- two histograms are filled at the same time. First accept only even
+-- numbers and second only the odd ones. Results are put into the tuple.
--
-- > (,) <$>
-- > (forceInt -<< mkSimple (BinI 0 4) <<? even)
-- > (forceInt -<< mkSimple (BinI 0 4) <<? odd)
--
-- Another approach is to use 'F.sequenceA' to simultaneously fill
--- list (or any other 'Travesable').
+-- a list (or any other 'Traversable').
--
-- > Data.Traversable.sequenceA [
-- > forceInt -<< mkSimple (BinI 0 4) <<? even
-- > , forceInt -<< mkSimple (BinI 0 4) <<? odd
-- > ]
--
--- If one wants to collect result from many histograms he can take an
--- advantage of 'Monoid' instance of 'HBuilder'. Example below
+-- If one wants to collect results from many histograms he can take an
+-- advantage of the 'Monoid' instance of 'HBuilder'. Example below
-- concatenates string outputs of individual histograms.
--
-- > mconcat [
@@ -202,18 +202,18 @@
-- Monadic builder
----------------------------------------------------------------
--- | Stateful histogram builder. Adding value to builder could be done
--- with 'feedOne' and result could be extracted with
+-- | Stateful histogram builder. Adding a value to builder could be done
+-- with 'feedOne' and the result could be extracted with
-- 'freezeHBuilderM'.
--
--- There are two ways to obtain stateful builder. First and
--- recommended is to thaw 'HBuilder' using 'toHBuilderIO' or
--- 'toHBuilderST'. Second is to use 'mkStatefulBuilder'.
+-- There are two ways to obtain a stateful builder. First and
+-- recommended way is to thaw 'HBuilder' using 'toHBuilderIO' or
+-- 'toHBuilderST'. Second possibility 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.
+-- | Builders modified using 'HistBuilder' API will share the same buffer.
instance Monad 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) }
@@ -242,14 +242,14 @@
{-# INLINE mconcat #-}
--- | Put one item into histogram
-feedOne :: Monad m => HBuilderM m a b -> a -> m ()
+-- | Put one item into the histogram
+feedOne :: HBuilderM m a b -> a -> m ()
feedOne = hbInput
{-# INLINE feedOne #-}
--- | Extract result from histogram builder. It's safe to call this
--- function multiple times and mutate builder afterwards.
-freezeHBuilderM :: Monad m => HBuilderM m a b -> m b
+-- | Extract the result from a histogram builder. It's safe to call
+-- this function multiple times, and mutate the builder afterwards.
+freezeHBuilderM :: HBuilderM m a b -> m b
freezeHBuilderM = hbOutput
{-# INLINE freezeHBuilderM #-}
@@ -259,21 +259,21 @@
-- Stateless
----------------------------------------------------------------
--- | Wrapper around stateful histogram builder. It is much more
--- convenient to work with than 'HBuilderM'.
+-- | Wrapper around the stateful histogram builder. It is much more
+-- convenient to work with this one than with 'HBuilderM'.
newtype HBuilder a b = HBuilder (forall m. PrimMonad m => m (HBuilderM m a b))
--- | Convert builder to stateful builder in primitive monad
+-- | Convert the builder to a stateful builder in a primitive monad
toHBuilderM :: PrimMonad m => HBuilder a b -> m (HBuilderM m a b)
{-# INLINE toHBuilderM #-}
toHBuilderM (HBuilder hb) = hb
--- | Convert builder to stateful builder in ST monad
+-- | Convert the builder to stateful builder in the ST monad
toHBuilderST :: HBuilder a b -> ST s (HBuilderM (ST s) a b)
{-# INLINE toHBuilderST #-}
toHBuilderST = toHBuilderM
--- | Convert builder to builder in IO monad
+-- | Convert the builder to builder in the IO monad
toHBuilderIO :: HBuilder a b -> IO (HBuilderM IO a b)
{-# INLINE toHBuilderIO #-}
toHBuilderIO = toHBuilderM
@@ -304,27 +304,27 @@
----------------------------------------------------------------
-- | Create builder. Bin content will be incremented by 1 for each
--- item put into histogram
+-- item put into the histogram
mkSimple :: (Bin bin, Unbox val, Num val
) => bin -> HBuilder (BinValue bin) (Histogram bin val)
mkSimple = mkSimpleG
{-# INLINE mkSimple #-}
--- | Create builder. Bin content will incremented by weight supplied
--- for each item put into histogram
+-- | Create builder. Bin content will be incremented by the weight supplied
+-- for each item put into the histogram
mkWeighted :: (Bin bin, Unbox val, Num val
) => bin -> HBuilder (BinValue bin,val) (Histogram bin val)
mkWeighted = mkWeightedG
{-# INLINE mkWeighted #-}
--- | Create builder. New value wil be mappended to current content of
--- a bin for each item put into histogram
+-- | Create builder. New value will be mappended to current content of
+-- a bin for each item put into the histogram
mkMonoidal :: (Bin bin, Unbox val, Monoid val
) => bin -> HBuilder (BinValue bin,val) (Histogram bin val)
mkMonoidal = mkMonoidalG
{-# INLINE mkMonoidal #-}
--- | Create most generic histogram builder.
+-- | Create a most generic histogram builder.
mkFoldBuilder :: (Bin bin, Unbox val)
=> bin -- ^ Binning algorithm
-> val -- ^ Initial value
@@ -336,7 +336,7 @@
-- | Create builder. Bin content will be incremented by 1 for each
--- item put into histogram
+-- item put into the histogram
mkSimpleG :: (Bin bin, G.Vector v val, Num val
) => bin -> HBuilder (BinValue bin) (H.Histogram v bin val)
mkSimpleG bin = HBuilder $ do
@@ -346,15 +346,15 @@
}
{-# INLINE mkSimpleG #-}
--- | Create builder. Bin content will incremented by weight supplied
--- for each item put into histogram
+-- | Create builder. Bin content will incremented by the weight supplied
+-- for each item put into the histogram
mkWeightedG :: (Bin bin, G.Vector v val, Num val
) => bin -> HBuilder (BinValue bin,val) (H.Histogram v bin val)
mkWeightedG bin = mkFoldBuilderG bin 0 (+)
{-# INLINE mkWeightedG #-}
--- | Create builder. New value wil be mappended to current content of
--- a bin for each item put into histogram
+-- | Create builder. New value will be mappended to current content of
+-- a bin for each item put into the histogram
mkMonoidalG :: (Bin bin, G.Vector v val, Monoid val
) => bin -> HBuilder (BinValue bin,val) (H.Histogram v bin val)
mkMonoidalG bin = mkFoldBuilderG bin mempty mappend
@@ -376,21 +376,21 @@
-- | Create histogram builder which just does ordinary pure fold. It
-- is intended for use when some fold should be performed together
--- with histogram filling
+-- with histogram filling.
mkFolder :: b -> (a -> b -> b) -> HBuilder a b
{-# INLINE mkFolder #-}
mkFolder a f = HBuilder $ do
- ref <- newPrimRef a
- return HBuilderM { hbInput = \x -> modifyPrimRef' ref (f x)
- , hbOutput = readPrimRef ref
+ ref <- newMutVar a
+ return HBuilderM { hbInput = \a -> do b <- readMutVar ref
+ writeMutVar ref $! f a b
+ , hbOutput = readMutVar ref
}
--- | Create stateful histogram builder. Output function should be safe
--- to call multiple times and builder could be modified afterwards.
+-- | Create stateful histogram builder. The output function should be safe
+-- to call multiple times and the builder could be modified afterwards.
-- So functions like @unsafeFreeze@ from @vector@ couldn't be used.
-mkStatefulBuilder :: Monad m
- => (a -> m ()) -- ^ Add value to accumulator
+mkStatefulBuilder :: (a -> m ()) -- ^ Add value to accumulator
-> m b -- ^ Extract result from accumulator
-> HBuilderM m a b
{-# INLINE mkStatefulBuilder #-}
@@ -421,14 +421,14 @@
-- $auxillary
--
--- In some cases builder constructors do not constrain output type
--- enough. Output type is still parametric in value type of histogram.
--- Functions below are just 'id' function with more restrictive
+-- In some cases the builder constructors do not constrain the output type
+-- enough. The output type is still parametric in value type of histogram.
+-- Functions below are just the 'id' function with a more restrictive
-- signature.
--
--- In example below 'forceInt' used to fix type of histogram to
--- 'Histogram BinI Int'. Without it compiler cannot infer type of
--- intermediate histogram.
+-- In example below 'forceInt' used to fix type of the histogram to
+-- 'Histogram BinI Int'. Without it, the compiler cannot infer type of
+-- the intermediate histogram.
--
-- > show . forceInt -<< mkSimple (BinI 1 10)
@@ -447,26 +447,26 @@
-- Deprecated
----------------------------------------------------------------
--- | Join histogram builders in container
+-- | Join histogram builders in a container
joinHBuilderM :: (F.Traversable f, Monad m) => f (HBuilderM m a b) ->
HBuilderM m a (f b)
joinHBuilderM = F.sequenceA
{-# INLINE joinHBuilderM #-}
{-# DEPRECATED joinHBuilderM "Use Data.Traversable.sequenceA instead" #-}
--- | Apply functions to builder
+-- | Apply functions to the builder
treeHBuilderM :: (Monad m, F.Traversable f) => f (HBuilderM m a b -> HBuilderM
m a' b') -> HBuilderM m a b -> HBuilderM m a' (f b')
treeHBuilderM fs h = F.traverse ($ h) fs
{-# INLINE treeHBuilderM #-}
{-# DEPRECATED treeHBuilderM
"Use Data.Traversable.traverse. treeHBuilderM fs h = F.traverse ($ h) fs" #-}
--- | Join hitogram builders in container.
+-- | Join histogram builders in a container.
joinHBuilder :: F.Traversable f => f (HBuilder a b) -> HBuilder a (f b)
joinHBuilder = F.sequenceA
{-# INLINE joinHBuilder #-}
{-# DEPRECATED joinHBuilder "Use Data.Traversable.sequenceA instead" #-}
--- | Apply function to builder
+-- | Apply function to a builder
treeHBuilder :: F.Traversable f => f (HBuilder a b -> HBuilder a' b') ->
HBuilder a b -> HBuilder a' (f b')
treeHBuilder fs h = F.traverse ($ h) fs
{-# INLINE treeHBuilder #-}
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/histogram-fill-0.8.4.1/Data/Histogram/Generic.hs
new/histogram-fill-0.8.5.0/Data/Histogram/Generic.hs
--- old/histogram-fill-0.8.4.1/Data/Histogram/Generic.hs 2015-01-07
10:59:33.000000000 +0100
+++ new/histogram-fill-0.8.5.0/Data/Histogram/Generic.hs 2017-02-19
10:23:04.000000000 +0100
@@ -1,15 +1,16 @@
-{-# LANGUAGE FlexibleContexts #-}
+{-# LANGUAGE CPP #-}
{-# LANGUAGE DeriveDataTypeable #-}
-{-# LANGUAGE CPP #-}
+{-# LANGUAGE DeriveFunctor #-}
+{-# LANGUAGE FlexibleContexts #-}
-- |
-- Module : Data.Histogram
-- Copyright : Copyright (c) 2009, Alexey Khudyakov
<[email protected]>
-- License : BSD3
-- Maintainer : Alexey Khudyakov <[email protected]>
-- Stability : experimental
---
--- Generic immutable histograms.
-module Data.Histogram.Generic (
+--
+-- Generic immutable histograms.
+module Data.Histogram.Generic (
-- * Immutable histograms
Histogram
, module Data.Histogram.Bin
@@ -30,7 +31,7 @@
, overflows
, outOfRange
-- ** Indexing
- , HistIndex(..)
+ , HistIndex(..)
, histIndex
, at
, atV
@@ -82,9 +83,8 @@
, liftY
) where
-import Control.Applicative ((<$>),(<*>))
-import Control.Arrow ((***), (&&&))
-import Control.Monad (ap)
+import Control.Applicative ((<$>),Applicative(..),liftA2)
+import Control.Arrow ((&&&))
import Control.DeepSeq (NFData(..))
import qualified Data.Vector.Generic as G
@@ -104,8 +104,8 @@
-- Data type & smart constructors & conversion
----------------------------------------------------------------
--- | Immutable histogram. Histogram consists of binning algorithm,
--- optional number of under and overflows, and data. Type parameter
+-- | Immutable histogram. A histogram consists of a binning algorithm,
+-- an optional number of under- and overflows, and data. Type parameters
-- have following meaning:
--
-- [@v@] type of vector used to store bin content.
@@ -113,31 +113,47 @@
-- [@bin@] binning. It should be instance of 'Bin'. Check that type class
description for details.
--
-- [@a@] type of bin content.
-data Histogram v bin a = Histogram !bin !(Maybe (a,a)) !(v a)
+data Histogram v bin a = Histogram !bin !(Overflows a) !(v a)
#if MIN_VERSION_base(4,7,0)
deriving (Eq, Typeable)
#else
deriving (Eq)
#endif
--- | Create histogram from binning algorithm and vector with
--- data. Overflows are set to Nothing.
+data Overflows a = NoOverflow
+ | Overflow !a !a
+ deriving (Eq, Typeable, Functor)
+
+instance NFData a => NFData (Overflows a) where
+ rnf NoOverflow = ()
+ rnf (Overflow u o) = rnf u `seq` rnf o `seq` ()
+
+instance Applicative Overflows where
+ pure x = Overflow x x
+ Overflow f g <*> Overflow a b = Overflow (f a) (g b)
+ _ <*> _ = NoOverflow
+
+-- | Create histogram from binning algorithm and a vector with
+-- data. Overflows are set to Nothing.
--
-- Number of bins and vector size must match.
histogram :: (Vector v a, Bin bin) => bin -> v a -> Histogram v bin a
histogram b = histogramUO b Nothing
--- | Create histogram from binning algorithm and vector with data.
+-- | Create histogram from binning algorithm and vector with data.
--
-- Number of bins and vector size must match.
histogramUO :: (Vector v a, Bin bin) => bin -> Maybe (a,a) -> v a -> Histogram
v bin a
-histogramUO b uo v
- | nBins b == G.length v = Histogram b uo v
+histogramUO b uo v
+ | nBins b == G.length v = Histogram b (toOverflow uo) v
| otherwise = error "Data.Histogram.Generic.histogramUO: number
of bins and vector size doesn't match"
+ where
+ toOverflow Nothing = NoOverflow
+ toOverflow (Just (u,o)) = Overflow u o
-- | Convert histogram data to list.
asList :: (Vector v a, Bin bin) => Histogram v bin a -> [(BinValue bin, a)]
-asList (Histogram bin _ arr) =
+asList (Histogram bin _ arr) =
Prelude.zip (fromIndex bin <$> [0..]) (G.toList arr)
-- | Convert histogram data to vector
@@ -149,13 +165,13 @@
----------------------------------------------------------------
--- Instances & reading histograms from strings
+-- Instances & reading histograms from strings
----------------------------------------------------------------
-- $serialization
--
-- 'Show' instance is abused for serialization and produces human
--- readable data like that:
+-- readable data like that:
--
-- > # Histogram
-- > # Underflows = 0
@@ -175,7 +191,7 @@
-- > 9 89
--
-- It could be deserialize using 'readHistogram' function. 'Read'
--- instance coulde provided as well but it turned out to be
+-- instance could be provided as well but it turned out to be
-- impractically slow.
--
-- Serialization with cereal package is provided by histogram-fill-cereal
@@ -185,21 +201,15 @@
unlines (fmap showT $ asList h)
where
showT (x,y) = show x ++ "\t" ++ show y
- showUO (Just (u,o)) = "# Underflows = " ++ show u ++ "\n" ++
- "# Overflows = " ++ show o ++ "\n"
- showUO Nothing = "# Underflows = \n" ++
- "# Overflows = \n"
+ showUO (Overflow u o) = "# Underflows = " ++ show u ++ "\n" ++
+ "# Overflows = " ++ show o ++ "\n"
+ showUO NoOverflow = "# Underflows = \n" ++
+ "# Overflows = \n"
#if !MIN_VERSION_base(4,7,0)
-
histTyCon :: String -> String -> TyCon
-#if MIN_VERSION_base(4,4,0)
histTyCon = mkTyCon3 "histogram-fill"
-#else
-histTyCon m s = mkTyCon $ m ++ "." ++ s
-#endif
--- end MIN_VERSION_base(4,4,0)
instance Typeable1 v => Typeable2 (Histogram v) where
typeOf2 h = mkTyConApp (histTyCon "Data.Histogram.Generic" "Histogram")
[typeOf1 $ histData h]
@@ -214,22 +224,25 @@
-- | If vector is a functor then histogram is functor as well
instance (Functor v) => Functor (Histogram v bin) where
- fmap f (Histogram bin uo vec) = Histogram bin (fmap (f *** f) uo) (fmap f
vec)
+ fmap f (Histogram bin uo vec) = Histogram bin (fmap f uo) (fmap f vec)
-- Parse histogram header
-histHeader :: (Read bin, Read a, Bin bin, Vector v a) => ReadPrec (v a ->
Histogram v bin a)
+histHeader :: (Read bin, Read a) => ReadPrec (v a -> Histogram v bin a)
histHeader = do
keyword "Histogram"
u <- maybeValue "Underflows"
o <- maybeValue "Overflows"
bin <- readPrec
- return $ Histogram bin ((,) `fmap` u `ap` o)
+ return $ Histogram bin $ case liftA2 (,) u o of
+ Nothing -> NoOverflow
+ Just (u',o') -> Overflow u' o'
+
--- | Convert String to histogram. Histogram do not have Read instance
--- because of slowness of ReadP
+-- | Convert a 'String' to a histogram. Histogram does not have a 'Read'
instance
+-- because of the slowness of ReadP
readHistogram :: (Read bin, Read a, Bin bin, Vector v a) => String ->
Histogram v bin a
-readHistogram str =
+readHistogram str =
let (h,rest) = case readPrec_to_S histHeader 0 str of
[x] -> x
_ -> error "Cannot parse histogram header"
@@ -256,7 +269,7 @@
-- | Number of underflows
underflows :: Histogram v bin a -> Maybe a
-underflows h = fst <$> outOfRange h
+underflows h = fst <$> outOfRange h
-- | Number of overflows
overflows :: Histogram v bin a -> Maybe a
@@ -264,7 +277,8 @@
-- | Underflows and overflows
outOfRange :: Histogram v bin a -> Maybe (a,a)
-outOfRange (Histogram _ uo _) = uo
+outOfRange (Histogram _ NoOverflow _) = Nothing
+outOfRange (Histogram _ (Overflow u o) _) = Just (u,o)
@@ -307,37 +321,35 @@
-- | fmap lookalike. It's not possible to create Functor instance
-- because of type class context.
map :: (Vector v a, Vector v b) => (a -> b) -> Histogram v bin a -> Histogram
v bin b
-map f (Histogram bin uo a) =
- Histogram bin (fmap (f *** f) uo) (G.map f a)
+map f (Histogram bin uo a) =
+ Histogram bin (fmap f uo) (G.map f a)
-- | Map histogram using bin value and content. Overflows and underflows are
set to Nothing.
bmap :: (Vector v a, Vector v b, Bin bin)
=> (BinValue bin -> a -> b) -> Histogram v bin a -> Histogram v bin b
bmap f (Histogram bin _ vec) =
- Histogram bin Nothing $ G.imap (f . fromIndex bin) vec
+ Histogram bin NoOverflow $ 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'
+ | otherwise = Histogram bin NoOverflow 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) =>
+zip :: (BinEq bin, Vector v a, Vector v b, Vector v c) =>
(a -> b -> c) -> Histogram v bin a -> Histogram v bin b -> Histogram v
bin c
zip f ha hb = fromMaybe (error msg) $ zipSafe f ha hb
where msg = "Data.Histogram.Generic.Histogram.histZip: bins are different"
--- | Zip two histogram elementwise. If bins are not equal return `Nothing`
-zipSafe :: (Bin bin, BinEq bin, Vector v a, Vector v b, Vector v c) =>
+-- | Zip two histograms elementwise. If bins are not equal return `Nothing`
+zipSafe :: (BinEq bin, Vector v a, Vector v b, Vector v c) =>
(a -> b -> c) -> Histogram v bin a -> Histogram v bin b -> Maybe
(Histogram v bin c)
zipSafe f (Histogram bin uo v) (Histogram bin' uo' v')
- | binEq bin bin' = Just $ Histogram bin (f2 <$> uo <*> uo') (G.zipWith f v
v')
+ | binEq bin bin' = Just $ Histogram bin (f <$> uo <*> uo') (G.zipWith f v v')
| otherwise = Nothing
- where
- f2 (x,x') (y,y') = (f x y, f x' y')
-- | Convert between different vector types
convert :: (Vector v a, Vector w a)
@@ -360,7 +372,7 @@
----------------------------------------------------------------
-- | Strict fold over bin content in index order. Underflows and overflows are
ignored.
-foldl :: (Bin bin, Vector v a) => (b -> a -> b) -> b -> Histogram v bin a -> b
+foldl :: (Vector v a) => (b -> a -> b) -> b -> Histogram v bin a -> b
foldl f x0 (Histogram _ _ vec) =
G.foldl' f x0 vec
@@ -371,41 +383,41 @@
G.ifoldl' (\acc -> f acc . fromIndex bin) x0 vec
-- | Sum contents of all bins
-sum :: (Bin bin, Vector v a, Num a) => Histogram v bin a -> a
+sum :: (Vector v a, Num a) => Histogram v bin a -> a
sum = foldl (+) 0
-- | Minimal bin content.
-minimum :: (Bin bin, Vector v a, Ord a) => Histogram v bin a -> a
+minimum :: (Vector v a, Ord a) => Histogram v bin a -> a
minimum = G.minimum . histData
-- | Minimal bin content using custom comparison.
-minimumBy :: (Bin bin, Vector v a) => (a -> a -> Ordering) -> Histogram v bin
a -> a
+minimumBy :: (Vector v a) => (a -> a -> Ordering) -> Histogram v bin a -> a
minimumBy f = G.minimumBy f . histData
--- | Maximal bin content
-maximum :: (Bin bin, Vector v a, Ord a) => Histogram v bin a -> a
+-- | Maximal bin content.
+maximum :: (Vector v a, Ord a) => Histogram v bin a -> a
maximum = G.maximum . histData
-- | Maximal bin content using custom comparison.
-maximumBy :: (Bin bin, Vector v a) => (a -> a -> Ordering) -> Histogram v bin
a -> a
+maximumBy :: (Vector v a) => (a -> a -> Ordering) -> Histogram v bin a -> a
maximumBy f = G.maximumBy f . histData
--- | Index of a bin with minimal content
-minIndex :: (Bin bin, Ord a, Vector v a) => Histogram v bin a -> Int
+-- | Index of a bin with minimal content.
+minIndex :: ( Ord a, Vector v a) => Histogram v bin a -> Int
minIndex = G.minIndex . histData
-- | Index of a bin with minimal content using custom comparison.
-minIndexBy :: (Bin bin, Ord a, Vector v a) => (a -> a -> Ordering) ->
Histogram v bin a -> Int
+minIndexBy :: (Vector v a) => (a -> a -> Ordering) -> Histogram v bin a -> Int
minIndexBy f = G.minIndexBy f . histData
--- | Index of a bin with maximal content
-maxIndex :: (Bin bin, Ord a, Vector v a) => Histogram v bin a -> Int
+-- | Index of a bin with maximal content.
+maxIndex :: (Ord a, Vector v a) => Histogram v bin a -> Int
maxIndex = G.maxIndex . histData
-- | Index of a bin with maximal content using custom comparison.
-maxIndexBy :: (Bin bin, Ord a, Vector v a) => (a -> a -> Ordering) ->
Histogram v bin a -> Int
+maxIndexBy :: (Vector v a) => (a -> a -> Ordering) -> Histogram v bin a -> Int
maxIndexBy f = G.maxIndexBy f . histData
@@ -414,15 +426,15 @@
minBin = minBinBy compare
-- | Value bin with minimal content using custom comparison.
-minBinBy :: (Bin bin, Ord a, Vector v a) => (a -> a -> Ordering) -> Histogram
v bin a -> BinValue bin
+minBinBy :: (Bin bin, Vector v a) => (a -> a -> Ordering) -> Histogram v bin a
-> BinValue bin
minBinBy f h = fromIndex (bins h) $ minIndexBy f h
--- | Value of a bin with maximal content
+-- | Value of a bin with maximal content.
maxBin :: (Bin bin, Ord a, Vector v a) => Histogram v bin a -> BinValue bin
maxBin = maxBinBy compare
-- | Value of a bin with maximal content using custom comparison.
-maxBinBy :: (Bin bin, Ord a, Vector v a) => (a -> a -> Ordering) -> Histogram
v bin a -> BinValue bin
+maxBinBy :: (Bin bin, Vector v a) => (a -> a -> Ordering) -> Histogram v bin a
-> BinValue bin
maxBinBy f h = fromIndex (bins h) $ maxIndexBy f h
@@ -432,10 +444,10 @@
-- Slicing and reducing histograms
----------------------------------------------------------------
--- | Slice histogram. Values/indices specify inclusive
+-- | Slice a histogram. Values/indices specify inclusive
-- variant. Under/overflows are discarded. If requested value falls
--- out of histogram range it will be truncated. Use 'First' or
--- 'Last' constructor if you need slice from first or to last bin
+-- out of histogram range, it will be truncated. Use 'First' or
+-- 'Last' constructor if you need to slice from first or to last bin
-- correspondingly.
slice :: (SliceableBin bin, Vector v a)
=> HistIndex bin -- ^ Lower inclusive bound
@@ -443,7 +455,7 @@
-> Histogram v bin a -- ^ Histogram to slice
-> Histogram v bin a
slice a b (Histogram bin _ v) =
- Histogram (sliceBin i j bin) Nothing (G.slice i (j - i + 1) v)
+ Histogram (sliceBin i j bin) NoOverflow (G.slice i (j - i + 1) v)
where
i = max 0 $ histIndex bin a
j = min n $ histIndex bin b
@@ -479,7 +491,7 @@
{-# INLINE rebinWorker #-}
rebinWorker dir k f (Histogram bin _ vec)
| G.length vec' /= nBins bin' = error "Data.Histogram.Generic.rebin: wrong
MergeableBin instance"
- | otherwise = Histogram bin' Nothing vec'
+ | otherwise = Histogram bin' NoOverflow vec'
where
bin' = mergeBins dir k bin
vec' = G.generate n $ \i -> f (G.slice (off + i*k) k vec)
@@ -496,26 +508,26 @@
-- $hist2D
--
-- Data in 2D histograms is stored in row major order. This in fact
--- dictated by implementation of 'Bin2D'. So indices of bin are
--- arranged in following pattern:
---
+-- is dictated by the implementation of 'Bin2D'. So indices of the bin are
+-- arranged in the following pattern:
+--
-- > 0 1 2 3
-- > 4 5 6 7
-- > 8 9 10 11
--
--- Function from @AlongX@ family work with histogram slices along X
--- axis (as name suggest) which are contigous and therefor are
--- generally faster than @AlongY@ family.
+-- Functions from @AlongX@ family work with histogram slices along the X
+-- axis (as the name suggests) which are contigous, and therefore are
+-- generally faster than those from the @AlongY@ family.
--- | Get slice of 2D histogram along X axis. This function is faster
--- than 'sliceAlongY' since no array reallocations is required
+-- | Get slice of 2D histogram along the X axis. This function is faster
+-- than 'sliceAlongY' since no array reallocations are required.
sliceAlongX :: (Vector v a, Bin bX, Bin bY)
=> Histogram v (Bin2D bX bY) a -- ^ 2D histogram
-> HistIndex bY -- ^ Position along Y axis
-> Histogram v bX a
sliceAlongX (Histogram (Bin2D bX bY) _ arr) y
- | iy >= 0 && iy < ny = Histogram bX Nothing $ G.slice (nx * iy) nx arr
+ | iy >= 0 && iy < ny = Histogram bX NoOverflow $ G.slice (nx * iy) nx arr
| otherwise = error "Data.Histogram.Generic.Histogram.sliceXatIx:
bad index"
where
nx = nBins bX
@@ -528,7 +540,7 @@
-> HistIndex bX -- ^ Position along X axis
-> Histogram v bY a
sliceAlongY (Histogram (Bin2D bX bY) _ arr) x
- | ix >= 0 && ix < nx = Histogram bY Nothing $ G.generate ny (\iy -> arr !
(iy*nx + ix))
+ | ix >= 0 && ix < nx = Histogram bY NoOverflow $ G.generate ny (\iy -> arr !
(iy*nx + ix))
| otherwise = error "Data.Histogram.Generic.Histogram.sliceXatIx:
bad index"
where
nx = nBins bX
@@ -557,7 +569,7 @@
-> Histogram v (Bin2D bX bY) a -- ^ 2D histogram
-> Histogram v bY b
reduceX f h@(Histogram (Bin2D _ bY) _ _) =
- Histogram bY Nothing $ G.generate (nBins bY) (f . sliceAlongX h . Index)
+ Histogram bY NoOverflow $ G.generate (nBins bY) (f . sliceAlongX h . Index)
-- | Reduce along X axis. Information about under/overlows is lost.
breduceX :: (Vector v a, Vector v b, Bin bX, Bin bY)
@@ -565,7 +577,7 @@
-> Histogram v (Bin2D bX bY) a -- ^ 2D histogram
-> Histogram v bY b
breduceX f h@(Histogram (Bin2D _ bY) _ _) =
- Histogram bY Nothing $ G.generate (nBins bY) $ \i -> f (fromIndex bY i) $
sliceAlongX h (Index i)
+ Histogram bY NoOverflow $ G.generate (nBins bY) $ \i -> f (fromIndex bY i) $
sliceAlongX h (Index i)
-- | Reduce along Y axis. Information about under/overflows is lost.
@@ -574,7 +586,7 @@
-> Histogram v (Bin2D bX bY) a -- ^ 2D histogram
-> Histogram v bX b
reduceY f h@(Histogram (Bin2D bX _) _ _) =
- Histogram bX Nothing $ G.generate (nBins bX) (f . sliceAlongY h . Index)
+ Histogram bX NoOverflow $ G.generate (nBins bX) (f . sliceAlongY h . Index)
-- | Reduce along Y axis. Information about under/overflows is lost.
breduceY :: (Vector v a, Vector v b, Bin bX, Bin bY)
@@ -582,7 +594,7 @@
-> Histogram v (Bin2D bX bY) a -- ^ 2D histogram
-> Histogram v bX b
breduceY f h@(Histogram (Bin2D bX _) _ _) =
- Histogram bX Nothing $ G.generate (nBins bX) $ \i -> f (fromIndex bX i) $
sliceAlongY h (Index i)
+ Histogram bX NoOverflow $ G.generate (nBins bX) $ \i -> f (fromIndex bX i) $
sliceAlongY h (Index i)
-- | Transform X slices of histogram.
@@ -595,7 +607,7 @@
[] -> error "Data.Histogram.Generic.Histogram.liftX: zero size along Y"
hs -> Histogram
(Bin2D (bins (head hs)) by)
- Nothing
+ NoOverflow
(G.concat (histData <$> hs))
-- | Transform Y slices of histogram.
@@ -608,7 +620,7 @@
[] -> error "Data.Histogram.Generic.Histogram.liftY: zero size along X"
hs -> make hs
where
- make hs = Histogram (Bin2D bx by') Nothing
+ make hs = Histogram (Bin2D bx by') NoOverflow
$ G.backpermute (G.concat (histData <$> hs)) (G.generate (nx*ny)
join)
where
by' = bins (head hs)
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/histogram-fill-0.8.4.1/Data/Histogram.hs
new/histogram-fill-0.8.5.0/Data/Histogram.hs
--- old/histogram-fill-0.8.4.1/Data/Histogram.hs 2015-01-07
10:59:33.000000000 +0100
+++ new/histogram-fill-0.8.5.0/Data/Histogram.hs 2017-02-19
10:23:04.000000000 +0100
@@ -8,9 +8,9 @@
-- Maintainer : Alexey Khudyakov <[email protected]>
-- Stability : experimental
--
--- Immutable histograms. This module export same APi as
--- 'Data.Histogram.Generic' but specialzed to unboxed vectors. Refer
--- aforementioned module for documentation.
+-- Immutable histograms. This module exports the same API as
+-- 'Data.Histogram.Generic' but specialized to unboxed vectors. Refer
+-- to the aforementioned module for documentation.
module Data.Histogram ( -- * Immutable histogram
-- * Immutable histograms
Histogram
@@ -93,8 +93,8 @@
--- | Immutable histogram. Histogram consists of binning algorithm,
--- optional number of under and overflows, and data.
+-- | Immutable histogram. A histogram consists of a binning algorithm,
+-- an optional number of under and overflows, and data.
type Histogram bin a = H.Histogram U.Vector bin a
histogram :: (Unbox a, Bin bin) => bin -> Vector a -> Histogram bin a
@@ -137,7 +137,7 @@
asList :: (Unbox a, Bin bin) => Histogram bin a -> [(BinValue bin, a)]
asList = H.asList
-asVector :: (Bin bin, Unbox a, Unbox (BinValue bin), Unbox (BinValue bin,a))
+asVector :: (Bin bin, Unbox a, Unbox (BinValue bin,a))
=> Histogram bin a -> Vector (BinValue bin, a)
asVector = H.asVector
@@ -168,11 +168,11 @@
mapData = H.mapData
-zip :: (Bin bin, BinEq bin, Unbox a, Unbox b, Unbox c)
+zip :: (BinEq bin, Unbox a, Unbox b, Unbox c)
=> (a -> b -> c) -> Histogram bin a -> Histogram bin b -> Histogram bin c
zip = H.zip
-zipSafe :: (Bin bin, BinEq bin, Unbox a, Unbox b, Unbox c)
+zipSafe :: (BinEq bin, Unbox a, Unbox b, Unbox c)
=> (a -> b -> c) -> Histogram bin a -> Histogram bin b -> Maybe
(Histogram bin c)
zipSafe = H.zipSafe
@@ -185,52 +185,52 @@
-- Folding
----------------------------------------------------------------
-foldl :: (Bin bin, Unbox a) => (b -> a -> b) -> b -> Histogram bin a -> b
+foldl :: (Unbox a) => (b -> a -> b) -> b -> Histogram bin a -> b
foldl = H.foldl
bfoldl :: (Bin bin, Unbox a) => (b -> BinValue bin -> a -> b) -> b ->
Histogram bin a -> b
bfoldl = H.bfoldl
-sum :: (Bin bin, Unbox a, Num a) => Histogram bin a -> a
+sum :: (Unbox a, Num a) => Histogram bin a -> a
sum = H.sum
-minimum :: (Bin bin, Unbox a, Ord a) => Histogram bin a -> a
+minimum :: (Unbox a, Ord a) => Histogram bin a -> a
minimum = H.minimum
-minimumBy :: (Bin bin, Unbox a) => (a -> a -> Ordering) -> Histogram bin a -> a
+minimumBy :: (Unbox a) => (a -> a -> Ordering) -> Histogram bin a -> a
minimumBy = H.minimumBy
-maximum :: (Bin bin, Unbox a, Ord a) => Histogram bin a -> a
+maximum :: (Unbox a, Ord a) => Histogram bin a -> a
maximum = H.maximum
-maximumBy :: (Bin bin, Unbox a) => (a -> a -> Ordering) -> Histogram bin a -> a
+maximumBy :: (Unbox a) => (a -> a -> Ordering) -> Histogram bin a -> a
maximumBy = H.maximumBy
-minIndex :: (Bin bin, Ord a, Unbox a) => Histogram bin a -> Int
+minIndex :: (Ord a, Unbox a) => Histogram bin a -> Int
minIndex = H.minIndex
-minIndexBy :: (Bin bin, Ord a, Unbox a) => (a -> a -> Ordering) -> Histogram
bin a -> Int
+minIndexBy :: (Unbox a) => (a -> a -> Ordering) -> Histogram bin a -> Int
minIndexBy = H.minIndexBy
-maxIndex :: (Bin bin, Ord a, Unbox a) => Histogram bin a -> Int
+maxIndex :: (Ord a, Unbox a) => Histogram bin a -> Int
maxIndex = H.maxIndex
-maxIndexBy :: (Bin bin, Ord a, Unbox a) => (a -> a -> Ordering) -> Histogram
bin a -> Int
+maxIndexBy :: (Unbox a) => (a -> a -> Ordering) -> Histogram bin a -> Int
maxIndexBy = H.maxIndexBy
minBin :: (Bin bin, Ord a, Unbox a) => Histogram bin a -> BinValue bin
minBin = H.minBin
-minBinBy :: (Bin bin, Ord a, Unbox a) => (a -> a -> Ordering) -> Histogram bin
a -> BinValue bin
+minBinBy :: (Bin bin, Unbox a) => (a -> a -> Ordering) -> Histogram bin a ->
BinValue bin
minBinBy = H.minBinBy
maxBin :: (Bin bin, Ord a, Unbox a) => Histogram bin a -> BinValue bin
maxBin = H.maxBin
-maxBinBy :: (Bin bin, Ord a, Unbox a) => (a -> a -> Ordering) -> Histogram bin
a -> BinValue bin
+maxBinBy :: (Bin bin, Unbox a) => (a -> a -> Ordering) -> Histogram bin a ->
BinValue bin
maxBinBy = H.maxBinBy
@@ -317,13 +317,13 @@
-> Histogram bX b
breduceY = H.breduceY
-liftX :: (Bin bX, Bin bY, Bin bX', BinEq bX', Unbox a, Unbox b)
+liftX :: (Bin bX, Bin bY, BinEq bX', Unbox a, Unbox b)
=> (Histogram bX a -> Histogram bX' b)
-> Histogram (Bin2D bX bY) a
-> Histogram (Bin2D bX' bY) b
liftX = H.liftX
-liftY :: (Bin bX, Bin bY, Bin bY', BinEq bY', Unbox a, Unbox b)
+liftY :: (Bin bX, Bin bY, BinEq bY', Unbox a, Unbox b)
=> (Histogram bY a -> Histogram bY' b)
-> Histogram (Bin2D bX bY ) a
-> Histogram (Bin2D bX bY') b
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/histogram-fill-0.8.4.1/histogram-fill.cabal
new/histogram-fill-0.8.5.0/histogram-fill.cabal
--- old/histogram-fill-0.8.4.1/histogram-fill.cabal 2015-01-07
10:59:33.000000000 +0100
+++ new/histogram-fill-0.8.5.0/histogram-fill.cabal 2017-02-19
10:23:04.000000000 +0100
@@ -1,5 +1,5 @@
Name: histogram-fill
-Version: 0.8.4.1
+Version: 0.8.5.0
Synopsis: Library for histograms creation.
Description:
This is library for histograms filling. Its aim to provide
@@ -15,7 +15,7 @@
Category: Data
Build-Type: Simple
extra-source-files:
- ChangeLog
+ ChangeLog.md
source-repository head
type: hg
@@ -27,13 +27,11 @@
Library
Ghc-options: -O2 -Wall
Ghc-prof-options: -auto-all
- Build-Depends:
- base >=3 && <5,
- deepseq,
- primitive,
- ghc-prim,
- monad-primitive >= 0.1,
- vector >= 0.10.0.1
+ Build-Depends: base >= 4.6 && <5
+ , deepseq
+ , primitive >= 0.5
+ , ghc-prim
+ , vector >= 0.10.0.1
Exposed-modules:
Data.Histogram
Data.Histogram.Generic
@@ -44,6 +42,7 @@
Data.Histogram.Bin.BinInt
Data.Histogram.Bin.BinEnum
Data.Histogram.Bin.BinF
+ Data.Histogram.Bin.BinVar
Data.Histogram.Bin.LogBinD
Data.Histogram.Bin.MaybeBin
Data.Histogram.Bin.Bin2D