MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / Compile

Method Compile

tensorflow/compiler/tf2xla/kernels/bcast_ops.cc:38–64  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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);

Callers

nothing calls this directly

Calls 14

UnimplementedFunction · 0.85
InvalidArgumentFunction · 0.85
InputShapeMethod · 0.80
SetConstantOutputMethod · 0.80
TensorShapeClass · 0.50
num_inputsMethod · 0.45
DebugStringMethod · 0.45
push_backMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
IsValidMethod · 0.45

Tested by

no test coverage detected