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

Function run_beta

dnn/test/naive/rng.cpp:238–267  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

236
237template <typename dtype>
238void run_beta(Handle* handle) {
239 using ctype = typename DTypeTrait<dtype>::ctype;
240 auto opr = handle->create_operator<BetaRNG>();
241
242 TensorLayout ly{TensorShape{200000 * 5}, dtype()};
243
244 Tensor<ctype> out(handle, ly);
245 Tensor<ctype> alpha(handle, ly);
246 Tensor<ctype> beta(handle, ly);
247
248 auto alpha_ptr = alpha.ptr();
249 auto beta_ptr = beta.ptr();
250 for (int i = 0; i < 5; ++i) {
251 for (int j = 0; j < 200000; ++j) {
252 alpha_ptr[i * 200000 + j] = 0.3 * i + 0.1;
253 beta_ptr[i * 200000 + j] = 2 * i * 0.3 + 0.1;
254 }
255 }
256 opr->exec(alpha.tensornd(), beta.tensornd(), out.tensornd(), {});
257
258 auto ptr = out.ptr();
259 for (int i = 0; i < 5; ++i) {
260 float a = 0.3 * i + 0.1, b = 2 * i * 0.3 + 0.1;
261 float mean = a / (a + b);
262 float std = a * b / ((a + b) * (a + b) * (a + b + 1));
263 auto stat = get_mean_var(ptr + i * 200000, 200000, ctype(mean));
264 ASSERT_LE(std::abs(stat.first - mean), 0.01);
265 ASSERT_LE(std::abs(stat.second - std), 0.01);
266 }
267}
268
269template <typename dtype>
270void run_permutation(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