From 4dcf4f63c2c0092b1dcf4ead2126321fa14a9f93 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fran=C3=A7ois=20Laurent?= <francois.laurent@posteo.net>
Date: Thu, 5 Oct 2023 13:30:56 +0200
Subject: [PATCH] reverting previous 2 commits and making capacitysampling
 behaves as in v0.14 (CapacitySampling was introduced in v0.14)

---
 src/Dataloaders.jl | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/src/Dataloaders.jl b/src/Dataloaders.jl
index 2e7f50b..e377da4 100644
--- a/src/Dataloaders.jl
+++ b/src/Dataloaders.jl
@@ -679,7 +679,9 @@ function sample(f, loader::DataLoader, features=:spine; kwargs...)
 end
 
 function sample(file::Formats.PreloadedFile, window, ix::LazyIndex, features; kwargs...)
-    ix.sampler.rng = Random.seed!(Random.default_rng(), ix.sampler.seed)
+    if !(ix.sampler isa CapacitySampling)
+        ix.sampler.rng = Random.seed!(Random.default_rng(), ix.sampler.seed)
+    end
     sample(ix.sampler, file, window, ix.targetcounts[file], features; kwargs...)
 end
 
@@ -767,11 +769,10 @@ end
 presample(_, ::Nothing, _, _, counts) = (0, sum(values(counts)))
 presample(_, cumulatedcount, _, _, counts) = (sum(cumulatedcount), sum(values(counts)))
 
-mutable struct CapacitySampling <: RatioBasedSampling
+struct CapacitySampling <: RatioBasedSampling
     selectors
     maxcount::Integer
     rng
-    seed
 end
 
 """
@@ -788,9 +789,9 @@ function capacitysampling(selectors, maxcount::Integer; seed=nothing, rng=nothin
         if isnothing(rng)
             rng = Random.default_rng()
         end
-        #Random.seed!(rng, seed)
+        Random.seed!(rng, seed)
     end
-    LazyIndex(CapacitySampling(asselectors(selectors), maxcount, rng, seed))
+    LazyIndex(CapacitySampling(asselectors(selectors), maxcount, rng))
 end
 
 function capacitysampling(maxcount::Integer; kwargs...)
-- 
GitLab