| 33 | }; |
| 34 | |
| 35 | void SampleEdge::ComputeAsync(OpKernelContext* ctx, DoneCallback done) { |
| 36 | auto count = ctx->input(0); |
| 37 | auto edge_type = ctx->input(1); |
| 38 | OP_REQUIRES(ctx, TensorShapeUtils::IsScalar(count.shape()), |
| 39 | errors::InvalidArgument("count must be a scalar, saw shape: ", |
| 40 | count.shape().DebugString())); |
| 41 | OP_REQUIRES(ctx, TensorShapeUtils::IsScalar(edge_type.shape()), |
| 42 | errors::InvalidArgument("edge_type must be a scalar, saw shape: ", |
| 43 | edge_type.shape().DebugString())); |
| 44 | auto count_value = (count.scalar<int32>())(); |
| 45 | auto type_value = (edge_type.scalar<int32>())(); |
| 46 | |
| 47 | TensorShape output_shape; |
| 48 | output_shape.AddDim(count_value); |
| 49 | output_shape.AddDim(3); |
| 50 | |
| 51 | Tensor* output = nullptr; |
| 52 | OP_REQUIRES_OK(ctx, ctx->allocate_output(0, output_shape, &output)); |
| 53 | |
| 54 | // build euler gremlin query |
| 55 | auto query = new euler::Query("sampleE(edge_type, count).as(eid)"); |
| 56 | auto t_edge_type = query->AllocInput("edge_type", {1}, euler::kInt32); |
| 57 | auto t_count = query->AllocInput("count", {1}, euler::kInt32); |
| 58 | *(t_edge_type->Raw<int32_t>()) = type_value; |
| 59 | *(t_count->Raw<int32_t>()) = count_value; |
| 60 | |
| 61 | auto callback = [output, done, query] () { |
| 62 | auto res = query->GetResult("eid:0"); |
| 63 | auto res_data = res->Raw<uint64_t>(); |
| 64 | auto data = output->flat<int64>().data(); |
| 65 | std::copy(res_data, res_data + res->NumElements(), data); |
| 66 | delete query; |
| 67 | done(); |
| 68 | }; |
| 69 | euler::QueryProxy::GetInstance()->RunAsyncGremlin(query, callback); |
| 70 | } |
| 71 | |
| 72 | REGISTER_KERNEL_BUILDER(Name("SampleEdge").Device(DEVICE_CPU), SampleEdge); |
| 73 |
nothing calls this directly
no test coverage detected