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

Function run_gamma

dnn/test/naive/rng.cpp:53–82  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

51
52template <typename dtype>
53void run_gamma(Handle* handle) {
54 using ctype = typename DTypeTrait<dtype>::ctype;
55 auto opr = handle->create_operator<GammaRNG>();
56
57 TensorLayout ly{TensorShape{2000000 * 5}, dtype()};
58
59 Tensor<ctype> out(handle, ly);
60 Tensor<ctype> shape(handle, ly);
61 Tensor<ctype> scale(handle, ly);
62
63 auto shape_ptr = shape.ptr();
64 auto scale_ptr = scale.ptr();
65 for (int i = 0; i < 5; ++i) {
66 for (int j = 0; j < 2000000; ++j) {
67 shape_ptr[i * 2000000 + j] = 2 * 0.3 * i + 0.5;
68 scale_ptr[i * 2000000 + j] = i * 0.2 + 0.1;
69 }
70 }
71 opr->exec(shape.tensornd(), scale.tensornd(), out.tensornd(), {});
72
73 auto ptr = out.ptr();
74 for (int i = 0; i < 5; ++i) {
75 float a = 2 * 0.3 * i + 0.5, b = i * 0.2 + 0.1;
76 float mean = a * b;
77 float std = a * (b * b);
78 auto stat = get_mean_var(ptr + i * 2000000, 2000000, ctype(mean));
79 ASSERT_LE(std::abs(stat.first - mean), 0.01);
80 ASSERT_LE(std::abs(stat.second - std), 0.01);
81 }
82}
83
84template <typename dtype>
85void run_poisson(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