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

Function run_gamma

dnn/test/cuda/rng.cpp:13–42  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

11
12template <typename T>
13void run_gamma(Handle* handle) {
14 using ctype = typename DTypeTrait<T>::ctype;
15 auto opr = handle->create_operator<GammaRNG>();
16
17 TensorLayout ly{TensorShape{2000000 * 5}, T()};
18
19 SyncedTensor<ctype> out(handle, ly);
20 SyncedTensor<ctype> shape(handle, ly);
21 SyncedTensor<ctype> scale(handle, ly);
22 auto shape_ptr = shape.ptr_mutable_host();
23 auto scale_ptr = scale.ptr_mutable_host();
24 for (int i = 0; i < 5; ++i) {
25 for (int j = 0; j < 2000000; ++j) {
26 shape_ptr[i * 2000000 + j] = 2 * 0.3 * i + 0.3;
27 scale_ptr[i * 2000000 + j] = i * 0.2 + 0.1;
28 }
29 }
30
31 opr->exec(shape.tensornd_dev(), scale.tensornd_dev(), out.tensornd_dev(), {});
32
33 auto ptr = out.ptr_mutable_host();
34 for (int i = 0; i < 5; ++i) {
35 float a = 2 * 0.3 * i + 0.3, b = i * 0.2 + 0.1;
36 float mean = a * b;
37 float std = a * (b * b);
38 auto stat = get_mean_var(ptr + i * 2000000, 2000000, ctype(mean));
39 ASSERT_LE(std::abs(stat.first - mean), 0.01);
40 ASSERT_LE(std::abs(stat.second - std), 0.01);
41 }
42}
43
44template <typename T>
45void run_poisson(Handle* handle) {

Callers

nothing calls this directly

Calls 4

TClass · 0.85
get_mean_varFunction · 0.85
absFunction · 0.50
execMethod · 0.45

Tested by

no test coverage detected