| 784 | explicit LookupTableFindOp(OpKernelConstruction* ctx) : OpKernel(ctx) {} |
| 785 | |
| 786 | void Compute(OpKernelContext* ctx) override { |
| 787 | lookup::LookupInterface* table; |
| 788 | OP_REQUIRES_OK(ctx, GetLookupTable("table_handle", ctx, &table)); |
| 789 | core::ScopedUnref unref_me(table); |
| 790 | |
| 791 | // Input 0 could be a STRING_REF or a RESOURCE |
| 792 | DataType expected_input_0 = |
| 793 | (ctx->input_dtype(0) == DT_RESOURCE) ? DT_RESOURCE : DT_STRING_REF; |
| 794 | DataTypeVector expected_inputs = {expected_input_0, table->key_dtype(), |
| 795 | table->value_dtype()}; |
| 796 | DataTypeVector expected_outputs = {table->value_dtype()}; |
| 797 | OP_REQUIRES_OK(ctx, ctx->MatchSignature(expected_inputs, expected_outputs)); |
| 798 | |
| 799 | const Tensor& key = ctx->input(1); |
| 800 | const Tensor& default_value = ctx->input(2); |
| 801 | OP_REQUIRES_OK(ctx, table->CheckFindArguments(key, default_value)); |
| 802 | |
| 803 | TensorShape output_shape = key.shape(); |
| 804 | output_shape.RemoveLastDims(table->key_shape().dims()); |
| 805 | output_shape.AppendShape(table->value_shape()); |
| 806 | Tensor* out; |
| 807 | OP_REQUIRES_OK(ctx, ctx->allocate_output("values", output_shape, &out)); |
| 808 | |
| 809 | OP_REQUIRES_OK(ctx, table->Find(ctx, key, out, default_value)); |
| 810 | } |
| 811 | }; |
| 812 | |
| 813 | REGISTER_KERNEL_BUILDER(Name("LookupTableFind").Device(DEVICE_CPU), |
nothing calls this directly
no test coverage detected