diff options
author | 2018-04-06 17:17:22 -0700 | |
---|---|---|
committer | 2018-04-06 17:19:59 -0700 | |
commit | 5e11bbacaffdf7bc4a9363301de6a0755f95e9c0 (patch) | |
tree | 48f37585cd3b01c71eaced8724be21151374264d /tensorflow/core/ops/encode_proto_ops.cc | |
parent | ddf54d1c24a2b4dcfd8eb52d21dc1f393785f1e9 (diff) |
Open sourcing proto/rpc ops.
PiperOrigin-RevId: 191962572
Diffstat (limited to 'tensorflow/core/ops/encode_proto_ops.cc')
-rw-r--r-- | tensorflow/core/ops/encode_proto_ops.cc | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/tensorflow/core/ops/encode_proto_ops.cc b/tensorflow/core/ops/encode_proto_ops.cc new file mode 100644 index 0000000000..f5ec3056e3 --- /dev/null +++ b/tensorflow/core/ops/encode_proto_ops.cc @@ -0,0 +1,49 @@ +/* Copyright 2018 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/core/framework/op.h" +#include "tensorflow/core/framework/shape_inference.h" + +namespace tensorflow { + +using tensorflow::shape_inference::InferenceContext; +using tensorflow::shape_inference::ShapeHandle; + +REGISTER_OP("EncodeProto") + .Input("sizes: int32") + .Input("values: Tinput_types") + .Attr("field_names: list(string)") + .Attr("message_type: string") + .Attr("descriptor_source: string = 'local://'") + .Attr("Tinput_types: list(type)") + .Output("bytes: string") + .SetShapeFn([](InferenceContext* c) { + int first_field_index = 1; + int num_fields = c->num_inputs() - 1; + + ShapeHandle output; + for (int i = num_fields - 1; i >= 0; --i) { + ShapeHandle input = c->input(first_field_index + i); + TF_RETURN_IF_ERROR(c->WithRankAtLeast(input, 2, &input)); + ShapeHandle inner; + TF_RETURN_IF_ERROR(c->Subshape(input, 0, -1, &inner)); + TF_RETURN_IF_ERROR(c->Merge(inner, output, &output)); + } + + c->set_output(0, output); + return Status::OK(); + }); + +} // namespace tensorflow |