| 303 | : OpKernel(context) {} |
| 304 | |
| 305 | void Compute(OpKernelContext* context) override { |
| 306 | const Tensor& input = context->input(0); |
| 307 | OP_REQUIRES(context, TensorShapeUtils::IsVector(input.shape()), |
| 308 | errors::InvalidArgument("Input must be a vector, got shape ", |
| 309 | input.shape().DebugString())); |
| 310 | Tensor* out; |
| 311 | const int64 num_elements = input.NumElements(); |
| 312 | OP_REQUIRES_OK(context, context->allocate_output( |
| 313 | 0, TensorShape({num_elements, 2}), &out)); |
| 314 | |
| 315 | const auto in_values = input.flat<tstring>(); |
| 316 | auto out_values = out->matrix<int64>(); |
| 317 | |
| 318 | for (int64 i = 0; i < num_elements; ++i) { |
| 319 | const Fprint128 fprint = Fingerprint128(in_values(i)); |
| 320 | // Never return 0 or 1 as the first value of the hash to allow these to |
| 321 | // safely be used as sentinel values (e.g. dense hash table empty key). |
| 322 | out_values(i, 0) = TF_PREDICT_TRUE(fprint.low64 >= 2) |
| 323 | ? fprint.low64 |
| 324 | : fprint.low64 + ~static_cast<uint64>(1); |
| 325 | out_values(i, 1) = fprint.high64; |
| 326 | } |
| 327 | } |
| 328 | }; |
| 329 | REGISTER_KERNEL_BUILDER(Name("SdcaFprint").Device(DEVICE_CPU), SdcaFprint); |
| 330 |
nothing calls this directly
no test coverage detected