Skip to content

Commit c26cbaf

Browse files
authored
Remove unused Samplers (#3219)
1 parent 0d0d1e7 commit c26cbaf

16 files changed

+102
-951
lines changed

utils/sampler/uniform_benchmark_test.go

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,29 +8,24 @@ import (
88
"testing"
99
)
1010

11-
// BenchmarkAllUniform
12-
func BenchmarkAllUniform(b *testing.B) {
11+
func BenchmarkUniform(b *testing.B) {
1312
sizes := []uint64{
1413
30,
1514
35,
1615
500,
1716
10000,
1817
100000,
1918
}
20-
for _, s := range uniformSamplers {
21-
for _, size := range sizes {
22-
b.Run(fmt.Sprintf("sampler %s with %d elements uniformly", s.name, size), func(b *testing.B) {
23-
UniformBenchmark(b, s.sampler, size, 30)
24-
})
25-
}
26-
}
27-
}
19+
for _, size := range sizes {
20+
b.Run(fmt.Sprintf("%d elements uniformly", size), func(b *testing.B) {
21+
s := NewUniform()
2822

29-
func UniformBenchmark(b *testing.B, s Uniform, size uint64, toSample int) {
30-
s.Initialize(size)
23+
s.Initialize(size)
3124

32-
b.ResetTimer()
33-
for i := 0; i < b.N; i++ {
34-
_, _ = s.Sample(toSample)
25+
b.ResetTimer()
26+
for i := 0; i < b.N; i++ {
27+
_, _ = s.Sample(30)
28+
}
29+
})
3530
}
3631
}

utils/sampler/uniform_best.go

Lines changed: 0 additions & 72 deletions
This file was deleted.

utils/sampler/uniform_resample.go

Lines changed: 0 additions & 58 deletions
This file was deleted.

utils/sampler/uniform_test.go

Lines changed: 14 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -4,82 +4,15 @@
44
package sampler
55

66
import (
7-
"fmt"
87
"math"
98
"slices"
109
"testing"
1110

1211
"github.com/stretchr/testify/require"
1312
)
1413

15-
var (
16-
uniformSamplers = []struct {
17-
name string
18-
sampler Uniform
19-
}{
20-
{
21-
name: "replacer",
22-
sampler: &uniformReplacer{
23-
rng: globalRNG,
24-
},
25-
},
26-
{
27-
name: "resampler",
28-
sampler: &uniformResample{
29-
rng: globalRNG,
30-
},
31-
},
32-
{
33-
name: "best",
34-
sampler: NewBestUniform(30),
35-
},
36-
}
37-
uniformTests = []struct {
38-
name string
39-
test func(*testing.T, Uniform)
40-
}{
41-
{
42-
name: "can sample large values",
43-
test: UniformInitializeMaxUint64Test,
44-
},
45-
{
46-
name: "out of range",
47-
test: UniformOutOfRangeTest,
48-
},
49-
{
50-
name: "empty",
51-
test: UniformEmptyTest,
52-
},
53-
{
54-
name: "singleton",
55-
test: UniformSingletonTest,
56-
},
57-
{
58-
name: "distribution",
59-
test: UniformDistributionTest,
60-
},
61-
{
62-
name: "over sample",
63-
test: UniformOverSampleTest,
64-
},
65-
{
66-
name: "lazily sample",
67-
test: UniformLazilySample,
68-
},
69-
}
70-
)
71-
72-
func TestAllUniform(t *testing.T) {
73-
for _, s := range uniformSamplers {
74-
for _, test := range uniformTests {
75-
t.Run(fmt.Sprintf("sampler %s test %s", s.name, test.name), func(t *testing.T) {
76-
test.test(t, s.sampler)
77-
})
78-
}
79-
}
80-
}
81-
82-
func UniformInitializeMaxUint64Test(t *testing.T, s Uniform) {
14+
func TestUniformInitializeMaxUint64(t *testing.T) {
15+
s := NewUniform()
8316
s.Initialize(math.MaxUint64)
8417

8518
for {
@@ -92,15 +25,17 @@ func UniformInitializeMaxUint64Test(t *testing.T, s Uniform) {
9225
}
9326
}
9427

95-
func UniformOutOfRangeTest(t *testing.T, s Uniform) {
28+
func TestUniformOutOfRange(t *testing.T) {
29+
s := NewUniform()
9630
s.Initialize(0)
9731

9832
_, ok := s.Sample(1)
9933
require.False(t, ok)
10034
}
10135

102-
func UniformEmptyTest(t *testing.T, s Uniform) {
36+
func TestUniformEmpty(t *testing.T) {
10337
require := require.New(t)
38+
s := NewUniform()
10439

10540
s.Initialize(1)
10641

@@ -109,8 +44,9 @@ func UniformEmptyTest(t *testing.T, s Uniform) {
10944
require.Empty(val)
11045
}
11146

112-
func UniformSingletonTest(t *testing.T, s Uniform) {
47+
func TestUniformSingleton(t *testing.T) {
11348
require := require.New(t)
49+
s := NewUniform()
11450

11551
s.Initialize(1)
11652

@@ -119,8 +55,9 @@ func UniformSingletonTest(t *testing.T, s Uniform) {
11955
require.Equal([]uint64{0}, val)
12056
}
12157

122-
func UniformDistributionTest(t *testing.T, s Uniform) {
58+
func TestUniformDistribution(t *testing.T) {
12359
require := require.New(t)
60+
s := NewUniform()
12461

12562
s.Initialize(3)
12663

@@ -131,15 +68,17 @@ func UniformDistributionTest(t *testing.T, s Uniform) {
13168
require.Equal([]uint64{0, 1, 2}, val)
13269
}
13370

134-
func UniformOverSampleTest(t *testing.T, s Uniform) {
71+
func TestUniformOverSample(t *testing.T) {
72+
s := NewUniform()
13573
s.Initialize(3)
13674

13775
_, ok := s.Sample(4)
13876
require.False(t, ok)
13977
}
14078

141-
func UniformLazilySample(t *testing.T, s Uniform) {
79+
func TestUniformLazilySample(t *testing.T) {
14280
require := require.New(t)
81+
s := NewUniform()
14382

14483
s.Initialize(3)
14584

utils/sampler/weighted.go

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,6 @@ type Weighted interface {
1010
Sample(sampleValue uint64) (int, bool)
1111
}
1212

13-
// NewWeighted returns a new sampler
1413
func NewWeighted() Weighted {
15-
return &weightedBest{
16-
samplers: []Weighted{
17-
&weightedArray{},
18-
&weightedHeap{},
19-
&weightedUniform{
20-
maxWeight: 1024,
21-
},
22-
},
23-
benchmarkIterations: 100,
24-
}
25-
}
26-
27-
func NewDeterministicWeighted() Weighted {
2814
return &weightedHeap{}
2915
}

0 commit comments

Comments
 (0)