| 37 | explicit SummaryScalarOp(OpKernelConstruction* context) : OpKernel(context) {} |
| 38 | |
| 39 | void Compute(OpKernelContext* c) override { |
| 40 | const Tensor& tags = c->input(0); |
| 41 | const Tensor& values = c->input(1); |
| 42 | |
| 43 | OP_REQUIRES( |
| 44 | c, |
| 45 | tags.IsSameSize(values) || |
| 46 | (IsLegacyScalar(tags.shape()) && IsLegacyScalar(values.shape())), |
| 47 | errors::InvalidArgument( |
| 48 | "tags and values not the same shape: ", tags.shape().DebugString(), |
| 49 | " != ", values.shape().DebugString(), SingleTag(tags))); |
| 50 | auto Ttags = tags.flat<tstring>(); |
| 51 | auto Tvalues = values.flat<T>(); |
| 52 | Summary s; |
| 53 | for (int i = 0; i < Ttags.size(); i++) { |
| 54 | Summary::Value* v = s.add_value(); |
| 55 | v->set_tag(string(Ttags(i))); // NOLINT |
| 56 | v->set_simple_value(float(Tvalues(i))); |
| 57 | } |
| 58 | |
| 59 | Tensor* summary_tensor = nullptr; |
| 60 | OP_REQUIRES_OK(c, c->allocate_output(0, TensorShape({}), &summary_tensor)); |
| 61 | CHECK(SerializeToTString(s, &summary_tensor->scalar<tstring>()())); |
| 62 | } |
| 63 | |
| 64 | // If there's only one tag, include it in the error message |
| 65 | static string SingleTag(const Tensor& tags) { |
nothing calls this directly
no test coverage detected