Hello community,

here is the log from the commit of package ghc-sampling for openSUSE:Factory 
checked in at 2017-03-24 02:15:14
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Comparing /work/SRC/openSUSE:Factory/ghc-sampling (Old)
 and      /work/SRC/openSUSE:Factory/.ghc-sampling.new (New)
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Package is "ghc-sampling"

Fri Mar 24 02:15:14 2017 rev:2 rq:476932 version:0.3.2

Changes:
--------
--- /work/SRC/openSUSE:Factory/ghc-sampling/ghc-sampling.changes        
2017-03-04 16:46:19.618371956 +0100
+++ /work/SRC/openSUSE:Factory/.ghc-sampling.new/ghc-sampling.changes   
2017-03-24 02:15:16.538218561 +0100
@@ -1,0 +2,10 @@
+Sun Feb 12 14:16:05 UTC 2017 - [email protected]
+
+- Update to version 0.3.2 with cabal2obs.
+
+-------------------------------------------------------------------
+Fri Dec 16 17:16:36 UTC 2016 - [email protected]
+
+- Update to version 0.2.0 revision 1 with cabal2obs.
+
+-------------------------------------------------------------------

Old:
----
  sampling-0.2.0.tar.gz

New:
----
  sampling-0.3.2.tar.gz

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Other differences:
------------------
++++++ ghc-sampling.spec ++++++
--- /var/tmp/diff_new_pack.RNZkqG/_old  2017-03-24 02:15:17.174128586 +0100
+++ /var/tmp/diff_new_pack.RNZkqG/_new  2017-03-24 02:15:17.174128586 +0100
@@ -1,7 +1,7 @@
 #
 # spec file for package ghc-sampling
 #
-# 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,15 +18,15 @@
 
 %global pkg_name sampling
 Name:           ghc-%{pkg_name}
-Version:        0.2.0
+Version:        0.3.2
 Release:        0
 Summary:        Sample values from collections
 License:        MIT
 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:  chrpath
 BuildRequires:  ghc-Cabal-devel
+BuildRequires:  ghc-containers-devel
 BuildRequires:  ghc-foldl-devel
 BuildRequires:  ghc-mwc-random-devel
 BuildRequires:  ghc-primitive-devel
@@ -42,7 +42,10 @@
 
 * 'sample', for sampling without replacement
 
-* 'resample', for sampling with replacement (i.e., a bootstrap).
+* 'resample', for sampling with replacement (i.e., a bootstrap)
+
+Each variation can be prefixed with 'p' to sample from a container of values
+weighted by probability.
 
 %package devel
 Summary:        Haskell %{pkg_name} library development files
@@ -63,7 +66,6 @@
 
 %install
 %ghc_lib_install
-%ghc_fix_dynamic_rpath sampling-test
 
 %post devel
 %ghc_pkg_recache
@@ -74,7 +76,6 @@
 %files -f %{name}.files
 %defattr(-,root,root,-)
 %doc LICENSE
-%{_bindir}/sampling-test
 
 %files devel -f %{name}-devel.files
 %defattr(-,root,root,-)

++++++ sampling-0.2.0.tar.gz -> sampling-0.3.2.tar.gz ++++++
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/sampling-0.2.0/lib/Numeric/Sampling.hs 
new/sampling-0.3.2/lib/Numeric/Sampling.hs
--- old/sampling-0.2.0/lib/Numeric/Sampling.hs  2016-03-03 09:34:11.000000000 
+0100
+++ new/sampling-0.3.2/lib/Numeric/Sampling.hs  2016-12-11 07:36:36.000000000 
+0100
@@ -13,6 +13,10 @@
   , resample
   , resampleIO
 
+    -- * Unequal probability, without replacement
+  , psample
+  , psampleIO
+
     -- * Unequal probability, with replacement
   , presample
   , presampleIO
@@ -21,17 +25,19 @@
   , module System.Random.MWC
   ) where
 
-import qualified Control.Foldl               as F
-import           Control.Monad.Primitive     (PrimMonad, PrimState)
-import qualified Data.Foldable               as Foldable
+import qualified Control.Foldl as F
+import Control.Monad.Primitive (PrimMonad, PrimState)
+import qualified Data.Foldable as Foldable
 #if __GLASGOW_HASKELL__ < 710
 import Data.Foldable (Foldable)
 #endif
-import           Data.Function               (on)
-import           Data.List                   (sortBy)
-import qualified Data.Vector                 as V (toList)
-import           Numeric.Sampling.Internal
-import           System.Random.MWC
+import Data.Function (on)
+import Data.List (sortBy)
+import Data.Monoid
+import qualified Data.Sequence as S
+import qualified Data.Vector as V (toList)
+import Numeric.Sampling.Internal
+import System.Random.MWC
 
 -- | (/O(n)/) Sample uniformly, without replacement.
 --
@@ -42,7 +48,9 @@
   => Int -> f a -> Gen (PrimState m) -> m (Maybe [a])
 sample n xs gen
   | n < 0     = return Nothing
