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

Function TEST

src/opr/test/tensor_manip.cpp:16–58  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

14using namespace opr;
15
16TEST(TestTensorManip, GetVarShape) {
17 HostTensorGenerator<> gen;
18 auto host_x = gen({3, 1}), host_y = gen({1, 2});
19 auto graph = ComputingGraph::make();
20 auto x = opr::Host2DeviceCopy::make(*graph, host_x),
21 y = opr::Host2DeviceCopy::make(*graph, host_y),
22 z0 = opr::GetVarShape::make({x, y, x.make_scalar(5)}),
23 z1 = opr::GetVarShape::make({x, y}, 1);
24
25 // ensure scalar is removed
26 ASSERT_EQ(2u, z0.node()->owner_opr()->input().size());
27
28 constexpr auto tdt = cg::OperatorNodeBase::NodeProp::DepType::SHAPE;
29 auto&& dt = z0.node()->owner_opr()->node_prop().dep_map();
30 ASSERT_EQ(2u, dt.size());
31 ASSERT_EQ(tdt, dt.at(x.node()));
32 ASSERT_EQ(tdt, dt.at(y.node()));
33
34 auto as_shp = [](const HostTensorND& hv) {
35 mgb_assert(hv.dtype() == dtype::Int32());
36 mgb_assert(hv.shape().ndim == 1);
37 TensorShape ret;
38 ret.ndim = hv.shape()[0];
39 auto p = hv.ptr<int>();
40 for (size_t i = 0; i < ret.ndim; ++i)
41 ret[i] = p[i];
42 return ret;
43 };
44 HostTensorND host_z0, host_z1;
45 auto func = graph->compile(
46 {make_callback_copy(z0, host_z0), make_callback_copy(z1, host_z1)});
47 func->execute();
48
49 ASSERT_EQ(TensorShape({3, 2}), as_shp(host_z0));
50 ASSERT_EQ(TensorShape({2}), as_shp(host_z1));
51
52 *host_x = *gen({5, 1, 6});
53 *host_y = *gen({1, 8, 1});
54 func->execute();
55
56 ASSERT_EQ(TensorShape({5, 8, 6}), as_shp(host_z0));
57 ASSERT_EQ(TensorShape({8}), as_shp(host_z1));
58}
59
60TEST(TestTensorManip, GetVarShapeBypass) {
61 HostTensorGenerator<> gen;

Callers

nothing calls this directly

Calls 15

make_callback_copyFunction · 0.85
TensorShapeClass · 0.85
addFunction · 0.85
is_static_var_storageFunction · 0.85
dev_ptrFunction · 0.85
make_no_fwdFunction · 0.85
gradFunction · 0.85
is_static_var_shapeFunction · 0.85
subFunction · 0.85
swapFunction · 0.85
TensorLayoutClass · 0.85
prev_dev_ptrFunction · 0.85

Tested by

no test coverage detected