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

Method make

dnn/test/common/cond_take.cpp:11–65  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

9using Param = CondTake::Param;
10
11std::vector<CondTakeTestcase> CondTakeTestcase::make() {
12 std::vector<CondTakeTestcase> ret;
13 for (uint32_t mode = 0; mode < Param::MODE_NR_MEMBER; ++mode) {
14 ret.push_back({
15 Param{static_cast<Param::Mode>(mode), 0.1f, 0.1f},
16 TensorLayout{{1}, dtype::Int8()},
17 TensorLayout{{1}, dtype::Float32()},
18 });
19 ret.push_back({
20 Param{static_cast<Param::Mode>(mode), 0.1f, 0.1f},
21 TensorLayout{{2, 3}, dtype::Int8()},
22 TensorLayout{{2, 3}, dtype::Float32()},
23 });
24 ret.push_back({
25 Param{static_cast<Param::Mode>(mode), 100},
26 TensorLayout{{1024}, dtype::Float32()},
27 TensorLayout{{1024}, dtype::Int32()},
28 });
29 }
30
31 NormalRNG data_rng;
32 UniformIntRNG rng_byte(0, 255);
33 auto fill_data = [&](TensorND data) {
34 auto sz = data.layout.span().dist_byte(), szf = sz / sizeof(dt_float32);
35 auto pf = static_cast<dt_float32*>(data.raw_ptr());
36 data_rng.fill_fast_float32(pf, szf);
37
38 auto prem = reinterpret_cast<uint8_t*>(pf + szf);
39 size_t szrem = sz % sizeof(dt_float32);
40 for (size_t i = 0; i < szrem; ++i) {
41 prem[i] = rng_byte.gen_single_val();
42 }
43 };
44
45 for (auto&& i : ret) {
46 auto size0 = i.m_data.layout.span().dist_byte(),
47 size1 = i.m_mask.layout.span().dist_byte();
48 i.m_mem.reset(new uint8_t[size0 + size1]);
49 i.m_data.reset_ptr(i.m_mem.get());
50 i.m_mask.reset_ptr(i.m_mem.get() + size0);
51 fill_data(i.m_data);
52
53 auto mean = i.m_param.val;
54 if (i.m_mask.layout.dtype == dtype::Int32()) {
55 UniformIntRNG rng(mean - 10, mean + 10);
56 rng.gen(i.m_mask);
57 } else {
58 megdnn_assert(i.m_mask.layout.dtype == dtype::Float32());
59 NormalRNG rng(mean);
60 rng.gen(i.m_mask);
61 }
62 }
63
64 return ret;
65}
66
67CondTakeTestcase::Result CondTakeTestcase::run(CondTake* opr) {
68 auto handle = opr->handle();

Callers

nothing calls this directly

Calls 10

dist_byteMethod · 0.80
spanMethod · 0.80
fill_fast_float32Method · 0.80
reset_ptrMethod · 0.80
push_backMethod · 0.45
raw_ptrMethod · 0.45
gen_single_valMethod · 0.45
resetMethod · 0.45
getMethod · 0.45
genMethod · 0.45

Tested by

no test coverage detected