summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexeyKhudyakov <>2019-09-14 20:19:00 (GMT)
committerhdiff <hdiff@hdiff.luite.com>2019-09-14 20:19:00 (GMT)
commit8025105ec2fed1d4d4b065ff18b808ae7172c335 (patch)
tree23a30e9d37f55880af33bba5943b6956c10aeafb
parentd83adc3c5e34952beca8001f00997d887844d33e (diff)
version 0.15.1.00.15.1.0
-rwxr-xr-x[-rw-r--r--]README.markdown0
-rw-r--r--Statistics/Regression.hs12
-rw-r--r--Statistics/Resampling.hs13
-rw-r--r--Statistics/Resampling/Bootstrap.hs13
-rwxr-xr-x[-rw-r--r--]benchmark/bench.hs0
-rwxr-xr-x[-rw-r--r--]changelog.md7
-rwxr-xr-x[-rw-r--r--]examples/kde/KDE.hs0
-rwxr-xr-x[-rw-r--r--]examples/kde/data/faithful.csv0
-rwxr-xr-x[-rw-r--r--]examples/kde/kde.html0
-rwxr-xr-x[-rw-r--r--]examples/kde/kde.tpl0
-rw-r--r--statistics.cabal21
-rwxr-xr-x[-rw-r--r--]tests/Tests/Math/Tables.hs0
-rwxr-xr-x[-rw-r--r--]tests/Tests/Math/gen.py0
-rwxr-xr-x[-rw-r--r--]tests/utils/Makefile0
-rwxr-xr-x[-rw-r--r--]tests/utils/fftw.c0
15 files changed, 48 insertions, 18 deletions
diff --git a/README.markdown b/README.markdown
index 5a0bc1c..5a0bc1c 100644..100755
--- a/README.markdown
+++ b/README.markdown
diff --git a/Statistics/Regression.hs b/Statistics/Regression.hs
index d886dcb..05d2268 100644
--- a/Statistics/Regression.hs
+++ b/Statistics/Regression.hs
@@ -14,10 +14,9 @@ module Statistics.Regression
) where
import Control.Applicative ((<$>))
-import Control.Concurrent (forkIO)
-import Control.Concurrent.Chan (newChan, readChan, writeChan)
+import Control.Concurrent.Async (forConcurrently)
import Control.DeepSeq (rnf)
-import Control.Monad (forM_, replicateM, when)
+import Control.Monad (when)
import Data.List (nub)
import GHC.Conc (getNumCapabilities)
import Prelude hiding (pred, sum)
@@ -140,16 +139,15 @@ bootstrapRegress gen0 numResamples cl rgrss preds0 resp0
caps <- getNumCapabilities
gens <- splitGen caps gen0
- done <- newChan
- forM_ (zip gens (balance caps numResamples)) $ \(gen,count) -> forkIO $ do
+ vs <- forConcurrently (zip gens (balance caps numResamples)) $ \(gen,count) -> do
v <- V.replicateM count $ do
let n = U.length resp0
ixs <- U.replicateM n $ uniformR (0,n-1) gen
let resp = U.backpermute resp0 ixs
preds = map (flip U.backpermute ixs) preds0
return $ rgrss preds resp
- rnf v `seq` writeChan done v
- (coeffsv, r2v) <- (G.unzip . V.concat) <$> replicateM caps (readChan done)
+ rnf v `seq` return v
+ let (coeffsv, r2v) = G.unzip (V.concat vs)
let coeffs = flip G.imap (G.convert coeffss) $ \i x ->
est x . U.generate numResamples $ \k -> (coeffsv G.! k) G.! i
r2 = est r2s (G.convert r2v)
diff --git a/Statistics/Resampling.hs b/Statistics/Resampling.hs
index 4ad98a4..0b3219a 100644
--- a/Statistics/Resampling.hs
+++ b/Statistics/Resampling.hs
@@ -37,8 +37,8 @@ module Statistics.Resampling
import Data.Aeson (FromJSON, ToJSON)
import Control.Applicative
-import Control.Concurrent (forkIO, newChan, readChan, writeChan)
-import Control.Monad (forM_, forM, replicateM, replicateM_, liftM2)
+import Control.Concurrent.Async (forConcurrently_)
+import Control.Monad (forM_, forM, replicateM, liftM2)
import Control.Monad.Primitive (PrimMonad(..))
import Data.Binary (Binary(..))
import Data.Data (Data, Typeable)
@@ -164,18 +164,17 @@ resample gen ests numResamples samples = do
(replicate r 1 ++ repeat 0)
where (q,r) = numResamples `quotRem` numCapabilities
results <- mapM (const (MU.new numResamples)) ests
- done <- newChan
gens <- splitGen numCapabilities gen
- forM_ (zip3 ixs (tail ixs) gens) $ \ (start,!end,gen') ->
- forkIO $ do
- let loop k ers | k >= end = writeChan done ()
+ forConcurrently_ (zip3 ixs (tail ixs) gens) $ \ (start,!end,gen') -> do
+ -- on GHCJS it doesn't make sense to do any forking.
+ -- JavaScript runtime has only single capability.
+ let loop k ers | k >= end = return ()
| otherwise = do
re <- resampleVector gen' samples
forM_ ers $ \(est,arr) ->
MU.write arr k . est $ re
loop (k+1) ers
loop start (zip ests' results)
- replicateM_ numCapabilities $ readChan done
mapM_ sort results
-- Build resamples
res <- mapM unsafeFreeze results
diff --git a/Statistics/Resampling/Bootstrap.hs b/Statistics/Resampling/Bootstrap.hs
index 0fc5cae..c4ddde7 100644
--- a/Statistics/Resampling/Bootstrap.hs
+++ b/Statistics/Resampling/Bootstrap.hs
@@ -1,3 +1,4 @@
+{-# LANGUAGE CPP #-}
-- |
-- Module : Statistics.Resampling.Bootstrap
-- Copyright : (c) 2009, 2011 Bryan O'Sullivan
@@ -16,7 +17,6 @@ module Statistics.Resampling.Bootstrap
-- $references
) where
-import Control.Monad.Par (parMap, runPar)
import Data.Vector.Generic ((!))
import qualified Data.Vector.Unboxed as U
import qualified Data.Vector.Generic as G
@@ -31,6 +31,9 @@ import Statistics.Function (gsort)
import qualified Statistics.Resampling as R
+#if !defined(__GHCJS__)
+import Control.Monad.Par (parMap, runPar)
+#endif
data T = {-# UNPACK #-} !Double :< {-# UNPACK #-} !Double
infixl 2 :<
@@ -48,7 +51,15 @@ bootstrapBCA
-- this.
-> [Estimate ConfInt Double]
bootstrapBCA confidenceLevel sample resampledData
+#if defined(__GHCJS__)
+ -- monad-par causes seems to cause "thread blocked indefinitely on MVar"
+ -- on GHCJS still
+ --
+ -- I (phadej) would change the interface to return IO, and use mapConcurrently from async
+ = map e resampledData
+#else
= runPar $ parMap e resampledData
+#endif
where
e (est, Bootstrap pt resample)
| U.length sample == 1 || isInfinite bias =
diff --git a/benchmark/bench.hs b/benchmark/bench.hs
index 6345980..6345980 100644..100755
--- a/benchmark/bench.hs
+++ b/benchmark/bench.hs
diff --git a/changelog.md b/changelog.md
index a856cc0..2b9b8ad 100644..100755
--- a/changelog.md
+++ b/changelog.md
@@ -1,3 +1,10 @@
+## Changes in 0.15.1.0
+
+ * GHCJS support
+
+ * Concurrent resampling now uses `async` instead of hand-rolled primitives
+
+
## Changes in 0.15.0.0
* Modules `Statistics.Matrix.*` are split into new package
diff --git a/examples/kde/KDE.hs b/examples/kde/KDE.hs
index 0cc677b..0cc677b 100644..100755
--- a/examples/kde/KDE.hs
+++ b/examples/kde/KDE.hs
diff --git a/examples/kde/data/faithful.csv b/examples/kde/data/faithful.csv
index 4a4569c..4a4569c 100644..100755
--- a/examples/kde/data/faithful.csv
+++ b/examples/kde/data/faithful.csv
diff --git a/examples/kde/kde.html b/examples/kde/kde.html
index 5d2545c..5d2545c 100644..100755
--- a/examples/kde/kde.html
+++ b/examples/kde/kde.html
diff --git a/examples/kde/kde.tpl b/examples/kde/kde.tpl
index 1bf9c32..1bf9c32 100644..100755
--- a/examples/kde/kde.tpl
+++ b/examples/kde/kde.tpl
diff --git a/statistics.cabal b/statistics.cabal
index 3638361..d143db0 100644
--- a/statistics.cabal
+++ b/statistics.cabal
@@ -1,5 +1,5 @@
name: statistics
-version: 0.15.0.0
+version: 0.15.1.0
synopsis: A library of statistical types, data, and functions
description:
This library provides a number of common functions and types useful
@@ -44,7 +44,18 @@ extra-source-files:
tests/Tests/Math/gen.py
tests/utils/Makefile
tests/utils/fftw.c
-tested-with: GHC==7.4.2, GHC==7.6.3, GHC==7.8.3, GHC==7.10.3, GHC==8.0.2, GHC==8.2.2, GHC==8.4.3
+
+tested-with:
+ GHC ==7.4.2
+ || ==7.6.3
+ || ==7.8.4
+ || ==7.10.3
+ || ==8.0.2
+ || ==8.2.2
+ || ==8.4.4
+ || ==8.6.5
+ , GHCJS ==8.4
+
library
exposed-modules:
@@ -103,9 +114,9 @@ library
, mwc-random >= 0.13.0.0
--
, aeson >= 0.6.0.0
+ , async >= 2.2.2 && <2.3
, deepseq >= 1.1.0.2
, binary >= 0.5.1.0
- , monad-par >= 0.3.4
, primitive >= 0.3
, dense-linear-algebra >= 0.1 && <0.2
, vector >= 0.10
@@ -113,6 +124,10 @@ library
, vector-th-unbox
, vector-binary-instances >= 0.2.1
, data-default-class >= 0.1.2
+ if !impl(ghcjs)
+ build-depends:
+ monad-par >= 0.3.4
+ -- Older GHC
if impl(ghc < 7.6)
build-depends:
ghc-prim
diff --git a/tests/Tests/Math/Tables.hs b/tests/Tests/Math/Tables.hs
index 89ac560..89ac560 100644..100755
--- a/tests/Tests/Math/Tables.hs
+++ b/tests/Tests/Math/Tables.hs
diff --git a/tests/Tests/Math/gen.py b/tests/Tests/Math/gen.py
index fde9da6..fde9da6 100644..100755
--- a/tests/Tests/Math/gen.py
+++ b/tests/Tests/Math/gen.py
diff --git a/tests/utils/Makefile b/tests/utils/Makefile
index 284f764..284f764 100644..100755
--- a/tests/utils/Makefile
+++ b/tests/utils/Makefile
diff --git a/tests/utils/fftw.c b/tests/utils/fftw.c
index ef12579..ef12579 100644..100755
--- a/tests/utils/fftw.c
+++ b/tests/utils/fftw.c