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

Function run_binary_trans20_test

src/gopt/test/gtrans.cpp:17–44  ·  view source on GitHub ↗

check that fop(gop(a, b), c) has been changed

Source from the content-addressed store, hash-verified

15
16//! check that fop(gop(a, b), c) has been changed
17void run_binary_trans20_test(
18 BinaryTrans20& trans, const TensorShape& sa, const TensorShape& sb,
19 const TensorShape& sc, const BinaryOp& fop, const BinaryOp& gop,
20 bool expect_succ, float err = 5e-6) {
21 HostTensorGenerator<> gen;
22 auto graph = ComputingGraph::make();
23 graph->options().graph_opt_level = 0;
24 auto mkvar = [&](const char* name, const TensorShape& shp) {
25 return opr::SharedDeviceTensor::make(*graph, *gen(shp)).rename(name);
26 };
27
28 auto a = mkvar("a", sa), b = mkvar("b", sb), ab = gop(a, b), c = mkvar("c", sc),
29 f = fop(ab, c);
30 auto ret = trans.apply(f.node()->owner_opr());
31 if (!expect_succ) {
32 ASSERT_FALSE(ret.valid());
33 return;
34 }
35 ASSERT_TRUE(ret.valid());
36
37 auto ft = ret->result;
38 ASSERT_NE(f.node(), ft);
39
40 HostTensorND host_f, host_ft;
41 graph->compile({make_callback_copy(f, host_f), make_callback_copy(ft, host_ft)})
42 ->execute();
43 MGB_ASSERT_TENSOR_NEAR(host_f, host_ft, err);
44}
45
46} // namespace
47

Callers 1

TESTFunction · 0.85

Calls 10

make_callback_copyFunction · 0.85
renameMethod · 0.80
makeFunction · 0.50
genFunction · 0.50
applyMethod · 0.45
owner_oprMethod · 0.45
nodeMethod · 0.45
validMethod · 0.45
executeMethod · 0.45
compileMethod · 0.45

Tested by

no test coverage detected