packages feed

random-cycle 0.1.1.0 → 0.1.2.0

raw patch · 3 files changed

+19/−17 lines, 3 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

Files

CHANGELOG.md view
@@ -1,5 +1,9 @@ # Revision history for random-cycle +## 0.1.2.0 -- 2023-11-19++* Fixes a bug in 'uniformCyclePartitionThin'.+ ## 0.1.1.0 -- 2023-05-07  * Adds Sattolo's algorithm to sample full cycles.
random-cycle.cabal view
@@ -1,6 +1,6 @@ cabal-version:      2.4 name:               random-cycle-version:            0.1.1.0+version:            0.1.2.0 synopsis: Uniform draws of partitions and cycle-partitions, with thinning.  description: 
src/RandomCycle/Vector/Cycle.hs view
@@ -4,7 +4,7 @@ -- Import 'RandomCycle.Vector' instead. module RandomCycle.Vector.Cycle where -import Control.Monad (when)+import Control.Monad (unless) import Control.Monad.Primitive (PrimMonad, PrimState, liftPrim) import Data.STRef import qualified Data.Vector as V@@ -29,21 +29,19 @@ uniformCyclePartitionThinM chk maxit r v gen = do   maxitVal <- liftPrim $ readSTRef maxit -  when (maxitVal <= 0) (pure ())--  uniformShuffleM v gen-  -- TODO: Repeated calls to freeze, indexed-  -- a possible opportunity for optimization,-  -- e.g. with imap or a check that takes 'chk'-  -- reference and shortcircuits.-  vVal <- V.freeze v-  if V.all r (V.indexed vVal)-    then do-      liftPrim $ modifySTRef' chk (const True)-    else do-      liftPrim $ modifySTRef' maxit (\x -> x - 1)-      uniformCyclePartitionThinM chk maxit r v gen-  pure ()+  unless (maxitVal <= 0) $ do+    uniformShuffleM v gen+    -- TODO: Repeated calls to freeze, indexed+    -- a possible opportunity for optimization,+    -- e.g. with imap or a check that takes 'chk'+    -- reference and shortcircuits.+    vVal <- V.freeze v+    if V.all r (V.indexed vVal)+      then do+        liftPrim $ modifySTRef' chk (const True)+      else do+        liftPrim $ modifySTRef' maxit (\x -> x - 1)+        uniformCyclePartitionThinM chk maxit r v gen  -- | Internal. Helper for'uniformCycle'. Caller's responsibility to ensure -- first input is the length of the vector, and that i ranges over @[0..n-2]@.