Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

all: migrate to math/rand/v2 #1027

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions fads/btagging.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ package fads

import (
"math"
"math/rand/v2"
"reflect"
"sync"

"go-hep.org/x/hep/fmom"
"go-hep.org/x/hep/fwk"
"golang.org/x/exp/rand"
"gonum.org/v1/gonum/stat/distuv"
)

Expand Down Expand Up @@ -74,7 +74,7 @@ func (tsk *BTagging) Configure(ctx fwk.Context) error {
return err
}

tsk.src = rand.New(rand.NewSource(tsk.seed))
tsk.src = rand.New(rand.NewPCG(tsk.seed, tsk.seed))
tsk.flat = distuv.Uniform{Min: 0, Max: 1, Src: tsk.src}
return err
}
Expand Down
4 changes: 2 additions & 2 deletions fads/calo.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ package fads
import (
"fmt"
"math"
"math/rand/v2"
"reflect"
"sort"
"sync"

"go-hep.org/x/hep/fwk"
"golang.org/x/exp/rand"
"gonum.org/v1/gonum/stat/distuv"
)

Expand Down Expand Up @@ -206,7 +206,7 @@ func (tsk *Calorimeter) Configure(ctx fwk.Context) error {
return err
}

tsk.src = rand.New(rand.NewSource(tsk.seed))
tsk.src = rand.New(rand.NewPCG(tsk.seed, tsk.seed))
tsk.gauss = distuv.Normal{Mu: 0, Sigma: 1, Src: tsk.src}
return err
}
Expand Down
4 changes: 2 additions & 2 deletions fads/efficiency.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
package fads

import (
"math/rand/v2"
"reflect"
"sync"

"go-hep.org/x/hep/fwk"
"golang.org/x/exp/rand"
"gonum.org/v1/gonum/stat/distuv"
)

