| 36 | } |
| 37 | |
| 38 | void Compile(XlaOpKernelContext* ctx) override { |
| 39 | OP_REQUIRES( |
| 40 | ctx, ctx->num_inputs() == 2, |
| 41 | errors::Unimplemented("Broadcast for n-ary operations (n > 2)")); |
| 42 | absl::InlinedVector<BCast::Vec, 2> shapes; |
| 43 | for (int i = 0; i < ctx->num_inputs(); ++i) { |
| 44 | const TensorShape in_shape = ctx->InputShape(i); |
| 45 | OP_REQUIRES(ctx, TensorShapeUtils::IsVector(in_shape), |
| 46 | errors::InvalidArgument("In[", i, "] must be a vector.", |
| 47 | in_shape.DebugString())); |
| 48 | std::vector<int64> shape; |
| 49 | OP_REQUIRES_OK(ctx, ctx->ConstantInputAsIntVector(i, &shape)); |
| 50 | shapes.push_back(BCast::Vec(shape.begin(), shape.end())); |
| 51 | } |
| 52 | BCast bcast(shapes[0], shapes[1]); |
| 53 | OP_REQUIRES(ctx, bcast.IsValid(), |
| 54 | errors::InvalidArgument( |
| 55 | "Incompatible shapes: [", absl::StrJoin(shapes[0], ","), |
| 56 | "] vs. [", absl::StrJoin(shapes[1], ","), "]")); |
| 57 | |
| 58 | const int64 len = bcast.output_shape().size(); |
| 59 | Tensor output(DT_INT32, TensorShape({len})); |
| 60 | for (int64 i = 0; i < len; ++i) { |
| 61 | output.flat<int32>()(i) = static_cast<int32>(bcast.output_shape()[i]); |
| 62 | } |
| 63 | ctx->SetConstantOutput(0, output); |
| 64 | } |
| 65 | |
| 66 | private: |
| 67 | TF_DISALLOW_COPY_AND_ASSIGN(BCastArgsOp); |
nothing calls this directly
no test coverage detected