| 226 | |
| 227 | template<typename T> |
| 228 | void testSetSeed(const uintl seed0, const uintl seed1) { |
| 229 | SUPPORTED_TYPE_CHECK(T); |
| 230 | |
| 231 | uintl orig_seed = getSeed(); |
| 232 | |
| 233 | const int num = 1024 * 1024; |
| 234 | dtype ty = (dtype)dtype_traits<T>::af_type; |
| 235 | |
| 236 | setSeed(seed0); |
| 237 | array in0 = randu(num, ty); |
| 238 | |
| 239 | setSeed(seed1); |
| 240 | array in1 = randu(num, ty); |
| 241 | |
| 242 | setSeed(seed0); |
| 243 | array in2 = randu(num, ty); |
| 244 | array in3 = randu(num, ty); |
| 245 | |
| 246 | vector<T> h_in0(num); |
| 247 | vector<T> h_in1(num); |
| 248 | vector<T> h_in2(num); |
| 249 | vector<T> h_in3(num); |
| 250 | |
| 251 | in0.host((void *)&h_in0[0]); |
| 252 | in1.host((void *)&h_in1[0]); |
| 253 | in2.host((void *)&h_in2[0]); |
| 254 | in3.host((void *)&h_in3[0]); |
| 255 | |
| 256 | for (int i = 0; i < num; i++) { |
| 257 | // Verify if same seed produces same arrays |
| 258 | ASSERT_EQ(h_in0[i], h_in2[i]) << "at : " << i; |
| 259 | |
| 260 | // Verify different arrays created with different seeds differ |
| 261 | // b8, s8 and u8 can clash because they generate a small set of values |
| 262 | if (ty != b8 && ty != s8 && ty != u8) { |
| 263 | ASSERT_NE(h_in0[i], h_in1[i]) << "at : " << i; |
| 264 | } |
| 265 | |
| 266 | // Verify different arrays created one after the other with same seed |
| 267 | // differ b8, s8 and u8 can clash because they generate a small set of |
| 268 | // values |
| 269 | if (ty != b8 && ty != s8 && ty != u8) { |
| 270 | ASSERT_NE(h_in2[i], h_in3[i]) << "at : " << i; |
| 271 | } |
| 272 | } |
| 273 | |
| 274 | setSeed(orig_seed); // Reset the seed |
| 275 | } |
| 276 | |
| 277 | TYPED_TEST(RandomSeed, setSeed) { testSetSeed<TypeParam>(10101, 23232); } |
| 278 | |