| 59 | }; |
| 60 | |
| 61 | void GetEdgeBinaryFeature::ComputeAsync(OpKernelContext* ctx, |
| 62 | DoneCallback done) { |
| 63 | auto edges = ctx->input(0); |
| 64 | auto& shape = edges.shape(); |
| 65 | OP_REQUIRES(ctx, shape.dim_size(1) == 3, |
| 66 | errors::InvalidArgument( |
| 67 | "Input `edges` must be a matrix with shape [n, 3]")); |
| 68 | |
| 69 | std::vector<Tensor*> outputs(N_, nullptr); |
| 70 | TensorShape output_shape; |
| 71 | output_shape.AddDim(shape.dim_size(0)); |
| 72 | for (auto i = 0; i < N_; ++i) { |
| 73 | OP_REQUIRES_OK(ctx, ctx->allocate_output(i, output_shape, &outputs[i])); |
| 74 | } |
| 75 | |
| 76 | auto edges_flat = edges.flat<int64>(); |
| 77 | size_t edges_size = edges_flat.size(); |
| 78 | size_t edge_num = edges_size / 3; |
| 79 | |
| 80 | auto query = new euler::Query(query_str_); |
| 81 | auto t_edges = query->AllocInput("edges", {edge_num, 3}, euler::kUInt64); |
| 82 | std::copy(edges_flat.data(), |
| 83 | edges_flat.data() + edges_size, t_edges->Raw<int64_t>()); |
| 84 | for (size_t i = 0; i < feature_names_.size(); ++i) { |
| 85 | auto t_fid = query->AllocInput("__" + feature_names_[i], {1}, |
| 86 | euler::kString); |
| 87 | *(t_fid->Raw<std::string*>()[0]) = "binary_" + feature_names_[i]; |
| 88 | } |
| 89 | |
| 90 | auto callback = [outputs, done, query, edge_num, this]() { |
| 91 | std::stringstream ss; |
| 92 | auto results_map = query->GetResult(res_names_); |
| 93 | for (size_t i = 0 ; i < feature_names_.size(); ++i) { |
| 94 | ss.str(""); |
| 95 | ss << "fea:" << i * 2; |
| 96 | std::string fea_idx = ss.str(); |
| 97 | |
| 98 | ss.str(""); |
| 99 | ss << "fea:" << i * 2 + 1; |
| 100 | std::string fea_val = ss.str(); |
| 101 | |
| 102 | if (results_map[fea_idx]->NumElements() != edge_num * 2) { |
| 103 | EULER_LOG(FATAL) << "Binary Feature Result Index Num Error:" << |
| 104 | results_map[fea_idx]->NumElements() << "Expect: " << edge_num * 2; |
| 105 | } |
| 106 | for (size_t j = 0; j < edge_num; ++j) { |
| 107 | size_t start = results_map[fea_idx]->Raw<int32_t>()[j * 2]; |
| 108 | size_t end = results_map[fea_idx]->Raw<int32_t>()[j * 2 + 1]; |
| 109 | auto data = outputs[i]->flat<tensorflow::string>(); |
| 110 | std::string f_v(end - start, 0); |
| 111 | std::copy(results_map[fea_val]->Raw<char>() + start, |
| 112 | results_map[fea_val]->Raw<char>() + end, |
| 113 | f_v.begin()); |
| 114 | data(j) = f_v; |
| 115 | } |
| 116 | } |
| 117 | delete query; |
| 118 | done(); |
nothing calls this directly
no test coverage detected