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

Function run_gaussian

dnn/test/naive/rng.cpp:32–50  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

30
31template <typename dtype>
32void run_gaussian(Handle* handle) {
33 using ctype = typename DTypeTrait<dtype>::ctype;
34 auto opr = handle->create_operator<GaussianRNG>();
35 opr->param().mean = 0.8;
36 opr->param().std = 2.3;
37 opr->param().dtype = DTypeTrait<dtype>::enumv;
38 Tensor<ctype> t(handle, {TensorShape{200001}, dtype()});
39 opr->exec(t.tensornd(), {});
40
41 auto ptr = t.ptr();
42 auto size = t.layout().total_nr_elems();
43 for (size_t i = 0; i < size; ++i) {
44 ASSERT_LE(std::abs(ptr[i] - 0.8), ctype(15));
45 }
46 auto stat = get_mean_var(ptr, size, ctype(0.8));
47
48 ASSERT_LE(std::abs(stat.first - 0.8), 5e-3);
49 ASSERT_LE(std::abs(stat.second - 2.3 * 2.3), 5e-2);
50}
51
52template <typename dtype>
53void run_gamma(Handle* handle) {

Callers

nothing calls this directly

Calls 8

get_mean_varFunction · 0.85
absFunction · 0.50
paramMethod · 0.45
execMethod · 0.45
tensorndMethod · 0.45
ptrMethod · 0.45
total_nr_elemsMethod · 0.45
layoutMethod · 0.45

Tested by

no test coverage detected