20
20
seq = InfiniteArrays. InfRandVector (rng, Float16)
21
21
rng2 = MersenneTwister (123 )
22
22
@test seq[1 : 10000 ] == [rand (rng2, Float16) for _ in 1 : 10000 ]
23
- end
23
+ end
24
24
25
- @testset " Distributions.jl" begin
25
+ @testset " Distributions.jl" begin
26
26
dist = Normal (0.3 , 1.7 ) # do Normal{Float32} for example if you want that number type
27
27
rng = Xoshiro (5 )
28
28
seq = InfiniteArrays. InfRandVector (rng, dist)
29
29
rng2 = Xoshiro (5 )
30
30
@test seq[1 : 100 ] == [0.3 + 1.7 randn (rng2) for _ in 1 : 100 ]
31
31
end
32
+ end
33
+
34
+ @testset " InfRandMatrix" begin
35
+ @testset " Default constructor" begin
36
+ Random. seed! (123 )
37
+ A = InfiniteArrays. InfRandMatrix (5 )
38
+ @test size (A) == (5 , ∞)
39
+ @test axes (A) == (1 : 5 , 1 : ∞)
40
+ val = A[1 , 1 ]
41
+ @inferred A[5 , 5 ]
42
+ @test A[1 : 3 , 1 : 100 ] == A[1 : 3 , 1 : 100 ]
43
+ @test_throws BoundsError A[0 , 1 ]
44
+ Random. seed! (123 )
45
+ _A = [rand () for _ in 1 : 5 , _ in 1 : 1000 ]
46
+ @test _A == A[1 : 5 , 1 : 1000 ]
47
+ @test (A+ A)[1 : 5 , 1 : 1000 ] ≈ 2_ A
48
+ @test (A' + A' )[1 : 1000 , 1 : 5 ] ≈ 2_ A'
49
+ @test A[11 ] ≈ A. seq[11 ] ≈ A[1 , 3 ]
50
+ end
51
+
52
+ @testset " Providing an RNG and a distribution" begin
53
+ rng = MersenneTwister (123 )
54
+ seq = InfiniteArrays. InfRandMatrix (rng, 10 ; dist= Float16)
55
+ rng2 = MersenneTwister (123 )
56
+ @test seq[1 : 10000 ] == [rand (rng2, Float16) for _ in 1 : 10000 ]
57
+ end
58
+
59
+ @testset " Distributions.jl" begin
60
+ dist = Normal (0.3 , 1.7 )
61
+ rng = Xoshiro (5 )
62
+ seq = InfiniteArrays. InfRandMatrix (rng, 2 ; dist)
63
+ rng2 = Xoshiro (5 )
64
+ @test seq[1 : 1000 ] == [0.3 + 1.7 randn (rng2) for _ in 1 : 1000 ]
65
+ end
32
66
end
0 commit comments