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

Function TEST

src/core/test/static_infer.cpp:120–145  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

118} // anonymous namespace
119
120TEST(TestStaticInfer, ValueInfer) {
121 using namespace cg::static_infer;
122 HostTensorGenerator<> gen;
123 constexpr size_t SIZE = 3;
124 auto host_x0 = gen({SIZE}), host_x1 = gen({SIZE});
125
126 auto graph = ComputingGraph::make();
127 auto x0 = opr::Host2DeviceCopy::make(*graph, host_x0),
128 x1 = opr::Host2DeviceCopy::make(*graph, host_x1), x2 = x0 + x1,
129 y0 = x0.make_scalar(2.f), y1 = x0.make_scalar(3.f), y2 = opr::pow(y0, y1);
130 auto&& mgr = x0.node()->owner_graph()->static_infer_manager();
131 ASSERT_EQ(InferType::RT_STATIC, mgr.get_infer_type(x2.node()).value);
132 ASSERT_EQ(InferType::CONST, mgr.get_infer_type(y0.node()).value);
133 ASSERT_EQ(InferType::CONST, mgr.get_infer_type(y1.node()).value);
134 ASSERT_EQ(InferType::CONST, mgr.get_infer_type(y2.node()).value);
135 auto x2v = mgr.infer_value(x2.node());
136 ASSERT_EQ(host_x0->shape(), x2v.shape());
137 for (size_t i = 0; i < SIZE; i++)
138 MGB_ASSERT_FLOAT_EQ(
139 host_x0->ptr<float>()[i] + host_x1->ptr<float>()[i],
140 x2v.ptr<float>()[i]);
141
142 auto y2v = mgr.infer_value(y2.node());
143 ASSERT_TRUE(y2v.shape().is_scalar());
144 MGB_ASSERT_FLOAT_EQ(8.f, y2v.ptr<float>()[0]);
145}
146
147TEST(TestStaticInfer, ValueNonContig) {
148 using namespace cg::static_infer;

Callers

nothing calls this directly

Calls 15

make_callback_copyFunction · 0.85
TensorShapeClass · 0.85
TensorLayoutClass · 0.85
maxFunction · 0.85
infer_valueMethod · 0.80
resizeMethod · 0.80
storageMethod · 0.80
as_immutable_scalarMethod · 0.80
add_destMethod · 0.80
makeFunction · 0.70
genFunction · 0.50

Tested by

no test coverage detected