| 69 | explicit ShapeNOp(OpKernelConstruction* ctx) : OpKernel(ctx) {} |
| 70 | |
| 71 | void Compute(OpKernelContext* ctx) override { |
| 72 | for (int i = 0; i < ctx->num_inputs(); ++i) { |
| 73 | TensorShape shape; |
| 74 | OP_REQUIRES_OK(ctx, shape_op_helpers::GetShape(ctx, i, &shape)); |
| 75 | const int dims = shape.dims(); |
| 76 | Tensor* out = nullptr; |
| 77 | OP_REQUIRES_OK(ctx, ctx->allocate_output(i, {dims}, &out)); |
| 78 | auto vec = out->vec<OutType>(); |
| 79 | |
| 80 | for (int j = 0; j < dims; ++j) { |
| 81 | int64 dim_size = shape.dim_size(j); |
| 82 | if (out->dtype() == DT_INT32) { |
| 83 | OP_REQUIRES( |
| 84 | ctx, FastBoundsCheck(dim_size, std::numeric_limits<int32>::max()), |
| 85 | errors::InvalidArgument("ShapeN output type is 32-bit but shape ", |
| 86 | i, " dim ", j, " is ", dim_size)); |
| 87 | } |
| 88 | vec(j) = static_cast<OutType>(dim_size); |
| 89 | } |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | bool IsExpensive() override { return false; } |
| 94 | }; |
nothing calls this directly
no test coverage detected