MCPcopy Create free account
hub / github.com/MegEngine/MegEngine / run_exponential

Function run_exponential

dnn/test/naive/rng.cpp:359–384  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

357
358template <typename dtype>
359void run_exponential(Handle* handle) {
360 using ctype = typename DTypeTrait<dtype>::ctype;
361 auto opr = handle->create_operator<ExponentialRNG>();
362
363 TensorLayout ly{TensorShape{200000 * 5}, dtype()};
364
365 Tensor<ctype> out(handle, ly);
366 Tensor<ctype> rate(handle, ly);
367
368 auto rate_ptr = rate.ptr();
369 for (int i = 0; i < 5; ++i) {
370 for (int j = 0; j < 200000; ++j) {
371 rate_ptr[i * 200000 + j] = ctype(i + 1);
372 }
373 }
374 opr->exec(rate.tensornd(), out.tensornd(), {});
375
376 auto ptr = out.ptr();
377 for (int i = 0; i < 5; ++i) {
378 auto stat = get_mean_var(ptr + i * 200000, 200000, ctype(i + 1));
379 float mean = 1.0 / (i + 1);
380 float var = 1.0 / ((i + 1) * (i + 1));
381 ASSERT_LE(std::abs(stat.first - mean), 0.01);
382 ASSERT_LE(std::abs(stat.second - var), 0.01);
383 }
384}
385
386template <typename T>
387void run_dropout(Handle* handle) {

Callers

nothing calls this directly

Calls 5

get_mean_varFunction · 0.85
absFunction · 0.50
ptrMethod · 0.45
execMethod · 0.45
tensorndMethod · 0.45

Tested by

no test coverage detected