| 79 | explicit SummaryHistoOp(OpKernelConstruction* context) : OpKernel(context) {} |
| 80 | |
| 81 | void Compute(OpKernelContext* c) override { |
| 82 | const Tensor& tags = c->input(0); |
| 83 | const Tensor& values = c->input(1); |
| 84 | const auto flat = values.flat<T>(); |
| 85 | OP_REQUIRES(c, IsLegacyScalar(tags.shape()), |
| 86 | errors::InvalidArgument("tags must be scalar")); |
| 87 | // Build histogram of values in "values" tensor |
| 88 | histogram::Histogram histo; |
| 89 | for (int64 i = 0; i < flat.size(); i++) { |
| 90 | const double double_val = static_cast<double>(flat(i)); |
| 91 | if (Eigen::numext::isnan(double_val)) { |
| 92 | c->SetStatus( |
| 93 | errors::InvalidArgument("Nan in summary histogram for: ", name())); |
| 94 | break; |
| 95 | } else if (Eigen::numext::isinf(double_val)) { |
| 96 | c->SetStatus(errors::InvalidArgument( |
| 97 | "Infinity in summary histogram for: ", name())); |
| 98 | break; |
| 99 | } |
| 100 | histo.Add(double_val); |
| 101 | } |
| 102 | |
| 103 | Summary s; |
| 104 | Summary::Value* v = s.add_value(); |
| 105 | v->set_tag(string(tags.scalar<tstring>()())); // NOLINT |
| 106 | histo.EncodeToProto(v->mutable_histo(), false /* Drop zero buckets */); |
| 107 | |
| 108 | Tensor* summary_tensor = nullptr; |
| 109 | OP_REQUIRES_OK(c, c->allocate_output(0, TensorShape({}), &summary_tensor)); |
| 110 | CHECK(SerializeToTString(s, &summary_tensor->scalar<tstring>()())); |
| 111 | } |
| 112 | }; |
| 113 | |
| 114 | #define REGISTER(T) \ |
nothing calls this directly
no test coverage detected