| 109 | } // anonymous namespace |
| 110 | |
| 111 | TEST(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 | |
| 140 | TEST(TestOprLoop, APlusBGrad) { |
| 141 | HostTensorGenerator<> gen; |
nothing calls this directly
no test coverage detected