-  | otherwise = fmap (fmap V.toList) (F.foldM (randomN n gen) xs)
+  | otherwise = do
+      collected <- F.foldM (randomN n gen) xs
+      return $ fmap V.toList collected
 {-# INLINABLE sample #-}
 
 -- | (/O(n)/) 'sample' specialized to IO.
@@ -62,12 +70,52 @@
 {-# INLINABLE resample #-}
 
 -- | (/O(n log n)/) 'resample' specialized to IO.
-resampleIO :: (Foldable f) => Int -> f a -> IO [a]
+resampleIO :: Foldable f => Int -> f a -> IO [a]
 resampleIO n xs = do
   gen <- createSystemRandom
   resample n xs gen
 {-# INLINABLE resampleIO #-}
 
+-- | (/O(n log n)/) Unequal probability sampling.
+--
+--   Returns Nothing if the desired sample size is larger than the collection
+--   being sampled from.
+psample
+  :: (PrimMonad m, Foldable f)
+  => Int -> f (Double, a) -> Gen (PrimState m) -> m (Maybe [a])
+psample n weighted gen = do
+    let sorted = sortProbs weighted
+    computeSample n sorted gen
+  where
+    computeSample
+      :: PrimMonad m
+      => Int -> [(Double, a)] -> Gen (PrimState m) -> m (Maybe [a])
+    computeSample size xs g = go 1 [] size (S.fromList xs) where
+      go !mass !acc j vs
+        | j <  0    = return Nothing
+        | j <= 0    = return (Just acc)
+        | otherwise = do
+            z <- fmap (* mass) (uniform g)
+
+            let cumulative = S.drop 1 $ S.scanl (\s (pr, _) -> s + pr) 0 vs
+                midx       = S.findIndexL (>= z) cumulative
+
+                idx = case midx of
+                  Nothing -> error "psample: no index found"
+                  Just x  -> x
+
+                (p, val) = S.index vs idx
+                (l, r)   = S.splitAt idx vs
+                deleted = l <> S.drop 1 r
+
+            go (mass - p) (val:acc) (pred j) deleted
+{-# INLINABLE psample #-}
+
+-- | (/O(n log n)/) 'psample' specialized to IO.
+psampleIO :: Foldable f => Int -> f (Double, a) -> IO (Maybe [a])
+psampleIO n weighted = withSystemRandom . asGenIO $ psample n weighted
+{-# INLINABLE psampleIO #-}
+
 -- | (/O(n log n)/) Unequal probability resampling.
 presample
   :: (PrimMonad m, Foldable f)
@@ -90,15 +138,14 @@
             case F.fold (F.find ((>= z) . fst)) xs of
               Just (_, val) -> go (val:acc) (pred s)
               Nothing       -> return acc
-
-    sortProbs :: (Foldable f, Ord a) => f (a, b) -> [(a, b)]
-    sortProbs = sortBy (compare `on` fst) . Foldable.toList
 {-# INLINABLE presample #-}
 
 -- | (/O(n log n)/) 'presample' specialized to IO.
 presampleIO :: (Foldable f) => Int -> f (Double, a) -> IO [a]
-presampleIO n weighted = do
-  gen <- createSystemRandom
-  presample n weighted gen
+presampleIO n weighted = withSystemRandom . asGenIO $ presample n weighted
 {-# INLINABLE presampleIO #-}
 
+sortProbs :: (Foldable f, Ord a) => f (a, b) -> [(a, b)]
+sortProbs = sortBy (flip compare `on` fst) . Foldable.toList
+{-# INLINABLE sortProbs #-}
+
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/sampling-0.2.0/sampling.cabal 
new/sampling-0.3.2/sampling.cabal
--- old/sampling-0.2.0/sampling.cabal   2016-03-03 09:50:41.000000000 +0100
+++ new/sampling-0.3.2/sampling.cabal   2017-01-31 23:34:14.000000000 +0100
@@ -1,5 +1,5 @@
 name:                sampling
-version:             0.2.0
+version:             0.3.2
 synopsis:            Sample values from collections.
 homepage:            https://github.com/jtobin/sampling
 license:             MIT
@@ -18,6 +18,9 @@
   * 'sample', for sampling without replacement
   .
   * 'resample', for sampling with replacement (i.e., a bootstrap)
+  .
+  Each variation can be prefixed with 'p' to sample from a container of values
+  weighted by probability.
 
 Source-repository head
   Type:     git
@@ -33,18 +36,18 @@
   exposed-modules:
       Numeric.Sampling
   build-depends:
-      base        < 5
+      base        > 4.8 && < 5
+    , containers  >= 0.5 && < 1
     , foldl       >= 1.1 && < 2
     , mwc-random  >= 0.13 && < 0.14
-    , primitive
-    , vector      >= 0.11 && < 0.12
+    , primitive   >= 0.6  && < 1
+    , vector      >= 0.11 && < 1
 
-executable sampling-test
-  hs-source-dirs: src
-  Main-is:        Main.hs
-  default-language:  Haskell2010
-  ghc-options:
-    -Wall -O2
+Test-suite resample
+  type:                exitcode-stdio-1.0
+  hs-source-dirs:      test
+  Main-is:             Main.hs
+  default-language:    Haskell2010
   build-depends:
       base
     , sampling
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/sampling-0.2.0/src/Main.hs 
new/sampling-0.3.2/src/Main.hs
--- old/sampling-0.2.0/src/Main.hs      2016-03-03 09:52:36.000000000 +0100
+++ new/sampling-0.3.2/src/Main.hs      1970-01-01 01:00:00.000000000 +0100
@@ -1,10 +0,0 @@
-{-# OPTIONS_GHC -fno-warn-type-defaults #-}
-
-module Main where
-
-import Numeric.Sampling
-
-main :: IO ()
-main = do
-  foo <- resampleIO 100 ([1..100000] :: [Int])
-  print foo
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/sampling-0.2.0/test/Main.hs 
new/sampling-0.3.2/test/Main.hs
--- old/sampling-0.2.0/test/Main.hs     1970-01-01 01:00:00.000000000 +0100
+++ new/sampling-0.3.2/test/Main.hs     2016-12-11 07:31:40.000000000 +0100
@@ -0,0 +1,10 @@
+{-# OPTIONS_GHC -fno-warn-type-defaults #-}
+
+module Main where
+
+import Numeric.Sampling
+
+main :: IO ()
+main = do
+  foo <- resampleIO 100 ([1..100000] :: [Int])
+  print foo


Reply via email to