| 42 | explicit ShapeOp(OpKernelConstruction* ctx) : OpKernel(ctx) {} |
| 43 | |
| 44 | void Compute(OpKernelContext* ctx) override { |
| 45 | TensorShape shape; |
| 46 | OP_REQUIRES_OK(ctx, shape_op_helpers::GetShape(ctx, 0, &shape)); |
| 47 | const int rank = shape.dims(); |
| 48 | Tensor* out = nullptr; |
| 49 | OP_REQUIRES_OK(ctx, ctx->allocate_output(0, TensorShape({rank}), &out)); |
| 50 | auto vec = out->vec<OutType>(); |
| 51 | for (int i = 0; i < rank; ++i) { |
| 52 | int64 dim_size = shape.dim_size(i); |
| 53 | if (out->dtype() == DT_INT32) { |
| 54 | OP_REQUIRES( |
| 55 | ctx, FastBoundsCheck(dim_size, std::numeric_limits<int32>::max()), |
| 56 | errors::InvalidArgument("Shape output type is 32-bit ", " but dim ", |
| 57 | i, " is ", dim_size)); |
| 58 | } |
| 59 | vec(i) = static_cast<OutType>(dim_size); |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | bool IsExpensive() override { return false; } |
| 64 | }; |
nothing calls this directly
no test coverage detected