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

Function run_beta

dnn/test/cuda/rng.cpp:208–237  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

206
207template <typename T>
208void run_beta(Handle* handle) {
209 using ctype = typename DTypeTrait<T>::ctype;
210 auto opr = handle->create_operator<BetaRNG>();
211
212 TensorLayout ly{TensorShape{200000 * 5}, T()};
213
214 SyncedTensor<ctype> out(handle, ly);
215 SyncedTensor<ctype> alpha(handle, ly);
216 SyncedTensor<ctype> beta(handle, ly);
217 auto alpha_ptr = alpha.ptr_mutable_host();
218 auto beta_ptr = beta.ptr_mutable_host();
219 for (int i = 0; i < 5; ++i) {
220 for (int j = 0; j < 200000; ++j) {
221 alpha_ptr[i * 200000 + j] = 0.3 * i + 0.1;
222 beta_ptr[i * 200000 + j] = 2 * i * 0.3 + 0.1;
223 }
224 }
225
226 opr->exec(alpha.tensornd_dev(), beta.tensornd_dev(), out.tensornd_dev(), {});
227
228 auto ptr = out.ptr_mutable_host();
229 for (int i = 0; i < 5; ++i) {
230 float a = 0.3 * i + 0.1, b = 2 * i * 0.3 + 0.1;
231 float mean = a / (a + b);
232 float std = a * b / ((a + b) * (a + b) * (a + b + 1));
233 auto stat = get_mean_var(ptr + i * 200000, 200000, ctype(mean));
234 ASSERT_LE(std::abs(stat.first - mean), 0.01);
235 ASSERT_LE(std::abs(stat.second - std), 0.01);
236 }
237}
238
239template <typename T>
240void run_permutation(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