all: replace internal rand shim with math/rand/v2

This commit is contained in:
Dan Kortschak
2025-01-02 12:07:22 +10:30
parent cf3307fa63
commit bc349ecfab
345 changed files with 1165 additions and 1214 deletions
+2 -3
View File
@@ -5,13 +5,12 @@
package gonum
import (
"math/rand/v2"
"testing"
"gonum.org/v1/gonum/internal/rand"
)
func benchmarkZdscal(b *testing.B, n, inc int) {
rnd := rand.New(rand.NewSource(1))
rnd := rand.New(rand.NewPCG(1, 1))
alpha := rnd.NormFloat64()
x := make([]complex128, (n-1)*inc+1)
for i := range x {
+1 -1
View File
@@ -7,10 +7,10 @@
package gonum
import (
"math/rand/v2"
"testing"
"gonum.org/v1/gonum/blas"
"gonum.org/v1/gonum/internal/rand"
)
const (
+2 -2
View File
@@ -6,10 +6,10 @@ package gonum
import (
"fmt"
"math/rand/v2"
"testing"
"gonum.org/v1/gonum/blas"
"gonum.org/v1/gonum/internal/rand"
)
var benchSinkZ []complex128
@@ -26,7 +26,7 @@ func BenchmarkZher(b *testing.B) {
func benchmarkZher(b *testing.B, uplo blas.Uplo, n, inc int) {
b.Run(fmt.Sprintf("Uplo%d-N%d-Inc%d", uplo, n, inc), func(b *testing.B) {
rnd := rand.New(rand.NewSource(1))
rnd := rand.New(rand.NewPCG(1, 1))
alpha := rnd.NormFloat64()
x := make([]complex128, (n-1)*inc+1)
for i := range x {
+2 -2
View File
@@ -5,15 +5,15 @@
package gonum
import (
"math/rand/v2"
"testing"
"gonum.org/v1/gonum/blas"
"gonum.org/v1/gonum/floats"
"gonum.org/v1/gonum/internal/rand"
)
func TestDgemmParallel(t *testing.T) {
rnd := rand.New(rand.NewSource(1))
rnd := rand.New(rand.NewPCG(1, 1))
for i, test := range []struct {
m int
n int
@@ -22,10 +22,10 @@ var copyrightnotice = []byte(`// Copyright ©2014 The Gonum Authors. All rights
var autogen = []byte("// Code generated by \"go run $GOPATH/src/gonum.org/v1/gonum/blas/testblas/benchautogen/autogen_bench_level1double.go\"; DO NOT EDIT.\n")
var imports = []byte(`import(
"math/rand/v2"
"testing"
"gonum.org/v1/gonum/blas"
"gonum.org/v1/gonum/internal/rand"
)`)
var randomSliceFunction = []byte(`func randomSlice(l, idx int) ([]float64) {
+1 -1
View File
@@ -7,11 +7,11 @@ package testblas
import (
"math"
"math/cmplx"
"math/rand/v2"
"testing"
"gonum.org/v1/gonum/blas"
"gonum.org/v1/gonum/floats/scalar"
"gonum.org/v1/gonum/internal/rand"
)
// throwPanic will throw unexpected panics if true, or will just report them as errors if false
+2 -2
View File
@@ -7,11 +7,11 @@ package testblas
import (
"math"
"math/cmplx"
"math/rand/v2"
"testing"
"gonum.org/v1/gonum/blas"
"gonum.org/v1/gonum/floats"
"gonum.org/v1/gonum/internal/rand"
)
func TestFlattenBanded(t *testing.T) {
@@ -193,7 +193,7 @@ func TestFlattenTriangular(t *testing.T) {
}
func TestPackUnpackAsHermitian(t *testing.T) {
rnd := rand.New(rand.NewSource(1))
rnd := rand.New(rand.NewPCG(1, 1))
for _, uplo := range []blas.Uplo{blas.Upper, blas.Lower} {
for _, n := range []int{1, 2, 5, 50} {
for _, lda := range []int{max(1, n), n + 11} {
+1 -1
View File
@@ -5,10 +5,10 @@
package testblas
import (
"math/rand/v2"
"testing"
"gonum.org/v1/gonum/blas"
"gonum.org/v1/gonum/internal/rand"
)
func DgemmBenchmark(b *testing.B, dgemm Dgemmer, m, n, k int, tA, tB blas.Transpose) {
+2 -2
View File
@@ -5,14 +5,14 @@
package testblas
import (
"math/rand/v2"
"testing"
"gonum.org/v1/gonum/blas"
"gonum.org/v1/gonum/internal/rand"
)
func DtrmvBenchmark(b *testing.B, dtrmv Dtrmver, n, lda, incX int, ul blas.Uplo, tA blas.Transpose, d blas.Diag) {
rnd := rand.New(rand.NewSource(0))
rnd := rand.New(rand.NewPCG(0, 0))
a := make([]float64, n*lda)
for i := range a {
a[i] = rnd.Float64()
+2 -2
View File
@@ -5,11 +5,11 @@
package testblas
import (
"math/rand/v2"
"testing"
"gonum.org/v1/gonum/blas"
"gonum.org/v1/gonum/floats"
"gonum.org/v1/gonum/internal/rand"
)
type Dtrsmer interface {
@@ -18,7 +18,7 @@ type Dtrsmer interface {
}
func DtrsmTest(t *testing.T, impl Dtrsmer) {
rnd := rand.New(rand.NewSource(1))
rnd := rand.New(rand.NewPCG(1, 1))
for i, test := range []struct {
s blas.Side
ul blas.Uplo
+4 -4
View File
@@ -5,10 +5,10 @@
package testblas
import (
"math/rand/v2"
"testing"
"gonum.org/v1/gonum/floats/scalar"
"gonum.org/v1/gonum/internal/rand"
)
type Dzasumer interface {
@@ -17,7 +17,7 @@ type Dzasumer interface {
func DzasumTest(t *testing.T, impl Dzasumer) {
const tol = 1e-14
rnd := rand.New(rand.NewSource(1))
rnd := rand.New(rand.NewPCG(1, 1))
for _, n := range []int{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 50, 100} {
for _, incX := range []int{-5, 1, 2, 10} {
aincX := abs(incX)
@@ -30,11 +30,11 @@ func DzasumTest(t *testing.T, impl Dzasumer) {
}
for i := 0; i < n; i++ {
re := float64(2*i + 1)
if rnd.Intn(2) == 0 {
if rnd.IntN(2) == 0 {
re *= -1
}
im := float64(2 * (i + 1))
if rnd.Intn(2) == 0 {
if rnd.IntN(2) == 0 {
im *= -1
}
x[i*aincX] = complex(re, im)
+2 -2
View File
@@ -7,10 +7,10 @@ package testblas
import (
"fmt"
"math"
"math/rand/v2"
"testing"
"gonum.org/v1/gonum/floats/scalar"
"gonum.org/v1/gonum/internal/rand"
)
type Dznrm2er interface {
@@ -105,7 +105,7 @@ func Dznrm2Test(t *testing.T, impl Dznrm2er) {
}
tol = 1e-14
rnd := rand.New(rand.NewSource(1))
rnd := rand.New(rand.NewPCG(1, 1))
for _, n := range []int{10, 50, 100} {
for _, incX := range []int{1, 2, 10} {
re := make([]float64, n)
+3 -4
View File
@@ -5,9 +5,8 @@
package testblas
import (
"math/rand/v2"
"testing"
"gonum.org/v1/gonum/internal/rand"
)
type Izamaxer interface {
@@ -15,7 +14,7 @@ type Izamaxer interface {
}
func IzamaxTest(t *testing.T, impl Izamaxer) {
rnd := rand.New(rand.NewSource(1))
rnd := rand.New(rand.NewPCG(1, 1))
for _, n := range []int{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 50, 100} {
for _, incX := range []int{-5, 1, 2, 10} {
aincX := abs(incX)
@@ -34,7 +33,7 @@ func IzamaxTest(t *testing.T, impl Izamaxer) {
want := -1
if incX > 0 && n > 0 {
want = rnd.Intn(n)
want = rnd.IntN(n)
x[want*incX] = 10 + 10i
}
got := impl.Izamax(n, x, incX)
+1 -1
View File
@@ -5,10 +5,10 @@
package testblas
import (
"math/rand/v2"
"testing"
"gonum.org/v1/gonum/blas"
"gonum.org/v1/gonum/internal/rand"
)
func DgemvBenchmark(b *testing.B, impl Dgemver, tA blas.Transpose, m, n, incX, incY int) {
+2 -3
View File
@@ -6,9 +6,8 @@ package testblas
import (
"fmt"
"math/rand/v2"
"testing"
"gonum.org/v1/gonum/internal/rand"
)
type Zcopyer interface {
@@ -16,7 +15,7 @@ type Zcopyer interface {
}
func ZcopyTest(t *testing.T, impl Zcopyer) {
rnd := rand.New(rand.NewSource(1))
rnd := rand.New(rand.NewPCG(1, 1))
for n := 0; n <= 20; n++ {
for _, inc := range allPairs([]int{-7, -3, 1, 13}, []int{-11, -5, 1, 17}) {
incX := inc[0]
+2 -2
View File
@@ -6,10 +6,10 @@ package testblas
import (
"fmt"
"math/rand/v2"
"testing"
"gonum.org/v1/gonum/blas"
"gonum.org/v1/gonum/internal/rand"
)
type Zgbmver interface {
@@ -19,7 +19,7 @@ type Zgbmver interface {
}
func ZgbmvTest(t *testing.T, impl Zgbmver) {
rnd := rand.New(rand.NewSource(1))
rnd := rand.New(rand.NewPCG(1, 1))
for _, trans := range []blas.Transpose{blas.NoTrans, blas.Trans, blas.ConjTrans} {
// Generate all possible size combinations.
for _, mn := range allPairs([]int{1, 2, 3, 5}, []int{1, 2, 3, 5}) {
+2 -2
View File
@@ -6,10 +6,10 @@ package testblas
import (
"fmt"
"math/rand/v2"
"testing"
"gonum.org/v1/gonum/blas"
"gonum.org/v1/gonum/internal/rand"
)
type Zgemmer interface {
@@ -36,7 +36,7 @@ func ZgemmTest(t *testing.T, impl Zgemmer) {
func zgemmTest(t *testing.T, impl Zgemmer, tA, tB blas.Transpose, m, n, k int) {
const tol = 1e-13
rnd := rand.New(rand.NewSource(1))
rnd := rand.New(rand.NewPCG(1, 1))
rowA, colA := m, k
if tA != blas.NoTrans {
+2 -2
View File
@@ -7,10 +7,10 @@ package testblas
import (
"fmt"
"math"
"math/rand/v2"
"testing"
"gonum.org/v1/gonum/blas"
"gonum.org/v1/gonum/internal/rand"
)
type Zhbmver interface {
@@ -20,7 +20,7 @@ type Zhbmver interface {
}
func ZhbmvTest(t *testing.T, impl Zhbmver) {
rnd := rand.New(rand.NewSource(1))
rnd := rand.New(rand.NewPCG(1, 1))
for _, uplo := range []blas.Uplo{blas.Upper, blas.Lower} {
for _, n := range []int{0, 1, 2, 3, 5} {
for k := 0; k < n; k++ {
+2 -2
View File
@@ -7,10 +7,10 @@ package testblas
import (
"fmt"
"math/cmplx"
"math/rand/v2"
"testing"
"gonum.org/v1/gonum/blas"
"gonum.org/v1/gonum/internal/rand"
)
type Zhemmer interface {
@@ -35,7 +35,7 @@ func ZhemmTest(t *testing.T, impl Zhemmer) {
func zhemmTest(t *testing.T, impl Zhemmer, side blas.Side, uplo blas.Uplo, m, n int) {
const tol = 1e-13
rnd := rand.New(rand.NewSource(1))
rnd := rand.New(rand.NewPCG(1, 1))
nA := m
if side == blas.Right {
+2 -2
View File
@@ -7,10 +7,10 @@ package testblas
import (
"fmt"
"math/cmplx"
"math/rand/v2"
"testing"
"gonum.org/v1/gonum/blas"
"gonum.org/v1/gonum/internal/rand"
)
type Zher2ker interface {
@@ -35,7 +35,7 @@ func Zher2kTest(t *testing.T, impl Zher2ker) {
func zher2kTest(t *testing.T, impl Zher2ker, uplo blas.Uplo, trans blas.Transpose, n, k int) {
const tol = 1e-13
rnd := rand.New(rand.NewSource(1))
rnd := rand.New(rand.NewPCG(1, 1))
row, col := n, k
if trans == blas.ConjTrans {
+2 -2
View File
@@ -7,10 +7,10 @@ package testblas
import (
"fmt"
"math/cmplx"
"math/rand/v2"
"testing"
"gonum.org/v1/gonum/blas"
"gonum.org/v1/gonum/internal/rand"
)
type Zherker interface {
@@ -35,7 +35,7 @@ func ZherkTest(t *testing.T, impl Zherker) {
func zherkTest(t *testing.T, impl Zherker, uplo blas.Uplo, trans blas.Transpose, n, k int) {
const tol = 1e-13
rnd := rand.New(rand.NewSource(1))
rnd := rand.New(rand.NewPCG(1, 1))
rowA, colA := n, k
if trans == blas.ConjTrans {
+2 -3
View File
@@ -6,9 +6,8 @@ package testblas
import (
"fmt"
"math/rand/v2"
"testing"
"gonum.org/v1/gonum/internal/rand"
)
type Zswaper interface {
@@ -16,7 +15,7 @@ type Zswaper interface {
}
func ZswapTest(t *testing.T, impl Zswaper) {
rnd := rand.New(rand.NewSource(1))
rnd := rand.New(rand.NewPCG(1, 1))
for n := 0; n < 20; n++ {
for _, inc := range allPairs([]int{-5, -1, 1, 2, 5, 10}, []int{-3, -1, 1, 3, 7, 12}) {
incX := inc[0]
+2 -2
View File
@@ -7,10 +7,10 @@ package testblas
import (
"fmt"
"math/cmplx"
"math/rand/v2"
"testing"
"gonum.org/v1/gonum/blas"
"gonum.org/v1/gonum/internal/rand"
)
type Zsymmer interface {
@@ -35,7 +35,7 @@ func ZsymmTest(t *testing.T, impl Zsymmer) {
func zsymmTest(t *testing.T, impl Zsymmer, side blas.Side, uplo blas.Uplo, m, n int) {
const tol = 1e-13
rnd := rand.New(rand.NewSource(1))
rnd := rand.New(rand.NewPCG(1, 1))
nA := m
if side == blas.Right {
+2 -2
View File
@@ -6,10 +6,10 @@ package testblas
import (
"fmt"
"math/rand/v2"
"testing"
"gonum.org/v1/gonum/blas"
"gonum.org/v1/gonum/internal/rand"
)
type Zsyr2ker interface {
@@ -34,7 +34,7 @@ func Zsyr2kTest(t *testing.T, impl Zsyr2ker) {
func zsyr2kTest(t *testing.T, impl Zsyr2ker, uplo blas.Uplo, trans blas.Transpose, n, k int) {
const tol = 1e-13
rnd := rand.New(rand.NewSource(1))
rnd := rand.New(rand.NewPCG(1, 1))
row, col := n, k
if trans == blas.Trans {
+2 -2
View File
@@ -7,10 +7,10 @@ package testblas
import (
"fmt"
"math/cmplx"
"math/rand/v2"
"testing"
"gonum.org/v1/gonum/blas"
"gonum.org/v1/gonum/internal/rand"
)
type Zsyrker interface {
@@ -35,7 +35,7 @@ func ZsyrkTest(t *testing.T, impl Zsyrker) {
func zsyrkTest(t *testing.T, impl Zsyrker, uplo blas.Uplo, trans blas.Transpose, n, k int) {
const tol = 1e-13
rnd := rand.New(rand.NewSource(1))
rnd := rand.New(rand.NewPCG(1, 1))
rowA, colA := n, k
if trans == blas.Trans {
+2 -2
View File
@@ -6,10 +6,10 @@ package testblas
import (
"fmt"
"math/rand/v2"
"testing"
"gonum.org/v1/gonum/blas"
"gonum.org/v1/gonum/internal/rand"
)
type Ztbmver interface {
@@ -19,7 +19,7 @@ type Ztbmver interface {
}
func ZtbmvTest(t *testing.T, impl Ztbmver) {
rnd := rand.New(rand.NewSource(1))
rnd := rand.New(rand.NewPCG(1, 1))
for _, uplo := range []blas.Uplo{blas.Upper, blas.Lower} {
for _, trans := range []blas.Transpose{blas.NoTrans, blas.Trans, blas.ConjTrans} {
for _, diag := range []blas.Diag{blas.NonUnit, blas.Unit} {
+2 -2
View File
@@ -6,10 +6,10 @@ package testblas
import (
"fmt"
"math/rand/v2"
"testing"
"gonum.org/v1/gonum/blas"
"gonum.org/v1/gonum/internal/rand"
)
type Ztbsver interface {
@@ -19,7 +19,7 @@ type Ztbsver interface {
}
func ZtbsvTest(t *testing.T, impl Ztbsver) {
rnd := rand.New(rand.NewSource(1))
rnd := rand.New(rand.NewPCG(1, 1))
for _, uplo := range []blas.Uplo{blas.Upper, blas.Lower} {
for _, trans := range []blas.Transpose{blas.NoTrans, blas.Trans, blas.ConjTrans} {
for _, diag := range []blas.Diag{blas.NonUnit, blas.Unit} {
+2 -2
View File
@@ -6,10 +6,10 @@ package testblas
import (
"fmt"
"math/rand/v2"
"testing"
"gonum.org/v1/gonum/blas"
"gonum.org/v1/gonum/internal/rand"
)
type Ztpsver interface {
@@ -19,7 +19,7 @@ type Ztpsver interface {
}
func ZtpsvTest(t *testing.T, impl Ztpsver) {
rnd := rand.New(rand.NewSource(1))
rnd := rand.New(rand.NewPCG(1, 1))
for _, uplo := range []blas.Uplo{blas.Upper, blas.Lower} {
for _, trans := range []blas.Transpose{blas.NoTrans, blas.Trans, blas.ConjTrans} {
for _, diag := range []blas.Diag{blas.NonUnit, blas.Unit} {
+2 -2
View File
@@ -6,10 +6,10 @@ package testblas
import (
"fmt"
"math/rand/v2"
"testing"
"gonum.org/v1/gonum/blas"
"gonum.org/v1/gonum/internal/rand"
)
type Ztrmmer interface {
@@ -38,7 +38,7 @@ func ZtrmmTest(t *testing.T, impl Ztrmmer) {
func ztrmmTest(t *testing.T, impl Ztrmmer, side blas.Side, uplo blas.Uplo, trans blas.Transpose, diag blas.Diag, m, n int) {
const tol = 1e-13
rnd := rand.New(rand.NewSource(1))
rnd := rand.New(rand.NewPCG(1, 1))
nA := m
if side == blas.Right {
+2 -2
View File
@@ -6,10 +6,10 @@ package testblas
import (
"fmt"
"math/rand/v2"
"testing"
"gonum.org/v1/gonum/blas"
"gonum.org/v1/gonum/internal/rand"
)
type Ztrsmer interface {
@@ -38,7 +38,7 @@ func ZtrsmTest(t *testing.T, impl Ztrsmer) {
func ztrsmTest(t *testing.T, impl Ztrsmer, side blas.Side, uplo blas.Uplo, trans blas.Transpose, diag blas.Diag, m, n int) {
const tol = 1e-12
rnd := rand.New(rand.NewSource(1))
rnd := rand.New(rand.NewPCG(1, 1))
nA := m
if side == blas.Right {
+2 -2
View File
@@ -6,10 +6,10 @@ package testblas
import (
"fmt"
"math/rand/v2"
"testing"
"gonum.org/v1/gonum/blas"
"gonum.org/v1/gonum/internal/rand"
)
type Ztrsver interface {
@@ -19,7 +19,7 @@ type Ztrsver interface {
}
func ZtrsvTest(t *testing.T, impl Ztrsver) {
rnd := rand.New(rand.NewSource(1))
rnd := rand.New(rand.NewPCG(1, 1))
for _, uplo := range []blas.Uplo{blas.Upper, blas.Lower} {
for _, trans := range []blas.Transpose{blas.NoTrans, blas.Trans, blas.ConjTrans} {
for _, diag := range []blas.Diag{blas.NonUnit, blas.Unit} {
+14 -14
View File
@@ -8,12 +8,12 @@ import (
"fmt"
"math"
"math/cmplx"
"math/rand/v2"
"strconv"
"testing"
"gonum.org/v1/gonum/cmplxs/cscalar"
"gonum.org/v1/gonum/floats"
"gonum.org/v1/gonum/internal/rand"
)
const (
@@ -1201,7 +1201,7 @@ func randomSlice(l int, src rand.Source) []complex128 {
}
func benchmarkAdd(b *testing.B, size int) {
src := rand.NewSource(1)
src := rand.NewPCG(1, 1)
s1 := randomSlice(size, src)
s2 := randomSlice(size, src)
b.ResetTimer()
@@ -1215,7 +1215,7 @@ func BenchmarkAddLarge(b *testing.B) { benchmarkAdd(b, Large) }
func BenchmarkAddHuge(b *testing.B) { benchmarkAdd(b, Huge) }
func benchmarkAddTo(b *testing.B, size int) {
src := rand.NewSource(1)
src := rand.NewPCG(1, 1)
s1 := randomSlice(size, src)
s2 := randomSlice(size, src)
dst := randomSlice(size, src)
@@ -1230,7 +1230,7 @@ func BenchmarkAddToLarge(b *testing.B) { benchmarkAddTo(b, Large) }
func BenchmarkAddToHuge(b *testing.B) { benchmarkAddTo(b, Huge) }
func benchmarkCumProd(b *testing.B, size int) {
src := rand.NewSource(1)
src := rand.NewPCG(1, 1)
s := randomSlice(size, src)
dst := randomSlice(size, src)
b.ResetTimer()
@@ -1244,7 +1244,7 @@ func BenchmarkCumProdLarge(b *testing.B) { benchmarkCumProd(b, Large) }
func BenchmarkCumProdHuge(b *testing.B) { benchmarkCumProd(b, Huge) }
func benchmarkCumSum(b *testing.B, size int) {
src := rand.NewSource(1)
src := rand.NewPCG(1, 1)
s := randomSlice(size, src)
dst := randomSlice(size, src)
b.ResetTimer()
@@ -1258,7 +1258,7 @@ func BenchmarkCumSumLarge(b *testing.B) { benchmarkCumSum(b, Large) }
func BenchmarkCumSumHuge(b *testing.B) { benchmarkCumSum(b, Huge) }
func benchmarkDiv(b *testing.B, size int) {
src := rand.NewSource(1)
src := rand.NewPCG(1, 1)
s := randomSlice(size, src)
dst := randomSlice(size, src)
b.ResetTimer()
@@ -1272,7 +1272,7 @@ func BenchmarkDivLarge(b *testing.B) { benchmarkDiv(b, Large) }
func BenchmarkDivHuge(b *testing.B) { benchmarkDiv(b, Huge) }
func benchmarkDivTo(b *testing.B, size int) {
src := rand.NewSource(1)
src := rand.NewPCG(1, 1)
s1 := randomSlice(size, src)
s2 := randomSlice(size, src)
dst := randomSlice(size, src)
@@ -1287,7 +1287,7 @@ func BenchmarkDivToLarge(b *testing.B) { benchmarkDivTo(b, Large) }
func BenchmarkDivToHuge(b *testing.B) { benchmarkDivTo(b, Huge) }
func benchmarkSub(b *testing.B, size int) {
src := rand.NewSource(1)
src := rand.NewPCG(1, 1)
s1 := randomSlice(size, src)
s2 := randomSlice(size, src)
b.ResetTimer()
@@ -1301,7 +1301,7 @@ func BenchmarkSubLarge(b *testing.B) { benchmarkSub(b, Large) }
func BenchmarkSubHuge(b *testing.B) { benchmarkSub(b, Huge) }
func benchmarkSubTo(b *testing.B, size int) {
src := rand.NewSource(1)
src := rand.NewPCG(1, 1)
s1 := randomSlice(size, src)
s2 := randomSlice(size, src)
dst := randomSlice(size, src)
@@ -1316,7 +1316,7 @@ func BenchmarkSubToLarge(b *testing.B) { benchmarkSubTo(b, Large) }
func BenchmarkSubToHuge(b *testing.B) { benchmarkSubTo(b, Huge) }
func benchmarkDot(b *testing.B, size int) {
src := rand.NewSource(1)
src := rand.NewPCG(1, 1)
s1 := randomSlice(size, src)
s2 := randomSlice(size, src)
b.ResetTimer()
@@ -1330,7 +1330,7 @@ func BenchmarkDotLarge(b *testing.B) { benchmarkDot(b, Large) }
func BenchmarkDotHuge(b *testing.B) { benchmarkDot(b, Huge) }
func benchmarkAddScaledTo(b *testing.B, size int) {
src := rand.NewSource(1)
src := rand.NewPCG(1, 1)
dst := randomSlice(size, src)
y := randomSlice(size, src)
s := randomSlice(size, src)
@@ -1345,7 +1345,7 @@ func BenchmarkAddScaledToLarge(b *testing.B) { benchmarkAddScaledTo(b, Large) }
func BenchmarkAddScaledToHuge(b *testing.B) { benchmarkAddScaledTo(b, Huge) }
func benchmarkScale(b *testing.B, size int) {
src := rand.NewSource(1)
src := rand.NewPCG(1, 1)
dst := randomSlice(size, src)
b.ResetTimer()
for i := 0; i < b.N; i += 2 {
@@ -1359,7 +1359,7 @@ func BenchmarkScaleLarge(b *testing.B) { benchmarkScale(b, Large) }
func BenchmarkScaleHuge(b *testing.B) { benchmarkScale(b, Huge) }
func benchmarkNorm2(b *testing.B, size int) {
src := rand.NewSource(1)
src := rand.NewPCG(1, 1)
s := randomSlice(size, src)
b.ResetTimer()
for i := 0; i < b.N; i++ {
@@ -1372,7 +1372,7 @@ func BenchmarkNorm2Large(b *testing.B) { benchmarkNorm2(b, Large) }
func BenchmarkNorm2Huge(b *testing.B) { benchmarkNorm2(b, Huge) }
func benchmarkReverse(b *testing.B, size int) {
src := rand.NewSource(1)
src := rand.NewPCG(1, 1)
s := randomSlice(size, src)
b.ResetTimer()
for i := 0; i < b.N; i++ {
+2 -2
View File
@@ -6,10 +6,10 @@ package fd
import (
"math"
"math/rand/v2"
"testing"
"gonum.org/v1/gonum/floats"
"gonum.org/v1/gonum/internal/rand"
)
type Rosenbrock struct {
@@ -42,7 +42,7 @@ func (r Rosenbrock) FDf(x []float64, deriv []float64) (sum float64) {
func TestGradient(t *testing.T) {
t.Parallel()
rnd := rand.New(rand.NewSource(1))
rnd := rand.New(rand.NewPCG(1, 1))
for i, test := range []struct {
nDim int
tol float64
+2 -2
View File
@@ -6,10 +6,10 @@ package fd
import (
"math"
"math/rand/v2"
"testing"
"gonum.org/v1/gonum/floats"
"gonum.org/v1/gonum/internal/rand"
"gonum.org/v1/gonum/mat"
)
@@ -56,7 +56,7 @@ func vecFunc43Jac(jac *mat.Dense, x []float64) {
func TestJacobian(t *testing.T) {
t.Parallel()
rnd := rand.New(rand.NewSource(1))
rnd := rand.New(rand.NewPCG(1, 1))
// Test with default settings.
for tc, test := range []struct {
+10 -10
View File
@@ -6,17 +6,17 @@ package fourier
import (
"fmt"
"math/rand/v2"
"reflect"
"testing"
"gonum.org/v1/gonum/floats"
"gonum.org/v1/gonum/internal/rand"
)
func TestFFT(t *testing.T) {
t.Parallel()
const tol = 1e-10
rnd := rand.New(rand.NewSource(1))
rnd := rand.New(rand.NewPCG(1, 1))
t.Run("NewFFT", func(t *testing.T) {
for n := 1; n <= 200; n++ {
fft := NewFFT(n)
@@ -122,7 +122,7 @@ func TestFFT(t *testing.T) {
func TestCmplxFFT(t *testing.T) {
const tol = 1e-12
rnd := rand.New(rand.NewSource(1))
rnd := rand.New(rand.NewPCG(1, 1))
t.Run("NewFFT", func(t *testing.T) {
for n := 1; n <= 200; n++ {
fft := NewCmplxFFT(n)
@@ -220,7 +220,7 @@ func TestCmplxFFT(t *testing.T) {
func TestDCT(t *testing.T) {
t.Parallel()
const tol = 1e-10
rnd := rand.New(rand.NewSource(1))
rnd := rand.New(rand.NewPCG(1, 1))
t.Run("NewDCT", func(t *testing.T) {
for n := 2; n <= 200; n++ {
dct := NewDCT(n)
@@ -263,7 +263,7 @@ func TestDCT(t *testing.T) {
func TestDST(t *testing.T) {
t.Parallel()
const tol = 1e-10
rnd := rand.New(rand.NewSource(1))
rnd := rand.New(rand.NewPCG(1, 1))
t.Run("NewDST", func(t *testing.T) {
for n := 1; n <= 200; n++ {
dst := NewDST(n)
@@ -306,7 +306,7 @@ func TestDST(t *testing.T) {
func TestQuarterWaveFFT(t *testing.T) {
t.Parallel()
const tol = 1e-10
rnd := rand.New(rand.NewSource(1))
rnd := rand.New(rand.NewPCG(1, 1))
t.Run("NewQuarterWaveFFT", func(t *testing.T) {
for n := 1; n <= 200; n++ {
qw := NewQuarterWaveFFT(n)
@@ -397,7 +397,7 @@ func BenchmarkRealFFTCoefficients(b *testing.B) {
sizes = append(sizes, 100, 4000, 1e6)
for _, n := range sizes {
fft := NewFFT(n)
seq := randFloats(n, rand.NewSource(1))
seq := randFloats(n, rand.NewPCG(1, 1))
dst := make([]complex128, n/2+1)
b.Run(fmt.Sprint(n), func(b *testing.B) {
@@ -416,7 +416,7 @@ func BenchmarkRealFFTSequence(b *testing.B) {
sizes = append(sizes, 100, 4000, 1e6)
for _, n := range sizes {
fft := NewFFT(n)
coeff := randComplexes(n/2+1, rand.NewSource(1))
coeff := randComplexes(n/2+1, rand.NewPCG(1, 1))
dst := make([]float64, n)
b.Run(fmt.Sprint(n), func(b *testing.B) {
@@ -435,7 +435,7 @@ func BenchmarkCmplxFFTCoefficients(b *testing.B) {
sizes = append(sizes, 100, 4000, 1e6)
for _, n := range sizes {
fft := NewCmplxFFT(n)
d := randComplexes(n, rand.NewSource(1))
d := randComplexes(n, rand.NewPCG(1, 1))
b.Run(fmt.Sprint(n), func(b *testing.B) {
for i := 0; i < b.N; i++ {
@@ -453,7 +453,7 @@ func BenchmarkCmplxFFTSequence(b *testing.B) {
sizes = append(sizes, 100, 4000, 1e6)
for _, n := range sizes {
fft := NewCmplxFFT(n)
d := randComplexes(n, rand.NewSource(1))
d := randComplexes(n, rand.NewPCG(1, 1))
b.Run(fmt.Sprint(n), func(b *testing.B) {
for i := 0; i < b.N; i++ {
+6 -6
View File
@@ -8,19 +8,19 @@ import (
"bytes"
"fmt"
"math/bits"
"math/rand/v2"
"slices"
"strconv"
"testing"
"unsafe"
"gonum.org/v1/gonum/cmplxs"
"gonum.org/v1/gonum/internal/rand"
)
func TestCoefficients(t *testing.T) {
const tol = 1e-8
src := rand.NewSource(1)
src := rand.NewPCG(1, 1)
for n := 4; n < 1<<20; n <<= 1 {
for i := 0; i < 10; i++ {
t.Run(fmt.Sprintf("Radix2/%d", n), func(t *testing.T) {
@@ -73,7 +73,7 @@ func TestCoefficients(t *testing.T) {
func TestSequence(t *testing.T) {
const tol = 1e-10
src := rand.NewSource(1)
src := rand.NewPCG(1, 1)
for n := 4; n < 1<<20; n <<= 1 {
for i := 0; i < 10; i++ {
t.Run(fmt.Sprintf("Radix2/%d", n), func(t *testing.T) {
@@ -185,7 +185,7 @@ func TestBitPairReversePermute(t *testing.T) {
}
func TestReversePairs(t *testing.T) {
rnd := rand.New(rand.NewSource(1))
rnd := rand.New(rand.NewPCG(1, 1))
for i := 0; i < 1000; i++ {
x := uint(rnd.Uint64())
got := reversePairs(x)
@@ -254,7 +254,7 @@ func TestTrimRadix4(t *testing.T) {
func BenchmarkCoefficients(b *testing.B) {
for n := 16; n < 1<<24; n <<= 3 {
d := randComplexes(n, rand.NewSource(1))
d := randComplexes(n, rand.NewPCG(1, 1))
b.Run(fmt.Sprintf("Radix2/%d", n), func(b *testing.B) {
for i := 0; i < b.N; i++ {
CoefficientsRadix2(d)
@@ -273,7 +273,7 @@ func BenchmarkCoefficients(b *testing.B) {
func BenchmarkSequence(b *testing.B) {
for n := 16; n < 1<<24; n <<= 3 {
d := randComplexes(n, rand.NewSource(1))
d := randComplexes(n, rand.NewPCG(1, 1))
b.Run(fmt.Sprintf("Radix2/%d", n), func(b *testing.B) {
for i := 0; i < b.N; i++ {
SequenceRadix2(d)
+18 -18
View File
@@ -7,12 +7,12 @@ package floats
import (
"fmt"
"math"
"math/rand/v2"
"sort"
"strconv"
"testing"
"gonum.org/v1/gonum/floats/scalar"
"gonum.org/v1/gonum/internal/rand"
)
const (
@@ -1609,7 +1609,7 @@ func randomSlice(l int, src rand.Source) []float64 {
}
func benchmarkMin(b *testing.B, size int) {
src := rand.NewSource(1)
src := rand.NewPCG(1, 1)
s := randomSlice(size, src)
b.ResetTimer()
for i := 0; i < b.N; i++ {
@@ -1622,7 +1622,7 @@ func BenchmarkMinLarge(b *testing.B) { benchmarkMin(b, Large) }
func BenchmarkMinHuge(b *testing.B) { benchmarkMin(b, Huge) }
func benchmarkAdd(b *testing.B, size int) {
src := rand.NewSource(1)
src := rand.NewPCG(1, 1)
s1 := randomSlice(size, src)
s2 := randomSlice(size, src)
b.ResetTimer()
@@ -1636,7 +1636,7 @@ func BenchmarkAddLarge(b *testing.B) { benchmarkAdd(b, Large) }
func BenchmarkAddHuge(b *testing.B) { benchmarkAdd(b, Huge) }
func benchmarkAddTo(b *testing.B, size int) {
src := rand.NewSource(1)
src := rand.NewPCG(1, 1)
s1 := randomSlice(size, src)
s2 := randomSlice(size, src)
dst := randomSlice(size, src)
@@ -1651,7 +1651,7 @@ func BenchmarkAddToLarge(b *testing.B) { benchmarkAddTo(b, Large) }
func BenchmarkAddToHuge(b *testing.B) { benchmarkAddTo(b, Huge) }
func benchmarkCumProd(b *testing.B, size int) {
src := rand.NewSource(1)
src := rand.NewPCG(1, 1)
s := randomSlice(size, src)
dst := randomSlice(size, src)
b.ResetTimer()
@@ -1665,7 +1665,7 @@ func BenchmarkCumProdLarge(b *testing.B) { benchmarkCumProd(b, Large) }
func BenchmarkCumProdHuge(b *testing.B) { benchmarkCumProd(b, Huge) }
func benchmarkCumSum(b *testing.B, size int) {
src := rand.NewSource(1)
src := rand.NewPCG(1, 1)
s := randomSlice(size, src)
dst := randomSlice(size, src)
b.ResetTimer()
@@ -1679,7 +1679,7 @@ func BenchmarkCumSumLarge(b *testing.B) { benchmarkCumSum(b, Large) }
func BenchmarkCumSumHuge(b *testing.B) { benchmarkCumSum(b, Huge) }
func benchmarkDiv(b *testing.B, size int) {
src := rand.NewSource(1)
src := rand.NewPCG(1, 1)
s := randomSlice(size, src)
dst := randomSlice(size, src)
b.ResetTimer()
@@ -1693,7 +1693,7 @@ func BenchmarkDivLarge(b *testing.B) { benchmarkDiv(b, Large) }
func BenchmarkDivHuge(b *testing.B) { benchmarkDiv(b, Huge) }
func benchmarkDivTo(b *testing.B, size int) {
src := rand.NewSource(1)
src := rand.NewPCG(1, 1)
s1 := randomSlice(size, src)
s2 := randomSlice(size, src)
dst := randomSlice(size, src)
@@ -1708,7 +1708,7 @@ func BenchmarkDivToLarge(b *testing.B) { benchmarkDivTo(b, Large) }
func BenchmarkDivToHuge(b *testing.B) { benchmarkDivTo(b, Huge) }
func benchmarkSub(b *testing.B, size int) {
src := rand.NewSource(1)
src := rand.NewPCG(1, 1)
s1 := randomSlice(size, src)
s2 := randomSlice(size, src)
b.ResetTimer()
@@ -1722,7 +1722,7 @@ func BenchmarkSubLarge(b *testing.B) { benchmarkSub(b, Large) }
func BenchmarkSubHuge(b *testing.B) { benchmarkSub(b, Huge) }
func benchmarkSubTo(b *testing.B, size int) {
src := rand.NewSource(1)
src := rand.NewPCG(1, 1)
s1 := randomSlice(size, src)
s2 := randomSlice(size, src)
dst := randomSlice(size, src)
@@ -1737,7 +1737,7 @@ func BenchmarkSubToLarge(b *testing.B) { benchmarkSubTo(b, Large) }
func BenchmarkSubToHuge(b *testing.B) { benchmarkSubTo(b, Huge) }
func benchmarkLogSumExp(b *testing.B, size int) {
src := rand.NewSource(1)
src := rand.NewPCG(1, 1)
s := randomSlice(size, src)
b.ResetTimer()
for i := 0; i < b.N; i++ {
@@ -1750,7 +1750,7 @@ func BenchmarkLogSumExpLarge(b *testing.B) { benchmarkLogSumExp(b, Large) }
func BenchmarkLogSumExpHuge(b *testing.B) { benchmarkLogSumExp(b, Huge) }
func benchmarkDot(b *testing.B, size int) {
src := rand.NewSource(1)
src := rand.NewPCG(1, 1)
s1 := randomSlice(size, src)
s2 := randomSlice(size, src)
b.ResetTimer()
@@ -1764,7 +1764,7 @@ func BenchmarkDotLarge(b *testing.B) { benchmarkDot(b, Large) }
func BenchmarkDotHuge(b *testing.B) { benchmarkDot(b, Huge) }
func benchmarkAddScaledTo(b *testing.B, size int) {
src := rand.NewSource(1)
src := rand.NewPCG(1, 1)
dst := randomSlice(size, src)
y := randomSlice(size, src)
s := randomSlice(size, src)
@@ -1779,7 +1779,7 @@ func BenchmarkAddScaledToLarge(b *testing.B) { benchmarkAddScaledTo(b, Large) }
func BenchmarkAddScaledToHuge(b *testing.B) { benchmarkAddScaledTo(b, Huge) }
func benchmarkScale(b *testing.B, size int) {
src := rand.NewSource(1)
src := rand.NewPCG(1, 1)
dst := randomSlice(size, src)
b.ResetTimer()
for i := 0; i < b.N; i += 2 {
@@ -1793,7 +1793,7 @@ func BenchmarkScaleLarge(b *testing.B) { benchmarkScale(b, Large) }
func BenchmarkScaleHuge(b *testing.B) { benchmarkScale(b, Huge) }
func benchmarkNorm2(b *testing.B, size int) {
src := rand.NewSource(1)
src := rand.NewPCG(1, 1)
s := randomSlice(size, src)
b.ResetTimer()
for i := 0; i < b.N; i++ {
@@ -1806,7 +1806,7 @@ func BenchmarkNorm2Large(b *testing.B) { benchmarkNorm2(b, Large) }
func BenchmarkNorm2Huge(b *testing.B) { benchmarkNorm2(b, Huge) }
func benchmarkSumCompensated(b *testing.B, size int) {
src := rand.NewSource(1)
src := rand.NewPCG(1, 1)
s := randomSlice(size, src)
b.ResetTimer()
for i := 0; i < b.N; i++ {
@@ -1820,7 +1820,7 @@ func BenchmarkSumCompensatedLarge(b *testing.B) { benchmarkSumCompensated(b, La
func BenchmarkSumCompensatedHuge(b *testing.B) { benchmarkSumCompensated(b, Huge) }
func benchmarkSum(b *testing.B, size int) {
src := rand.NewSource(1)
src := rand.NewPCG(1, 1)
s := randomSlice(size, src)
b.ResetTimer()
for i := 0; i < b.N; i++ {
@@ -1834,7 +1834,7 @@ func BenchmarkSumLarge(b *testing.B) { benchmarkSum(b, Large) }
func BenchmarkSumHuge(b *testing.B) { benchmarkSum(b, Huge) }
func benchmarkReverse(b *testing.B, size int) {
src := rand.NewSource(1)
src := rand.NewPCG(1, 1)
s := randomSlice(size, src)
b.ResetTimer()
for i := 0; i < b.N; i++ {
+1 -1
View File
@@ -9,6 +9,7 @@ package coloring
import (
"errors"
"math/rand/v2"
"slices"
"sort"
@@ -16,7 +17,6 @@ import (
"gonum.org/v1/gonum/graph/internal/set"
"gonum.org/v1/gonum/graph/iterator"
"gonum.org/v1/gonum/graph/topo"
"gonum.org/v1/gonum/internal/rand"
)
// ErrInvalidPartialColoring is returned when a partial coloring
+3 -3
View File
@@ -7,6 +7,7 @@ package coloring
import (
"context"
"flag"
"math/rand/v2"
"testing"
"time"
@@ -14,7 +15,6 @@ import (
"gonum.org/v1/gonum/graph/encoding/graph6"
"gonum.org/v1/gonum/graph/internal/set"
"gonum.org/v1/gonum/graph/simple"
"gonum.org/v1/gonum/internal/rand"
)
var runLong = flag.Bool("color.long", false, "run long exact coloring tests")
@@ -511,7 +511,7 @@ func TestRandomized(t *testing.T) {
for seed := uint64(1); seed <= 1000; seed++ {
for _, test := range coloringTests {
for _, partial := range []map[int64]int{nil, test.partial} {
k, colors, err := Randomized(test.g, partial, rand.NewSource(seed))
k, colors, err := Randomized(test.g, partial, rand.NewPCG(seed, seed))
if partial == nil && k != test.colors && !test.randomized.Has(k) {
t.Errorf("unexpected chromatic number for %q with seed=%d: got:%d want:%d or in %v\ncolors:%v",
@@ -767,7 +767,7 @@ func BenchmarkColoring(b *testing.B) {
})
}
b.Run("Randomized", func(b *testing.B) {
rnd := rand.NewSource(1)
rnd := rand.NewPCG(1, 1)
b.ResetTimer()
for i := 0; i < b.N; i++ {
_, _, err := Randomized(bench.g, nil, rnd)
+1 -1
View File
@@ -8,9 +8,9 @@ import (
"errors"
"fmt"
"math"
"math/rand/v2"
"gonum.org/v1/gonum/graph"
"gonum.org/v1/gonum/internal/rand"
)
// Interval is an interval of resolutions with a common score.
+5 -5
View File
@@ -7,11 +7,11 @@ package community_test
import (
"fmt"
"log"
"math/rand/v2"
"gonum.org/v1/gonum/graph/community"
"gonum.org/v1/gonum/graph/simple"
"gonum.org/v1/gonum/internal/order"
"gonum.org/v1/gonum/internal/rand"
)
func ExampleProfile_simple() {
@@ -19,7 +19,7 @@ func ExampleProfile_simple() {
// Since this is a randomized algorithm we use a defined random source to ensure
// consistency between test runs. In practice, results will not differ greatly
// between runs with different PRNG seeds.
src := rand.NewSource(1)
src := rand.NewPCG(1, 1)
// Create dumbell graph:
//
@@ -173,7 +173,7 @@ func ExampleProfile_multiplex() {
// algorithm. Since this is a randomized algorithm we use a defined random source
// to ensure consistency between test runs. In practice, results will not differ
// greatly between runs with different PRNG seeds.
src := rand.NewSource(1)
src := rand.NewPCG(1, 1)
// The undirected graphs, friends and enemies, are the political relationships
// in the Middle East as described in the Slate article:
@@ -209,10 +209,10 @@ func ExampleProfile_multiplex() {
// Low:0.1 High:0.72 Score:26 Communities:[[0] [1 7 9 12] [2 8 11] [3 4 5 10] [6]] Q=[24.7 1.97]
// Low:0.72 High:1.1 Score:24 Communities:[[0 6] [1 7 9 12] [2 8 11] [3 4 5 10]] Q=[16.9 14.1]
// Low:1.1 High:1.2 Score:18 Communities:[[0 2 6 11] [1 7 9 12] [3 4 5 8 10]] Q=[9.16 25.1]
// Low:1.2 High:1.6 Score:10 Communities:[[0 3 4 5 6 10] [1 7 9 12] [2 8 11]] Q=[11 25.2]
// Low:1.2 High:1.6 Score:10 Communities:[[0 3 4 5 6 10] [1 7 9 12] [2 8 11]] Q=[10.7 26]
// Low:1.6 High:1.6 Score:8 Communities:[[0 1 6 7 9 12] [2 8 11] [3 4 5 10]] Q=[5.56 39.8]
// Low:1.6 High:1.8 Score:2 Communities:[[0 2 3 4 5 6 10] [1 7 8 9 11 12]] Q=[-1.82 48.6]
// Low:1.8 High:2.3 Score:-6 Communities:[[0 2 3 4 5 6 8 10 11] [1 7 9 12]] Q=[-5 57.5]
// Low:1.8 High:2.3 Score:-6 Communities:[[0 2 3 4 5 6 8 10 11] [1 7 9 12]] Q=[-5.02 57.5]
// Low:2.3 High:2.4 Score:-10 Communities:[[0 1 2 6 7 8 9 11 12] [3 4 5 10]] Q=[-11.2 79]
// Low:2.4 High:4.3 Score:-52 Communities:[[0 1 2 3 4 5 6 7 8 9 10 11 12]] Q=[-46.1 117]
// Low:4.3 High:10 Score:-54 Communities:[[0 1 2 3 4 6 7 8 9 10 11 12] [5]] Q=[-82 254]
+3 -2
View File
@@ -5,6 +5,7 @@
package community
import (
"math/rand/v2"
"testing"
"gonum.org/v1/gonum/graph"
@@ -46,7 +47,7 @@ func TestProfileWeightedUndirected(t *testing.T) {
}
func testProfileUndirected(t *testing.T, test communityUndirectedQTest, g graph.Undirected) {
fn := ModularScore(g, Weight, 10, nil)
fn := ModularScore(g, Weight, 10, rand.NewPCG(1, 1))
p, err := Profile(fn, true, 1e-3, 0.1, 10)
if err != nil {
t.Errorf("%s: unexpected error: %v", test.name, err)
@@ -105,7 +106,7 @@ func TestProfileWeightedDirected(t *testing.T) {
}
func testProfileDirected(t *testing.T, test communityDirectedQTest, g graph.Directed) {
fn := ModularScore(g, Weight, 10, nil)
fn := ModularScore(g, Weight, 10, rand.NewPCG(1, 1))
p, err := Profile(fn, true, 1e-3, 0.1, 10)
if err != nil {
t.Errorf("%s: unexpected error: %v", test.name, err)
+3 -3
View File
@@ -6,11 +6,11 @@ package community
import (
"fmt"
"math/rand/v2"
"slices"
"gonum.org/v1/gonum/graph"
"gonum.org/v1/gonum/graph/internal/set"
"gonum.org/v1/gonum/internal/rand"
)
// Q returns the modularity Q score of the graph g subdivided into the
@@ -71,7 +71,7 @@ type ReducedGraph interface {
}
// Modularize returns the hierarchical modularization of g at the given resolution
// using the Louvain algorithm. If src is nil, rand.Intn is used as the random
// using the Louvain algorithm. If src is nil, rand.IntN is used as the random
// generator. Modularize will panic if g has any edge with negative edge weight.
//
// If g is undirected it is modularised to minimise
@@ -186,7 +186,7 @@ type ReducedMultiplex interface {
// ModularizeMultiplex returns the hierarchical modularization of g at the given resolution
// using the Louvain algorithm. If all is true and g have negatively weighted layers, all
// communities will be searched during the modularization. If src is nil, rand.Intn is
// communities will be searched during the modularization. If src is nil, rand.IntN is
// used as the random generator. ModularizeMultiplex will panic if g has any edge with
// edge weight that does not sign-match the layer weight.
//
+4 -4
View File
@@ -6,13 +6,13 @@ package community
import (
"math"
"math/rand/v2"
"slices"
"gonum.org/v1/gonum/graph"
"gonum.org/v1/gonum/graph/internal/set"
"gonum.org/v1/gonum/graph/iterator"
"gonum.org/v1/gonum/internal/order"
"gonum.org/v1/gonum/internal/rand"
)
// qDirected returns the modularity Q score of the graph g subdivided into the
@@ -77,7 +77,7 @@ func qDirected(g graph.Directed, communities [][]graph.Node, resolution float64)
}
// louvainDirected returns the hierarchical modularization of g at the given
// resolution using the Louvain algorithm. If src is nil, rand.Intn is used
// resolution using the Louvain algorithm. If src is nil, rand.IntN is used
// as the random generator. louvainDirected will panic if g has any edge with negative
// edge weight.
func louvainDirected(g graph.Directed, resolution float64, src rand.Source) ReducedGraph {
@@ -85,9 +85,9 @@ func louvainDirected(g graph.Directed, resolution float64, src rand.Source) Redu
// of the algorithm used here.
c := reduceDirected(g, nil)
rnd := rand.Intn
rnd := rand.IntN
if src != nil {
rnd = rand.New(src).Intn
rnd = rand.New(src).IntN
}
for {
l := newDirectedLocalMover(c, c.communities, resolution)
@@ -7,12 +7,12 @@ package community
import (
"fmt"
"math"
"math/rand/v2"
"gonum.org/v1/gonum/graph"
"gonum.org/v1/gonum/graph/internal/set"
"gonum.org/v1/gonum/graph/iterator"
"gonum.org/v1/gonum/internal/order"
"gonum.org/v1/gonum/internal/rand"
)
// DirectedMultiplex is a directed multiplex graph.
@@ -166,7 +166,7 @@ func (g DirectedLayers) Layer(l int) graph.Directed { return g[l] }
// louvainDirectedMultiplex returns the hierarchical modularization of g at the given resolution
// using the Louvain algorithm. If all is true and g has negatively weighted layers, all
// communities will be searched during the modularization. If src is nil, rand.Intn is
// communities will be searched during the modularization. If src is nil, rand.IntN is
// used as the random generator. louvainDirectedMultiplex will panic if g has any edge with
// edge weight that does not sign-match the layer weight.
//
@@ -183,9 +183,9 @@ func louvainDirectedMultiplex(g DirectedMultiplex, weights, resolutions []float6
// of the algorithm used here.
c := reduceDirectedMultiplex(g, nil, weights)
rnd := rand.Intn
rnd := rand.IntN
if src != nil {
rnd = rand.New(src).Intn
rnd = rand.New(src).IntN
}
for {
l := newDirectedMultiplexLocalMover(c, c.communities, weights, resolutions, all)
@@ -7,6 +7,7 @@ package community
import (
"fmt"
"math"
"math/rand/v2"
"reflect"
"slices"
"testing"
@@ -16,7 +17,6 @@ import (
"gonum.org/v1/gonum/graph"
"gonum.org/v1/gonum/graph/simple"
"gonum.org/v1/gonum/internal/order"
"gonum.org/v1/gonum/internal/rand"
)
var communityDirectedMultiplexQTests = []struct {
@@ -326,7 +326,7 @@ tests:
continue
}
rnd := rand.New(rand.NewSource(1)).Intn
rnd := rand.New(rand.NewPCG(1, 1)).IntN
for _, structure := range test.structures {
communityOf := make(map[int64]int)
communities := make([][]graph.Node, len(structure.memberships))
@@ -588,7 +588,7 @@ func TestLouvainDirectedMultiplex(t *testing.T) {
)
// Modularize is randomised so we do this to
// ensure the level tests are consistent.
src := rand.New(rand.NewSource(1))
src := rand.New(rand.NewPCG(1, 1))
for i := 0; i < louvainIterations; i++ {
r := ModularizeMultiplex(g, weights, nil, true, src).(*ReducedDirectedMultiplex)
if q := floats.Sum(QMultiplex(r, nil, weights, nil)); q > bestQ || math.IsNaN(q) {
@@ -689,7 +689,7 @@ func TestNonContiguousWeightedDirectedMultiplex(t *testing.T) {
}
func BenchmarkLouvainDirectedMultiplex(b *testing.B) {
src := rand.New(rand.NewSource(1))
src := rand.New(rand.NewPCG(1, 1))
for i := 0; i < b.N; i++ {
ModularizeMultiplex(DirectedLayers{dupGraphDirected}, nil, nil, true, src)
}
+7 -8
View File
@@ -6,6 +6,7 @@ package community
import (
"math"
"math/rand/v2"
"reflect"
"slices"
"testing"
@@ -14,7 +15,6 @@ import (
"gonum.org/v1/gonum/graph"
"gonum.org/v1/gonum/graph/simple"
"gonum.org/v1/gonum/internal/order"
"gonum.org/v1/gonum/internal/rand"
)
type communityDirectedQTest struct {
@@ -90,13 +90,12 @@ var communityDirectedQTests = []communityDirectedQTest{
},
},
{
q: 0.3911232174331037,
q: 0.4037814452812049,
communities: [][]graph.Node{
{simple.Node(0), simple.Node(1), simple.Node(2), simple.Node(3), simple.Node(7), simple.Node(11), simple.Node(12), simple.Node(13), simple.Node(17), simple.Node(19), simple.Node(21)},
{simple.Node(4), simple.Node(10)},
{simple.Node(5), simple.Node(6), simple.Node(16)},
{simple.Node(8), simple.Node(30)},
{simple.Node(9), simple.Node(14), simple.Node(15), simple.Node(18), simple.Node(20), simple.Node(22), simple.Node(32), simple.Node(33)},
{simple.Node(8), simple.Node(9), simple.Node(14), simple.Node(15), simple.Node(18), simple.Node(20), simple.Node(22), simple.Node(30), simple.Node(32), simple.Node(33)},
{simple.Node(23), simple.Node(24), simple.Node(25), simple.Node(27), simple.Node(28), simple.Node(31)},
{simple.Node(26), simple.Node(29)},
},
@@ -166,7 +165,7 @@ var communityDirectedQTests = []communityDirectedQTest{
},
},
{
q: 0.3405612244897959,
q: 0.34056122448979587,
communities: [][]graph.Node{
{simple.Node(0), simple.Node(1), simple.Node(2), simple.Node(4), simple.Node(5)},
{simple.Node(3), simple.Node(6), simple.Node(7)},
@@ -295,7 +294,7 @@ func TestCommunityDeltaQWeightedDirected(t *testing.T) {
}
func testCommunityDeltaQDirected(t *testing.T, test communityDirectedQTest, g graph.Directed) {
rnd := rand.New(rand.NewSource(1)).Intn
rnd := rand.New(rand.NewPCG(1, 1)).IntN
for _, structure := range test.structures {
communityOf := make(map[int64]int)
communities := make([][]graph.Node, len(structure.memberships))
@@ -632,7 +631,7 @@ func testModularizeDirected(t *testing.T, test communityDirectedQTest, g graph.D
)
// Modularize is randomised so we do this to
// ensure the level tests are consistent.
src := rand.New(rand.NewSource(1))
src := rand.New(rand.NewPCG(1, 1))
for i := 0; i < louvainIterations; i++ {
r := Modularize(g, 1, src).(*ReducedDirected)
if q := Q(r, nil, 1); q > bestQ || math.IsNaN(q) {
@@ -732,7 +731,7 @@ func TestNonContiguousWeightedDirected(t *testing.T) {
}
func BenchmarkLouvainDirected(b *testing.B) {
src := rand.New(rand.NewSource(1))
src := rand.New(rand.NewPCG(1, 1))
for i := 0; i < b.N; i++ {
Modularize(dupGraphDirected, 1, src)
}
+2 -2
View File
@@ -6,11 +6,11 @@ package community
import (
"fmt"
"math/rand/v2"
"gonum.org/v1/gonum/graph"
"gonum.org/v1/gonum/graph/graphs/gen"
"gonum.org/v1/gonum/graph/simple"
"gonum.org/v1/gonum/internal/rand"
)
// intset is an integer set.
@@ -228,7 +228,7 @@ var (
)
func init() {
err := gen.Duplication(dupGraph, 1000, 0.8, 0.1, 0.5, rand.New(rand.NewSource(1)))
err := gen.Duplication(dupGraph, 1000, 0.8, 0.1, 0.5, rand.New(rand.NewPCG(1, 1)))
if err != nil {
panic(err)
}
+4 -4
View File
@@ -6,13 +6,13 @@ package community
import (
"math"
"math/rand/v2"
"slices"
"gonum.org/v1/gonum/graph"
"gonum.org/v1/gonum/graph/internal/set"
"gonum.org/v1/gonum/graph/iterator"
"gonum.org/v1/gonum/internal/order"
"gonum.org/v1/gonum/internal/rand"
)
// qUndirected returns the modularity Q score of the graph g subdivided into the
@@ -73,7 +73,7 @@ func qUndirected(g graph.Undirected, communities [][]graph.Node, resolution floa
}
// louvainUndirected returns the hierarchical modularization of g at the given
// resolution using the Louvain algorithm. If src is nil, rand.Intn is used as
// resolution using the Louvain algorithm. If src is nil, rand.IntN is used as
// the random generator. louvainUndirected will panic if g has any edge with negative edge
// weight.
//
@@ -83,9 +83,9 @@ func louvainUndirected(g graph.Undirected, resolution float64, src rand.Source)
// of the algorithm used here.
c := reduceUndirected(g, nil)
rnd := rand.Intn
rnd := rand.IntN
if src != nil {
rnd = rand.New(src).Intn
rnd = rand.New(src).IntN
}
for {
l := newUndirectedLocalMover(c, c.communities, resolution)
@@ -7,12 +7,12 @@ package community
import (
"fmt"
"math"
"math/rand/v2"
"gonum.org/v1/gonum/graph"
"gonum.org/v1/gonum/graph/internal/set"
"gonum.org/v1/gonum/graph/iterator"
"gonum.org/v1/gonum/internal/order"
"gonum.org/v1/gonum/internal/rand"
)
// UndirectedMultiplex is an undirected multiplex graph.
@@ -162,7 +162,7 @@ func (g UndirectedLayers) Layer(l int) graph.Undirected { return g[l] }
// louvainUndirectedMultiplex returns the hierarchical modularization of g at the given resolution
// using the Louvain algorithm. If all is true and g has negatively weighted layers, all
// communities will be searched during the modularization. If src is nil, rand.Intn is
// communities will be searched during the modularization. If src is nil, rand.IntN is
// used as the random generator. louvainUndirectedMultiplex will panic if g has any edge with
// edge weight that does not sign-match the layer weight.
//
@@ -179,9 +179,9 @@ func louvainUndirectedMultiplex(g UndirectedMultiplex, weights, resolutions []fl
// of the algorithm used here.
c := reduceUndirectedMultiplex(g, nil, weights)
rnd := rand.Intn
rnd := rand.IntN
if src != nil {
rnd = rand.New(src).Intn
rnd = rand.New(src).IntN
}
for {
l := newUndirectedMultiplexLocalMover(c, c.communities, weights, resolutions, all)
@@ -7,6 +7,7 @@ package community
import (
"fmt"
"math"
"math/rand/v2"
"reflect"
"slices"
"testing"
@@ -16,7 +17,6 @@ import (
"gonum.org/v1/gonum/graph"
"gonum.org/v1/gonum/graph/simple"
"gonum.org/v1/gonum/internal/order"
"gonum.org/v1/gonum/internal/rand"
)
var communityUndirectedMultiplexQTests = []struct {
@@ -295,7 +295,7 @@ tests:
continue
}
rnd := rand.New(rand.NewSource(1)).Intn
rnd := rand.New(rand.NewPCG(1, 1)).IntN
for _, structure := range test.structures {
communityOf := make(map[int64]int)
communities := make([][]graph.Node, len(structure.memberships))
@@ -557,7 +557,7 @@ func TestLouvainMultiplex(t *testing.T) {
)
// Modularize is randomised so we do this to
// ensure the level tests are consistent.
src := rand.New(rand.NewSource(1))
src := rand.New(rand.NewPCG(1, 1))
for i := 0; i < louvainIterations; i++ {
r := ModularizeMultiplex(g, weights, nil, true, src).(*ReducedUndirectedMultiplex)
if q := floats.Sum(QMultiplex(r, nil, weights, nil)); q > bestQ || math.IsNaN(q) {
@@ -658,7 +658,7 @@ func TestNonContiguousWeightedUndirectedMultiplex(t *testing.T) {
}
func BenchmarkLouvainMultiplex(b *testing.B) {
src := rand.New(rand.NewSource(1))
src := rand.New(rand.NewPCG(1, 1))
for i := 0; i < b.N; i++ {
ModularizeMultiplex(UndirectedLayers{dupGraph}, nil, nil, true, src)
}
+4 -4
View File
@@ -6,6 +6,7 @@ package community
import (
"math"
"math/rand/v2"
"reflect"
"slices"
"testing"
@@ -14,7 +15,6 @@ import (
"gonum.org/v1/gonum/graph"
"gonum.org/v1/gonum/graph/simple"
"gonum.org/v1/gonum/internal/order"
"gonum.org/v1/gonum/internal/rand"
)
type communityUndirectedQTest struct {
@@ -356,7 +356,7 @@ func TestCommunityDeltaQWeightedUndirected(t *testing.T) {
}
func testCommunityDeltaQUndirected(t *testing.T, test communityUndirectedQTest, g graph.Undirected) {
rnd := rand.New(rand.NewSource(1)).Intn
rnd := rand.New(rand.NewPCG(1, 1)).IntN
for _, structure := range test.structures {
communityOf := make(map[int64]int)
communities := make([][]graph.Node, len(structure.memberships))
@@ -693,7 +693,7 @@ func testModularizeUndirected(t *testing.T, test communityUndirectedQTest, g gra
)
// Modularize is randomised so we do this to
// ensure the level tests are consistent.
src := rand.New(rand.NewSource(1))
src := rand.New(rand.NewPCG(1, 1))
for i := 0; i < louvainIterations; i++ {
r := Modularize(g, 1, src).(*ReducedUndirected)
if q := Q(r, nil, 1); q > bestQ || math.IsNaN(q) {
@@ -793,7 +793,7 @@ func TestNonContiguousWeightedUndirected(t *testing.T) {
}
func BenchmarkLouvain(b *testing.B) {
src := rand.New(rand.NewSource(1))
src := rand.New(rand.NewPCG(1, 1))
for i := 0; i < b.N; i++ {
Modularize(dupGraph, 1, src)
}
+6 -6
View File
@@ -6,23 +6,23 @@ package graph_test
import (
"fmt"
"math/rand/v2"
"testing"
"gonum.org/v1/gonum/graph"
"gonum.org/v1/gonum/graph/graphs/gen"
"gonum.org/v1/gonum/graph/iterator"
"gonum.org/v1/gonum/graph/simple"
"gonum.org/v1/gonum/internal/rand"
)
var complementTests = []struct {
g graph.Graph
}{
{g: gnp(100, 0, rand.NewSource(1))},
{g: gnp(100, 0.05, rand.NewSource(1))},
{g: gnp(100, 0.5, rand.NewSource(1))},
{g: gnp(100, 0.95, rand.NewSource(1))},
{g: gnp(100, 1, rand.NewSource(1))},
{g: gnp(100, 0, rand.NewPCG(1, 1))},
{g: gnp(100, 0.05, rand.NewPCG(1, 1))},
{g: gnp(100, 0.5, rand.NewPCG(1, 1))},
{g: gnp(100, 0.95, rand.NewPCG(1, 1))},
{g: gnp(100, 1, rand.NewPCG(1, 1))},
}
func TestComplement(t *testing.T) {
+3 -3
View File
@@ -6,13 +6,13 @@ package dot
import (
"fmt"
"math/rand/v2"
"testing"
"gonum.org/v1/gonum/graph"
"gonum.org/v1/gonum/graph/graphs/gen"
"gonum.org/v1/gonum/graph/multi"
"gonum.org/v1/gonum/graph/simple"
"gonum.org/v1/gonum/internal/rand"
)
var (
@@ -33,7 +33,7 @@ var (
func gnpDirected(n int, p float64) graph.Directed {
g := simple.NewDirectedGraph()
err := gen.Gnp(g, n, p, rand.NewSource(1))
err := gen.Gnp(g, n, p, rand.NewPCG(1, 1))
if err != nil {
panic(fmt.Sprintf("dot: bad test: %v", err))
}
@@ -42,7 +42,7 @@ func gnpDirected(n int, p float64) graph.Directed {
func powerLawMultiDirected(n, d int) graph.DirectedMultigraph {
g := multi.NewDirectedGraph()
err := gen.PowerLaw(g, n, d, rand.NewSource(1))
err := gen.PowerLaw(g, n, d, rand.NewPCG(1, 1))
if err != nil {
panic(fmt.Sprintf("dot: bad test: %v", err))
}
+8 -8
View File
@@ -8,6 +8,7 @@ import (
"flag"
"fmt"
"math"
"math/rand/v2"
"os"
"path/filepath"
"strings"
@@ -20,7 +21,6 @@ import (
"gonum.org/v1/gonum/graph/iterator"
"gonum.org/v1/gonum/graph/simple"
"gonum.org/v1/gonum/graph/topo"
"gonum.org/v1/gonum/internal/rand"
)
var slta = flag.Bool("slta", false, "specify DominatorsSLT benchmark")
@@ -165,7 +165,7 @@ func BenchmarkRandomGraphDominators(b *testing.B) {
}
for _, test := range tests {
rnd := rand.New(rand.NewSource(1))
rnd := rand.New(rand.NewPCG(1, 1))
g := test.g()
// Guess a maximally expensive entry to the graph.
@@ -177,7 +177,7 @@ func BenchmarkRandomGraphDominators(b *testing.B) {
// in the first position of the error. Pick one
// of the nodes at random.
unordered := err.(topo.Unorderable)
root = unordered[0][rnd.Intn(len(unordered[0]))]
root = unordered[0][rnd.IntN(len(unordered[0]))]
}
if root == nil {
b.Error("no entry node label for graph")
@@ -198,11 +198,11 @@ func BenchmarkRandomGraphDominators(b *testing.B) {
for i, v := range sort[1:] {
u := sort[i]
if u == nil {
u = unordered[ui][rnd.Intn(len(unordered[ui]))]
u = unordered[ui][rnd.IntN(len(unordered[ui]))]
ui++
}
if v == nil {
v = unordered[ui][rnd.Intn(len(unordered[ui]))]
v = unordered[ui][rnd.IntN(len(unordered[ui]))]
}
if !g.HasEdgeFromTo(u.ID(), v.ID()) {
g.SetEdge(g.NewEdge(u, v))
@@ -225,7 +225,7 @@ func BenchmarkRandomGraphDominators(b *testing.B) {
func gnm(n, m int) func() *simple.DirectedGraph {
return func() *simple.DirectedGraph {
dg := simple.NewDirectedGraph()
err := gen.Gnm(dg, n, m, rand.New(rand.NewSource(1)))
err := gen.Gnm(dg, n, m, rand.New(rand.NewPCG(1, 1)))
if err != nil {
panic(err)
}
@@ -238,13 +238,13 @@ func gnm(n, m int) func() *simple.DirectedGraph {
func duplication(n int, delta, alpha, sigma float64) func() *simple.DirectedGraph {
return func() *simple.DirectedGraph {
g := undirected{simple.NewDirectedGraph()}
rnd := rand.New(rand.NewSource(1))
rnd := rand.New(rand.NewPCG(1, 1))
err := gen.Duplication(g, n, delta, alpha, sigma, rnd)
if err != nil {
panic(err)
}
for _, e := range graph.EdgesOf(g.Edges()) {
if rnd.Intn(2) == 0 {
if rnd.IntN(2) == 0 {
g.RemoveEdge(e.From().ID(), e.To().ID())
}
}
+5 -5
View File
@@ -7,6 +7,7 @@ package rdf_test
import (
"io"
"math"
"math/rand/v2"
"slices"
"strings"
"testing"
@@ -19,7 +20,6 @@ import (
"gonum.org/v1/gonum/graph/iterator"
"gonum.org/v1/gonum/graph/multi"
"gonum.org/v1/gonum/graph/testgraph"
"gonum.org/v1/gonum/internal/rand"
)
func graphBuilder(nodes []graph.Node, edges []testgraph.WeightedLine, _, _ float64) (g graph.Graph, n []graph.Node, e []testgraph.Edge, s, a float64, ok bool) {
@@ -88,10 +88,10 @@ func TestGraph(t *testing.T) {
g.AddNode(it.Node())
}
it.Reset()
rnd := rand.New(rand.NewSource(1))
rnd := rand.New(rand.NewPCG(1, 1))
for it.Next() {
u := it.Node()
d := rnd.Intn(5)
d := rnd.IntN(5)
vit := g.Nodes()
for d >= 0 && vit.Next() {
v := vit.Node()
@@ -116,10 +116,10 @@ func TestGraph(t *testing.T) {
}
it.Reset()
var lines []graph.Line
rnd := rand.New(rand.NewSource(1))
rnd := rand.New(rand.NewPCG(1, 1))
for it.Next() {
u := it.Node()
d := rnd.Intn(5)
d := rnd.IntN(5)
vit := g.Nodes()
for d >= 0 && vit.Next() {
v := vit.Node()
+2 -3
View File
@@ -11,6 +11,7 @@ import (
"fmt"
"hash"
"io"
"math/rand/v2"
"os"
"path/filepath"
"reflect"
@@ -19,8 +20,6 @@ import (
"testing"
"text/tabwriter"
"time"
"gonum.org/v1/gonum/internal/rand"
)
var (
@@ -53,7 +52,7 @@ func TestIsoCanonicalHashes(t *testing.T) {
for _, path := range glob {
name := filepath.Base(path)
t.Run(name, func(t *testing.T) {
src := rand.NewSource(seed)
src := rand.NewPCG(seed, seed)
f, err := os.Open(path)
if err != nil {
+5 -5
View File
@@ -6,12 +6,12 @@ package rdf
import (
"io"
"math/rand/v2"
"reflect"
"strings"
"testing"
"gonum.org/v1/gonum/internal/order"
"gonum.org/v1/gonum/internal/rand"
)
var andTests = []struct {
@@ -52,7 +52,7 @@ var andTests = []struct {
}
func TestQueryAnd(t *testing.T) {
src := rand.NewSource(1)
src := rand.NewPCG(1, 1)
for _, test := range andTests {
for i := 0; i < 10; i++ {
a := Query{terms: permutedTerms(test.a, src)}
@@ -108,7 +108,7 @@ var orTests = []struct {
}
func TestQueryOr(t *testing.T) {
src := rand.NewSource(1)
src := rand.NewPCG(1, 1)
for _, test := range orTests {
for i := 0; i < 10; i++ {
a := Query{terms: permutedTerms(test.a, src)}
@@ -164,7 +164,7 @@ var notTests = []struct {
}
func TestQueryNot(t *testing.T) {
src := rand.NewSource(1)
src := rand.NewPCG(1, 1)
for _, test := range notTests {
for i := 0; i < 10; i++ {
a := Query{terms: permutedTerms(test.a, src)}
@@ -271,7 +271,7 @@ var uniqueTests = []struct {
}
func TestQueryUnique(t *testing.T) {
src := rand.NewSource(1)
src := rand.NewPCG(1, 1)
for _, test := range uniqueTests {
for i := 0; i < 10; i++ {
a := Query{terms: permutedTerms(test.in, src)}
+12 -12
View File
@@ -10,9 +10,9 @@ package gen
import (
"fmt"
"math"
"math/rand/v2"
"gonum.org/v1/gonum/graph"
"gonum.org/v1/gonum/internal/rand"
)
// Gnp constructs a Gilberts model subgraph in the destination, dst, of order n. Edges
@@ -77,7 +77,7 @@ func Gnp(dst graph.Builder, n int, p float64, src rand.Source) error {
// Gnm constructs a Erdős-Rényi model subgraph in the destination, dst, of
// order n and size m. If src is not nil it is used as the random source,
// otherwise rand.Intn is used. The graph is constructed in O(m) expected
// otherwise rand.IntN is used. The graph is constructed in O(m) expected
// time for m ≤ (n choose 2)/2.
func Gnm(dst GraphBuilder, n, m int, src rand.Source) error {
if m == 0 {
@@ -101,9 +101,9 @@ func Gnm(dst GraphBuilder, n, m int, src rand.Source) error {
var rnd func(int) int
if src == nil {
rnd = rand.Intn
rnd = rand.IntN
} else {
rnd = rand.New(src).Intn
rnd = rand.New(src).IntN
}
nodes := make([]graph.Node, n)
@@ -166,11 +166,11 @@ func SmallWorldsBB(dst GraphBuilder, n, d int, p float64, src rand.Source) error
)
if src == nil {
rnd = rand.Float64
rndN = rand.Intn
rndN = rand.IntN
} else {
r := rand.New(src)
rnd = r.Float64
rndN = r.Intn
rndN = r.IntN
}
hasEdge := dst.HasEdgeBetween
@@ -309,7 +309,7 @@ func edgeNodesFor(i int, nodes []graph.Node) (v, w graph.Node) {
// PowerLaw constructs a power-law degree graph by preferential attachment in dst
// with n nodes and minimum degree d. PowerLaw does not consider nodes in dst prior
// to the call. If src is not nil it is used as the random source, otherwise rand.Intn
// to the call. If src is not nil it is used as the random source, otherwise rand.IntN
// is used.
// The graph is constructed in O(nd) — O(n+m) — time.
//
@@ -320,9 +320,9 @@ func PowerLaw(dst graph.MultigraphBuilder, n, d int, src rand.Source) error {
}
var rnd func(int) int
if src == nil {
rnd = rand.Intn
rnd = rand.IntN
} else {
rnd = rand.New(src).Intn
rnd = rand.New(src).IntN
}
m := make([]graph.Node, 2*n*d)
@@ -345,7 +345,7 @@ func PowerLaw(dst graph.MultigraphBuilder, n, d int, src rand.Source) error {
// BipartitePowerLaw constructs a bipartite power-law degree graph by preferential attachment
// in dst with 2×n nodes and minimum degree d. BipartitePowerLaw does not consider nodes in
// dst prior to the call. The two partitions are returned in p1 and p2. If src is not nil it is
// used as the random source, otherwise rand.Intn is used.
// used as the random source, otherwise rand.IntN is used.
// The graph is constructed in O(nd) — O(n+m) — time.
//
// The algorithm used is described in http://algo.uni-konstanz.de/publications/bb-eglrn-05.pdf
@@ -355,9 +355,9 @@ func BipartitePowerLaw(dst graph.MultigraphBuilder, n, d int, src rand.Source) (
}
var rnd func(int) int
if src == nil {
rnd = rand.Intn
rnd = rand.IntN
} else {
rnd = rand.New(src).Intn
rnd = rand.New(src).IntN
}
p := make([]graph.Node, 2*n)
+3 -3
View File
@@ -7,10 +7,10 @@ package gen
import (
"fmt"
"math"
"math/rand/v2"
"gonum.org/v1/gonum/graph"
"gonum.org/v1/gonum/internal/order"
"gonum.org/v1/gonum/internal/rand"
)
// UndirectedMutator is an undirected graph builder that can remove edges.
@@ -47,11 +47,11 @@ func Duplication(dst UndirectedMutator, n int, delta, alpha, sigma float64, src
)
if src == nil {
rnd = rand.Float64
rndN = rand.Intn
rndN = rand.IntN
} else {
r := rand.New(src)
rnd = r.Float64
rndN = r.Intn
rndN = r.IntN
}
nodes := graph.NodesOf(dst.Nodes())
+4 -4
View File
@@ -7,10 +7,10 @@ package gen
import (
"errors"
"fmt"
"math/rand/v2"
"gonum.org/v1/gonum/graph"
"gonum.org/v1/gonum/graph/simple"
"gonum.org/v1/gonum/internal/rand"
"gonum.org/v1/gonum/stat/sampleuv"
)
@@ -20,7 +20,7 @@ import (
// additional edges joining existing nodes with probability proportional to the nodes'
// degrees. The edges are formed as a triad with probability, p.
// If src is not nil it is used as the random source, otherwise rand.Float64 and
// rand.Intn are used for the random number generators.
// rand.IntN are used for the random number generators.
//
// The algorithm is essentially as described in http://arxiv.org/abs/cond-mat/0110452.
func TunableClusteringScaleFree(dst graph.UndirectedBuilder, n, m int, p float64, src rand.Source) error {
@@ -37,11 +37,11 @@ func TunableClusteringScaleFree(dst graph.UndirectedBuilder, n, m int, p float64
)
if src == nil {
rnd = rand.Float64
rndN = rand.Intn
rndN = rand.IntN
} else {
r := rand.New(src)
rnd = r.Float64
rndN = r.Intn
rndN = r.IntN
}
// Initial condition.
+1 -1
View File
@@ -8,9 +8,9 @@ import (
"errors"
"fmt"
"math"
"math/rand/v2"
"gonum.org/v1/gonum/graph"
"gonum.org/v1/gonum/internal/rand"
"gonum.org/v1/gonum/stat/sampleuv"
)
+1 -1
View File
@@ -6,9 +6,9 @@ package layout
import (
"math"
"math/rand/v2"
"gonum.org/v1/gonum/graph"
"gonum.org/v1/gonum/internal/rand"
"gonum.org/v1/gonum/spatial/barneshut"
"gonum.org/v1/gonum/spatial/r2"
)
+8 -8
View File
@@ -5,12 +5,12 @@
package layout_test
import (
"math/rand/v2"
"path/filepath"
"testing"
"gonum.org/v1/gonum/graph"
"gonum.org/v1/gonum/graph/simple"
"gonum.org/v1/gonum/internal/rand"
"gonum.org/v1/gonum/spatial/r2"
"gonum.org/v1/plot"
"gonum.org/v1/plot/vg"
@@ -37,7 +37,7 @@ func TestEadesR2(t *testing.T) {
}
return orderedGraph{g}
}(),
param: EadesR2{Repulsion: 1, Rate: 0.1, Updates: 100, Theta: 0.1, Src: rand.NewSource(1)},
param: EadesR2{Repulsion: 1, Rate: 0.1, Updates: 100, Theta: 0.1, Src: rand.NewPCG(1, 1)},
wantIters: 100,
},
{
@@ -55,7 +55,7 @@ func TestEadesR2(t *testing.T) {
}
return orderedGraph{g}
}(),
param: EadesR2{Repulsion: 1, Rate: 0.1, Updates: 100, Theta: 0.1, Src: rand.NewSource(1)},
param: EadesR2{Repulsion: 1, Rate: 0.1, Updates: 100, Theta: 0.1, Src: rand.NewPCG(1, 1)},
wantIters: 100,
},
{
@@ -75,7 +75,7 @@ func TestEadesR2(t *testing.T) {
}
return orderedGraph{g}
}(),
param: EadesR2{Repulsion: 1, Rate: 0.1, Updates: 100, Theta: 0.1, Src: rand.NewSource(1)},
param: EadesR2{Repulsion: 1, Rate: 0.1, Updates: 100, Theta: 0.1, Src: rand.NewPCG(1, 1)},
wantIters: 100,
},
{
@@ -101,7 +101,7 @@ func TestEadesR2(t *testing.T) {
}
return orderedGraph{g}
}(),
param: EadesR2{Repulsion: 1, Rate: 0.1, Updates: 100, Theta: 0.1, Src: rand.NewSource(1)},
param: EadesR2{Repulsion: 1, Rate: 0.1, Updates: 100, Theta: 0.1, Src: rand.NewPCG(1, 1)},
wantIters: 100,
},
{
@@ -130,7 +130,7 @@ func TestEadesR2(t *testing.T) {
}
return orderedGraph{g}
}(),
param: EadesR2{Repulsion: 1, Rate: 0.1, Updates: 100, Theta: 0.1, Src: rand.NewSource(1)},
param: EadesR2{Repulsion: 1, Rate: 0.1, Updates: 100, Theta: 0.1, Src: rand.NewPCG(1, 1)},
wantIters: 100,
},
{
@@ -161,7 +161,7 @@ func TestEadesR2(t *testing.T) {
}
return orderedGraph{g}
}(),
param: EadesR2{Repulsion: 1, Rate: 1, Updates: 100, Theta: 0.1, Src: rand.NewSource(1)},
param: EadesR2{Repulsion: 1, Rate: 1, Updates: 100, Theta: 0.1, Src: rand.NewPCG(1, 1)},
wantIters: 96,
},
@@ -191,7 +191,7 @@ func TestEadesR2(t *testing.T) {
}
return orderedGraph{g}
}(),
param: EadesR2{Repulsion: 1, Rate: 0.01, Updates: 100, Theta: 0.1, Src: rand.NewSource(1)},
param: EadesR2{Repulsion: 1, Rate: 0.01, Updates: 100, Theta: 0.1, Src: rand.NewPCG(1, 1)},
wantIters: 100,
},
}
+5 -5
View File
@@ -6,6 +6,7 @@ package multi_test
import (
"math"
"math/rand/v2"
"testing"
"gonum.org/v1/gonum/graph"
@@ -13,7 +14,6 @@ import (
"gonum.org/v1/gonum/graph/iterator"
"gonum.org/v1/gonum/graph/multi"
"gonum.org/v1/gonum/graph/testgraph"
"gonum.org/v1/gonum/internal/rand"
)
func directedBuilder(nodes []graph.Node, edges []testgraph.WeightedLine, _, _ float64) (g graph.Graph, n []graph.Node, e []testgraph.Edge, s, a float64, ok bool) {
@@ -86,10 +86,10 @@ func TestDirected(t *testing.T) {
g.AddNode(it.Node())
}
it.Reset()
rnd := rand.New(rand.NewSource(1))
rnd := rand.New(rand.NewPCG(1, 1))
for it.Next() {
u := it.Node()
d := rnd.Intn(5)
d := rnd.IntN(5)
vit := g.Nodes()
for d >= 0 && vit.Next() {
v := vit.Node()
@@ -114,10 +114,10 @@ func TestDirected(t *testing.T) {
}
it.Reset()
var lines []graph.Line
rnd := rand.New(rand.NewSource(1))
rnd := rand.New(rand.NewPCG(1, 1))
for it.Next() {
u := it.Node()
d := rnd.Intn(5)
d := rnd.IntN(5)
vit := g.Nodes()
for d >= 0 && vit.Next() {
v := vit.Node()
+5 -5
View File
@@ -6,6 +6,7 @@ package multi_test
import (
"math"
"math/rand/v2"
"testing"
"gonum.org/v1/gonum/graph"
@@ -13,7 +14,6 @@ import (
"gonum.org/v1/gonum/graph/iterator"
"gonum.org/v1/gonum/graph/multi"
"gonum.org/v1/gonum/graph/testgraph"
"gonum.org/v1/gonum/internal/rand"
)
const (
@@ -91,10 +91,10 @@ func TestUndirected(t *testing.T) {
g.AddNode(it.Node())
}
it.Reset()
rnd := rand.New(rand.NewSource(1))
rnd := rand.New(rand.NewPCG(1, 1))
for it.Next() {
u := it.Node()
d := rnd.Intn(5)
d := rnd.IntN(5)
vit := g.Nodes()
for d >= 0 && vit.Next() {
v := vit.Node()
@@ -119,10 +119,10 @@ func TestUndirected(t *testing.T) {
}
it.Reset()
var lines []graph.Line
rnd := rand.New(rand.NewSource(1))
rnd := rand.New(rand.NewPCG(1, 1))
for it.Next() {
u := it.Node()
d := rnd.Intn(5)
d := rnd.IntN(5)
vit := g.Nodes()
for d >= 0 && vit.Next() {
v := vit.Node()
+5 -5
View File
@@ -5,6 +5,7 @@
package multi_test
import (
"math/rand/v2"
"testing"
"gonum.org/v1/gonum/graph"
@@ -12,7 +13,6 @@ import (
"gonum.org/v1/gonum/graph/iterator"
"gonum.org/v1/gonum/graph/multi"
"gonum.org/v1/gonum/graph/testgraph"
"gonum.org/v1/gonum/internal/rand"
)
func weightedDirectedBuilder(nodes []graph.Node, edges []testgraph.WeightedLine, self, absent float64) (g graph.Graph, n []graph.Node, e []testgraph.Edge, s, a float64, ok bool) {
@@ -102,10 +102,10 @@ func TestWeightedDirected(t *testing.T) {
g.AddNode(it.Node())
}
it.Reset()
rnd := rand.New(rand.NewSource(1))
rnd := rand.New(rand.NewPCG(1, 1))
for it.Next() {
u := it.Node()
d := rnd.Intn(5)
d := rnd.IntN(5)
vit := g.Nodes()
for d >= 0 && vit.Next() {
v := vit.Node()
@@ -131,10 +131,10 @@ func TestWeightedDirected(t *testing.T) {
}
it.Reset()
var lines []graph.Line
rnd := rand.New(rand.NewSource(1))
rnd := rand.New(rand.NewPCG(1, 1))
for it.Next() {
u := it.Node()
d := rnd.Intn(5)
d := rnd.IntN(5)
vit := g.Nodes()
for d >= 0 && vit.Next() {
v := vit.Node()
+5 -5
View File
@@ -5,6 +5,7 @@
package multi_test
import (
"math/rand/v2"
"testing"
"gonum.org/v1/gonum/graph"
@@ -12,7 +13,6 @@ import (
"gonum.org/v1/gonum/graph/iterator"
"gonum.org/v1/gonum/graph/multi"
"gonum.org/v1/gonum/graph/testgraph"
"gonum.org/v1/gonum/internal/rand"
)
func weightedUndirectedBuilder(nodes []graph.Node, edges []testgraph.WeightedLine, self, absent float64) (g graph.Graph, n []graph.Node, e []testgraph.Edge, s, a float64, ok bool) {
@@ -102,10 +102,10 @@ func TestWeightedUndirected(t *testing.T) {
g.AddNode(it.Node())
}
it.Reset()
rnd := rand.New(rand.NewSource(1))
rnd := rand.New(rand.NewPCG(1, 1))
for it.Next() {
u := it.Node()
d := rnd.Intn(5)
d := rnd.IntN(5)
vit := g.Nodes()
for d >= 0 && vit.Next() {
v := vit.Node()
@@ -131,10 +131,10 @@ func TestWeightedUndirected(t *testing.T) {
}
it.Reset()
var lines []graph.Line
rnd := rand.New(rand.NewSource(1))
rnd := rand.New(rand.NewPCG(1, 1))
for it.Next() {
u := it.Node()
d := rnd.Intn(5)
d := rnd.IntN(5)
vit := g.Nodes()
for d >= 0 && vit.Next() {
v := vit.Node()
+1 -1
View File
@@ -6,10 +6,10 @@ package network
import (
"math"
"math/rand/v2"
"gonum.org/v1/gonum/floats"
"gonum.org/v1/gonum/graph"
"gonum.org/v1/gonum/internal/rand"
"gonum.org/v1/gonum/mat"
)
+2 -2
View File
@@ -6,10 +6,10 @@ package path
import (
"math"
"math/rand/v2"
"gonum.org/v1/gonum/graph"
"gonum.org/v1/gonum/graph/simple"
"gonum.org/v1/gonum/internal/rand"
)
// JohnsonAllPaths returns a shortest-path tree for shortest paths in the graph g.
@@ -32,7 +32,7 @@ func JohnsonAllPaths(g graph.Graph) (paths AllShortest, ok bool) {
for {
// Choose a random node ID until we find
// one that is not in g.
q = sign * rand.Int63()
q = sign * rand.Int64()
if _, exists := paths.indexOf[q]; !exists {
break
}
+4 -4
View File
@@ -6,12 +6,12 @@ package path
import (
"math"
"math/rand/v2"
"slices"
"gonum.org/v1/gonum/floats/scalar"
"gonum.org/v1/gonum/graph"
"gonum.org/v1/gonum/graph/internal/set"
"gonum.org/v1/gonum/internal/rand"
"gonum.org/v1/gonum/mat"
)
@@ -354,7 +354,7 @@ func (p ShortestAlts) To(vid int64) (path []graph.Node, weight float64, unique b
var next int
if len(c) != 1 {
unique = false
next = c[rand.Intn(len(c))]
next = c[rand.IntN(len(c))]
} else {
next = c[0]
}
@@ -382,7 +382,7 @@ func (p ShortestAlts) To(vid int64) (path []graph.Node, weight float64, unique b
c := p.next[to]
if len(c) != 1 {
unique = false
next = c[rand.Intn(len(c))]
next = c[rand.IntN(len(c))]
} else {
next = c[0]
}
@@ -659,7 +659,7 @@ func (p AllShortest) Between(uid, vid int64) (path []graph.Node, weight float64,
c := p.at(from, to)
if len(c) != 1 {
unique = false
next = c[rand.Intn(len(c))]
next = c[rand.IntN(len(c))]
} else {
next = c[0]
}
+5 -5
View File
@@ -7,6 +7,7 @@ package path
import (
"fmt"
"math"
"math/rand/v2"
"reflect"
"slices"
"testing"
@@ -15,7 +16,6 @@ import (
"gonum.org/v1/gonum/graph/graphs/gen"
"gonum.org/v1/gonum/graph/simple"
"gonum.org/v1/gonum/internal/order"
"gonum.org/v1/gonum/internal/rand"
)
var shortestTests = []struct {
@@ -35,7 +35,7 @@ func TestShortestAlts(t *testing.T) {
for _, test := range shortestTests {
t.Run(fmt.Sprintf("AllTo_%d×%d|%v", test.n, test.d, test.p), func(t *testing.T) {
g := simple.NewDirectedGraph()
gen.SmallWorldsBB(g, test.n, test.d, test.p, rand.New(rand.NewSource(test.seed)))
gen.SmallWorldsBB(g, test.n, test.d, test.p, rand.New(rand.NewPCG(test.seed, test.seed)))
all := allShortest(DijkstraAllPaths(g))
for uid := int64(0); uid < int64(test.n); uid++ {
@@ -82,7 +82,7 @@ func TestAllShortest(t *testing.T) {
for _, test := range shortestTests {
t.Run(fmt.Sprintf("AllBetween_%d×%d|%v", test.n, test.d, test.p), func(t *testing.T) {
g := simple.NewDirectedGraph()
gen.SmallWorldsBB(g, test.n, test.d, test.p, rand.New(rand.NewSource(test.seed)))
gen.SmallWorldsBB(g, test.n, test.d, test.p, rand.New(rand.NewPCG(test.seed, test.seed)))
p := DijkstraAllPaths(g)
for uid := int64(0); uid < int64(test.n); uid++ {
@@ -221,7 +221,7 @@ var shortestBenchmarks = []struct {
func BenchmarkShortestAlts(b *testing.B) {
for _, bench := range shortestBenchmarks {
g := simple.NewDirectedGraph()
gen.SmallWorldsBB(g, bench.n, bench.d, bench.p, rand.New(rand.NewSource(bench.seed)))
gen.SmallWorldsBB(g, bench.n, bench.d, bench.p, rand.New(rand.NewPCG(bench.seed, bench.seed)))
// Find the widest path set.
var (
@@ -282,7 +282,7 @@ func BenchmarkAllShortest(b *testing.B) {
for _, bench := range shortestBenchmarks {
for _, f := range shortestPathAlgs {
g := simple.NewDirectedGraph()
gen.SmallWorldsBB(g, bench.n, bench.d, bench.p, rand.New(rand.NewSource(bench.seed)))
gen.SmallWorldsBB(g, bench.n, bench.d, bench.p, rand.New(rand.NewPCG(bench.seed, bench.seed)))
p := f.fn(g)
// Find the widest path set.
+6 -6
View File
@@ -7,13 +7,13 @@ package product
import (
"bytes"
"fmt"
"math/rand/v2"
"testing"
"gonum.org/v1/gonum/graph"
"gonum.org/v1/gonum/graph/encoding/dot"
"gonum.org/v1/gonum/graph/graphs/gen"
"gonum.org/v1/gonum/graph/simple"
"gonum.org/v1/gonum/internal/rand"
)
func (n Node) DOTID() string { return fmt.Sprintf("(%d,%d)", n.A.ID(), n.B.ID()) }
@@ -69,10 +69,10 @@ var productTests = []struct {
{name: "paths", a: path(-1), b: path(1)},
{name: "wp_mp", a: path(-2), b: path(2)},
{name: "wp_gp", a: left(), b: right()},
{name: "gnp_2×2", a: gnp(2, 0.5, rand.NewSource(1)), b: gnp(2, 0.5, rand.NewSource(2))},
{name: "gnp_2×3", a: gnp(2, 0.5, rand.NewSource(1)), b: gnp(3, 0.5, rand.NewSource(2))},
{name: "gnp_3×3", a: gnp(3, 0.5, rand.NewSource(1)), b: gnp(3, 0.5, rand.NewSource(2))},
{name: "gnp_4×4", a: gnp(4, 0.5, rand.NewSource(1)), b: gnp(4, 0.5, rand.NewSource(2))},
{name: "gnp_2×2", a: gnp(2, 0.5, rand.NewPCG(1, 1)), b: gnp(2, 0.5, rand.NewPCG(2, 2))},
{name: "gnp_2×3", a: gnp(2, 0.5, rand.NewPCG(1, 1)), b: gnp(3, 0.5, rand.NewPCG(2, 2))},
{name: "gnp_3×3", a: gnp(3, 0.5, rand.NewPCG(1, 1)), b: gnp(3, 0.5, rand.NewPCG(2, 2))},
{name: "gnp_4×4", a: gnp(4, 0.5, rand.NewPCG(1, 1)), b: gnp(4, 0.5, rand.NewPCG(2, 2))},
}
func TestCartesian(t *testing.T) {
@@ -373,7 +373,7 @@ func BenchmarkProduct(b *testing.B) {
} {
for _, p := range []float64{0.05, 0.25, 0.5, 0.75, 0.95} {
for _, n := range bench.len {
src := rand.NewSource(uint64(seed))
src := rand.NewPCG(uint64(seed), uint64(seed))
b.Run(fmt.Sprintf("%s %d-%.2f", bench.name, n, p), func(b *testing.B) {
g1 := gnp(n, p, src)
g2 := gnp(n, p, src)
+3 -4
View File
@@ -7,13 +7,12 @@ package uid
import (
"math"
"math/rand/v2"
"testing"
"gonum.org/v1/gonum/internal/rand"
)
func TestSetChurn(t *testing.T) {
rnd := rand.New(rand.NewSource(1))
rnd := rand.New(rand.NewPCG(1, 1))
set := NewSet()
@@ -29,7 +28,7 @@ func TestSetChurn(t *testing.T) {
set.Use(id)
seen[id] = true
if rnd.Float64() < 0.01 {
j := rnd.Intn(10)
j := rnd.IntN(10)
for id := range seen {
set.Release(id)
delete(seen, id)
+9 -9
View File
@@ -6,6 +6,7 @@ package simple_test
import (
"math"
"math/rand/v2"
"testing"
"gonum.org/v1/gonum/graph"
@@ -13,7 +14,6 @@ import (
"gonum.org/v1/gonum/graph/simple"
"gonum.org/v1/gonum/graph/testgraph"
"gonum.org/v1/gonum/internal/order"
"gonum.org/v1/gonum/internal/rand"
)
func isZeroContiguousSet(nodes []graph.Node) bool {
@@ -129,11 +129,11 @@ func TestDirectedMatrix(t *testing.T) {
})
t.Run("RemoveEdges", func(t *testing.T) {
g := newEdgeShimDir{simple.NewDirectedMatrix(100, 0, 1, 0)}
rnd := rand.New(rand.NewSource(1))
rnd := rand.New(rand.NewPCG(1, 1))
it := g.Nodes()
for it.Next() {
u := it.Node()
d := rnd.Intn(5)
d := rnd.IntN(5)
vit := g.Nodes()
for d >= 0 && vit.Next() {
v := vit.Node()
@@ -250,11 +250,11 @@ func TestDirectedMatrixFrom(t *testing.T) {
})
t.Run("RemoveEdges", func(t *testing.T) {
g := newEdgeShimDir{simple.NewDirectedMatrixFrom(makeNodes(numNodes), 0, 1, 0)}
rnd := rand.New(rand.NewSource(1))
rnd := rand.New(rand.NewPCG(1, 1))
it := g.Nodes()
for it.Next() {
u := it.Node()
d := rnd.Intn(5)
d := rnd.IntN(5)
vit := g.Nodes()
for d >= 0 && vit.Next() {
v := vit.Node()
@@ -380,11 +380,11 @@ func TestUnirectedMatrix(t *testing.T) {
})
t.Run("RemoveEdges", func(t *testing.T) {
g := newEdgeShimUndir{simple.NewUndirectedMatrix(100, 0, 1, 0)}
rnd := rand.New(rand.NewSource(1))
rnd := rand.New(rand.NewPCG(1, 1))
it := g.Nodes()
for it.Next() {
u := it.Node()
d := rnd.Intn(5)
d := rnd.IntN(5)
vit := g.Nodes()
for d >= 0 && vit.Next() {
v := vit.Node()
@@ -501,11 +501,11 @@ func TestUndirectedMatrixFrom(t *testing.T) {
})
t.Run("RemoveEdges", func(t *testing.T) {
g := newEdgeShimUndir{simple.NewUndirectedMatrixFrom(makeNodes(numNodes), 0, 1, 0)}
rnd := rand.New(rand.NewSource(1))
rnd := rand.New(rand.NewPCG(1, 1))
it := g.Nodes()
for it.Next() {
u := it.Node()
d := rnd.Intn(5)
d := rnd.IntN(5)
vit := g.Nodes()
for d >= 0 && vit.Next() {
v := vit.Node()
+5 -5
View File
@@ -6,13 +6,13 @@ package simple_test
import (
"math"
"math/rand/v2"
"testing"
"gonum.org/v1/gonum/graph"
"gonum.org/v1/gonum/graph/internal/set"
"gonum.org/v1/gonum/graph/simple"
"gonum.org/v1/gonum/graph/testgraph"
"gonum.org/v1/gonum/internal/rand"
)
func directedBuilder(nodes []graph.Node, edges []testgraph.WeightedLine, _, _ float64) (g graph.Graph, n []graph.Node, e []testgraph.Edge, s, a float64, ok bool) {
@@ -91,10 +91,10 @@ func TestDirected(t *testing.T) {
g.AddNode(it.Node())
}
it.Reset()
rnd := rand.New(rand.NewSource(1))
rnd := rand.New(rand.NewPCG(1, 1))
for it.Next() {
u := it.Node()
d := rnd.Intn(5)
d := rnd.IntN(5)
vit := g.Nodes()
for d >= 0 && vit.Next() {
v := vit.Node()
@@ -128,10 +128,10 @@ func TestDirected(t *testing.T) {
g.AddNode(it.Node())
}
it.Reset()
rnd := rand.New(rand.NewSource(1))
rnd := rand.New(rand.NewPCG(1, 1))
for it.Next() {
u := it.Node()
d := rnd.Intn(5)
d := rnd.IntN(5)
vit := g.Nodes()
for d >= 0 && vit.Next() {
v := vit.Node()
+5 -5
View File
@@ -6,13 +6,13 @@ package simple_test
import (
"math"
"math/rand/v2"
"testing"
"gonum.org/v1/gonum/graph"
"gonum.org/v1/gonum/graph/internal/set"
"gonum.org/v1/gonum/graph/simple"
"gonum.org/v1/gonum/graph/testgraph"
"gonum.org/v1/gonum/internal/rand"
)
const (
@@ -96,10 +96,10 @@ func TestUndirected(t *testing.T) {
g.AddNode(it.Node())
}
it.Reset()
rnd := rand.New(rand.NewSource(1))
rnd := rand.New(rand.NewPCG(1, 1))
for it.Next() {
u := it.Node()
d := rnd.Intn(5)
d := rnd.IntN(5)
vit := g.Nodes()
for d >= 0 && vit.Next() {
v := vit.Node()
@@ -133,10 +133,10 @@ func TestUndirected(t *testing.T) {
g.AddNode(it.Node())
}
it.Reset()
rnd := rand.New(rand.NewSource(1))
rnd := rand.New(rand.NewPCG(1, 1))
for it.Next() {
u := it.Node()
d := rnd.Intn(5)
d := rnd.IntN(5)
vit := g.Nodes()
for d >= 0 && vit.Next() {
v := vit.Node()
+5 -5
View File
@@ -6,13 +6,13 @@ package simple_test
import (
"math"
"math/rand/v2"
"testing"
"gonum.org/v1/gonum/graph"
"gonum.org/v1/gonum/graph/internal/set"
"gonum.org/v1/gonum/graph/simple"
"gonum.org/v1/gonum/graph/testgraph"
"gonum.org/v1/gonum/internal/rand"
)
func weightedDirectedBuilder(nodes []graph.Node, edges []testgraph.WeightedLine, self, absent float64) (g graph.Graph, n []graph.Node, e []testgraph.Edge, s, a float64, ok bool) {
@@ -100,10 +100,10 @@ func TestWeightedDirected(t *testing.T) {
g.AddNode(it.Node())
}
it.Reset()
rnd := rand.New(rand.NewSource(1))
rnd := rand.New(rand.NewPCG(1, 1))
for it.Next() {
u := it.Node()
d := rnd.Intn(5)
d := rnd.IntN(5)
vit := g.Nodes()
for d >= 0 && vit.Next() {
v := vit.Node()
@@ -139,10 +139,10 @@ func TestWeightedDirected(t *testing.T) {
g.AddNode(it.Node())
}
it.Reset()
rnd := rand.New(rand.NewSource(1))
rnd := rand.New(rand.NewPCG(1, 1))
for it.Next() {
u := it.Node()
d := rnd.Intn(5)
d := rnd.IntN(5)
vit := g.Nodes()
for d >= 0 && vit.Next() {
v := vit.Node()
+5 -5
View File
@@ -6,13 +6,13 @@ package simple_test
import (
"math"
"math/rand/v2"
"testing"
"gonum.org/v1/gonum/graph"
"gonum.org/v1/gonum/graph/internal/set"
"gonum.org/v1/gonum/graph/simple"
"gonum.org/v1/gonum/graph/testgraph"
"gonum.org/v1/gonum/internal/rand"
)
func weightedUndirectedBuilder(nodes []graph.Node, edges []testgraph.WeightedLine, self, absent float64) (g graph.Graph, n []graph.Node, e []testgraph.Edge, s, a float64, ok bool) {
@@ -116,10 +116,10 @@ func TestWeightedUndirected(t *testing.T) {
g.AddNode(it.Node())
}
it.Reset()
rnd := rand.New(rand.NewSource(1))
rnd := rand.New(rand.NewPCG(1, 1))
for it.Next() {
u := it.Node()
d := rnd.Intn(5)
d := rnd.IntN(5)
vit := g.Nodes()
for d >= 0 && vit.Next() {
v := vit.Node()
@@ -139,10 +139,10 @@ func TestWeightedUndirected(t *testing.T) {
g.AddNode(it.Node())
}
it.Reset()
rnd := rand.New(rand.NewSource(1))
rnd := rand.New(rand.NewPCG(1, 1))
for it.Next() {
u := it.Node()
d := rnd.Intn(5)
d := rnd.IntN(5)
vit := g.Nodes()
for d >= 0 && vit.Next() {
v := vit.Node()
+16 -16
View File
@@ -9,6 +9,7 @@ package testgraph // import "gonum.org/v1/gonum/graph/testgraph"
import (
"cmp"
"fmt"
"math/rand/v2"
"reflect"
"slices"
"testing"
@@ -17,7 +18,6 @@ import (
"gonum.org/v1/gonum/graph"
"gonum.org/v1/gonum/graph/internal/set"
"gonum.org/v1/gonum/internal/order"
"gonum.org/v1/gonum/internal/rand"
"gonum.org/v1/gonum/mat"
)
@@ -1607,12 +1607,12 @@ func AddEdges(t *testing.T, n int, g EdgeAdder, newNode func(id int64) graph.Nod
graph.Node
}
rnd := rand.New(rand.NewSource(1))
rnd := rand.New(rand.NewPCG(1, 1))
for i := 0; i < n; i++ {
u := newNode(rnd.Int63n(int64(n)))
u := newNode(rnd.Int64N(int64(n)))
var v graph.Node
for {
v = newNode(rnd.Int63n(int64(n)))
v = newNode(rnd.Int64N(int64(n)))
if g.Edge(u.ID(), v.ID()) != nil {
continue
}
@@ -1674,12 +1674,12 @@ func AddWeightedEdges(t *testing.T, n int, g WeightedEdgeAdder, w float64, newNo
graph.Node
}
rnd := rand.New(rand.NewSource(1))
rnd := rand.New(rand.NewPCG(1, 1))
for i := 0; i < n; i++ {
u := newNode(rnd.Int63n(int64(n)))
u := newNode(rnd.Int64N(int64(n)))
var v graph.Node
for {
v = newNode(rnd.Int63n(int64(n)))
v = newNode(rnd.Int64N(int64(n)))
if g.Edge(u.ID(), v.ID()) != nil {
continue
}
@@ -1797,11 +1797,11 @@ func AddLines(t *testing.T, n int, g LineAdder, newNode func(id int64) graph.Nod
graph.Node
}
rnd := rand.New(rand.NewSource(1))
rnd := rand.New(rand.NewPCG(1, 1))
seen := make(tripleInt64s)
for i := 0; i < n; i++ {
u := newNode(rnd.Int63n(int64(n)))
v := newNode(rnd.Int63n(int64(n)))
u := newNode(rnd.Int64N(int64(n)))
v := newNode(rnd.Int64N(int64(n)))
prev := g.Lines(u.ID(), v.ID())
l := g.NewLine(u, v)
if seen.has(u.ID(), v.ID(), l.ID()) {
@@ -1861,11 +1861,11 @@ func AddWeightedLines(t *testing.T, n int, g WeightedLineAdder, w float64, newNo
graph.Node
}
rnd := rand.New(rand.NewSource(1))
rnd := rand.New(rand.NewPCG(1, 1))
seen := make(tripleInt64s)
for i := 0; i < n; i++ {
u := newNode(rnd.Int63n(int64(n)))
v := newNode(rnd.Int63n(int64(n)))
u := newNode(rnd.Int64N(int64(n)))
v := newNode(rnd.Int64N(int64(n)))
prev := g.Lines(u.ID(), v.ID())
l := g.NewWeightedLine(u, v, w)
if seen.has(u.ID(), v.ID(), l.ID()) {
@@ -2113,7 +2113,7 @@ func NewRandomNodes(n int, seed uint64, new func(id int64) graph.Node) *RandomNo
seed: seed,
newNode: new,
state: rand.New(rand.NewSource(seed)),
state: rand.New(rand.NewPCG(seed, seed)),
seen: make(set.Ints[int64]),
count: 0,
}
@@ -2135,7 +2135,7 @@ func (n *RandomNodes) Next() bool {
if n.state.Float64() < 0.5 {
sign *= -1
}
n.curr = sign * n.state.Int63()
n.curr = sign * n.state.Int64()
if !n.seen.Has(n.curr) {
n.seen.Add(n.curr)
return true
@@ -2154,7 +2154,7 @@ func (n *RandomNodes) Node() graph.Node {
// Reset returns the iterator to its initial state.
func (n *RandomNodes) Reset() {
n.state = rand.New(rand.NewSource(n.seed))
n.state = rand.New(rand.NewPCG(n.seed, n.seed))
n.seen = make(set.Ints[int64])
n.count = 0
}
+3 -3
View File
@@ -6,12 +6,12 @@ package topo
import (
"fmt"
"math/rand/v2"
"testing"
"gonum.org/v1/gonum/graph"
"gonum.org/v1/gonum/graph/graphs/gen"
"gonum.org/v1/gonum/graph/simple"
"gonum.org/v1/gonum/internal/rand"
)
var (
@@ -34,7 +34,7 @@ var (
func gnpDirected(n int, p float64) graph.Directed {
g := simple.NewDirectedGraph()
err := gen.Gnp(g, n, p, rand.NewSource(1))
err := gen.Gnp(g, n, p, rand.NewPCG(1, 1))
if err != nil {
panic(fmt.Sprintf("topo: bad test: %v", err))
}
@@ -43,7 +43,7 @@ func gnpDirected(n int, p float64) graph.Directed {
func gnpUndirected(n int, p float64) graph.Undirected {
g := simple.NewUndirectedGraph()
err := gen.Gnp(g, n, p, rand.NewSource(1))
err := gen.Gnp(g, n, p, rand.NewPCG(1, 1))
if err != nil {
panic(fmt.Sprintf("topo: bad test: %v", err))
}
+2 -2
View File
@@ -6,15 +6,15 @@ package integrate
import (
"math"
"math/rand/v2"
"testing"
"gonum.org/v1/gonum/integrate/testquad"
"gonum.org/v1/gonum/internal/rand"
)
func TestSimpsons(t *testing.T) {
t.Parallel()
rnd := rand.New(rand.NewSource(1))
rnd := rand.New(rand.NewPCG(1, 1))
for i, test := range []struct {
integral testquad.Integral
n int
+2 -2
View File
@@ -6,15 +6,15 @@ package integrate
import (
"math"
"math/rand/v2"
"testing"
"gonum.org/v1/gonum/integrate/testquad"
"gonum.org/v1/gonum/internal/rand"
)
func TestTrapezoidal(t *testing.T) {
t.Parallel()
rnd := rand.New(rand.NewSource(1))
rnd := rand.New(rand.NewPCG(1, 1))
for i, test := range []struct {
integral testquad.Integral
n int
+1 -1
View File
@@ -6,10 +6,10 @@ package f64_test
import (
"math"
"math/rand/v2"
"testing"
"gonum.org/v1/gonum/floats/scalar"
"gonum.org/v1/gonum/internal/rand"
)
const (
+1 -1
View File
@@ -7,10 +7,10 @@ package f64_test
import (
"fmt"
"math"
"math/rand/v2"
"testing"
. "gonum.org/v1/gonum/internal/asm/f64"
"gonum.org/v1/gonum/internal/rand"
)
func TestDotUnitary(t *testing.T) {
+3 -3
View File
@@ -6,11 +6,11 @@ package f64_test
import (
"fmt"
"math/rand/v2"
"testing"
"gonum.org/v1/gonum/floats/scalar"
. "gonum.org/v1/gonum/internal/asm/f64"
"gonum.org/v1/gonum/internal/rand"
)
var scalTests = []struct {
@@ -100,7 +100,7 @@ func TestScalUnitary(t *testing.T) {
func TestScalUnitaryTo(t *testing.T) {
const xGdVal, dstGdVal = -1, 0.5
rng := rand.New(rand.NewSource(42))
rng := rand.New(rand.NewPCG(42, 42))
for i, test := range scalTests {
n := len(test.x)
for _, align := range align2 {
@@ -155,7 +155,7 @@ func TestScalInc(t *testing.T) {
func TestScalIncTo(t *testing.T) {
const xGdVal, dstGdVal = -1, 0.5
gdLn := 4
rng := rand.New(rand.NewSource(42))
rng := rand.New(rand.NewPCG(42, 42))
for i, test := range scalTests {
n := len(test.x)
for _, inc := range newIncSet(1, 2, 3, 4, 7, 10) {
+32 -39
View File
@@ -6,8 +6,7 @@ package testrand
import (
"math"
"gonum.org/v1/gonum/internal/rand"
"math/rand/v2"
)
// extreme is a pseudo-random number generator that has high probability of returning extreme values.
@@ -28,12 +27,6 @@ func newExtreme(p, nan float64, rnd Rand) *extreme {
// Perm returns a permutation of integers [0, n).
func (e *extreme) Perm(n int) []int { return e.rnd.Perm(n) }
// Read generates len(p) pseudo-random bytes.
func (e *extreme) Read(p []byte) (n int, err error) { return e.rnd.Read(p) }
// Seed reseeds the pseudo-random generator.
func (e *extreme) Seed(seed uint64) { e.rnd.Seed(seed) }
// Shuffle shuffles n items using the swap callback.
func (e *extreme) Shuffle(n int, swap func(i, j int)) { e.rnd.Shuffle(n, swap) }
@@ -57,7 +50,7 @@ func (e *extreme) nan() bool {
func (e *extreme) ExpFloat64() float64 {
switch {
case e.p():
return extremeFloat64Exp[e.rnd.Intn(len(extremeFloat64Exp))]
return extremeFloat64Exp[e.rnd.IntN(len(extremeFloat64Exp))]
case e.nan():
return math.NaN()
}
@@ -69,7 +62,7 @@ func (e *extreme) ExpFloat64() float64 {
func (e *extreme) Float32() float32 {
switch {
case e.p():
return extremeFloat32Unit[e.rnd.Intn(len(extremeFloat32Unit))]
return extremeFloat32Unit[e.rnd.IntN(len(extremeFloat32Unit))]
case e.nan():
return float32(math.NaN())
}
@@ -81,7 +74,7 @@ func (e *extreme) Float32() float32 {
func (e *extreme) Float64() float64 {
switch {
case e.p():
return extremeFloat64Unit[e.rnd.Intn(len(extremeFloat64Unit))]
return extremeFloat64Unit[e.rnd.IntN(len(extremeFloat64Unit))]
case e.nan():
return math.NaN()
}
@@ -92,23 +85,23 @@ func (e *extreme) Float64() float64 {
// Int returns a non-negative pseudo-random int.
func (e *extreme) Int() int {
if e.p() {
return extremeInt[e.rnd.Intn(len(extremeInt))]
return extremeInt[e.rnd.IntN(len(extremeInt))]
}
return e.rnd.Int()
}
// Int31 returns a non-negative pseudo-random int32.
func (e *extreme) Int31() int32 {
// Int32 returns a non-negative pseudo-random int32.
func (e *extreme) Int32() int32 {
if e.p() {
return extremeInt31[e.rnd.Intn(len(extremeInt31))]
return extremeInt31[e.rnd.IntN(len(extremeInt31))]
}
return e.rnd.Int31()
return e.rnd.Int32()
}
// Int31n returns a non-negative pseudo-random int32 from range [0, n).
func (e *extreme) Int31n(n int32) int32 {
// Int32N returns a non-negative pseudo-random int32 from range [0, n).
func (e *extreme) Int32N(n int32) int32 {
if e.p() {
switch rand.Intn(4) {
switch rand.IntN(4) {
case 0:
return 0
case 1:
@@ -119,21 +112,21 @@ func (e *extreme) Int31n(n int32) int32 {
return n - 1
}
}
return e.rnd.Int31n(n)
return e.rnd.Int32N(n)
}
// Int63 returns a non-negative pseudo-random int64.
func (e *extreme) Int63() int64 {
// Int64 returns a non-negative pseudo-random int64.
func (e *extreme) Int64() int64 {
if e.p() {
return extremeInt63[e.rnd.Intn(len(extremeInt63))]
return extremeInt63[e.rnd.IntN(len(extremeInt63))]
}
return e.rnd.Int63()
return e.rnd.Int64()
}
// Int63n returns a non-negative pseudo-random int from range [0, n).
func (e *extreme) Int63n(n int64) int64 {
// Int64N returns a non-negative pseudo-random int from range [0, n).
func (e *extreme) Int64N(n int64) int64 {
if e.p() {
switch rand.Intn(4) {
switch rand.IntN(4) {
case 0:
return 0
case 1:
@@ -144,13 +137,13 @@ func (e *extreme) Int63n(n int64) int64 {
return n - 1
}
}
return e.rnd.Int63n(n)
return e.rnd.Int64N(n)
}
// Int returns a non-negative pseudo-random int from range [0, n).
func (e *extreme) Intn(n int) int {
// IntN returns a non-negative pseudo-random int from range [0, n).
func (e *extreme) IntN(n int) int {
if e.p() {
switch rand.Intn(4) {
switch rand.IntN(4) {
case 0:
return 0
case 1:
@@ -161,14 +154,14 @@ func (e *extreme) Intn(n int) int {
return n - 1
}
}
return e.rnd.Intn(n)
return e.rnd.IntN(n)
}
// NormFloat64 returns a normally distributed pseudo-random float64 in range [-math.MaxFloat64, math.MaxFloat64].
func (e *extreme) NormFloat64() float64 {
switch {
case e.p():
return extremeFloat64Norm[e.rnd.Intn(len(extremeFloat64Norm))]
return extremeFloat64Norm[e.rnd.IntN(len(extremeFloat64Norm))]
case e.nan():
return math.NaN()
}
@@ -179,7 +172,7 @@ func (e *extreme) NormFloat64() float64 {
// Uint32 returns a pseudo-random uint32.
func (e *extreme) Uint32() uint32 {
if e.p() {
return extremeUint32[e.rnd.Intn(len(extremeUint32))]
return extremeUint32[e.rnd.IntN(len(extremeUint32))]
}
return e.rnd.Uint32()
}
@@ -187,15 +180,15 @@ func (e *extreme) Uint32() uint32 {
// Uint64 returns a pseudo-random uint64.
func (e *extreme) Uint64() uint64 {
if e.p() {
return extremeUint64[e.rnd.Intn(len(extremeUint64))]
return extremeUint64[e.rnd.IntN(len(extremeUint64))]
}
return e.rnd.Uint64()
}
// Uint64n returns a pseudo-random uint64 from range [0, n).
func (e *extreme) Uint64n(n uint64) uint64 {
// Uint64N returns a pseudo-random uint64 from range [0, n).
func (e *extreme) Uint64N(n uint64) uint64 {
if e.p() {
switch rand.Intn(4) {
switch rand.IntN(4) {
case 0:
return 0
case 1:
@@ -206,5 +199,5 @@ func (e *extreme) Uint64n(n uint64) uint64 {
return n - 1
}
}
return e.rnd.Uint64n(n)
return e.rnd.Uint64N(n)
}
+2 -3
View File
@@ -6,13 +6,12 @@ package testrand
import (
"math"
"math/rand/v2"
"testing"
"gonum.org/v1/gonum/internal/rand"
)
func TestExtreme_NaN(t *testing.T) {
src := rand.NewSource(1)
src := rand.NewPCG(1, 1)
rnd := rand.New(src)
ext := newExtreme(0, 1, rnd)
+12 -15
View File
@@ -7,8 +7,7 @@ package testrand
import (
"flag"
"gonum.org/v1/gonum/internal/rand"
"math/rand/v2"
)
var (
@@ -25,25 +24,23 @@ type TB interface {
// Source corresponds to the interface in golang.org/x/exp/rand.Source.
type Source = rand.Source
// Rand corresponds to golang.org/x/exp/rand.Rand.
// Rand corresponds to math/rand/v2.Rand.
type Rand interface {
ExpFloat64() float64
Float32() float32
Float64() float64
Int() int
Int31() int32
Int31n(n int32) int32
Int63() int64
Int63n(n int64) int64
Intn(n int) int
Int32() int32
Int32N(n int32) int32
Int64() int64
Int64N(n int64) int64
IntN(n int) int
NormFloat64() float64
Perm(n int) []int
Read(p []byte) (n int, err error)
Seed(seed uint64)
Shuffle(n int, swap func(i, j int))
Uint32() uint32
Uint64() uint64
Uint64n(n uint64) uint64
Uint64N(n uint64) uint64
}
// New returns a new random number generator using the global flags.
@@ -55,13 +52,13 @@ func New(tb TB) Rand {
// Don't log the default case.
if seed == 1 && *extremeFlag == 0 && *nanFlag == 0 {
base := rand.New(rand.NewSource(seed))
base := rand.New(rand.NewPCG(seed, seed))
return base
}
tb.Logf("seed=%d, prob=%.2f, nan=%.2f", seed, *extremeFlag, *nanFlag)
base := rand.New(rand.NewSource(seed))
base := rand.New(rand.NewPCG(seed, seed))
if *extremeFlag <= 0 && *nanFlag <= 0 {
return base
}
@@ -78,9 +75,9 @@ func NewSource(tb TB) Source {
// Don't log the default case.
if seed == 1 {
return rand.NewSource(seed)
return rand.NewPCG(seed, seed)
}
tb.Logf("seed %d", seed)
return rand.NewSource(seed)
return rand.NewPCG(seed, seed)
}
+2 -2
View File
@@ -6,6 +6,7 @@ package testlapack
import (
"fmt"
"math/rand/v2"
"sort"
"testing"
@@ -13,7 +14,6 @@ import (
"gonum.org/v1/gonum/blas/blas64"
"gonum.org/v1/gonum/floats"
"gonum.org/v1/gonum/floats/scalar"
"gonum.org/v1/gonum/internal/rand"
)
type Dbdsqrer interface {
@@ -21,7 +21,7 @@ type Dbdsqrer interface {
}
func DbdsqrTest(t *testing.T, impl Dbdsqrer) {
rnd := rand.New(rand.NewSource(1))
rnd := rand.New(rand.NewPCG(1, 1))
bi := blas64.Implementation()
for _, uplo := range []blas.Uplo{blas.Upper, blas.Lower} {
for _, test := range []struct {
+7 -7
View File
@@ -6,11 +6,11 @@ package testlapack
import (
"fmt"
"math/rand/v2"
"testing"
"gonum.org/v1/gonum/blas"
"gonum.org/v1/gonum/blas/blas64"
"gonum.org/v1/gonum/internal/rand"
"gonum.org/v1/gonum/lapack"
)
@@ -19,19 +19,19 @@ type Dgebaker interface {
}
func DgebakTest(t *testing.T, impl Dgebaker) {
rnd := rand.New(rand.NewSource(1))
rnd := rand.New(rand.NewPCG(1, 1))
for _, job := range []lapack.BalanceJob{lapack.BalanceNone, lapack.Permute, lapack.Scale, lapack.PermuteScale} {
for _, side := range []lapack.EVSide{lapack.EVLeft, lapack.EVRight} {
for _, n := range []int{0, 1, 2, 3, 4, 5, 6, 10, 18, 31, 53} {
for _, extra := range []int{0, 11} {
for cas := 0; cas < 100; cas++ {
m := rnd.Intn(n + 1)
m := rnd.IntN(n + 1)
v := randomGeneral(n, m, m+extra, rnd)
var ilo, ihi int
if v.Rows > 0 {
ihi = rnd.Intn(n)
ilo = rnd.Intn(ihi + 1)
ihi = rnd.IntN(n)
ilo = rnd.IntN(ihi + 1)
} else {
ihi = -1
}
@@ -70,12 +70,12 @@ func testDgebak(t *testing.T, impl Dgebaker, job lapack.BalanceJob, side lapack.
if job == lapack.Permute || job == lapack.PermuteScale {
// Make up some random permutations.
for i := n - 1; i > ihi; i-- {
scale[i] = float64(rnd.Intn(i + 1))
scale[i] = float64(rnd.IntN(i + 1))
blas64.Swap(blas64.Vector{N: n, Data: p.Data[i:], Inc: p.Stride},
blas64.Vector{N: n, Data: p.Data[int(scale[i]):], Inc: p.Stride})
}
for i := 0; i < ilo; i++ {
scale[i] = float64(i + rnd.Intn(ihi-i+1))
scale[i] = float64(i + rnd.IntN(ihi-i+1))
blas64.Swap(blas64.Vector{N: n, Data: p.Data[i:], Inc: p.Stride},
blas64.Vector{N: n, Data: p.Data[int(scale[i]):], Inc: p.Stride})
}
+2 -2
View File
@@ -6,11 +6,11 @@ package testlapack
import (
"fmt"
"math/rand/v2"
"testing"
"gonum.org/v1/gonum/blas"
"gonum.org/v1/gonum/blas/blas64"
"gonum.org/v1/gonum/internal/rand"
"gonum.org/v1/gonum/lapack"
)
@@ -19,7 +19,7 @@ type Dgebaler interface {
}
func DgebalTest(t *testing.T, impl Dgebaler) {
rnd := rand.New(rand.NewSource(1))
rnd := rand.New(rand.NewPCG(1, 1))
for _, job := range []lapack.BalanceJob{lapack.BalanceNone, lapack.Permute, lapack.Scale, lapack.PermuteScale} {
for _, n := range []int{0, 1, 2, 3, 4, 5, 6, 10, 18, 31, 53, 100} {
+2 -3
View File
@@ -5,9 +5,8 @@
package testlapack
import (
"math/rand/v2"
"testing"
"gonum.org/v1/gonum/internal/rand"
)
type Dgebd2er interface {
@@ -15,7 +14,7 @@ type Dgebd2er interface {
}
func Dgebd2Test(t *testing.T, impl Dgebd2er) {
rnd := rand.New(rand.NewSource(1))
rnd := rand.New(rand.NewPCG(1, 1))
for _, test := range []struct {
m, n, lda int
}{
+2 -2
View File
@@ -6,10 +6,10 @@ package testlapack
import (
"math"
"math/rand/v2"
"testing"
"gonum.org/v1/gonum/floats"
"gonum.org/v1/gonum/internal/rand"
)
type Dgebrder interface {
@@ -18,7 +18,7 @@ type Dgebrder interface {
}
func DgebrdTest(t *testing.T, impl Dgebrder) {
rnd := rand.New(rand.NewSource(1))
rnd := rand.New(rand.NewPCG(1, 1))
for _, test := range []struct {
m, n, lda int
}{
+2 -2
View File
@@ -7,10 +7,10 @@ package testlapack
import (
"fmt"
"math"
"math/rand/v2"
"testing"
"gonum.org/v1/gonum/floats"
"gonum.org/v1/gonum/internal/rand"
"gonum.org/v1/gonum/lapack"
)
@@ -22,7 +22,7 @@ type Dgeconer interface {
}
func DgeconTest(t *testing.T, impl Dgeconer) {
rnd := rand.New(rand.NewSource(1))
rnd := rand.New(rand.NewPCG(1, 1))
for _, n := range []int{0, 1, 2, 3, 4, 5, 10, 50} {
for _, lda := range []int{max(1, n), n + 3} {
dgeconTest(t, impl, rnd, n, lda)
+4 -4
View File
@@ -8,12 +8,12 @@ import (
"fmt"
"math"
"math/cmplx"
"math/rand/v2"
"strconv"
"testing"
"gonum.org/v1/gonum/blas"
"gonum.org/v1/gonum/blas/blas64"
"gonum.org/v1/gonum/internal/rand"
"gonum.org/v1/gonum/lapack"
)
@@ -30,7 +30,7 @@ type dgeevTest struct {
}
func DgeevTest(t *testing.T, impl Dgeever) {
rnd := rand.New(rand.NewSource(1))
rnd := rand.New(rand.NewPCG(1, 1))
for i, test := range []dgeevTest{
{
@@ -488,7 +488,7 @@ func DgeevTest(t *testing.T, impl Dgeever) {
re := rnd.NormFloat64()
if i == n-1 || rnd.Float64() < 0.5 {
// Real eigenvalue.
nb := rnd.Intn(min(4, n-i)) + 1
nb := rnd.IntN(min(4, n-i)) + 1
for k := 0; k < nb; k++ {
tmat.Data[i*tmat.Stride+i] = re
ev[i] = complex(re, 0)
@@ -498,7 +498,7 @@ func DgeevTest(t *testing.T, impl Dgeever) {
}
// Complex eigenvalue.
im := rnd.NormFloat64()
nb := rnd.Intn(min(4, (n-i)/2)) + 1
nb := rnd.IntN(min(4, (n-i)/2)) + 1
for k := 0; k < nb; k++ {
// 2×2 block for the complex eigenvalue.
tmat.Data[i*tmat.Stride+i] = re
+2 -2
View File
@@ -5,16 +5,16 @@
package testlapack
import (
"math/rand/v2"
"testing"
"gonum.org/v1/gonum/blas/blas64"
"gonum.org/v1/gonum/internal/rand"
"gonum.org/v1/gonum/lapack"
)
func DgeevBenchmark(b *testing.B, impl Dgeever) {
var resultGeneral blas64.General
rnd := rand.New(rand.NewSource(1))
rnd := rand.New(rand.NewPCG(1, 1))
benchmarks := []struct {
name string
a blas64.General
+4 -4
View File
@@ -7,11 +7,11 @@ package testlapack
import (
"fmt"
"math"
"math/rand/v2"
"testing"
"gonum.org/v1/gonum/blas"
"gonum.org/v1/gonum/blas/blas64"
"gonum.org/v1/gonum/internal/rand"
)
type Dgehd2er interface {
@@ -19,7 +19,7 @@ type Dgehd2er interface {
}
func Dgehd2Test(t *testing.T, impl Dgehd2er) {
rnd := rand.New(rand.NewSource(1))
rnd := rand.New(rand.NewPCG(1, 1))
for _, n := range []int{1, 2, 3, 4, 5, 7, 10, 30} {
for _, extra := range []int{0, 1, 13} {
for cas := 0; cas < 100; cas++ {
@@ -32,8 +32,8 @@ func Dgehd2Test(t *testing.T, impl Dgehd2er) {
func testDgehd2(t *testing.T, impl Dgehd2er, n, extra int, rnd *rand.Rand) {
const tol = 1e-14
ilo := rnd.Intn(n)
ihi := rnd.Intn(n)
ilo := rnd.IntN(n)
ihi := rnd.IntN(n)
if ilo > ihi {
ilo, ihi = ihi, ilo
}
+4 -4
View File
@@ -7,11 +7,11 @@ package testlapack
import (
"fmt"
"math"
"math/rand/v2"
"testing"
"gonum.org/v1/gonum/blas"
"gonum.org/v1/gonum/blas/blas64"
"gonum.org/v1/gonum/internal/rand"
)
type Dgehrder interface {
@@ -21,7 +21,7 @@ type Dgehrder interface {
}
func DgehrdTest(t *testing.T, impl Dgehrder) {
rnd := rand.New(rand.NewSource(1))
rnd := rand.New(rand.NewPCG(1, 1))
// Randomized tests for small matrix sizes that will most likely
// use the unblocked algorithm.
@@ -29,8 +29,8 @@ func DgehrdTest(t *testing.T, impl Dgehrder) {
for _, extra := range []int{0, 13} {
for _, optwork := range []bool{true, false} {
for cas := 0; cas < 10; cas++ {
ilo := rnd.Intn(n)
ihi := rnd.Intn(n)
ilo := rnd.IntN(n)
ihi := rnd.IntN(n)
if ilo > ihi {
ilo, ihi = ihi, ilo
}
+2 -2
View File
@@ -5,12 +5,12 @@
package testlapack
import (
"math/rand/v2"
"testing"
"gonum.org/v1/gonum/blas"
"gonum.org/v1/gonum/blas/blas64"
"gonum.org/v1/gonum/floats"
"gonum.org/v1/gonum/internal/rand"
)
type Dgelq2er interface {
@@ -20,7 +20,7 @@ type Dgelq2er interface {
func Dgelq2Test(t *testing.T, impl Dgelq2er) {
const tol = 1e-14
rnd := rand.New(rand.NewSource(1))
rnd := rand.New(rand.NewPCG(1, 1))
for c, test := range []struct {
m, n, lda int
}{

Some files were not shown because too many files have changed in this diff Show More