| 30 | } |
| 31 | |
| 32 | void Compute(OpKernelContext* context) override { |
| 33 | T before_increment; |
| 34 | { |
| 35 | mutex_lock l(*context->input_ref_mutex(0)); |
| 36 | Tensor tensor = context->mutable_input(0, true); |
| 37 | OP_REQUIRES(context, TensorShapeUtils::IsScalar(tensor.shape()), |
| 38 | errors::InvalidArgument("input is not a scalar: ", |
| 39 | tensor.shape().DebugString())); |
| 40 | T* ptr = &tensor.scalar<T>()(); |
| 41 | before_increment = *ptr; |
| 42 | if (*ptr >= limit_) { |
| 43 | context->SetStatus(errors::OutOfRange("Reached limit of ", limit_)); |
| 44 | return; |
| 45 | } |
| 46 | ++*ptr; |
| 47 | } |
| 48 | // Output if no error. |
| 49 | Tensor* out_tensor; |
| 50 | OP_REQUIRES_OK(context, context->allocate_output("output", TensorShape({}), |
| 51 | &out_tensor)); |
| 52 | out_tensor->scalar<T>()() = before_increment; |
| 53 | } |
| 54 | |
| 55 | private: |
| 56 | T limit_; |
nothing calls this directly
no test coverage detected