| 115 | explicit SizeOp(OpKernelConstruction* ctx) : OpKernel(ctx) {} |
| 116 | |
| 117 | void Compute(OpKernelContext* ctx) override { |
| 118 | TensorShape shape; |
| 119 | OP_REQUIRES_OK(ctx, shape_op_helpers::GetShape(ctx, 0, &shape)); |
| 120 | const int64 size = shape.num_elements(); |
| 121 | Tensor* out = nullptr; |
| 122 | OP_REQUIRES_OK(ctx, ctx->allocate_output(0, TensorShape({}), &out)); |
| 123 | if (out->dtype() == DT_INT32) { |
| 124 | OP_REQUIRES( |
| 125 | ctx, FastBoundsCheck(size, std::numeric_limits<int32>::max()), |
| 126 | errors::InvalidArgument("Number of elements was larger than " |
| 127 | "representable by 32-bit output type")); |
| 128 | } |
| 129 | out->scalar<OutType>()() = static_cast<OutType>(size); |
| 130 | } |
| 131 | |
| 132 | bool IsExpensive() override { return false; } |
| 133 | }; |
nothing calls this directly
no test coverage detected