|
| 1 | +using Random |
| 2 | + |
| 3 | +@testset "rand" begin |
| 4 | + |
| 5 | +# in-place |
| 6 | +for (f,T) in ((rand!,Float16), |
| 7 | + (rand!,Float32), |
| 8 | + (randn!,Float16), |
| 9 | + (randn!,Float32)), |
| 10 | + d in (2, (2,2), (2,2,2), 3, (3,3), (3,3,3)) |
| 11 | + A = oneArray{T}(undef, d) |
| 12 | + fill!(A, T(0)) |
| 13 | + f(A) |
| 14 | + @test !iszero(collect(A)) |
| 15 | +end |
| 16 | + |
| 17 | +# out-of-place, with implicit type |
| 18 | +for (f,T) in ((oneAPI.rand,Float32), (oneAPI.randn,Float32)), |
| 19 | + args in ((2,), (2, 2), (3,), (3, 3)) |
| 20 | + A = f(args...) |
| 21 | + @test eltype(A) == T |
| 22 | +end |
| 23 | + |
| 24 | +# out-of-place, with type specified |
| 25 | +for (f,T) in ((oneAPI.rand,Float32), (oneAPI.randn,Float32), |
| 26 | + (rand,Float32), (randn,Float32)), |
| 27 | + args in ((T, 2), (T, 2, 2), (T, (2, 2)), (T, 3), (T, 3, 3), (T, (3, 3))) |
| 28 | + A = f(args...) |
| 29 | + @test eltype(A) == T |
| 30 | +end |
| 31 | + |
| 32 | +## seeding |
| 33 | +oneAPI.seed!(1) |
| 34 | +a = oneAPI.rand(Int32, 1) |
| 35 | +oneAPI.seed!(1) |
| 36 | +b = oneAPI.rand(Int32, 1) |
| 37 | +@test iszero(collect(a) - collect(b)) |
| 38 | + |
| 39 | +end # testset |
0 commit comments