|
1 | 1 | const RAND_ALGS = (AK.SplitMix64(), AK.Philox(), AK.Threefry()) |
2 | | -const RAND_SCALAR_TYPES_ALL = (UInt32, UInt64, Int32, Int64, Float32, Float64, Bool) |
| 2 | +const RAND_SCALAR_TYPES_ALL = ( |
| 3 | + UInt8, UInt16, UInt32, UInt64, |
| 4 | + Int8, Int16, Int32, Int64, |
| 5 | + Float16, Float32, Float64, |
| 6 | + Bool, |
| 7 | +) |
3 | 8 | const RAND_SCALAR_TYPES_BACKEND = IS_CPU_BACKEND ? |
4 | 9 | RAND_SCALAR_TYPES_ALL : |
5 | | - (UInt32, UInt64, Int32, Int64, Float32, Bool) |
| 10 | + (UInt8, UInt16, UInt32, UInt64, Int8, Int16, Int32, Int64, Float16, Float32, Bool) |
6 | 11 | const RUN_FLOAT64_RAND_TESTS = IS_CPU_BACKEND |
7 | 12 |
|
8 | 13 |
|
|
62 | 67 | @test AK._counter_from_index(1) == UInt64(0) |
63 | 68 | @test AK._counter_from_index(17) == UInt64(16) |
64 | 69 |
|
| 70 | + @test AK.raw_uint_type(UInt8) === UInt32 |
| 71 | + @test AK.raw_uint_type(UInt16) === UInt32 |
65 | 72 | @test AK.raw_uint_type(UInt32) === UInt32 |
| 73 | + @test AK.raw_uint_type(Int8) === UInt32 |
| 74 | + @test AK.raw_uint_type(Int16) === UInt32 |
66 | 75 | @test AK.raw_uint_type(Int32) === UInt32 |
| 76 | + @test AK.raw_uint_type(Float16) === UInt32 |
67 | 77 | @test AK.raw_uint_type(Float32) === UInt32 |
68 | 78 | @test AK.raw_uint_type(UInt64) === UInt64 |
69 | 79 | @test AK.raw_uint_type(Int64) === UInt64 |
|
72 | 82 | @test AK.raw_uint_type(Float64) === UInt64 |
73 | 83 | end |
74 | 84 |
|
| 85 | + @test AK.from_uint(UInt8, UInt32(0xabcdef01)) == UInt8(0xab) |
| 86 | + @test AK.from_uint(UInt16, UInt32(0xabcdef01)) == UInt16(0xabcd) |
75 | 87 | @test AK.from_uint(UInt32, 0b1010 % UInt32) == 0b1010 % UInt32 |
76 | 88 | @test AK.from_uint(UInt64, 0b1010 % UInt64) == 0b1010 % UInt64 |
| 89 | + @test AK.from_uint(Int8, UInt32(0xff000000)) == Int8(-1) |
| 90 | + @test AK.from_uint(Int16, UInt32(0xffff0000)) == Int16(-1) |
77 | 91 | @test AK.from_uint(Int32, 0b11111111111111111111111111111111 % UInt32) == Int32(-1) |
78 | 92 | @test AK.from_uint( |
79 | 93 | Int64, 0b1111111111111111111111111111111111111111111111111111111111111111 % UInt64 |
80 | 94 | ) == Int64(-1) |
| 95 | + @test AK.from_uint(Float16, UInt32(0)) == Float16(0) |
81 | 96 | @test AK.from_uint(Bool, UInt32(0)) == false |
82 | 97 | @test AK.from_uint(Bool, UInt32(1)) == true |
83 | 98 |
|
| 99 | + @test AK.uint32_to_unit_float16(UInt32(0)) == Float16(0) |
| 100 | + @test Float16(0) <= AK.uint32_to_unit_float16(typemax(UInt32)) < Float16(1) |
84 | 101 | @test AK.uint32_to_unit_float32(UInt32(0)) == 0.0f0 |
85 | 102 | @test 0.0f0 <= AK.uint32_to_unit_float32(typemax(UInt32)) < 1.0f0 |
86 | 103 | if RUN_FLOAT64_RAND_TESTS |
|
126 | 143 | s1 = AK.rand_scalar(rng, UInt64(1), T) |
127 | 144 | @test s0 isa T |
128 | 145 | @test s1 isa T |
129 | | - if T !== Bool |
| 146 | + if !(T in (Bool, Float16, UInt8, UInt16, Int8, Int16)) |
130 | 147 | @test s0 != s1 |
131 | 148 | end |
132 | 149 | if T <: AbstractFloat |
|
136 | 153 | end |
137 | 154 |
|
138 | 155 | c = UInt64(42) |
| 156 | + @test AK.rand_scalar(rng, c, UInt8) == trunc(UInt8, AK.rand_uint(rng, c, UInt32) >> 24) |
| 157 | + @test AK.rand_scalar(rng, c, UInt16) == trunc(UInt16, AK.rand_uint(rng, c, UInt32) >> 16) |
| 158 | + @test AK.rand_scalar( |
| 159 | + rng, c, Int8 |
| 160 | + ) == reinterpret(Int8, trunc(UInt8, AK.rand_uint(rng, c, UInt32) >> 24)) |
| 161 | + @test AK.rand_scalar( |
| 162 | + rng, c, Int16 |
| 163 | + ) == reinterpret(Int16, trunc(UInt16, AK.rand_uint(rng, c, UInt32) >> 16)) |
139 | 164 | @test AK.rand_scalar(rng, c, Int32) == reinterpret(Int32, AK.rand_uint(rng, c, UInt32)) |
140 | 165 | @test AK.rand_scalar(rng, c, Int64) == reinterpret(Int64, AK.rand_uint(rng, c, UInt64)) |
| 166 | + @test AK.rand_scalar(rng, c, Float16) == AK.uint32_to_unit_float16( |
| 167 | + AK.rand_uint(rng, c, UInt32) |
| 168 | + ) |
141 | 169 | @test AK.rand_scalar(rng, c, Float32) == AK.uint32_to_unit_float32( |
142 | 170 | AK.rand_uint(rng, c, UInt32) |
143 | 171 | ) |
|
150 | 178 | bools = [AK.rand_scalar(rng, UInt64(i), Bool) for i in 0:511] |
151 | 179 | @test any(identity, bools) |
152 | 180 | @test any(!, bools) |
153 | | - @test_throws ArgumentError AK.rand_scalar(rng, UInt64(0), UInt16) |
| 181 | + @test_throws ArgumentError AK.rand_scalar(rng, UInt64(0), UInt128) |
154 | 182 | end |
155 | 183 |
|
156 | 184 |
|
|
185 | 213 | @test Array(x1) != Array(x2) |
186 | 214 | end |
187 | 215 |
|
188 | | - for T in (Float32, UInt64, Bool) |
| 216 | + for T in (Float16, Float32, UInt64, Bool) |
189 | 217 | xnd = array_from_host(zeros(T, 7, 11, 5)) |
190 | 218 | _assert_rand_matches_reference!(rng, xnd; prefer_threads, block_size=128) |
191 | 219 | end |
|
226 | 254 | @test Array(x1) == Array(ref1) |
227 | 255 | @test Array(x2) == Array(ref2) |
228 | 256 |
|
229 | | - x_bad = array_from_host(zeros(UInt16, 16)) |
| 257 | + x_bad = zeros(UInt128, 16) |
230 | 258 | @test_throws ArgumentError AK.rand!(x_bad; prefer_threads) |
231 | 259 | @test_throws ArgumentError AK.rand!(AK.CounterRNG(0x1), x_bad; prefer_threads) |
232 | 260 | end |
|
0 commit comments