Expand Down Expand Up @@ -42,7 +42,7 @@ func (tsk *Efficiency) Configure(ctx fwk.Context) error {

func (tsk *Efficiency) StartTask(ctx fwk.Context) error {
var err error
src := rand.New(rand.NewSource(tsk.seed))
src := rand.New(rand.NewPCG(tsk.seed, tsk.seed))
tsk.dist = distuv.Uniform{Min: 0, Max: 1, Src: src}
return err
}
Expand Down
4 changes: 2 additions & 2 deletions fads/energy_smearing.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ package fads

import (
"math"
"math/rand/v2"
"reflect"
"sync"

"go-hep.org/x/hep/fmom"
"go-hep.org/x/hep/fwk"
"golang.org/x/exp/rand"
"gonum.org/v1/gonum/stat/distuv"
)

Expand Down Expand Up @@ -45,7 +45,7 @@ func (tsk *EnergySmearing) Configure(ctx fwk.Context) error {

func (tsk *EnergySmearing) StartTask(ctx fwk.Context) error {
var err error
tsk.src = rand.New(rand.NewSource(tsk.seed))
tsk.src = rand.New(rand.NewPCG(tsk.seed, tsk.seed))
return err
}

Expand Down
4 changes: 2 additions & 2 deletions fads/momentum_smearing.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ package fads

import (
"math"
"math/rand/v2"
"reflect"
"sync"

"go-hep.org/x/hep/fmom"
"go-hep.org/x/hep/fwk"
"golang.org/x/exp/rand"
"gonum.org/v1/gonum/stat/distuv"
)

Expand Down Expand Up @@ -45,7 +45,7 @@ func (tsk *MomentumSmearing) Configure(ctx fwk.Context) error {

func (tsk *MomentumSmearing) StartTask(ctx fwk.Context) error {
var err error
tsk.src = rand.New(rand.NewSource(tsk.seed))
tsk.src = rand.New(rand.NewPCG(tsk.seed, tsk.seed))
return err
}

Expand Down
4 changes: 2 additions & 2 deletions fads/tautagging.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ package fads

import (
"math"
"math/rand/v2"
"reflect"
"sync"

"go-hep.org/x/hep/fmom"
"go-hep.org/x/hep/fwk"
"golang.org/x/exp/rand"
"gonum.org/v1/gonum/stat/distuv"
)

Expand Down Expand Up @@ -90,7 +90,7 @@ func (tsk *TauTagging) Configure(ctx fwk.Context) error {
return err
}

tsk.src = rand.New(rand.NewSource(tsk.seed))
tsk.src = rand.New(rand.NewPCG(tsk.seed, tsk.seed))
tsk.flat = distuv.Uniform{Min: 0, Max: 1, Src: tsk.src}
return err
}
Expand Down
5 changes: 2 additions & 3 deletions fit/curve_nd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
package fit_test

import (
"math/rand/v2"
"testing"

"golang.org/x/exp/rand"
)

func TestCurve2D(t *testing.T) {
Expand All @@ -18,7 +17,7 @@ func genData2D(n0, n1 int, f func(x, ps []float64) float64, ps []float64, x0min,
var (
xdata = make([][]float64, n0*n1)
ydata = make([]float64, n0*n1)
rnd = rand.New(rand.NewSource(1234))
rnd = rand.New(rand.NewPCG(1234, 1234))
x0step = (x0max - x0min) / float64(n0)
x1step = (x1max - x1min) / float64(n1)
p = make([]float64, len(ps))
Expand Down
4 changes: 2 additions & 2 deletions fit/hist_example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ import (
"image/color"
"log"
"math"
"math/rand/v2"

"go-hep.org/x/hep/fit"
"go-hep.org/x/hep/hbook"
"go-hep.org/x/hep/hplot"
"golang.org/x/exp/rand"
"gonum.org/v1/gonum/floats"
"gonum.org/v1/gonum/optimize"
"gonum.org/v1/gonum/stat/distuv"
Expand All @@ -36,7 +36,7 @@ func ExampleH1D_gaussian() {
dist := distuv.Normal{
Mu: mean,
Sigma: sigma,
Src: rand.New(rand.NewSource(0)),
Src: rand.New(rand.NewPCG(0, 0)),
}

// Draw some random values from the standard
Expand Down
4 changes: 2 additions & 2 deletions groot/rhist/hist_example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"bytes"
"fmt"
"log"
"math/rand/v2"
"os"
"testing"

Expand All @@ -18,7 +19,6 @@ import (
"go-hep.org/x/hep/hbook"
"go-hep.org/x/hep/hbook/rootcnv"
"go-hep.org/x/hep/hbook/yodacnv"
"golang.org/x/exp/rand"
"gonum.org/v1/gonum/stat/distuv"
)

Expand All @@ -38,7 +38,7 @@ func ExampleCreate_histo1D() {
dist := distuv.Normal{
Mu: 0,
Sigma: 1,
Src: rand.New(rand.NewSource(0)),
Src: rand.New(rand.NewPCG(0, 0)),
}

// Draw some random values from the standard
Expand Down
4 changes: 2 additions & 2 deletions groot/rtree/writer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package rtree
import (
"compress/flate"
"fmt"
"math/rand/v2"
"os"
"path/filepath"
"reflect"
Expand All @@ -16,7 +17,6 @@ import (
"go-hep.org/x/hep/groot/internal/rcompress"
"go-hep.org/x/hep/groot/rbase"
"go-hep.org/x/hep/groot/riofs"
"golang.org/x/exp/rand"
)

func TestFlattenArrayType(t *testing.T) {
Expand Down Expand Up @@ -143,7 +143,7 @@ func TestConcurrentWrite(t *testing.T) {
}
defer w.Close()

rng := rand.New(rand.NewSource(1234))
rng := rand.New(rand.NewPCG(1234, 1234))
for i := 0; i < 100; i++ {
evt.N = rng.Int31n(10) + 1
evt.Sli = evt.Sli[:0]
Expand Down
4 changes: 2 additions & 2 deletions hbook/h1d_example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ package hbook_test
import (
"fmt"
"math"
"math/rand/v2"

"go-hep.org/x/hep/hbook"
"golang.org/x/exp/rand"
"gonum.org/v1/gonum/stat/distuv"
)

Expand All @@ -20,7 +20,7 @@ func ExampleH1D() {
dist := distuv.Normal{
Mu: 0,
Sigma: 1,
Src: rand.New(rand.NewSource(0)),
Src: rand.New(rand.NewPCG(0, 0)),
}

// Draw some random values from the standard
Expand Down
4 changes: 2 additions & 2 deletions hbook/h2d_example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ package hbook_test

import (
"log"
"math/rand/v2"

"go-hep.org/x/hep/hbook"
"golang.org/x/exp/rand"
"gonum.org/v1/gonum/mat"
"gonum.org/v1/gonum/stat/distmv"
)
Expand All @@ -21,7 +21,7 @@ func ExampleH2D() {
dist, ok := distmv.NewNormal(
[]float64{0, 1},
mat.NewSymDense(2, []float64{4, 0, 0, 2}),
rand.New(rand.NewSource(1234)),
rand.New(rand.NewPCG(1234, 1234)),
)
if !ok {
log.Fatalf("error creating distmv.Normal")
Expand Down
4 changes: 2 additions & 2 deletions hbook/p1d_example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ package hbook_test
import (
"fmt"
"log"
"math/rand/v2"

"go-hep.org/x/hep/hbook"
"golang.org/x/exp/rand"
"gonum.org/v1/gonum/mat"
"gonum.org/v1/gonum/stat/distmv"
)
Expand All @@ -21,7 +21,7 @@ func ExampleP1D() {
dist, ok := distmv.NewNormal(
[]float64{0, 1},
mat.NewSymDense(2, []float64{4, 0, 0, 2}),
rand.New(rand.NewSource(1234)),
rand.New(rand.NewPCG(1234, 1234)),
)
if !ok {
log.Fatalf("error creating distmv.Normal")
Expand Down
2 changes: 1 addition & 1 deletion hbook/rand_h1d.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
package hbook

import (
"math/rand/v2"
"sort"

"golang.org/x/exp/rand"
"gonum.org/v1/gonum/stat/distuv"
)

Expand Down Expand Up @@ -44,7 +44,7 @@
bins[n].Range.Max = bins[n-1].Range.Max + bins[n-1].Range.Width()

return Rand1D{
y: &distuv.Uniform{Min: 0, Max: 1, Src: src},

Check failure on line 47 in hbook/rand_h1d.go

View workflow job for this annotation

GitHub Actions / Build (1.23.x, ubuntu-20.04)

cannot use src (variable of type "math/rand/v2".Source) as "golang.org/x/exp/rand".Source value in struct literal: "math/rand/v2".Source does not implement "golang.org/x/exp/rand".Source (missing method Seed)

Check failure on line 47 in hbook/rand_h1d.go

View workflow job for this annotation

GitHub Actions / Build (1.23.x, macos-latest)

cannot use src (variable of type "math/rand/v2".Source) as "golang.org/x/exp/rand".Source value in struct literal: "math/rand/v2".Source does not implement "golang.org/x/exp/rand".Source (missing method Seed)

Check failure on line 47 in hbook/rand_h1d.go

View workflow job for this annotation

GitHub Actions / Build (1.22.x, ubuntu-20.04)

cannot use src (variable of type "math/rand/v2".Source) as "golang.org/x/exp/rand".Source value in struct literal: "math/rand/v2".Source does not implement "golang.org/x/exp/rand".Source (missing method Seed)

Check failure on line 47 in hbook/rand_h1d.go

View workflow job for this annotation

GitHub Actions / Build (1.22.x, macos-latest)

cannot use src (variable of type "math/rand/v2".Source) as "golang.org/x/exp/rand".Source value in struct literal: "math/rand/v2".Source does not implement "golang.org/x/exp/rand".Source (missing method Seed)
bins: bins,
cdf: cdf,
}
Expand Down
6 changes: 3 additions & 3 deletions hbook/rand_h1d_example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ import (
"fmt"
"image/color"
"log"
"math/rand/v2"
"os"
"path"
"testing"

"go-hep.org/x/hep/hbook"
"go-hep.org/x/hep/hplot"
"golang.org/x/exp/rand"
"gonum.org/v1/gonum/stat/distuv"
"gonum.org/v1/plot/cmpimg"
"gonum.org/v1/plot/vg"
Expand All @@ -24,7 +24,7 @@ func ExampleRand1D() {
const N = 10000
var (
h1 = hbook.NewH1D(100, -10, 10)
src = rand.New(rand.NewSource(1234))
src = rand.New(rand.NewPCG(1234, 1234))
rnd = distuv.Normal{
Mu: 0,
Sigma: 2,
Expand All @@ -38,7 +38,7 @@ func ExampleRand1D() {

var (
h2 = hbook.NewH1D(100, -10, 10)
hr = hbook.NewRand1D(h1, rand.NewSource(5678))
hr = hbook.NewRand1D(h1, rand.NewPCG(5678, 5678))
)

for i := 0; i < N; i++ {
Expand Down
4 changes: 2 additions & 2 deletions hbook/rand_h1d_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
package hbook

import (
"math/rand/v2"
"reflect"
"testing"

"github.com/google/go-cmp/cmp"
"golang.org/x/exp/rand"
)

func TestRand1D(t *testing.T) {
Expand All @@ -22,7 +22,7 @@ func TestRand1D(t *testing.T) {
3, 3, 3, 3, 3,
}, nil)

hr := NewRand1D(h1, rand.NewSource(1234))
hr := NewRand1D(h1, rand.NewPCG(1234, 1234))
h2 := NewH1DFromEdges(edges)

if got, want := hr.cdf, []float64{0, 0.1, 0.4, 0.5, 1}; !reflect.DeepEqual(got, want) {
Expand Down
4 changes: 2 additions & 2 deletions hbook/rootcnv/root_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"bytes"
"fmt"
"log"
"math/rand/v2"
"reflect"
"runtime"
"testing"
Expand All @@ -19,7 +20,6 @@ import (
"go-hep.org/x/hep/hbook"
"go-hep.org/x/hep/hbook/rootcnv"
"go-hep.org/x/hep/hbook/yodacnv"
"golang.org/x/exp/rand"
"gonum.org/v1/gonum/stat/distuv"
)

Expand Down Expand Up @@ -383,7 +383,7 @@ func TestFromH1D(t *testing.T) {
dist := distuv.Normal{
Mu: 0,
Sigma: 1,
Src: rand.New(rand.NewSource(0)),
Src: rand.New(rand.NewPCG(0, 0)),
}

// Draw some random values from the standard
Expand Down
4 changes: 2 additions & 2 deletions hplot/band_example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import (
"image/color"
"log"
"math"
"math/rand/v2"

"go-hep.org/x/hep/hplot"
"golang.org/x/exp/rand"
"gonum.org/v1/gonum/stat/distuv"
"gonum.org/v1/plot/plotter"
"gonum.org/v1/plot/vg"
Expand All @@ -28,7 +28,7 @@ func ExampleBand() {
dist := distuv.Normal{
Mu: 0,
Sigma: 1,
Src: rand.New(rand.NewSource(0)),
Src: rand.New(rand.NewPCG(0, 0)),
}

topData := make(plotter.XYs, npoints)
Expand Down
Loading
Loading