check that fop(gop(a, b), c) has been changed
| 15 | |
| 16 | //! check that fop(gop(a, b), c) has been changed |
| 17 | void 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 |