MCPcopy Create free account
hub / github.com/arrayfire/arrayfire / testSetSeed

Function testSetSeed

test/random.cpp:228–275  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

226
227template<typename T>
228void 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
277TYPED_TEST(RandomSeed, setSeed) { testSetSeed<TypeParam>(10101, 23232); }
278

Callers

nothing calls this directly

Calls 4

getSeedFunction · 0.85
setSeedFunction · 0.85
randuFunction · 0.85
hostMethod · 0.80

Tested by

no test coverage detected