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

Function TEST

src/opr/test/loop/basic.cpp:111–138  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

109} // anonymous namespace
110
111TEST(TestOprLoop, APlusB) {
112 HostTensorGenerator<> gen;
113
114 auto host_x = gen({23});
115 auto graph = ComputingGraph::make();
116 auto x = opr::Host2DeviceCopy::make(*graph, host_x);
117
118 auto desc_maker = [&](LoopDesc& loop_desc) {
119 auto xl = loop_desc.add_input_assignable(x).rename("xl"), xu = xl * 2 + 1;
120 loop_desc.assign(xl, xu);
121 loop_desc.add_output(xu, OutputMode::LAST);
122 loop_desc.set_loop_condition(loop_desc.get_counter_var() < 3);
123 };
124
125 auto y = opr::Loop::make(desc_maker, 3)[0];
126 HostTensorND host_y;
127 auto func = graph->compile({make_callback_copy(y, host_y)});
128 func->execute();
129 ASSERT_EQ(host_x->shape(), host_y.shape());
130 auto px = host_x->ptr<float>(), py = host_y.ptr<float>();
131 for (size_t i = 0; i < 23; ++i) {
132 auto yv = px[i];
133 for (int j = 0; j < 4; ++j) {
134 yv = yv * 2 + 1;
135 }
136 ASSERT_EQ(yv, py[i]);
137 }
138}
139
140TEST(TestOprLoop, APlusBGrad) {
141 HostTensorGenerator<> gen;

Callers

nothing calls this directly

Calls 15

make_callback_copyFunction · 0.85
gradFunction · 0.85
unpack_vectorFunction · 0.85
output_fileFunction · 0.85
test_basic_fwd_with_gradFunction · 0.85
is_static_var_shapeFunction · 0.85
make_no_value_inferFunction · 0.85
TensorShapeClass · 0.85
test_null_gradFunction · 0.85
set_priorityFunction · 0.85
renameMethod · 0.80
add_input_assignableMethod · 0.80

Tested by

no test coverage detected