| 41 | } |
| 42 | |
| 43 | void Compute(OpKernelContext* ctx) override { |
| 44 | const Tensor* names; |
| 45 | const Tensor* serialized; |
| 46 | OpInputList dense_keys; |
| 47 | OpInputList sparse_keys; |
| 48 | OpInputList dense_defaults; |
| 49 | |
| 50 | // Grab the input list arguments. |
| 51 | OP_REQUIRES_OK(ctx, ctx->input("names", &names)); |
| 52 | OP_REQUIRES_OK(ctx, ctx->input("serialized", &serialized)); |
| 53 | OP_REQUIRES_OK(ctx, ctx->input_list("dense_keys", &dense_keys)); |
| 54 | OP_REQUIRES_OK(ctx, ctx->input_list("sparse_keys", &sparse_keys)); |
| 55 | OP_REQUIRES_OK(ctx, ctx->input_list("dense_defaults", &dense_defaults)); |
| 56 | |
| 57 | std::vector<string> dense_keys_t(attrs_.num_dense); |
| 58 | std::vector<string> sparse_keys_t(attrs_.num_sparse); |
| 59 | |
| 60 | // Check that the input list sizes match the attribute declared sizes. |
| 61 | CHECK_EQ(dense_keys.size(), attrs_.num_dense); |
| 62 | CHECK_EQ(sparse_keys.size(), attrs_.num_sparse); |
| 63 | |
| 64 | // Copy from OpInputList to std::vector<string>. |
| 65 | for (int di = 0; di < attrs_.num_dense; ++di) { |
| 66 | dense_keys_t[di] = dense_keys[di].scalar<tstring>()(); |
| 67 | } |
| 68 | for (int di = 0; di < attrs_.num_sparse; ++di) { |
| 69 | sparse_keys_t[di] = sparse_keys[di].scalar<tstring>()(); |
| 70 | } |
| 71 | |
| 72 | if (names->NumElements() > 0) { |
| 73 | OP_REQUIRES( |
| 74 | ctx, TensorShapeUtils::IsVector(names->shape()), |
| 75 | errors::InvalidArgument("Expected names to be a vector, got shape: ", |
| 76 | names->shape().DebugString())); |
| 77 | OP_REQUIRES( |
| 78 | ctx, names->NumElements() == serialized->NumElements(), |
| 79 | errors::InvalidArgument( |
| 80 | "Expected len(names) == len(serialized), but got: ", |
| 81 | names->NumElements(), " vs. ", serialized->NumElements())); |
| 82 | } |
| 83 | |
| 84 | OP_REQUIRES(ctx, TensorShapeUtils::IsVector(serialized->shape()), |
| 85 | errors::InvalidArgument( |
| 86 | "Expected serialized to be a vector, got shape: ", |
| 87 | serialized->shape().DebugString())); |
| 88 | OP_REQUIRES(ctx, dense_defaults.size() == attrs_.num_dense, |
| 89 | errors::InvalidArgument( |
| 90 | "Expected len(dense_defaults) == len(dense_keys) but got: ", |
| 91 | dense_defaults.size(), " vs. ", attrs_.num_dense)); |
| 92 | |
| 93 | for (int d = 0; d < static_cast<int>(attrs_.num_dense); ++d) { |
| 94 | const Tensor& def_value = dense_defaults[d]; |
| 95 | if (attrs_.variable_length[d]) { |
| 96 | OP_REQUIRES(ctx, def_value.NumElements() == 1, |
| 97 | errors::InvalidArgument( |
| 98 | "dense_shape[", d, "] is a variable length shape: ", |
| 99 | attrs_.dense_shapes[d].DebugString(), |
| 100 | ", therefore " |
nothing calls this directly
no test coverage detected